diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2012-05-29 22:53:08 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-05-30 12:04:45 +0100 |
commit | 5996b2b58e36864edc077326a942795ca12f48da (patch) | |
tree | 5f67615a25685f4b0d4a8150f51932a5b478ccfa | |
parent | d760fb97f52c705944a259be267e0ea8516074e3 (diff) | |
download | poky-5996b2b58e36864edc077326a942795ca12f48da.tar.gz |
meta: replace os.popen with subprocess.Popen
Replace os.popen with subprocess.Popen since the older function would
fail (more or less) silently if the executed program cannot be found
There are both bb.process.run() and bb.process.Popen() which wraps the
subprocess module, use it for simplifying the code.
Note: We don't need the "2>/dev/null" or "2>&1" since bb.process.run()
can handle it, it will raise exception when error occurs, we should
handle the exception ourselves if we want to ignore the error.
More info:
http://docs.python.org/library/subprocess.html#subprocess-replacements
[YOCTO #2454]
(From OE-Core rev: e83d8e58a6b107eea87df0ec233a1bc932b2c6ea)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/debian.bbclass | 12 | ||||
-rw-r--r-- | meta/classes/distrodata.bbclass | 12 | ||||
-rw-r--r-- | meta/classes/icecc.bbclass | 6 | ||||
-rw-r--r-- | meta/classes/insane.bbclass | 31 | ||||
-rw-r--r-- | meta/classes/kernel.bbclass | 2 | ||||
-rw-r--r-- | meta/classes/metadata_scm.bbclass | 12 | ||||
-rw-r--r-- | meta/classes/package.bbclass | 16 |
7 files changed, 53 insertions, 38 deletions
diff --git a/meta/classes/debian.bbclass b/meta/classes/debian.bbclass index 3637e2ebe7..963d11c129 100644 --- a/meta/classes/debian.bbclass +++ b/meta/classes/debian.bbclass | |||
@@ -60,10 +60,14 @@ python debian_package_name_hook () { | |||
60 | for f in files: | 60 | for f in files: |
61 | if so_re.match(f): | 61 | if so_re.match(f): |
62 | fp = os.path.join(root, f) | 62 | fp = os.path.join(root, f) |
63 | cmd = (d.getVar('BUILD_PREFIX', True) or "") + "objdump -p " + fp + " 2>/dev/null" | 63 | cmd = (d.getVar('BUILD_PREFIX', True) or "") + "objdump -p " + fp |
64 | fd = os.popen(cmd) | 64 | try: |
65 | lines = fd.readlines() | 65 | lines = "" |
66 | fd.close() | 66 | lines = bb.process.run(cmd)[0] |
67 | # Some ".so" maybe ascii text, e.g: /usr/lib64/libpthread.so, | ||
68 | # ingore those errors. | ||
69 | except Exception: | ||
70 | sys.exc_clear() | ||
67 | for l in lines: | 71 | for l in lines: |
68 | m = re.match("\s+SONAME\s+([^\s]*)", l) | 72 | m = re.match("\s+SONAME\s+([^\s]*)", l) |
69 | if m and not m.group(1) in sonames: | 73 | if m and not m.group(1) in sonames: |
diff --git a/meta/classes/distrodata.bbclass b/meta/classes/distrodata.bbclass index df6d300666..7f9c83e7c7 100644 --- a/meta/classes/distrodata.bbclass +++ b/meta/classes/distrodata.bbclass | |||
@@ -564,10 +564,10 @@ python do_checkpkg() { | |||
564 | gitproto = parm['protocol'] | 564 | gitproto = parm['protocol'] |
565 | else: | 565 | else: |
566 | gitproto = "git" | 566 | gitproto = "git" |
567 | gitcmd = "git ls-remote %s://%s%s%s *tag* 2>&1" % (gitproto, gituser, host, path) | 567 | gitcmd = "git ls-remote %s://%s%s%s *tag*" % (gitproto, gituser, host, path) |
568 | gitcmd2 = "git ls-remote %s://%s%s%s HEAD 2>&1" % (gitproto, gituser, host, path) | 568 | gitcmd2 = "git ls-remote %s://%s%s%s HEAD" % (gitproto, gituser, host, path) |
569 | tmp = os.popen(gitcmd).read() | 569 | tmp = bb.process.run(gitcmd)[0] |
570 | tmp2 = os.popen(gitcmd2).read() | 570 | tmp2 = bb.process.run(gitcmd2)[0] |
571 | #This is for those repo have tag like: refs/tags/1.2.2 | 571 | #This is for those repo have tag like: refs/tags/1.2.2 |
572 | if tmp: | 572 | if tmp: |
573 | tmpline = tmp.split("\n") | 573 | tmpline = tmp.split("\n") |
@@ -613,9 +613,9 @@ python do_checkpkg() { | |||
613 | if 'rev' in parm: | 613 | if 'rev' in parm: |
614 | pcurver = parm['rev'] | 614 | pcurver = parm['rev'] |
615 | 615 | ||
616 | svncmd = "svn info %s %s://%s%s/%s/ 2>&1" % (" ".join(options), svnproto, host, path, parm["module"]) | 616 | svncmd = "svn info %s %s://%s%s/%s/" % (" ".join(options), svnproto, host, path, parm["module"]) |
617 | print svncmd | 617 | print svncmd |
618 | svninfo = os.popen(svncmd).read() | 618 | svninfo = bb.process.run(svncmd)[0] |
619 | for line in svninfo.split("\n"): | 619 | for line in svninfo.split("\n"): |
620 | if re.search("^Last Changed Rev:", line): | 620 | if re.search("^Last Changed Rev:", line): |
621 | pupver = line.split(" ")[-1] | 621 | pupver = line.split(" ")[-1] |
diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass index ae74050f6b..64a182e523 100644 --- a/meta/classes/icecc.bbclass +++ b/meta/classes/icecc.bbclass | |||
@@ -54,7 +54,7 @@ def create_path(compilers, bb, d): | |||
54 | staging += "-kernel" | 54 | staging += "-kernel" |
55 | 55 | ||
56 | #check if the icecc path is set by the user | 56 | #check if the icecc path is set by the user |
57 | icecc = d.getVar('ICECC_PATH') or os.popen("which icecc").read()[:-1] | 57 | icecc = d.getVar('ICECC_PATH') or bb.process.run("which icecc")[0][:-1] |
58 | 58 | ||
59 | # Create the dir if necessary | 59 | # Create the dir if necessary |
60 | try: | 60 | try: |
@@ -151,9 +151,9 @@ def icc_path(bb,d): | |||
151 | 151 | ||
152 | def icc_get_tool(bb, d, tool): | 152 | def icc_get_tool(bb, d, tool): |
153 | if icc_is_native(bb, d): | 153 | if icc_is_native(bb, d): |
154 | return os.popen("which %s" % tool).read()[:-1] | 154 | return bb.process.run("which %s" % tool)[0][:-1] |
155 | elif icc_is_kernel(bb, d): | 155 | elif icc_is_kernel(bb, d): |
156 | return os.popen("which %s" % get_cross_kernel_cc(bb, d)).read()[:-1] | 156 | return bb.process.run("which %s" % get_cross_kernel_cc(bb, d))[0][:-1] |
157 | else: | 157 | else: |
158 | ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}') | 158 | ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}') |
159 | target_sys = d.expand('${TARGET_SYS}') | 159 | target_sys = d.expand('${TARGET_SYS}') |
diff --git a/meta/classes/insane.bbclass b/meta/classes/insane.bbclass index 4d139e813f..fa7b5f0bc2 100644 --- a/meta/classes/insane.bbclass +++ b/meta/classes/insane.bbclass | |||
@@ -154,14 +154,29 @@ def package_qa_check_rpath(file,name, d, elf, messages): | |||
154 | if not bad_dirs[0] in d.getVar('WORKDIR', True): | 154 | if not bad_dirs[0] in d.getVar('WORKDIR', True): |
155 | bb.fatal("This class assumed that WORKDIR is ${TMPDIR}/work... Not doing any check") | 155 | bb.fatal("This class assumed that WORKDIR is ${TMPDIR}/work... Not doing any check") |
156 | 156 | ||
157 | output = os.popen("%s -B -F%%r#F '%s'" % (scanelf,file)) | 157 | output, errors = bb.process.run("%s -B -F%%r#F '%s'" % (scanelf,file)) |
158 | txt = output.readline().split() | 158 | txt = output.split() |
159 | for line in txt: | 159 | for line in txt: |
160 | for dir in bad_dirs: | 160 | for dir in bad_dirs: |
161 | if dir in line: | 161 | if dir in line: |
162 | messages.append("package %s contains bad RPATH %s in file %s" % (name, line, file)) | 162 | messages.append("package %s contains bad RPATH %s in file %s" % (name, line, file)) |
163 | 163 | ||
164 | QAPATHTEST[useless-rpaths] = "package_qa_check_useless_rpaths" | 164 | QAPATHTEST[useless-rpaths] = "package_qa_check_useless_rpaths" |
165 | |||
166 | def package_qa_get_objdump(d, path): | ||
167 | """ | ||
168 | Get the result of objdump, ignore the errors since not all files can be objdumped | ||
169 | """ | ||
170 | env_path = d.getVar('PATH', True) | ||
171 | objdump = d.getVar('OBJDUMP', True) | ||
172 | |||
173 | try: | ||
174 | lines = "" | ||
175 | lines = bb.process.run("LC_ALL=C PATH=%s %s -p '%s'" % (env_path, objdump, path))[0] | ||
176 | except Exception: | ||
177 | sys.exc_clear() | ||
178 | return lines | ||
179 | |||
165 | def package_qa_check_useless_rpaths(file, name, d, elf, messages): | 180 | def package_qa_check_useless_rpaths(file, name, d, elf, messages): |
166 | """ | 181 | """ |
167 | Check for RPATHs that are useless but not dangerous | 182 | Check for RPATHs that are useless but not dangerous |
@@ -169,15 +184,12 @@ def package_qa_check_useless_rpaths(file, name, d, elf, messages): | |||
169 | if not elf: | 184 | if not elf: |
170 | return | 185 | return |
171 | 186 | ||
172 | objdump = d.getVar('OBJDUMP', True) | ||
173 | env_path = d.getVar('PATH', True) | ||
174 | |||
175 | libdir = d.getVar("libdir", True) | 187 | libdir = d.getVar("libdir", True) |
176 | base_libdir = d.getVar("base_libdir", True) | 188 | base_libdir = d.getVar("base_libdir", True) |
177 | 189 | ||
178 | import re | 190 | import re |
179 | rpath_re = re.compile("\s+RPATH\s+(.*)") | 191 | rpath_re = re.compile("\s+RPATH\s+(.*)") |
180 | for line in os.popen("LC_ALL=C PATH=%s %s -p '%s' 2> /dev/null" % (env_path, objdump, file), "r"): | 192 | for line in package_qa_get_objdump(d, file): |
181 | m = rpath_re.match(line) | 193 | m = rpath_re.match(line) |
182 | if m: | 194 | if m: |
183 | rpath = m.group(1) | 195 | rpath = m.group(1) |
@@ -369,7 +381,7 @@ def package_qa_check_desktop(path, name, d, elf, messages): | |||
369 | """ | 381 | """ |
370 | if path.endswith(".desktop"): | 382 | if path.endswith(".desktop"): |
371 | desktop_file_validate = os.path.join(d.getVar('STAGING_BINDIR_NATIVE',True),'desktop-file-validate') | 383 | desktop_file_validate = os.path.join(d.getVar('STAGING_BINDIR_NATIVE',True),'desktop-file-validate') |
372 | output = os.popen("%s %s" % (desktop_file_validate, path)) | 384 | output, errors = bb.process.run("%s %s" % (desktop_file_validate, path)) |
373 | # This only produces output on errors | 385 | # This only produces output on errors |
374 | for l in output: | 386 | for l in output: |
375 | messages.append("Desktop file issue: " + l.strip()) | 387 | messages.append("Desktop file issue: " + l.strip()) |
@@ -392,14 +404,11 @@ def package_qa_hash_style(path, name, d, elf, messages): | |||
392 | if not gnu_hash: | 404 | if not gnu_hash: |
393 | return | 405 | return |
394 | 406 | ||
395 | objdump = d.getVar('OBJDUMP', True) | ||
396 | env_path = d.getVar('PATH', True) | ||
397 | |||
398 | sane = False | 407 | sane = False |
399 | has_syms = False | 408 | has_syms = False |
400 | 409 | ||
401 | # If this binary has symbols, we expect it to have GNU_HASH too. | 410 | # If this binary has symbols, we expect it to have GNU_HASH too. |
402 | for line in os.popen("LC_ALL=C PATH=%s %s -p '%s' 2> /dev/null" % (env_path, objdump, path), "r"): | 411 | for line in package_qa_get_objdump(d, path): |
403 | if "SYMTAB" in line: | 412 | if "SYMTAB" in line: |
404 | has_syms = True | 413 | has_syms = True |
405 | if "GNU_HASH" in line: | 414 | if "GNU_HASH" in line: |
diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass index 116e10b9de..d74361bf93 100644 --- a/meta/classes/kernel.bbclass +++ b/meta/classes/kernel.bbclass | |||
@@ -349,7 +349,7 @@ python populate_packages_prepend () { | |||
349 | path = d.getVar("PATH", True) | 349 | path = d.getVar("PATH", True) |
350 | 350 | ||
351 | cmd = "PATH=\"%s\" depmod -n -a -b %s -F %s/boot/System.map-%s %s" % (path, dvar, dvar, kernelver, kernelver_stripped) | 351 | cmd = "PATH=\"%s\" depmod -n -a -b %s -F %s/boot/System.map-%s %s" % (path, dvar, dvar, kernelver, kernelver_stripped) |
352 | f = os.popen(cmd, 'r') | 352 | f = bb.process.Popen(cmd, shell=True).stdout |
353 | 353 | ||
354 | deps = {} | 354 | deps = {} |
355 | pattern0 = "^(.*\.k?o):..*$" | 355 | pattern0 = "^(.*\.k?o):..*$" |
diff --git a/meta/classes/metadata_scm.bbclass b/meta/classes/metadata_scm.bbclass index 62650be675..5af593ae46 100644 --- a/meta/classes/metadata_scm.bbclass +++ b/meta/classes/metadata_scm.bbclass | |||
@@ -60,18 +60,16 @@ def base_get_metadata_svn_revision(path, d): | |||
60 | return revision | 60 | return revision |
61 | 61 | ||
62 | def base_get_metadata_git_branch(path, d): | 62 | def base_get_metadata_git_branch(path, d): |
63 | branch = os.popen('cd %s; git branch 2>&1 | grep "^* " | tr -d "* "' % path).read() | 63 | branch = bb.process.run('cd %s; git branch | grep "^* " | tr -d "* "' % path)[0] |
64 | 64 | ||
65 | if len(branch) != 0: | 65 | if len(branch) != 0: |
66 | return branch | 66 | return branch |
67 | return "<unknown>" | 67 | return "<unknown>" |
68 | 68 | ||
69 | def base_get_metadata_git_revision(path, d): | 69 | def base_get_metadata_git_revision(path, d): |
70 | f = os.popen("cd %s; git log -n 1 --pretty=oneline -- 2>&1" % path) | 70 | rev = bb.process.run("cd %s; git log -n 1 --pretty=oneline" % path)[0] |
71 | data = f.read() | 71 | if len(rev) != 0: |
72 | if f.close() is None: | 72 | rev = rev.split(" ")[0] |
73 | rev = data.split(" ")[0] | 73 | return rev |
74 | if len(rev) != 0: | ||
75 | return rev | ||
76 | return "<unknown>" | 74 | return "<unknown>" |
77 | 75 | ||
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 41139ef921..bc83bfbf4e 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -1061,7 +1061,7 @@ python emit_pkgdata() { | |||
1061 | 1061 | ||
1062 | def get_directory_size(dir): | 1062 | def get_directory_size(dir): |
1063 | if os.listdir(dir): | 1063 | if os.listdir(dir): |
1064 | size = int(os.popen('du -sk %s' % dir).readlines()[0].split('\t')[0]) | 1064 | size = int(bb.process.run('du -sk %s' % dir)[0].split('\t')[0]) |
1065 | else: | 1065 | else: |
1066 | size = 0 | 1066 | size = 0 |
1067 | return size | 1067 | return size |
@@ -1221,7 +1221,7 @@ python package_do_filedeps() { | |||
1221 | rpfiles.append(os.path.join(root, file)) | 1221 | rpfiles.append(os.path.join(root, file)) |
1222 | 1222 | ||
1223 | for files in chunks(rpfiles, 100): | 1223 | for files in chunks(rpfiles, 100): |
1224 | dep_pipe = os.popen(rpmdeps + " " + " ".join(files)) | 1224 | dep_pipe = bb.process.Popen(rpmdeps + " " + " ".join(files), shell=True).stdout |
1225 | 1225 | ||
1226 | process_deps(dep_pipe, pkg, provides_files, requires_files) | 1226 | process_deps(dep_pipe, pkg, provides_files, requires_files) |
1227 | 1227 | ||
@@ -1263,11 +1263,15 @@ python package_do_shlibs() { | |||
1263 | 1263 | ||
1264 | def linux_so(root, path, file): | 1264 | def linux_so(root, path, file): |
1265 | needs_ldconfig = False | 1265 | needs_ldconfig = False |
1266 | cmd = d.getVar('OBJDUMP', True) + " -p " + pipes.quote(os.path.join(root, file)) + " 2>/dev/null" | 1266 | cmd = d.getVar('OBJDUMP', True) + " -p " + pipes.quote(os.path.join(root, file)) |
1267 | cmd = "PATH=\"%s\" %s" % (d.getVar('PATH', True), cmd) | 1267 | cmd = "PATH=\"%s\" %s" % (d.getVar('PATH', True), cmd) |
1268 | fd = os.popen(cmd) | 1268 | try: |
1269 | lines = fd.readlines() | 1269 | lines = "" |
1270 | fd.close() | 1270 | lines = bb.process.run(cmd)[0] |
1271 | # Some ".so" maybe ascii text, e.g: /usr/lib64/libpthread.so, | ||
1272 | # ingore those errors. | ||
1273 | except Exception: | ||
1274 | sys.exc_clear() | ||
1271 | for l in lines: | 1275 | for l in lines: |
1272 | m = re.match("\s+NEEDED\s+([^\s]*)", l) | 1276 | m = re.match("\s+NEEDED\s+([^\s]*)", l) |
1273 | if m: | 1277 | if m: |