summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/tests/setup.py46
-rw-r--r--bitbake/lib/toaster/bldcontrol/localhostbecontroller.py99
2 files changed, 99 insertions, 46 deletions
diff --git a/bitbake/lib/bb/tests/setup.py b/bitbake/lib/bb/tests/setup.py
index a17b8ac46a..ba2a90009d 100644
--- a/bitbake/lib/bb/tests/setup.py
+++ b/bitbake/lib/bb/tests/setup.py
@@ -148,9 +148,10 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
148 "oe-fragments": ["test-fragment-2"] 148 "oe-fragments": ["test-fragment-2"]
149 }, 149 },
150 { 150 {
151 "name": "gizmo-notemplate-with-thisdir", 151 "name": "gizmo-notemplate-with-relative-layers",
152 "description": "Gizmo notemplate configuration using THISDIR", 152 "description": "Gizmo notemplate configuration using relative layers",
153 "bb-layers": ["layerC","layerD/meta-layer","{THISDIR}/layerE/meta-layer"], 153 "bb-layers": ["layerC","layerD/meta-layer"],
154 "bb-layers-relative": ["layerE/meta-layer"],
154 "oe-fragments": ["test-fragment-2"] 155 "oe-fragments": ["test-fragment-2"]
155 } 156 }
156 ] 157 ]
@@ -177,14 +178,22 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
177 self.git('add {}'.format(name), cwd=self.testrepopath) 178 self.git('add {}'.format(name), cwd=self.testrepopath)
178 self.git('commit -m "Adding {}"'.format(name), cwd=self.testrepopath) 179 self.git('commit -m "Adding {}"'.format(name), cwd=self.testrepopath)
179 180
180 def check_setupdir_files(self, setuppath, test_file_content, json_config): 181 def check_setupdir_files(self, setuppath, test_file_content):
182 with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
183 config_upstream = json.load(f)
181 with open(os.path.join(setuppath, 'layers', 'test-repo', 'test-file')) as f: 184 with open(os.path.join(setuppath, 'layers', 'test-repo', 'test-file')) as f:
182 self.assertEqual(f.read(), test_file_content) 185 self.assertEqual(f.read(), test_file_content)
183 bitbake_config = json_config["bitbake-config"] 186 bitbake_config = config_upstream["bitbake-config"]
184 bb_build_path = os.path.join(setuppath, 'build') 187 bb_build_path = os.path.join(setuppath, 'build')
185 bb_conf_path = os.path.join(bb_build_path, 'conf') 188 bb_conf_path = os.path.join(bb_build_path, 'conf')
186 self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env'))) 189 self.assertTrue(os.path.exists(os.path.join(bb_build_path, 'init-build-env')))
187 190
191 with open(os.path.join(setuppath, 'config', "sources-fixed-revisions.json")) as f:
192 sources_fixed_revisions = json.load(f)
193 self.assertTrue('test-repo' in sources_fixed_revisions['sources'].keys())
194 revision = self.git('rev-parse HEAD', cwd=self.testrepopath).strip()
195 self.assertEqual(revision, sources_fixed_revisions['sources']['test-repo']['git-remote']['rev'])
196
188 if "oe-template" in bitbake_config: 197 if "oe-template" in bitbake_config:
189 with open(os.path.join(bb_conf_path, 'conf-summary.txt')) as f: 198 with open(os.path.join(bb_conf_path, 'conf-summary.txt')) as f:
190 self.assertEqual(f.read(), bitbake_config["oe-template"]) 199 self.assertEqual(f.read(), bitbake_config["oe-template"])
@@ -196,14 +205,13 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
196 with open(os.path.join(bb_conf_path, 'bblayers.conf')) as f: 205 with open(os.path.join(bb_conf_path, 'bblayers.conf')) as f:
197 bblayers = f.read() 206 bblayers = f.read()
198 for l in bitbake_config["bb-layers"]: 207 for l in bitbake_config["bb-layers"]:
199 if l.startswith('{THISDIR}/'): 208 self.assertIn(os.path.join(setuppath, "layers", l), bblayers)
200 thisdir_layer = os.path.join( 209 for l in bitbake_config.get("bb-layers-relative") or []:
201 os.path.dirname(json_config["path"]), 210 relative_layer = os.path.join(
202 l.removeprefix("{THISDIR}/"), 211 os.path.dirname(config_upstream["path"]),
212 l,
203 ) 213 )
204 self.assertIn(thisdir_layer, bblayers) 214 self.assertIn(relative_layer, bblayers)
205 else:
206 self.assertIn(os.path.join(setuppath, "layers", l), bblayers)
207 215
208 if 'oe-fragment' in bitbake_config.keys(): 216 if 'oe-fragment' in bitbake_config.keys():
209 for f in bitbake_config["oe-fragments"]: 217 for f in bitbake_config["oe-fragments"]:
@@ -290,15 +298,13 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
290 'gizmo-env-passthrough', 298 'gizmo-env-passthrough',
291 'gizmo-no-fragment', 299 'gizmo-no-fragment',
292 'gadget-notemplate','gizmo-notemplate', 300 'gadget-notemplate','gizmo-notemplate',
293 'gizmo-notemplate-with-thisdir')} 301 'gizmo-notemplate-with-relative-layers')}
294 } 302 }
295 for cf, v in test_configurations.items(): 303 for cf, v in test_configurations.items():
296 for c in v['buildconfigs']: 304 for c in v['buildconfigs']:
297 out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c)) 305 out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c))
298 setuppath = os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c)) 306 setuppath = os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c))
299 with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: 307 self.check_setupdir_files(setuppath, test_file_content)
300 config_upstream = json.load(f)
301 self.check_setupdir_files(setuppath, test_file_content, config_upstream)
302 os.environ['BBPATH'] = os.path.join(setuppath, 'build') 308 os.environ['BBPATH'] = os.path.join(setuppath, 'build')
303 out = self.runbbsetup("status") 309 out = self.runbbsetup("status")
304 self.assertIn("Configuration in {} has not changed".format(setuppath), out[0]) 310 self.assertIn("Configuration in {} has not changed".format(setuppath), out[0])
@@ -327,9 +333,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
327 if c in ('gadget', 'gizmo'): 333 if c in ('gadget', 'gizmo'):
328 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0]) 334 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
329 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0]) 335 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
330 with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: 336 self.check_setupdir_files(setuppath, test_file_content)
331 config_upstream = json.load(f)
332 self.check_setupdir_files(setuppath, test_file_content, config_upstream)
333 337
334 # make a new branch in the test layer repo, change a file on that branch, 338 # make a new branch in the test layer repo, change a file on that branch,
335 # make a new commit, update the top level json config to refer to that branch, 339 # make a new commit, update the top level json config to refer to that branch,
@@ -353,6 +357,4 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
353 if c in ('gadget', 'gizmo'): 357 if c in ('gadget', 'gizmo'):
354 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0]) 358 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
355 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0]) 359 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
356 with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f: 360 self.check_setupdir_files(setuppath, test_file_content)
357 config_upstream = json.load(f)
358 self.check_setupdir_files(setuppath, test_file_content, config_upstream)
diff --git a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py
index 577e765f11..37b0a75199 100644
--- a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py
+++ b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py
@@ -6,6 +6,11 @@
6# SPDX-License-Identifier: GPL-2.0-only 6# SPDX-License-Identifier: GPL-2.0-only
7# 7#
8 8
9# DEBUGGING NOTE: if you need to add debug statements into the files within a
10# Toaster-imported layer, you must disable the "git fetch ..." command after
11# the initial clone else any changes will be automatically replaced with the
12# original code
13
9import os 14import os
10import re 15import re
11import shutil 16import shutil
@@ -183,6 +188,8 @@ class LocalhostBEController(BuildEnvironmentController):
183 if commit != "HEAD": 188 if commit != "HEAD":
184 logger.debug("localhostbecontroller: checking out commit %s to %s " % (commit, localdirname)) 189 logger.debug("localhostbecontroller: checking out commit %s to %s " % (commit, localdirname))
185 ref = commit if re.match('^[a-fA-F0-9]+$', commit) else 'origin/%s' % commit 190 ref = commit if re.match('^[a-fA-F0-9]+$', commit) else 'origin/%s' % commit
191 # DEBUGGING NOTE: this is the 'git fetch" to disable after the initial clone to
192 # prevent inserted debugging commands from being lost
186 self._shellcmd('git fetch && git reset --hard "%s"' % ref, localdirname,env=git_env) 193 self._shellcmd('git fetch && git reset --hard "%s"' % ref, localdirname,env=git_env)
187 194
188 # take the localdirname as poky dir if we can find the oe-init-build-env 195 # take the localdirname as poky dir if we can find the oe-init-build-env
@@ -319,7 +326,28 @@ class LocalhostBEController(BuildEnvironmentController):
319 layers = self.setLayers(bitbake, layers, targets) 326 layers = self.setLayers(bitbake, layers, targets)
320 is_merged_attr = bitbake.req.project.merged_attr 327 is_merged_attr = bitbake.req.project.merged_attr
321 328
329 # Is this build for a Bitbake Setup installation?
330 isBBSetup = False
331 release_description = bitbake.req.project.release.description
332 if 'master' in release_description:
333 # This release going forward is Bitbake Setup
334 isBBSetup = True
335 else:
336 try:
337 # Yocto Project 5.3 "Whinlatter"
338 params = release_description.split(' ')
339 # Work past YP "10.1"
340 release_params = params[2].split('.')
341 if int(release_params[0]) > 5:
342 isBBSetup = True
343 if (release_params[0] == '5') and (int(release_params[1]) >= 3):
344 isBBSetup = True
345 except:
346 # If release schema not recognized, then this release is in the future
347 isBBSetup = True
348
322 git_env = os.environ.copy() 349 git_env = os.environ.copy()
350 toaster_run_dir = git_env['BUILDDIR']
323 # (note: add custom environment settings here) 351 # (note: add custom environment settings here)
324 try: 352 try:
325 # insure that the project init/build uses the selected bitbake, and not Toaster's 353 # insure that the project init/build uses the selected bitbake, and not Toaster's
@@ -335,28 +363,44 @@ class LocalhostBEController(BuildEnvironmentController):
335 else: 363 else:
336 builddir = '%s-toaster-%d' % (self.be.builddir, bitbake.req.project.id) 364 builddir = '%s-toaster-%d' % (self.be.builddir, bitbake.req.project.id)
337 oe_init = os.path.join(self.pokydirname, 'oe-init-build-env') 365 oe_init = os.path.join(self.pokydirname, 'oe-init-build-env')
338 # init build environment 366 setup_init = os.path.join(builddir, 'init-build-env')
367 # init build environment and build directory structure
339 try: 368 try:
340 custom_script = ToasterSetting.objects.get(name="CUSTOM_BUILD_INIT_SCRIPT").value 369 custom_script = ToasterSetting.objects.get(name="CUSTOM_BUILD_INIT_SCRIPT").value
341 custom_script = custom_script.replace("%BUILDDIR%" ,builddir) 370 custom_script = custom_script.replace("%BUILDDIR%" ,builddir)
342 self._shellcmd("bash -c 'source %s'" % (custom_script),env=git_env) 371 self._shellcmd("bash -c 'source %s'" % (custom_script),env=git_env)
343 except ToasterSetting.DoesNotExist: 372 except ToasterSetting.DoesNotExist:
344 self._shellcmd("bash -c 'source %s %s'" % (oe_init, builddir), 373 # Normal setup
345 self.be.sourcedir,env=git_env) 374 if isBBSetup:
375 # Create an 'init-build-env' for the build directory that points to respective cloned bitbake
376 os.makedirs(builddir, exist_ok = True)
377 build_init_script = os.path.join(builddir,'init-build-env')
378 os.system(f"cp {os.path.join(toaster_run_dir,'init-build-env')} {build_init_script}")
379 os.system(f"sed -i -e 's|^cd .*$|cd {self.pokydirname}|g' {build_init_script}")
380 os.system(f"sed -i -e 's|^set .*$|set {builddir}|g' {build_init_script}")
381 # Execute the init
382 self._shellcmd(f"bash -c 'source {build_init_script}'", env=git_env)
383 else:
384 self._shellcmd("bash -c 'source %s %s'" % (oe_init, builddir),
385 self.be.sourcedir,env=git_env)
346 386
347 # update bblayers.conf 387 # update bblayers.conf
348 if not is_merged_attr: 388 if not is_merged_attr:
349 bblconfpath = os.path.join(builddir, "conf/toaster-bblayers.conf") 389 bblconfpath = os.path.join(builddir, "conf/toaster-bblayers.conf")
350 with open(bblconfpath, 'w') as bblayers: 390 with open(bblconfpath, 'w') as bblayers:
351 bblayers.write('# line added by toaster build control\n' 391 bblayers.write('# line added by toaster build control\n'
352 'BBLAYERS = "%s"' % ' '.join(layers)) 392 'BBLAYERS = "%s"\n' % ' '.join(layers))
353 393
354 # write configuration file 394 # write configuration file
355 confpath = os.path.join(builddir, 'conf/toaster.conf') 395 confpath = os.path.join(builddir, 'conf/toaster.conf')
356 with open(confpath, 'w') as conf: 396 with open(confpath, 'w') as conf:
397 if isBBSetup:
398 # Force TOPDIR
399 conf.write(f'# Force TOPDIR\n')
400 conf.write(f'TOPDIR = "{builddir}"\n\n')
357 for var in variables: 401 for var in variables:
358 conf.write('%s="%s"\n' % (var.name, var.value)) 402 conf.write('%s = "%s"\n' % (var.name, var.value))
359 conf.write('INHERIT+="toaster buildhistory"') 403 conf.write('INHERIT += "toaster buildhistory"\n')
360 else: 404 else:
361 # Append the Toaster-specific values directly to the bblayers.conf 405 # Append the Toaster-specific values directly to the bblayers.conf
362 bblconfpath = os.path.join(builddir, "conf/bblayers.conf") 406 bblconfpath = os.path.join(builddir, "conf/bblayers.conf")
@@ -443,15 +487,25 @@ class LocalhostBEController(BuildEnvironmentController):
443 else: 487 else:
444 logger.error("Looks like Bitbake is not available, please fix your environment") 488 logger.error("Looks like Bitbake is not available, please fix your environment")
445 489
490 # NOTE: BB SETUP requires a 'bblayers.conf' even though Toaster immediately overrides it with 'toaster-bblayers.conf'
491 bblayers = os.path.join(builddir,"conf/bblayers.conf")
446 toasterlayers = os.path.join(builddir,"conf/toaster-bblayers.conf") 492 toasterlayers = os.path.join(builddir,"conf/toaster-bblayers.conf")
447 if not is_merged_attr: 493 if isBBSetup:
448 self._shellcmd('%s bash -c \"source %s %s; BITBAKE_UI="knotty" %s --read %s --read %s ' 494 # Use 'init-build-env' model
449 '--server-only -B 0.0.0.0:0\"' % (env_clean, oe_init, 495 if not is_merged_attr:
450 builddir, bitbake, confpath, toasterlayers), self.be.sourcedir) 496 self._shellcmd(f'{env_clean} bash -c \"source {setup_init}; BITBAKE_UI="knotty" {bitbake} --read {confpath} --read {bblayers} --read {toasterlayers} '
497 '--server-only -B 0.0.0.0:0\"', self.be.sourcedir)
498 else:
499 self._shellcmd(f'{env_clean} bash -c \"source {setup_init}; BITBAKE_UI="knotty" {bitbake} '
500 '--server-only -B 0.0.0.0:0\"', self.be.sourcedir)
451 else: 501 else:
452 self._shellcmd('%s bash -c \"source %s %s; BITBAKE_UI="knotty" %s ' 502 # Use 'oe-init-build-env' model
453 '--server-only -B 0.0.0.0:0\"' % (env_clean, oe_init, 503 if not is_merged_attr:
454 builddir, bitbake), self.be.sourcedir) 504 self._shellcmd(f'{env_clean} bash -c \"source {oe_init} {builddir}; BITBAKE_UI="knotty" {bitbake} --read {confpath} --read {bblayers} --read {toasterlayers} '
505 '--server-only -B 0.0.0.0:0\"', self.be.sourcedir)
506 else:
507 self._shellcmd(f'{env_clean} bash -c \"source {oe_init} {builddir}; BITBAKE_UI="knotty" {bitbake} '
508 '--server-only -B 0.0.0.0:0\"', self.be.sourcedir)
455 509
456 # read port number from bitbake.lock 510 # read port number from bitbake.lock
457 self.be.bbport = -1 511 self.be.bbport = -1
@@ -497,20 +551,17 @@ class LocalhostBEController(BuildEnvironmentController):
497 log = os.path.join(builddir, 'toaster_ui.log') 551 log = os.path.join(builddir, 'toaster_ui.log')
498 local_bitbake = os.path.join(os.path.dirname(os.getenv('BBBASEDIR')), 552 local_bitbake = os.path.join(os.path.dirname(os.getenv('BBBASEDIR')),
499 'bitbake') 553 'bitbake')
554
500 if not is_merged_attr: 555 if not is_merged_attr:
501 self._shellcmd(['%s bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:%s" ' 556 self._shellcmd([f'{env_clean} bash -c \"(TOASTER_BRBE="{brbe}" BBSERVER="0.0.0.0:{self.be.bbport}" '
502 '%s %s -u toasterui --read %s --read %s --token="" >>%s 2>&1;' 557 f'{bitbake} {bbtargets} -u toasterui --read {confpath} --read {bblayers} --read {toasterlayers} --token="" >>{log} 2>&1;'
503 'BITBAKE_UI="knotty" BBSERVER=0.0.0.0:%s %s -m)&\"' \ 558 f'BITBAKE_UI="knotty" BBSERVER=0.0.0.0:{self.be.bbport} {bitbake} -m)&\"'],
504 % (env_clean, brbe, self.be.bbport, local_bitbake, bbtargets, confpath, toasterlayers, log,
505 self.be.bbport, bitbake,)],
506 builddir, nowait=True) 559 builddir, nowait=True)
507 else: 560 else:
508 self._shellcmd(['%s bash -c \"(TOASTER_BRBE="%s" BBSERVER="0.0.0.0:%s" ' 561 self._shellcmd([f'{env_clean} bash -c \"(TOASTER_BRBE="{brbe}" BBSERVER="0.0.0.0:{self.be.bbport}" '
509 '%s %s -u toasterui --token="" >>%s 2>&1;' 562 f'{local_bitbake} {bbtargets} -u toasterui --token="" >>{log} 2>&1;'
510 'BITBAKE_UI="knotty" BBSERVER=0.0.0.0:%s %s -m)&\"' \ 563 f'BITBAKE_UI="knotty" BBSERVER=0.0.0.0:{self.be.bbport} {bitbake} -m)&\"'],
511 % (env_clean, brbe, self.be.bbport, local_bitbake, bbtargets, log,
512 self.be.bbport, bitbake,)],
513 builddir, nowait=True) 564 builddir, nowait=True)
514 565
515 logger.debug('localhostbecontroller: Build launched, exiting. ' 566 logger.debug('localhostbecontroller: Build launched, exiting. '
516 'Follow build logs at %s' % log) 567 f'Follow build logs at {log}')