devtool: refactor deploy-target

Make the deploy function independent from d. This allows to call the
function also from Python code not running in bitbake.
This is needed to for the devtool ide plugin which will call the
do_install task and the code from devtool deploy-target independently
from a bitbake server. This allows a much quicker workflow.

(From OE-Core rev: c8697d1132cbd4b2a2502b4c48e7d91fc18de786)

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Adrian Freihofer
2024-01-22 14:58:25 +01:00
committed by Richard Purdie
parent 50618e59dd
commit c2813a4c69

View File

@@ -133,17 +133,38 @@ def _prepare_remote_script(deploy, verbose=False, dryrun=False, undeployall=Fals
return '\n'.join(lines) return '\n'.join(lines)
def deploy(args, config, basepath, workspace): def deploy(args, config, basepath, workspace):
"""Entry point for the devtool 'deploy' subcommand""" """Entry point for the devtool 'deploy' subcommand"""
import math
import oe.recipeutils
import oe.package
import oe.utils import oe.utils
check_workspace_recipe(workspace, args.recipename, checksrc=False) check_workspace_recipe(workspace, args.recipename, checksrc=False)
tinfoil = setup_tinfoil(basepath=basepath)
try:
try:
rd = tinfoil.parse_recipe(args.recipename)
except Exception as e:
raise DevtoolError('Exception parsing recipe %s: %s' %
(args.recipename, e))
srcdir = rd.getVar('D')
workdir = rd.getVar('WORKDIR')
path = rd.getVar('PATH')
strip_cmd = rd.getVar('STRIP')
libdir = rd.getVar('libdir')
base_libdir = rd.getVar('base_libdir')
max_process = oe.utils.get_bb_number_threads(rd)
fakerootcmd = rd.getVar('FAKEROOTCMD')
fakerootenv = rd.getVar('FAKEROOTENV')
finally:
tinfoil.shutdown()
return deploy_no_d(srcdir, workdir, path, strip_cmd, libdir, base_libdir, max_process, fakerootcmd, fakerootenv, args)
def deploy_no_d(srcdir, workdir, path, strip_cmd, libdir, base_libdir, max_process, fakerootcmd, fakerootenv, args):
import math
import oe.package
try: try:
host, destdir = args.target.split(':') host, destdir = args.target.split(':')
except ValueError: except ValueError:
@@ -153,32 +174,21 @@ def deploy(args, config, basepath, workspace):
if not destdir.endswith('/'): if not destdir.endswith('/'):
destdir += '/' destdir += '/'
tinfoil = setup_tinfoil(basepath=basepath) recipe_outdir = srcdir
try:
try:
rd = tinfoil.parse_recipe(args.recipename)
except Exception as e:
raise DevtoolError('Exception parsing recipe %s: %s' %
(args.recipename, e))
recipe_outdir = rd.getVar('D')
if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir):
raise DevtoolError('No files to deploy - have you built the %s ' raise DevtoolError('No files to deploy - have you built the %s '
'recipe? If so, the install step has not installed ' 'recipe? If so, the install step has not installed '
'any files.' % args.recipename) 'any files.' % args.recipename)
fakerootcmd = rd.getVar('FAKEROOTCMD')
fakerootenv = rd.getVar('FAKEROOTENV')
if args.strip and not args.dry_run: if args.strip and not args.dry_run:
# Fakeroot copy to new destination # Fakeroot copy to new destination
srcdir = recipe_outdir srcdir = recipe_outdir
recipe_outdir = os.path.join(rd.getVar('WORKDIR'), 'devtool-deploy-target-stripped') recipe_outdir = os.path.join(workdir, 'devtool-deploy-target-stripped')
if os.path.isdir(recipe_outdir): if os.path.isdir(recipe_outdir):
exec_fakeroot_no_d(fakerootcmd, fakerootenv, "rm -rf %s" % recipe_outdir, shell=True) exec_fakeroot_no_d(fakerootcmd, fakerootenv, "rm -rf %s" % recipe_outdir, shell=True)
exec_fakeroot_no_d(fakerootcmd, fakerootenv, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True) exec_fakeroot_no_d(fakerootcmd, fakerootenv, "cp -af %s %s" % (os.path.join(srcdir, '.'), recipe_outdir), shell=True)
os.environ['PATH'] = ':'.join([os.environ['PATH'], rd.getVar('PATH') or '']) os.environ['PATH'] = ':'.join([os.environ['PATH'], path or ''])
oe.package.strip_execs(args.recipename, recipe_outdir, rd.getVar('STRIP'), rd.getVar('libdir'), oe.package.strip_execs(args.recipename, recipe_outdir, strip_cmd, libdir, base_libdir, max_process)
rd.getVar('base_libdir'), oe.utils.get_bb_number_threads(rd), rd)
filelist = [] filelist = []
inodes = set({}) inodes = set({})
@@ -266,8 +276,6 @@ def deploy(args, config, basepath, workspace):
for filename in files: for filename in files:
filename = os.path.relpath(os.path.join(root, filename), recipe_outdir) filename = os.path.relpath(os.path.join(root, filename), recipe_outdir)
files_list.append(os.path.join(destdir, filename)) files_list.append(os.path.join(destdir, filename))
finally:
tinfoil.shutdown()
return 0 return 0