bitbake-setup: rename function 'default_settings_path' to 'topdir_settings_path'
PATCH 1/6 bitbake-setup: rename function 'default_settings_path' to 'topdir_settings_path'
From: Johannes Schneider <[email protected]>
Rename the function to align with the corresponding 'global_settings_path' function, and move it down just above the later.
This is done to differentiate from the built-in default settings, and to align with the other places in the code that use 'topdir_settings' (or 'global_settings')
--- bin/bitbake-setup | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
bin/bitbake-setup +8 -8
@@ -634,9 +634,6 @@ def install_buildtools(top_dir, settings, args, d): print("Buildtools archive is downloaded into {} and its content installed into {}".format(buildtools_download_dir, buildtools_install_dir)) subprocess.check_call("{} -d {} --downloads-directory {}".format(install_buildtools, buildtools_install_dir, buildtools_download_dir), shell=True) -def default_settings_path(top_dir): - return os.path.join(top_dir, 'settings.conf') - def create_siteconf(top_dir, non_interactive=True): siteconfpath = os.path.join(top_dir, 'site.conf') print('A common site.conf file will be created, please edit or replace before running builds\n {}\n'.format(siteconfpath))
@@ -653,6 +650,9 @@ def create_siteconf(top_dir, non_interactive=True): with open(siteconfpath, 'w') as siteconffile: siteconffile.write('# This file is intended for build host-specific bitbake settings\n') +def topdir_settings_path(top_dir): + return os.path.join(top_dir, 'settings.conf') + def global_settings_path(args): return os.path.abspath(args.global_settings) if args.global_settings else os.path.join(os.path.expanduser('~'), '.config', 'bitbake-setup', 'settings.conf')
@@ -667,7 +667,7 @@ def change_setting(top_dir, args): if vars(args)['global']: settings_path = global_settings_path(args) else: - settings_path = default_settings_path(top_dir) + settings_path = topdir_settings_path(top_dir) settings = load_settings(settings_path) if args.subcommand == 'set':
@@ -709,7 +709,7 @@ def get_top_dir(args, settings): setup_dir_via_bbpath = get_setup_dir_via_bbpath() if setup_dir_via_bbpath: top_dir = os.path.dirname(setup_dir_via_bbpath) - if os.path.exists(default_settings_path(top_dir)): + if os.path.exists(topdir_settings_path(top_dir)): return top_dir if hasattr(args, 'setup_dir'):
@@ -720,10 +720,10 @@ def get_top_dir(args, settings): top_dir_name = settings['default']['top-dir-name'] return os.path.join(top_dir_prefix, top_dir_name) -def merge_settings(builtin_settings, global_settings, local_settings, cmdline_settings): +def merge_settings(builtin_settings, global_settings, topdir_settings, cmdline_settings): all_settings = builtin_settings - for s in (global_settings, local_settings): + for s in (global_settings, topdir_settings): for section, section_settings in s.items(): for setting, value in section_settings.items(): all_settings[section][setting] = value
@@ -841,7 +841,7 @@ def main(): # This cannot be set with the rest of the builtin settings as top_dir needs to be determined first builtin_settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads') - topdir_settings = load_settings(default_settings_path(top_dir)) + topdir_settings = load_settings(topdir_settings_path(top_dir)) all_settings = merge_settings(builtin_settings, global_settings, topdir_settings, args.cmdline_settings) if args.func == settings_func:
Signature · 1 line
2.39.5
PATCH 2/6 bitbake-setup: fix key-error when changing a new 'section'
From: Johannes Schneider <[email protected]>
Setting a key=value in a new section would raise a key-error when using in-memory settings, e.g:
./bin/bitbake-setup --setting default top-dir-prefix /tmp/bitbake-setup --setting default top-dir-name gs settings foo bar baz
Loading settings from
/tmp/bitbake-setup/gs/settings.conf
Traceback (most recent call last):
File "/tmp/bitbake-setup/bitbake/./bin/bitbake-setup", line 853, in <module>
main()
File "/tmp/bitbake-setup/bitbake/./bin/bitbake-setup", line 838, in main
all_settings = merge_settings(builtin_settings, global_settings, topdir_settings, args.setting)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/bitbake-setup/bitbake/./bin/bitbake-setup", line 733, in merge_settings
all_settings[section][setting] = value
~~~~~~~~~~~~^^^^^^^^^
KeyError: 'foo'
--- bin/bitbake-setup | 4 ++++ 1 file changed, 4 insertions(+)
bin/bitbake-setup +4 -0
@@ -726,9 +726,13 @@ def merge_settings(builtin_settings, global_settings, topdir_settings, cmdline_s for s in (global_settings, topdir_settings): for section, section_settings in s.items(): for setting, value in section_settings.items(): + if section not in all_settings.keys(): + all_settings[section] = {} all_settings[section][setting] = value for (section, setting, value) in cmdline_settings: + if section not in all_settings.keys(): + all_settings[section] = {} all_settings[section][setting] = value return all_settings
Signature · 1 line
2.39.5
PATCH 3/6 bitbake-setup: rename 'write_config' into 'write_upstream_config'
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
Rename the function to reflect which (of the possibly many) files in the build/config directory it writes to.
--- bin/bitbake-setup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
bin/bitbake-setup +4 -4
@@ -57,9 +57,9 @@ def get_config_name(config): else: raise Exception("Config file {} does not end with {}, please rename the file.".format(config, suffix)) -def write_config(config, config_dir): +def write_upstream_config(config_dir, config_data): with open(os.path.join(config_dir, "config-upstream.json"),'w') as s: - json.dump(config, s, sort_keys=True, indent=4) + json.dump(config_data, s, sort_keys=True, indent=4) def commit_config(config_dir): bb.process.run("git -C {} add .".format(config_dir))
@@ -469,7 +469,7 @@ def init_config(top_dir, settings, args, d): bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d) - write_config(upstream_config, confdir) + write_upstream_config(confdir, upstream_config) commit_config(confdir) update_build(upstream_config, confdir, setupdir, layerdir, d)
@@ -526,7 +526,7 @@ def build_status(top_dir, settings, args, d, update=False): source_overrides = current_upstream_config["source-overrides"] new_upstream_config = obtain_config(top_dir, settings, args, source_overrides, d) - write_config(new_upstream_config, confdir) + write_upstream_config(confdir, new_upstream_config) config_diff = bb.process.run('git -C {} diff'.format(confdir))[0] if config_diff:
Signature · 1 line
2.39.5
PATCH 4/6 bitbake-setup: checkout_layers: construct 'src_uri' separatly
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
Construct the 'src_uri' separately, and then pass either variant into one call that creates the Fetch. Making use of format-strings to shorten/simplify the code.
Also: using 'proto' instead of 'type' for a variable name, to avoid the protected keyword.
--- bin/bitbake-setup | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
bin/bitbake-setup +4 -3
@@ -90,13 +90,14 @@ def checkout_layers(layers, layerdir, d): remotes = r_remote['remotes'] for remote in remotes: - type,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"]) + prot,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"]) fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params)) print(" {}".format(r_name)) if branch: - fetcher = bb.fetch.Fetch(["{};protocol={};rev={};branch={};destsuffix={}".format(fetchuri,type,rev,branch,repodir)], d) + src_uri = f"{fetchuri};protocol={prot};rev={rev};branch={branch};destsuffix={repodir}" else: - fetcher = bb.fetch.Fetch(["{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir)], d) + src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}" + fetcher = bb.fetch.Fetch([src_uri], d) do_fetch(fetcher, layerdir) if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')):
Signature · 1 line
2.39.5
PATCH 5/6 bitbake-setup: tests: move duplicate code into 'check_setupdir_files'
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
All places that called into 'check_setupdir_files' did the same preparation step to load the upstream-config.json and then pass it into the function.
Since the 'setuppath' is already passed into the function, and the name and relative location of the upstream-config.json is fixed, constructing the file path and loading the json could be done in the function.
De-duplicate code by loading the json inside the function instead.
--- lib/bb/tests/setup.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
lib/bb/tests/setup.py +8 -12
@@ -177,10 +177,12 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) self.git('add {}'.format(name), cwd=self.testrepopath) self.git('commit -m "Adding {}"'.format(name), cwd=self.testrepopath) - def check_setupdir_files(self, setuppath, test_file_content, json_config): + def check_setupdir_files(self, setuppath, test_file_content): + with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: + config_upstream = json.load(f) with open(os.path.join(setuppath, 'layers', 'test-repo', 'test-file')) as f: self.assertEqual(f.read(), test_file_content) - bitbake_config = json_config["bitbake-config"] + bitbake_config = config_upstream["bitbake-config"] bb_build_path = os.path.join(setuppath, 'build') bb_conf_path = os.path.join(bb_build_path, 'conf') self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env')))
@@ -198,7 +200,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) for l in bitbake_config["bb-layers"]: if l.startswith('{THISDIR}/'): thisdir_layer = os.path.join( - os.path.dirname(json_config["path"]), + os.path.dirname(config_upstream["path"]), l.removeprefix("{THISDIR}/"), ) self.assertIn(thisdir_layer, bblayers)
@@ -296,9 +298,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) for c in v['buildconfigs']: out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c)) setuppath = os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c)) - with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: - config_upstream = json.load(f) - self.check_setupdir_files(setuppath, test_file_content, config_upstream) + self.check_setupdir_files(setuppath, test_file_content) os.environ['BBPATH'] = os.path.join(setuppath, 'build') out = self.runbbsetup("status") self.assertIn("Configuration in {} has not changed".format(setuppath), out[0])
@@ -327,9 +327,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) if c in ('gadget', 'gizmo'): self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0]) self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0]) - with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: - config_upstream = json.load(f) - self.check_setupdir_files(setuppath, test_file_content, config_upstream) + self.check_setupdir_files(setuppath, test_file_content) # make a new branch in the test layer repo, change a file on that branch, # make a new commit, update the top level json config to refer to that branch,
@@ -353,6 +351,4 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) if c in ('gadget', 'gizmo'): self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0]) self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0]) - with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: - config_upstream = json.load(f) - self.check_setupdir_files(setuppath, test_file_content, config_upstream) + self.check_setupdir_files(setuppath, test_file_content)
Signature · 1 line
2.39.5
PATCH 6/6 bitbake-setup: capture revisions while checking out layers
In reply to Alexander KanavinFrom: Johannes Schneider <[email protected]>
When initializing a build setup from a conf.json that only sets 'rev' to a tag or branch, the actual revision would not be captured or logged.
To capture the current layer state after an 'init' or 'update', the checkout_layers function is extended to store the revision the bb.fetch.Fetch pulled, and write that information into a sources-fixed-revisions.json file. This file can then be fed back into bitbake-setup init as: --sources-overrides
This new 'sources-fixed-revisions.json' is written during 'update_build' and stored alongside the 'config-upstream.json' in the config dir. And put with the later under version control by calling 'commit_config" after 'update_build'.
The use of 'deepcopy' is necessary to not modify the original input data - which python passes around as reference.
--- bin/bitbake-setup | 20 +++++++++++++++++--- lib/bb/tests/setup.py | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-)
bin/bitbake-setup +17 -3
@@ -18,6 +18,7 @@ import configparser import datetime import glob import subprocess +import copy default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry")
@@ -61,6 +62,12 @@ def write_upstream_config(config_dir, config_data): with open(os.path.join(config_dir, "config-upstream.json"),'w') as s: json.dump(config_data, s, sort_keys=True, indent=4) +def write_sources_fixed_revisions(config_dir, config_data): + sources = {} + sources['sources'] = config_data + with open(os.path.join(config_dir, "sources-fixed-revisions.json"),'w') as s: + json.dump(sources, s, sort_keys=True, indent=4) + def commit_config(config_dir): bb.process.run("git -C {} add .".format(config_dir)) bb.process.run("git -C {} commit --no-verify -a -m 'Configuration at {}'".format(config_dir, time.asctime()))
@@ -76,6 +83,7 @@ def _write_layer_list(dest, repodirs): json.dump({"version":"1.0","layers":layers}, f, sort_keys=True, indent=4) def checkout_layers(layers, layerdir, d): + layers_fixed_revisions = copy.deepcopy(layers) repodirs = [] oesetupbuild = None print("Fetching layer/tool repositories into {}".format(layerdir))
@@ -99,6 +107,9 @@ def checkout_layers(layers, layerdir, d): src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}" fetcher = bb.fetch.Fetch([src_uri], d) do_fetch(fetcher, layerdir) + urldata = fetcher.ud[src_uri] + revision = urldata.revision + layers_fixed_revisions[r_name]['git-remote']['rev'] = revision if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')): oesetupbuild = os.path.join(layerdir, repodir, 'scripts/oe-setup-build')
@@ -115,6 +126,8 @@ def checkout_layers(layers, layerdir, d): os.remove(symlink) os.symlink(os.path.relpath(t,layerdir),symlink) + return layers_fixed_revisions + def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir): def _setup_build_conf(layers, build_conf_dir): os.makedirs(build_conf_dir)
@@ -269,15 +282,16 @@ def get_registry_config(registry_path, id): raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id)) def update_build(config, confdir, setupdir, layerdir, d): - layer_config = config["data"]["sources"] + layer_config = copy.deepcopy(config["data"]["sources"]) layer_overrides = config["source-overrides"]["sources"] for k,v in layer_overrides.items(): if k in layer_config: layer_config[k]["git-remote"] = v["git-remote"] - checkout_layers(layer_config, layerdir, d) + sources_fixed_revisions = checkout_layers(layer_config, layerdir, d) bitbake_config = config["bitbake-config"] thisdir = os.path.dirname(config["path"]) if config["type"] == 'local' else None setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir) + write_sources_fixed_revisions(confdir, sources_fixed_revisions) def int_input(allowed_values): n = None
@@ -471,8 +485,8 @@ def init_config(top_dir, settings, args, d): bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d) write_upstream_config(confdir, upstream_config) - commit_config(confdir) update_build(upstream_config, confdir, setupdir, layerdir, d) + commit_config(confdir) bb.event.remove("bb.build.TaskProgress", None)
lib/bb/tests/setup.py +6 -0
@@ -187,6 +187,12 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) bb_conf_path = os.path.join(bb_build_path, 'conf') self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env'))) + with open(os.path.join(setuppath, 'config', "sources-fixed-revisions.json")) as f: + sources_fixed_revisions = json.load(f) + self.assertTrue('test-repo' in sources_fixed_revisions['sources'].keys()) + revision = self.git('rev-parse HEAD', cwd=self.testrepopath).strip() + self.assertEqual(revision, sources_fixed_revisions['sources']['test-repo']['git-remote']['rev']) + if "oe-template" in bitbake_config: with open(os.path.join(bb_conf_path, 'conf-summary.txt')) as f: self.assertEqual(f.read(), bitbake_config["oe-template"])
Signature · 1 line
2.39.5