summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alex@linutronix.de>2025-09-29 14:56:15 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-10-05 23:47:05 +0100
commit29841a05bedcbc6be4de0873a694eaadf95bd03c (patch)
treeae05fdffbd223492e8fb0b2da289c0d599b9b7cc
parent01b884c8fbc24e8901cb6149bdbfd94ce9f4a4b5 (diff)
downloadpoky-29841a05bedcbc6be4de0873a694eaadf95bd03c.tar.gz
bitbake: bitbake-setup: add support for specifying branches in repo checkouts
Previously bitbake-setup was checking out 'detached commits' using fetcher's nobranch feature, as that is the only option when only a revision is in the config. Branches are optional, but beneficial, as - checkout directory will be on a branch, making it easier for users to understand where they are if they need to make changes (also bitbake will print branch information instead of saying 'HEAD:sha'). - supply chain security! Enforcing a branch means any specified revision has to be on it, and no one can sneak in (accidentally or deliberately!) some dangling commit, or something from their private branch in the same repo. (Bitbake rev: 14dd5f53913419a6c26c0b809a592bd19ae8495a) Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/bin/bitbake-setup12
-rw-r--r--bitbake/default-registry/configurations/oe-nodistro.conf.json3
-rw-r--r--bitbake/default-registry/configurations/poky-master.conf.json4
-rw-r--r--bitbake/lib/bb/tests/setup.py11
4 files changed, 23 insertions, 7 deletions
diff --git a/bitbake/bin/bitbake-setup b/bitbake/bin/bitbake-setup
index ce5cd5e65f..8ceacada9a 100755
--- a/bitbake/bin/bitbake-setup
+++ b/bitbake/bin/bitbake-setup
@@ -86,13 +86,17 @@ def checkout_layers(layers, layerdir, d):
86 86
87 r_remote = r_data['git-remote'] 87 r_remote = r_data['git-remote']
88 rev = r_remote['rev'] 88 rev = r_remote['rev']
89 branch = r_remote.get('branch', None)
89 remotes = r_remote['remotes'] 90 remotes = r_remote['remotes']
90 91
91 for remote in remotes: 92 for remote in remotes:
92 type,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"]) 93 type,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"])
93 fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params)) 94 fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params))
94 print(" {}".format(r_name)) 95 print(" {}".format(r_name))
95 fetcher = bb.fetch.Fetch(["{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir)], d) 96 if branch:
97 fetcher = bb.fetch.Fetch(["{};protocol={};rev={};branch={};destsuffix={}".format(fetchuri,type,rev,branch,repodir)], d)
98 else:
99 fetcher = bb.fetch.Fetch(["{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir)], d)
96 do_fetch(fetcher, layerdir) 100 do_fetch(fetcher, layerdir)
97 101
98 if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')): 102 if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')):
@@ -444,12 +448,16 @@ def are_layers_changed(layers, layerdir, d):
444 448
445 r_remote = r_data['git-remote'] 449 r_remote = r_data['git-remote']
446 rev = r_remote['rev'] 450 rev = r_remote['rev']
451 branch = r_remote.get('branch', None)
447 remotes = r_remote['remotes'] 452 remotes = r_remote['remotes']
448 453
449 for remote in remotes: 454 for remote in remotes:
450 type,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"]) 455 type,host,path,user,pswd,params = bb.fetch.decodeurl(remotes[remote]["uri"])
451 fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params)) 456 fetchuri = bb.fetch.encodeurl(('git',host,path,user,pswd,params))
452 fetcher = bb.fetch.FetchData("{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir), d) 457 if branch:
458 fetcher = bb.fetch.FetchData("{};protocol={};rev={};branch={};destsuffix={}".format(fetchuri,type,rev,branch,repodir), d)
459 else:
460 fetcher = bb.fetch.FetchData("{};protocol={};rev={};nobranch=1;destsuffix={}".format(fetchuri,type,rev,repodir), d)
453 upstream_revision = fetcher.method.latest_revision(fetcher, d, 'default') 461 upstream_revision = fetcher.method.latest_revision(fetcher, d, 'default')
454 rev_parse_result = bb.process.run('git -C {} rev-parse HEAD'.format(os.path.join(layerdir, repodir))) 462 rev_parse_result = bb.process.run('git -C {} rev-parse HEAD'.format(os.path.join(layerdir, repodir)))
455 local_revision = rev_parse_result[0].strip() 463 local_revision = rev_parse_result[0].strip()
diff --git a/bitbake/default-registry/configurations/oe-nodistro.conf.json b/bitbake/default-registry/configurations/oe-nodistro.conf.json
index f4a7492f39..7619738b1d 100644
--- a/bitbake/default-registry/configurations/oe-nodistro.conf.json
+++ b/bitbake/default-registry/configurations/oe-nodistro.conf.json
@@ -8,6 +8,7 @@
8 "uri": "git://git.openembedded.org/bitbake;protocol=https" 8 "uri": "git://git.openembedded.org/bitbake;protocol=https"
9 } 9 }
10 }, 10 },
11 "branch": "master",
11 "rev": "master" 12 "rev": "master"
12 }, 13 },
13 "path": "bitbake" 14 "path": "bitbake"
@@ -19,6 +20,7 @@
19 "uri": "git://git.openembedded.org/openembedded-core;protocol=https" 20 "uri": "git://git.openembedded.org/openembedded-core;protocol=https"
20 } 21 }
21 }, 22 },
23 "branch": "master",
22 "rev": "master" 24 "rev": "master"
23 }, 25 },
24 "path": "openembedded-core" 26 "path": "openembedded-core"
@@ -30,6 +32,7 @@
30 "uri": "git://git.yoctoproject.org/yocto-docs;protocol=https" 32 "uri": "git://git.yoctoproject.org/yocto-docs;protocol=https"
31 } 33 }
32 }, 34 },
35 "branch": "master",
33 "rev": "master" 36 "rev": "master"
34 }, 37 },
35 "path": "yocto-docs" 38 "path": "yocto-docs"
diff --git a/bitbake/default-registry/configurations/poky-master.conf.json b/bitbake/default-registry/configurations/poky-master.conf.json
index 227816983b..3f12991799 100644
--- a/bitbake/default-registry/configurations/poky-master.conf.json
+++ b/bitbake/default-registry/configurations/poky-master.conf.json
@@ -8,6 +8,7 @@
8 "uri": "git://git.openembedded.org/bitbake;protocol=https" 8 "uri": "git://git.openembedded.org/bitbake;protocol=https"
9 } 9 }
10 }, 10 },
11 "branch": "master",
11 "rev": "master" 12 "rev": "master"
12 }, 13 },
13 "path": "bitbake" 14 "path": "bitbake"
@@ -19,6 +20,7 @@
19 "uri": "git://git.openembedded.org/openembedded-core;protocol=https" 20 "uri": "git://git.openembedded.org/openembedded-core;protocol=https"
20 } 21 }
21 }, 22 },
23 "branch": "master",
22 "rev": "master" 24 "rev": "master"
23 }, 25 },
24 "path": "openembedded-core" 26 "path": "openembedded-core"
@@ -30,6 +32,7 @@
30 "uri": "git://git.yoctoproject.org/meta-yocto;protocol=https" 32 "uri": "git://git.yoctoproject.org/meta-yocto;protocol=https"
31 } 33 }
32 }, 34 },
35 "branch": "master",
33 "rev": "master" 36 "rev": "master"
34 }, 37 },
35 "path": "meta-yocto" 38 "path": "meta-yocto"
@@ -41,6 +44,7 @@
41 "uri": "git://git.yoctoproject.org/yocto-docs;protocol=https" 44 "uri": "git://git.yoctoproject.org/yocto-docs;protocol=https"
42 } 45 }
43 }, 46 },
47 "branch": "master",
44 "rev": "master" 48 "rev": "master"
45 }, 49 },
46 "path": "yocto-docs" 50 "path": "yocto-docs"
diff --git a/bitbake/lib/bb/tests/setup.py b/bitbake/lib/bb/tests/setup.py
index fb2c15f545..329a0c5259 100644
--- a/bitbake/lib/bb/tests/setup.py
+++ b/bitbake/lib/bb/tests/setup.py
@@ -87,7 +87,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
87 bbsetup = os.path.abspath(os.path.dirname(__file__) + "/../../../bin/bitbake-setup") 87 bbsetup = os.path.abspath(os.path.dirname(__file__) + "/../../../bin/bitbake-setup")
88 return bb.process.run("{} --global-settings {} {}".format(bbsetup, os.path.join(self.tempdir, 'global-config'), cmd)) 88 return bb.process.run("{} --global-settings {} {}".format(bbsetup, os.path.join(self.tempdir, 'global-config'), cmd))
89 89
90 def add_json_config_to_registry(self, name, rev): 90 def add_json_config_to_registry(self, name, rev, branch):
91 config = """ 91 config = """
92{ 92{
93 "sources": { 93 "sources": {
@@ -98,6 +98,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
98 "uri": "file://%s" 98 "uri": "file://%s"
99 } 99 }
100 }, 100 },
101 "branch": "%s",
101 "rev": "%s" 102 "rev": "%s"
102 }, 103 },
103 "path": "test-repo" 104 "path": "test-repo"
@@ -134,7 +135,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
134 }, 135 },
135 "version": "1.0" 136 "version": "1.0"
136} 137}
137""" % (self.testrepopath, rev) 138""" % (self.testrepopath, branch, rev)
138 os.makedirs(os.path.join(self.registrypath, os.path.dirname(name)), exist_ok=True) 139 os.makedirs(os.path.join(self.registrypath, os.path.dirname(name)), exist_ok=True)
139 with open(os.path.join(self.registrypath, name), 'w') as f: 140 with open(os.path.join(self.registrypath, name), 'w') as f:
140 f.write(config) 141 f.write(config)
@@ -208,12 +209,12 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
208 self.assertNotIn("test-config-1", out[0]) 209 self.assertNotIn("test-config-1", out[0])
209 self.assertNotIn("test-config-2", out[0]) 210 self.assertNotIn("test-config-2", out[0])
210 211
211 json_1 = self.add_json_config_to_registry('test-config-1.conf.json', 'master') 212 json_1 = self.add_json_config_to_registry('test-config-1.conf.json', 'master', 'master')
212 out = self.runbbsetup("list") 213 out = self.runbbsetup("list")
213 self.assertIn("test-config-1", out[0]) 214 self.assertIn("test-config-1", out[0])
214 self.assertNotIn("test-config-2", out[0]) 215 self.assertNotIn("test-config-2", out[0])
215 216
216 json_2 = self.add_json_config_to_registry('config-2/test-config-2.conf.json', 'master') 217 json_2 = self.add_json_config_to_registry('config-2/test-config-2.conf.json', 'master', 'master')
217 out = self.runbbsetup("list --write-json={}".format(os.path.join(self.tempdir, "test-configs.json"))) 218 out = self.runbbsetup("list --write-json={}".format(os.path.join(self.tempdir, "test-configs.json")))
218 self.assertIn("test-config-1", out[0]) 219 self.assertIn("test-config-1", out[0])
219 self.assertIn("test-config-2", out[0]) 220 self.assertIn("test-config-2", out[0])
@@ -270,7 +271,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
270 branch = "another-branch" 271 branch = "another-branch"
271 self.git('checkout -b {}'.format(branch), cwd=self.testrepopath) 272 self.git('checkout -b {}'.format(branch), cwd=self.testrepopath)
272 self.add_file_to_testrepo('test-file', test_file_content) 273 self.add_file_to_testrepo('test-file', test_file_content)
273 json_1 = self.add_json_config_to_registry('test-config-1.conf.json', branch) 274 json_1 = self.add_json_config_to_registry('test-config-1.conf.json', branch, branch)
274 for c in ('gadget','gizmo','gadget-notemplate','gizmo-notemplate'): 275 for c in ('gadget','gizmo','gadget-notemplate','gizmo-notemplate'):
275 buildpath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c)) 276 buildpath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c))
276 os.environ['BBPATH'] = os.path.join(buildpath, 'build') 277 os.environ['BBPATH'] = os.path.join(buildpath, 'build')