diff options
| author | Johannes Schneider <johannes.schneider@leica-geosystems.com> | 2025-11-05 20:06:36 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-11-06 18:03:46 +0000 |
| commit | 9780ec24d070b0638492c0f153a7ed776c150ed5 (patch) | |
| tree | b78f5a34c970027658b7e4e51d94922e469c1ad1 | |
| parent | 13b7a749eccccac9d78a546afb856cc4d3004ed9 (diff) | |
| download | poky-9780ec24d070b0638492c0f153a7ed776c150ed5.tar.gz | |
bitbake: bitbake-setup: capture revisions while checking out layers
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.
(Bitbake rev: 95866ff03f78e987ae7e47daad053bc0f353eea4)
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rwxr-xr-x | bitbake/bin/bitbake-setup | 20 | ||||
| -rw-r--r-- | bitbake/lib/bb/tests/setup.py | 6 |
2 files changed, 23 insertions, 3 deletions
diff --git a/bitbake/bin/bitbake-setup b/bitbake/bin/bitbake-setup index ff753557ce..47de4654e3 100755 --- a/bitbake/bin/bitbake-setup +++ b/bitbake/bin/bitbake-setup | |||
| @@ -18,6 +18,7 @@ import configparser | |||
| 18 | import datetime | 18 | import datetime |
| 19 | import glob | 19 | import glob |
| 20 | import subprocess | 20 | import subprocess |
| 21 | import copy | ||
| 21 | 22 | ||
| 22 | default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry") | 23 | default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry") |
| 23 | 24 | ||
| @@ -61,6 +62,12 @@ def write_upstream_config(config_dir, config_data): | |||
| 61 | with open(os.path.join(config_dir, "config-upstream.json"),'w') as s: | 62 | with open(os.path.join(config_dir, "config-upstream.json"),'w') as s: |
| 62 | json.dump(config_data, s, sort_keys=True, indent=4) | 63 | json.dump(config_data, s, sort_keys=True, indent=4) |
| 63 | 64 | ||
| 65 | def write_sources_fixed_revisions(config_dir, config_data): | ||
| 66 | sources = {} | ||
| 67 | sources['sources'] = config_data | ||
| 68 | with open(os.path.join(config_dir, "sources-fixed-revisions.json"),'w') as s: | ||
| 69 | json.dump(sources, s, sort_keys=True, indent=4) | ||
| 70 | |||
| 64 | def commit_config(config_dir): | 71 | def commit_config(config_dir): |
| 65 | bb.process.run("git -C {} add .".format(config_dir)) | 72 | bb.process.run("git -C {} add .".format(config_dir)) |
| 66 | bb.process.run("git -C {} commit --no-verify -a -m 'Configuration at {}'".format(config_dir, time.asctime())) | 73 | 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): | |||
| 76 | json.dump({"version":"1.0","layers":layers}, f, sort_keys=True, indent=4) | 83 | json.dump({"version":"1.0","layers":layers}, f, sort_keys=True, indent=4) |
| 77 | 84 | ||
| 78 | def checkout_layers(layers, layerdir, d): | 85 | def checkout_layers(layers, layerdir, d): |
| 86 | layers_fixed_revisions = copy.deepcopy(layers) | ||
| 79 | repodirs = [] | 87 | repodirs = [] |
| 80 | oesetupbuild = None | 88 | oesetupbuild = None |
| 81 | print("Fetching layer/tool repositories into {}".format(layerdir)) | 89 | print("Fetching layer/tool repositories into {}".format(layerdir)) |
| @@ -99,6 +107,9 @@ def checkout_layers(layers, layerdir, d): | |||
| 99 | src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}" | 107 | src_uri = f"{fetchuri};protocol={prot};rev={rev};nobranch=1;destsuffix={repodir}" |
| 100 | fetcher = bb.fetch.Fetch([src_uri], d) | 108 | fetcher = bb.fetch.Fetch([src_uri], d) |
| 101 | do_fetch(fetcher, layerdir) | 109 | do_fetch(fetcher, layerdir) |
| 110 | urldata = fetcher.ud[src_uri] | ||
| 111 | revision = urldata.revision | ||
| 112 | layers_fixed_revisions[r_name]['git-remote']['rev'] = revision | ||
| 102 | 113 | ||
| 103 | if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')): | 114 | if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')): |
| 104 | oesetupbuild = os.path.join(layerdir, repodir, 'scripts/oe-setup-build') | 115 | oesetupbuild = os.path.join(layerdir, repodir, 'scripts/oe-setup-build') |
| @@ -115,6 +126,8 @@ def checkout_layers(layers, layerdir, d): | |||
| 115 | os.remove(symlink) | 126 | os.remove(symlink) |
| 116 | os.symlink(os.path.relpath(t,layerdir),symlink) | 127 | os.symlink(os.path.relpath(t,layerdir),symlink) |
| 117 | 128 | ||
| 129 | return layers_fixed_revisions | ||
| 130 | |||
| 118 | def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir): | 131 | def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir): |
| 119 | def _setup_build_conf(layers, build_conf_dir): | 132 | def _setup_build_conf(layers, build_conf_dir): |
| 120 | os.makedirs(build_conf_dir) | 133 | os.makedirs(build_conf_dir) |
| @@ -269,15 +282,16 @@ def get_registry_config(registry_path, id): | |||
| 269 | raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id)) | 282 | raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id)) |
| 270 | 283 | ||
| 271 | def update_build(config, confdir, setupdir, layerdir, d): | 284 | def update_build(config, confdir, setupdir, layerdir, d): |
| 272 | layer_config = config["data"]["sources"] | 285 | layer_config = copy.deepcopy(config["data"]["sources"]) |
| 273 | layer_overrides = config["source-overrides"]["sources"] | 286 | layer_overrides = config["source-overrides"]["sources"] |
| 274 | for k,v in layer_overrides.items(): | 287 | for k,v in layer_overrides.items(): |
| 275 | if k in layer_config: | 288 | if k in layer_config: |
| 276 | layer_config[k]["git-remote"] = v["git-remote"] | 289 | layer_config[k]["git-remote"] = v["git-remote"] |
| 277 | checkout_layers(layer_config, layerdir, d) | 290 | sources_fixed_revisions = checkout_layers(layer_config, layerdir, d) |
| 278 | bitbake_config = config["bitbake-config"] | 291 | bitbake_config = config["bitbake-config"] |
| 279 | thisdir = os.path.dirname(config["path"]) if config["type"] == 'local' else None | 292 | thisdir = os.path.dirname(config["path"]) if config["type"] == 'local' else None |
| 280 | setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir) | 293 | setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir) |
| 294 | write_sources_fixed_revisions(confdir, sources_fixed_revisions) | ||
| 281 | 295 | ||
| 282 | def int_input(allowed_values): | 296 | def int_input(allowed_values): |
| 283 | n = None | 297 | n = None |
| @@ -471,8 +485,8 @@ def init_config(top_dir, settings, args, d): | |||
| 471 | bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d) | 485 | bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d) |
| 472 | 486 | ||
| 473 | write_upstream_config(confdir, upstream_config) | 487 | write_upstream_config(confdir, upstream_config) |
| 474 | commit_config(confdir) | ||
| 475 | update_build(upstream_config, confdir, setupdir, layerdir, d) | 488 | update_build(upstream_config, confdir, setupdir, layerdir, d) |
| 489 | commit_config(confdir) | ||
| 476 | 490 | ||
| 477 | bb.event.remove("bb.build.TaskProgress", None) | 491 | bb.event.remove("bb.build.TaskProgress", None) |
| 478 | 492 | ||
diff --git a/bitbake/lib/bb/tests/setup.py b/bitbake/lib/bb/tests/setup.py index e18d6fc6ae..767a6298da 100644 --- a/bitbake/lib/bb/tests/setup.py +++ b/bitbake/lib/bb/tests/setup.py | |||
| @@ -187,6 +187,12 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) | |||
| 187 | bb_conf_path = os.path.join(bb_build_path, 'conf') | 187 | bb_conf_path = os.path.join(bb_build_path, 'conf') |
| 188 | self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env'))) | 188 | self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env'))) |
| 189 | 189 | ||
| 190 | with open(os.path.join(setuppath, 'config', "sources-fixed-revisions.json")) as f: | ||
| 191 | sources_fixed_revisions = json.load(f) | ||
| 192 | self.assertTrue('test-repo' in sources_fixed_revisions['sources'].keys()) | ||
| 193 | revision = self.git('rev-parse HEAD', cwd=self.testrepopath).strip() | ||
| 194 | self.assertEqual(revision, sources_fixed_revisions['sources']['test-repo']['git-remote']['rev']) | ||
| 195 | |||
| 190 | if "oe-template" in bitbake_config: | 196 | if "oe-template" in bitbake_config: |
| 191 | with open(os.path.join(bb_conf_path, 'conf-summary.txt')) as f: | 197 | with open(os.path.join(bb_conf_path, 'conf-summary.txt')) as f: |
| 192 | self.assertEqual(f.read(), bitbake_config["oe-template"]) | 198 | self.assertEqual(f.read(), bitbake_config["oe-template"]) |
