Skip to content

Commit

Permalink
devtool: ide make deploy-target quicker
Browse files Browse the repository at this point in the history
Instead of calling devtool deploy-target which starts a bitbake server
to get some variables the previous refactoring allows to generate a
simple script which does no longer depend on variables from bitbake.
This is much faster.
  • Loading branch information
afreof authored and deribaucourt committed Sep 27, 2023
1 parent a80eabf commit 199bb41
Showing 1 changed file with 55 additions and 60 deletions.
115 changes: 55 additions & 60 deletions scripts/lib/devtool/ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import stat
import sys
import logging
import json
import re
Expand Down Expand Up @@ -360,15 +361,19 @@ def __init__(self, name):
self.bbappend = None
# recipe variables from d.getVar
self.b = None
self.base_libdir = None
self.bpn = None
self.d = None
self.fakerootcmd = None
self.fakerootenv = None
self.libdir = None
self.max_process = None
self.package_arch = None
self.path = None
self.recipe_sysroot = None
self.recipe_sysroot_native = None
self.staging_incdir = None
self.strip_cmd = None
self.target_arch = None
self.workdir = None
# replicate bitbake build environment
Expand All @@ -387,11 +392,6 @@ def __init__(self, name):
self.meson_cross_file = None
# vscode
self.dot_code_dir = None
# TODO: remove calling devtool
self.bb_env_passthrough_additions = None
self.bbpath = None
self.bitbakepath = None
self.topdir = None

def initialize(self, config, workspace, tinfoil):
recipe_d = parse_recipe(
Expand All @@ -413,10 +413,14 @@ def initialize(self, config, workspace, tinfoil):
shutil.rmtree(self.temp_dir)

self.b = recipe_d.getVar('B')
self.base_libdir = recipe_d.getVar('base_libdir')
self.bpn = recipe_d.getVar('BPN')
self.d = recipe_d.getVar('D')
self.fakerootcmd = recipe_d.getVar('FAKEROOTCMD')
self.fakerootenv = recipe_d.getVar('FAKEROOTENV')
self.libdir = recipe_d.getVar('libdir'),
self.max_process = int(recipe_d.getVar(
"BB_NUMBER_THREADS") or os.cpu_count() or 1)
self.package_arch = recipe_d.getVar('PACKAGE_ARCH')
self.path = recipe_d.getVar('PATH')
self.recipe_sysroot = os.path.realpath(
Expand All @@ -425,15 +429,10 @@ def initialize(self, config, workspace, tinfoil):
recipe_d.getVar('RECIPE_SYSROOT_NATIVE'))
self.staging_incdir = os.path.realpath(
recipe_d.getVar('STAGING_INCDIR'))
self.strip_cmd = recipe_d.getVar('STRIP')
self.target_arch = recipe_d.getVar('TARGET_ARCH')
self.workdir = os.path.realpath(recipe_d.getVar('WORKDIR'))

self.bb_env_passthrough_additions = recipe_d.getVar(
'BB_ENV_PASSTHROUGH_ADDITIONS')
self.bbpath = recipe_d.getVar('BBPATH')
self.bitbakepath = recipe_d.getVar('BITBAKEPATH')
self.topdir = recipe_d.getVar('TOPDIR')

self.__init_exported_variables(recipe_d)

if bb.data.inherits_class('cmake', recipe_d):
Expand Down Expand Up @@ -971,6 +970,38 @@ def gen_fakeroot_install_script(self):
cmd_lines.append(install_cmd)
return self.write_script(cmd_lines, 'bb_run_do_install')

def gen_deploy_target_script(self, args):
"""Generate a quicker (works without tinfoil) variant of devtool target-deploy"""
cmd_lines = ['#!/usr/bin/env python3']
cmd_lines.append('import sys')
cmd_lines.append('devtool_sys_path = %s' % str(sys.path))
cmd_lines.append('devtool_sys_path.reverse()')
cmd_lines.append('for p in devtool_sys_path:')
cmd_lines.append(' if p not in sys.path:')
cmd_lines.append(' sys.path.insert(0, p)')
cmd_lines.append('from devtool.deploy import deploy_cached')
args_filter = ['debug', 'dry_run', 'key', 'no_check_space', 'no_host_check',
'no_preserve', 'port', 'recipename', 'show_status', 'ssh_exec', 'strip', 'target']
filtered_args_dict = {key: value for key, value in vars(
args).items() if key in args_filter}
cmd_lines.append('filtered_args_dict = %s' % str(filtered_args_dict))
cmd_lines.append('class Dict2Class(object):')
cmd_lines.append(' def __init__(self, my_dict):')
cmd_lines.append(' for key in my_dict:')
cmd_lines.append(' setattr(self, key, my_dict[key])')
cmd_lines.append('filtered_args = Dict2Class(filtered_args_dict)')
cmd_lines.append('deploy_cached("%s", "%s", "%s", "%s", "%s", "%s", %d, "%s", "%s", filtered_args)' %
(self.d, self.workdir, self.path, self.strip_cmd,
self.libdir, self.base_libdir, self.max_process,
self.fakerootcmd, self.fakerootenv))
return self.write_script(cmd_lines, 'deploy_target')

def gen_install_deploy_script(self, args):
cmd_lines = ['#!/bin/sh']
cmd_lines.append(self.gen_fakeroot_install_script())
cmd_lines.append(self.gen_deploy_target_script(args))
return self.write_script(cmd_lines, 'install_and_deploy')

def write_script(self, cmd_lines, script_name):
bb.utils.mkdirhier(self.temp_dir)
script_file = os.path.join(self.temp_dir, script_name)
Expand All @@ -981,61 +1012,15 @@ def write_script(self, cmd_lines, script_name):
return script_file

def vscode_tasks(self, args, gdb_cross):
run_do_install = self.gen_fakeroot_install_script()
pythonpath_new = os.path.realpath(
os.path.join(self.bitbakepath, '../lib'))
try:
pythonpath = os.environ['PYTONPATH'].split(':')
if pythonpath_new not in pythonpath:
pythonpath = pythonpath_new + ":" + pythonpath
except KeyError:
pythonpath = pythonpath_new
install_label = "do_install %s" % self.bpn
deploy_label = "devtool deploy-target %s" % self.bpn
bb_env = {
# "BBPATH": self.bbpath,
"PYTHONPATH": pythonpath,
"BUILDDIR": self.topdir,
# Use e.g. Python from host, not python-native
"PATH": os.environ['PATH'],
"BB_ENV_PASSTHROUGH_ADDITIONS": self.bb_env_passthrough_additions
}
bb_options = {
"cwd": self.topdir
}
run_install_deploy = self.gen_install_deploy_script(args)
tasks_dict = {
"version": "2.0.0",
"tasks": [
{
"label": install_label,
"type": "shell",
"command": run_do_install,
"problemMatcher": []
},
{
"label": deploy_label,
"label": "install && deploy-target %s" % self.bpn,
"type": "shell",
"command": "devtool", # TODO: Generate a self contained script which does what devtool target-deploy does but without connection to the bitbake server
"args": ["--bbpath", self.bbpath, "deploy-target", self.bpn, args.target, "--strip", "--no-host-check"],
"linux": {
"options": {
"env": bb_env
}},
"options": bb_options,
"command": run_install_deploy,
"problemMatcher": []
},
{
"label": "install && deploy-target %s" % self.bpn,
"dependsOrder": "sequence",
"dependsOn": [
install_label,
deploy_label
],
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": True
}
}
]
}
Expand Down Expand Up @@ -1183,6 +1168,16 @@ def register_commands(subparsers, context):
'--skip-bitbake', help='Generate IDE configuration but skip calling bibtake to update the SDK.', action='store_true')
parser_ide.add_argument(
'-k', '--bitbake-k', help='Pass -k parameter to bitbake', action='store_true')
parser_ide.add_argument(
'--no-strip', help='Do not strip executables prior to deploy', dest='strip', action='store_false')
parser_ide.add_argument(
'-n', '--dry-run', help='List files to be undeployed only', action='store_true')
parser_ide.add_argument(
'-s', '--show-status', help='Show progress/status output', action='store_true')
parser_ide.add_argument(
'-p', '--no-preserve', help='Do not preserve existing files', action='store_true')
parser_ide.add_argument(
'--no-check-space', help='Do not check for available space before deploying', action='store_true')
parser_ide.add_argument(
'--debug-build-config', help='Use debug build flags, for example set CMAKE_BUILD_TYPE=Debug', action='store_true')
parser_ide.set_defaults(func=ide_setup)
Expand Down

0 comments on commit 199bb41

Please sign in to comment.