devtool deploy-target --strip option
v5 cover devtool deploy-target --strip option
New devtool deploy-target option --strip which enables deploying stripped binaries, saving some space on target.
Updates in v5:
- Updated according to feedback from Richard Purdie
- Separate lint issue fixes
- Verified devtool-deploy-target with poky-master
[YOCTO #11227]
Tobias Hagelborn (3):
package.py: Fix some lint errors
package.py: strip_execs: Support for .ko modules
devtool: deploy-target: Support stripped libs and execs
meta/lib/oe/package.py | 42 +++++++++++++++++++++++------------------- scripts/lib/devtool/deploy.py | 33 +++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 23 deletions(-)
Signature · 1 line
2.1.4
PATCH v5 1/3 package.py: Fix some lint errors
- rename type to exec_type not to shadow type
- rename isELF is_elf
--- meta/lib/oe/package.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
meta/lib/oe/package.py +9 -10
@@ -67,24 +67,23 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= # 4 - executable # 8 - shared library # 16 - kernel module - def isELF(path): - type = 0 + def is_elf(path): + exec_type = 0 ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) if ret: bb.error("split_and_strip_files: 'file %s' failed" % path) - return type + return exec_type - # Not stripped if "ELF" in result: - type |= 1 + exec_type |= 1 if "not stripped" not in result: - type |= 2 + exec_type |= 2 if "executable" in result: - type |= 4 + exec_type |= 4 if "shared" in result: - type |= 8 - return type + exec_type |= 8 + return exec_type elffiles = {}
@@ -119,7 +118,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= # It's a file (or hardlink), not a link # ...but is it ELF, and is it already stripped? - elf_file = isELF(file) + elf_file = is_elf(file) if elf_file & 1: if elf_file & 2: if qa_already_stripped:
Signature · 1 line
2.1.4
PATCH v5 2/3 package.py: strip_execs: Support for .ko modules
In reply to Tobias Hagelborn* Support stripping of .ko modules verifying file extension and check of content "vermagic="
--- meta/lib/oe/package.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
meta/lib/oe/package.py +14 -9
@@ -56,9 +56,12 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= :param qa_already_stripped: Set to True if already-stripped' in ${INSANE_SKIP} This is for proper logging and messages only. """ - import stat, errno, oe.path, oe.utils + import stat, errno, oe.path, oe.utils, mmap - os.chdir(dstdir) + # Detect .ko module by searching for "vermagic=" string + def is_kernel_module(path): + with open(path) as f: + return mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ).find(b"vermagic=") >= 0 # Return type (bits): # 0 - not elf
@@ -69,7 +72,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= # 16 - kernel module def is_elf(path): exec_type = 0 - ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\"")) + ret, result = oe.utils.getstatusoutput( + "file \"%s\"" % path.replace("\"", "\\\"")) if ret: bb.error("split_and_strip_files: 'file %s' failed" % path)
@@ -83,14 +87,15 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= exec_type |= 4 if "shared" in result: exec_type |= 8 + if "relocatable" in result and is_kernel_module(path): + exec_type |= 16 return exec_type - elffiles = {} inodes = {} libdir = os.path.abspath(dstdir + os.sep + libdir) base_libdir = os.path.abspath(dstdir + os.sep + base_libdir) - + exec_mask = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH # # First lets figure out all of the files we may have to process #
@@ -110,8 +115,9 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= if not s: continue # Check its an excutable - if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \ - or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f): + if s[stat.ST_MODE] & exec_mask \ + or ((file.startswith(libdir) or file.startswith(base_libdir)) and ".so" in f) \ + or file.endswith('.ko'): # If it's a symlink, and points to an ELF file, we capture the readlink target if os.path.islink(file): continue
@@ -131,8 +137,8 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= os.unlink(file) os.link(inodes[s.st_ino], file) else: + # break hardlinks so that we do not strip the original. inodes[s.st_ino] = file - # break hardlink bb.utils.copyfile(file, file) elffiles[file] = elf_file
@@ -142,7 +148,6 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped= sfiles = [] for file in elffiles: elf_file = int(elffiles[file]) - #bb.note("Strip %s" % file) sfiles.append((file, elf_file, strip_cmd)) oe.utils.multiprocess_exec(sfiles, runstrip)
Signature · 1 line
2.1.4
PATCH v5 3/3 devtool: deploy-target: Support stripped libs and execs
In reply to Tobias HagelbornNew devtool deploy-target option --strip which enables deploying stripped binaries, saving some space on target.
* Copies the files of ${D} into a new directory and strips them in place
* Used oe.package.strip_execs for stripping directory
* Added devtool.conf option "strip" for changing default behavior
Config example:
[Deploy]
strip = true
[YOCTO #11227]
--- scripts/lib/devtool/deploy.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
scripts/lib/devtool/deploy.py +29 -4
@@ -16,12 +16,16 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """Devtool plugin containing the deploy subcommands""" +import logging import os +import shutil import subprocess -import logging import tempfile -import shutil + +import bb.utils import argparse_oe +import oe.types + from devtool import exec_fakeroot, setup_tinfoil, check_workspace_recipe, DevtoolError logger = logging.getLogger('devtool')
@@ -140,11 +144,12 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals return '\n'.join(lines) + def deploy(args, config, basepath, workspace): """Entry point for the devtool 'deploy' subcommand""" - import re import math import oe.recipeutils + import oe.package check_workspace_recipe(workspace, args.recipename, checksrc=False)
@@ -170,6 +175,17 @@ def deploy(args, config, basepath, workspace): 'recipe? If so, the install step has not installed ' 'any files.' % args.recipename) + if args.strip and not args.dry_run: + # Fakeroot copy to new destination + srcdir = recipe_outdir + recipe_outdir = os.path.join(rd.getVar('WORKDIR', True), 'deploy-target-stripped') + if os.path.isdir(recipe_outdir): + bb.utils.remove(recipe_outdir, True) + exec_fakeroot(rd, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True) + os.environ['PATH'] = ':'.join([os.environ['PATH'], rd.getVar('PATH', True) or '']) + oe.package.strip_execs(args.recipename, recipe_outdir, rd.getVar('STRIP', True), rd.getVar('libdir', True), + rd.getVar('base_libdir', True)) + filelist = [] ftotalsize = 0 for root, _, files in os.walk(recipe_outdir):
@@ -189,7 +205,6 @@ def deploy(args, config, basepath, workspace): print(' %s' % item) return 0 - extraoptions = '' if args.no_host_check: extraoptions += '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
@@ -301,6 +316,7 @@ def undeploy(args, config, basepath, workspace): def register_commands(subparsers, context): """Register devtool subcommands from the deploy plugin""" + parser_deploy = subparsers.add_parser('deploy-target', help='Deploy recipe output files to live target machine', description='Deploys a recipe\'s build output (i.e. the output of the do_install task) to a live target machine over ssh. By default, any existing files will be preserved instead of being overwritten and will be restored if you run devtool undeploy-target. Note: this only deploys the recipe itself and not any runtime dependencies, so it is assumed that those have been installed on the target beforehand.',
@@ -313,6 +329,15 @@ def register_commands(subparsers, context): parser_deploy.add_argument('-p', '--no-preserve', help='Do not preserve existing files', action='store_true') parser_deploy.add_argument('--no-check-space', help='Do not check for available space before deploying', action='store_true') parser_deploy.add_argument('-P', '--port', default='22', help='Port to use for connection to the target') + + strip_opts = parser_deploy.add_mutually_exclusive_group(required=False) + strip_opts.add_argument('-S', '--strip', + help='Strip executables prior to deploying (default: %(default)s). ' + 'The default value of this option can be controlled by setting the strip option in the [Deploy] section to True or False.', + default=oe.types.boolean(context.config.get('Deploy', 'strip', default='0')), + action='store_true') + strip_opts.add_argument('--no-strip', help='Do not strip executables prior to deploy', dest='strip', action='store_false') + parser_deploy.set_defaults(func=deploy) parser_undeploy = subparsers.add_parser('undeploy-target',
Signature · 1 line
2.1.4
✗ patchtest: failure for devtool deploy-target --strip option (rev2)
In reply to Tobias Hagelborn== Series Details ==
Series: devtool deploy-target --strip option (rev2)
Revision: 2
URL : https://patchwork.openembedded.org/series/8485/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Patch [v5,1/3] package.py: Fix some lint errors Issue Patch is missing Signed-off-by [test_signed_off_by_presence] Suggested fix Sign off the patch (either manually or with "git commit --amend -s")
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe