diff options
Diffstat (limited to 'meta/classes/package.bbclass')
-rw-r--r-- | meta/classes/package.bbclass | 106 |
1 files changed, 45 insertions, 61 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index a38b4ed944..6dbb7413e2 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -135,59 +135,51 @@ python () { | |||
135 | bb.data.setVarFlag('do_package', 'deptask', 'do_package', d) | 135 | bb.data.setVarFlag('do_package', 'deptask', 'do_package', d) |
136 | } | 136 | } |
137 | 137 | ||
138 | # file(1) output to match to consider a file an unstripped executable | ||
139 | FILE_UNSTRIPPED_MATCH ?= "not stripped" | ||
140 | #FIXME: this should be "" when any errors are gone! | ||
141 | IGNORE_STRIP_ERRORS ?= "1" | ||
142 | |||
143 | runstrip() { | ||
144 | # Function to strip a single file, called from RUNSTRIP in populate_packages below | ||
145 | # A working 'file' (one which works on the target architecture) | ||
146 | # is necessary for this stuff to work, hence the addition to do_package[depends] | ||
147 | |||
148 | local ro st | ||
149 | |||
150 | st=0 | ||
151 | if { file "$1" || { | ||
152 | oewarn "file $1: failed (forced strip)" >&2 | ||
153 | echo '${FILE_UNSTRIPPED_MATCH}' | ||
154 | } | ||
155 | } | grep -q '${FILE_UNSTRIPPED_MATCH}' | ||
156 | then | ||
157 | oenote "${STRIP} $1" | ||
158 | ro= | ||
159 | test -w "$1" || { | ||
160 | ro=1 | ||
161 | chmod +w "$1" | ||
162 | } | ||
163 | mkdir -p $(dirname "$1")/.debug | ||
164 | debugfile="$(dirname "$1")/.debug/$(basename "$1")" | ||
165 | '${OBJCOPY}' --only-keep-debug "$1" "$debugfile" | ||
166 | '${STRIP}' "$1" | ||
167 | st=$? | ||
168 | '${OBJCOPY}' --add-gnu-debuglink="$debugfile" "$1" | ||
169 | test -n "$ro" && chmod -w "$1" | ||
170 | if test $st -ne 0 | ||
171 | then | ||
172 | oewarn "runstrip: ${STRIP} $1: strip failed" >&2 | ||
173 | if [ x${IGNORE_STRIP_ERRORS} = x1 ] | ||
174 | then | ||
175 | #FIXME: remove this, it's for error detection | ||
176 | if file "$1" 2>/dev/null >&2 | ||
177 | then | ||
178 | (oefatal "${STRIP} $1: command failed" >/dev/tty) | ||
179 | else | ||
180 | (oefatal "file $1: command failed" >/dev/tty) | ||
181 | fi | ||
182 | st=0 | ||
183 | fi | ||
184 | fi | ||
185 | else | ||
186 | oenote "runstrip: skip $1" | ||
187 | fi | ||
188 | return $st | ||
189 | } | ||
190 | 138 | ||
139 | def runstrip(file, d): | ||
140 | # Function to strip a single file, called from populate_packages below | ||
141 | # A working 'file' (one which works on the target architecture) | ||
142 | # is necessary for this stuff to work, hence the addition to do_package[depends] | ||
143 | |||
144 | import bb, os, commands | ||
145 | |||
146 | pathprefix = "export PATH=%s; " % bb.data.getVar('PATH', d, 1) | ||
147 | |||
148 | ret, result = commands.getstatusoutput("%sfile '%s'" % (pathprefix, file)) | ||
149 | |||
150 | if ret: | ||
151 | bb.error("runstrip: 'file %s' failed (forced strip)" % file) | ||
152 | |||
153 | if "not stripped" not in result: | ||
154 | bb.debug(1, "runstrip: skip %s" % file) | ||
155 | return 0 | ||
156 | |||
157 | strip = bb.data.getVar("STRIP", d, 1) | ||
158 | objcopy = bb.data.getVar("OBJCOPY", d, 1) | ||
159 | |||
160 | bb.debug(1, "runstrip: %s %s" % (strip, file)) | ||
161 | |||
162 | newmode = None | ||
163 | if not os.access(file, os.W_OK): | ||
164 | origmode = os.stat(file)[os.stat.ST_MODE] | ||
165 | newmode = origmode | os.stat.S_IWRITE | ||
166 | os.chmod(file, newmode) | ||
167 | |||
168 | bb.mkdirhier(os.path.join(os.path.dirname(file), ".debug")) | ||
169 | |||
170 | debugfile=os.path.join(os.path.dirname(file), ".debug", os.path.basename(file)) | ||
171 | |||
172 | os.system("%s'%s' --only-keep-debug '%s' '%s'" % (pathprefix, objcopy, file, debugfile)) | ||
173 | ret = os.system("%s'%s' '%s'" % (pathprefix, strip, file)) | ||
174 | os.system("%s'%s' --add-gnu-debuglink='%s' '%s'" % (pathprefix, objcopy, debugfile, file)) | ||
175 | |||
176 | if newmode: | ||
177 | os.chmod(file, origmode) | ||
178 | |||
179 | if ret: | ||
180 | bb.error("runstrip: %s %s: strip failed" % (strip, file)) | ||
181 | |||
182 | return 1 | ||
191 | 183 | ||
192 | # | 184 | # |
193 | # Package data handling routines | 185 | # Package data handling routines |
@@ -375,19 +367,11 @@ python populate_packages () { | |||
375 | package_list.append(pkg) | 367 | package_list.append(pkg) |
376 | 368 | ||
377 | if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'): | 369 | if (bb.data.getVar('INHIBIT_PACKAGE_STRIP', d, 1) != '1'): |
378 | stripfunc = "" | ||
379 | for root, dirs, files in os.walk(dvar): | 370 | for root, dirs, files in os.walk(dvar): |
380 | for f in files: | 371 | for f in files: |
381 | file = os.path.join(root, f) | 372 | file = os.path.join(root, f) |
382 | if not os.path.islink(file) and not os.path.isdir(file) and isexec(file): | 373 | if not os.path.islink(file) and not os.path.isdir(file) and isexec(file): |
383 | stripfunc += "\trunstrip %s || st=1\n" % (file) | 374 | runstrip(file, d) |
384 | if not stripfunc == "": | ||
385 | from bb import build | ||
386 | localdata = bb.data.createCopy(d) | ||
387 | # strip | ||
388 | bb.data.setVar('RUNSTRIP', '\tlocal st\n\tst=0\n%s\treturn $st' % stripfunc, localdata) | ||
389 | bb.data.setVarFlag('RUNSTRIP', 'func', 1, localdata) | ||
390 | bb.build.exec_func('RUNSTRIP', localdata) | ||
391 | 375 | ||
392 | for pkg in package_list: | 376 | for pkg in package_list: |
393 | localdata = bb.data.createCopy(d) | 377 | localdata = bb.data.createCopy(d) |