diff options
| author | Tobias Hagelborn <tobias.hagelborn@axis.com> | 2017-06-20 09:42:42 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-28 20:55:07 +0100 |
| commit | 0e23081d701f57ad1f294b0e0e35c514415a339a (patch) | |
| tree | 136652e2cc1c482c80ca5129ac077b0c0f706f11 | |
| parent | 2065fb7f639b7349d24d5b81693993ee2a53a956 (diff) | |
| download | poky-0e23081d701f57ad1f294b0e0e35c514415a339a.tar.gz | |
package.py: Add function strip_execs
Strip all executables in a directory.
Utility function placed in oe-package together with run_strip.
strip_execs is based on strip_sysroot from staging.bbclass
Moving out datastore references in favor of function parameters.
(From OE-Core rev: a350bfc41e8a19dfdc5b16e5fb8f2b198e7c55c1)
Signed-off-by: Tobias Hagelborn <tobiasha@axis.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oe/package.py | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py index 52c5f16cf8..43748b277c 100644 --- a/meta/lib/oe/package.py +++ b/meta/lib/oe/package.py | |||
| @@ -45,6 +45,111 @@ def runstrip(arg): | |||
| 45 | return | 45 | return |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=False): | ||
| 49 | """ | ||
| 50 | Strip executable code (like executables, shared libraries) _in_place_ | ||
| 51 | - Based on sysroot_strip in staging.bbclass | ||
| 52 | :param dstdir: directory in which to strip files | ||
| 53 | :param strip_cmd: Strip command (usually ${STRIP}) | ||
| 54 | :param libdir: ${libdir} - strip .so files in this directory | ||
| 55 | :param base_libdir: ${base_libdir} - strip .so files in this directory | ||
| 56 | :param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP} | ||
| 57 | This is for proper logging and messages only. | ||
| 58 | """ | ||
| 59 | import stat, errno, oe.path, oe.utils | ||
| 60 | |||
| 61 | os.chdir(dstdir) | ||
| 62 | |||
| 63 | # Return type (bits): | ||
| 64 | # 0 - not elf | ||
| 65 | # 1 - ELF | ||
| 66 | # 2 - stripped | ||
| 67 | # 4 - executable | ||
| 68 | # 8 - shared library | ||
| 69 | # 16 - kernel module | ||
| 70 | def isELF(path): | ||
| 71 | type = 0 | ||
| 72 | ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) | ||
| 73 | |||
| 74 | if ret: | ||
| 75 | bb.error("split_and_strip_files: 'file %s' failed" % path) | ||
| 76 | return type | ||
| 77 | |||
| 78 | # Not stripped | ||
| 79 | if "ELF" in result: | ||
| 80 | type |= 1 | ||
| 81 | if "not stripped" not in result: | ||
| 82 | type |= 2 | ||
| 83 | if "executable" in result: | ||
| 84 | type |= 4 | ||
| 85 | if "shared" in result: | ||
| 86 | type |= 8 | ||
| 87 | return type | ||
| 88 | |||
| 89 | |||
| 90 | elffiles = {} | ||
| 91 | inodes = {} | ||
| 92 | libdir = os.path.abspath(dstdir + os.sep + libdir) | ||
| 93 | base_libdir = os.path.abspath(dstdir + os.sep + base_libdir) | ||
| 94 | |||
| 95 | # | ||
| 96 | # First lets figure out all of the files we may have to process | ||
| 97 | # | ||
| 98 | for root, dirs, files in os.walk(dstdir): | ||
| 99 | for f in files: | ||
| 100 | file = os.path.join(root, f) | ||
| 101 | |||
| 102 | try: | ||
| 103 | ltarget = oe.path.realpath(file, dstdir, False) | ||
| 104 | s = os.lstat(ltarget) | ||
| 105 | except OSError as e: | ||
| 106 | (err, strerror) = e.args | ||
| 107 | if err != errno.ENOENT: | ||
| 108 | raise | ||
| 109 | # Skip broken symlinks | ||
| 110 | continue | ||
| 111 | if not s: | ||
| 112 | continue | ||
| 113 | # Check its an excutable | ||
| 114 | if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ | ||
| 115 | or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f): | ||
| 116 | # If it's a symlink, and points to an ELF file, we capture the readlink target | ||
| 117 | if os.path.islink(file): | ||
| 118 | continue | ||
| 119 | |||
| 120 | # It's a file (or hardlink), not a link | ||
| 121 | # ...but is it ELF, and is it already stripped? | ||
| 122 | elf_file = isELF(file) | ||
| 123 | if elf_file & 1: | ||
| 124 | if elf_file & 2: | ||
| 125 | if qa_already_stripped: | ||
| 126 | bb.note("Skipping file %s from %s for already-stripped QA test" % (file[len(dstdir):], pn)) | ||
| 127 | else: | ||
| 128 | bb.warn("File '%s' from %s was already stripped, this will prevent future debugging!" % (file[len(dstdir):], pn)) | ||
| 129 | continue | ||
| 130 | |||
| 131 | if s.st_ino in inodes: | ||
| 132 | os.unlink(file) | ||
| 133 | os.link(inodes[s.st_ino], file) | ||
| 134 | else: | ||
| 135 | inodes[s.st_ino] = file | ||
| 136 | # break hardlink | ||
| 137 | bb.utils.copyfile(file, file) | ||
| 138 | elffiles[file] = elf_file | ||
| 139 | |||
| 140 | # | ||
| 141 | # Now strip them (in parallel) | ||
| 142 | # | ||
| 143 | sfiles = [] | ||
| 144 | for file in elffiles: | ||
| 145 | elf_file = int(elffiles[file]) | ||
| 146 | #bb.note("Strip %s" % file) | ||
| 147 | sfiles.append((file, elf_file, strip_cmd)) | ||
| 148 | |||
| 149 | oe.utils.multiprocess_exec(sfiles, runstrip) | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 48 | def file_translate(file): | 153 | def file_translate(file): |
| 49 | ft = file.replace("@", "@at@") | 154 | ft = file.replace("@", "@at@") |
| 50 | ft = ft.replace(" ", "@space@") | 155 | ft = ft.replace(" ", "@space@") |
