Skip to contentSkip to conversation

bitbake-setup: suggest "." instead of "source"

PATCH New Alexander Kanavin 1 participant 7 messages Oct 2, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 bitbake-setup: suggest "." instead of "source"

From: Yoann Congal <[email protected]>

"." is in POSIX standard[0], whereas "source" is only supported in more feature-full shells (bash, zsh, ...)

[0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot

---
 bin/bitbake-setup | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
index 1fbb65494..51d9503c4 100755
@@ -219,7 +219,7 @@ The bitbake configuration files (local.conf, bblayers.conf and more) can be foun
         f.write(readme)
     print("Usage instructions and additional information are in\n     {}\n".format(readme_file))
     print("The bitbake configuration files (local.conf, bblayers.conf and more) can be found in\n    {}/conf\n".format(bitbake_builddir))
-    print("To run builds, source the environment using\n    source {}".format(init_script))
+    print("To run builds, source the environment using\n    . {}".format(init_script))
 
 def get_registry_config(registry_path, id):
     for root, dirs, files in os.walk(registry_path):
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/7 bitbake-setup: dash support for init-build-env script

From: Yoann Congal <[email protected]>

Being minimalist, dash does not support the (non-POSIX) feature of passing an argument while sourcing a script. Like in
. <some path>/oe-init-build-env <build dir>

With dash, one must use:
set <build dir> # puts <build dir> in $1
cd <some path>
. ./oe-init-build-env # can only be called from its directory in dash

To do this:
* Instead of a symlink to oe-init-build-env, keep a symlink to the directory containing it (called "oe-init-build-env-dir")
* Generate a init-build-env script that dash can source using the above snippet.

---
 bin/bitbake-setup | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
bin/bitbake-setup +8 -7
index 51d9503c4..36a1bbd91 100755
@@ -101,13 +101,13 @@ def checkout_layers(layers, layerdir, d):
 
         if os.path.exists(os.path.join(layerdir, repodir, 'scripts/oe-setup-build')):
             oesetupbuild = os.path.join(layerdir, repodir, 'scripts/oe-setup-build')
-            oeinitbuildenv = os.path.join(layerdir, repodir, 'oe-init-build-env')
+            oeinitbuildenvdir = os.path.join(layerdir, repodir)
 
     print("        ")
     _write_layer_list(layerdir, repodirs)
 
     if oesetupbuild:
-        links = {'setup-build': oesetupbuild, 'oe-scripts': os.path.dirname(oesetupbuild), 'init-build-env': oeinitbuildenv}
+        links = {'setup-build': oesetupbuild, 'oe-scripts': os.path.dirname(oesetupbuild), 'oe-init-build-env-dir': oeinitbuildenvdir}
         for l,t in links.items():
             symlink = os.path.join(layerdir, l)
             if os.path.lexists(symlink):
@@ -145,8 +145,9 @@ def setup_bitbake_build(bitbake_config, layerdir, builddir):
         with open(os.path.join(build_conf_dir, "conf-notes.txt"), 'w') as f:
             f.write("")
 
-    def _make_init_build_env(builddir, initbuildenv):
-        cmd = ". {} {}".format(initbuildenv, builddir)
+    def _make_init_build_env(builddir, oeinitbuildenvdir):
+        builddir = os.path.realpath(builddir)
+        cmd = "cd {}\nset {}\n. ./oe-init-build-env\n".format(oeinitbuildenvdir, builddir)
         initbuild_in_builddir = os.path.join(builddir, 'init-build-env')
         with open(initbuild_in_builddir, 'w') as f:
             f.write(cmd)
@@ -174,11 +175,11 @@ def setup_bitbake_build(bitbake_config, layerdir, builddir):
     if template:
         bb.process.run("{} setup -c {} -b {} --no-shell".format(oesetupbuild, template, bitbake_builddir))
     else:
-        initbuildenv = os.path.join(layerdir, 'init-build-env')
-        if not os.path.exists(initbuildenv):
+        oeinitbuildenvdir = os.path.join(layerdir, 'oe-init-build-env-dir')
+        if not os.path.exists(os.path.join(oeinitbuildenvdir, "oe-init-build-env")):
             print("Could not find oe-init-build-env in any of the layers; please use another mechanism to initialize the bitbake environment")
             return
-        _make_init_build_env(bitbake_builddir, os.path.realpath(initbuildenv))
+        _make_init_build_env(bitbake_builddir, os.path.realpath(oeinitbuildenvdir))
 
     siteconf_symlink = os.path.join(bitbake_confdir, "site.conf")
     siteconf = os.path.normpath(os.path.join(builddir, '..', "site.conf"))
Signature · 1 line
2.39.5
#2 lore raw

PATCH 3/7 lib/bb/tests/setup.py: define test parameters in a single dictionary

In reply to Alexander Kanavin

From: Alexander Kanavin <[email protected]>

This makes maintaining and extending them easier.

---
 lib/bb/tests/setup.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
lib/bb/tests/setup.py +7 -3
index 329a0c525..c77e750db 100644
@@ -227,9 +227,13 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         # (the latter two should do nothing and say that config hasn't changed)
         test_file_content = 'initial\n'
         self.add_file_to_testrepo('test-file', test_file_content)
-        for cf in ('test-config-1', 'test-config-2'):
-            for c in ('gadget','gizmo','gadget-notemplate','gizmo-notemplate'):
-                out = self.runbbsetup("init --non-interactive {} {}".format(os.path.join(self.registrypath,'config-2/test-config-2.conf.json') if cf == 'test-config-2' else cf, c))
+
+        # test-config-1 is tested as a registry config, test-config-2 as a local file
+        test_configurations = {'test-config-1': {'cmdline': 'test-config-1', 'buildconfigs':('gadget','gizmo','gadget-notemplate','gizmo-notemplate')},
+                               'test-config-2': {'cmdline': os.path.join(self.registrypath,'config-2/test-config-2.conf.json'), 'buildconfigs': ('gadget','gizmo','gadget-notemplate','gizmo-notemplate') } }
+        for cf, v in test_configurations.items():
+            for c in v['buildconfigs']:
+                out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c))
                 buildpath = os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c))
                 with open(os.path.join(buildpath, 'config', "config-upstream.json")) as f:
                     config_upstream = json.load(f)
Signature · 1 line
2.39.5
#3 lore raw

PATCH 4/7 lib/bb/tests/setup.py: unset BBPATH to ensure isolation from the existing bitbake environment

In reply to Alexander Kanavin

From: Alexander Kanavin <[email protected]>

bitbake-setup deduces top directory from BBPATH, which, if set, interferes with the tests' own setup.

---
 lib/bb/tests/setup.py | 5 +++++
 1 file changed, 5 insertions(+)
lib/bb/tests/setup.py +5 -0
index c77e750db..2076613d9 100644
@@ -181,6 +181,11 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
 
 
     def test_setup(self):
+        # unset BBPATH to ensure tests run in isolation from the existing bitbake environment
+        import os
+        if 'BBPATH' in os.environ:
+            del os.environ['BBPATH']
+
         # check that no arguments works
         self.runbbsetup("")
 
Signature · 1 line
2.39.5
#4 lore raw

PATCH 5/7 bitbake-setup: allow using {THISDIR}/my-layer

In reply to Alexander Kanavin

From: Yoann Congal <[email protected]>

This implement the ability to use "{THISDIR}/my-layer" in the "bb-layers" list. "{THISDIR}" is remplaced by the directory containing the configuration file.

In small projects, we try to keep the setup a simple as possible: a single git repo containing both the build confguration (e.g. a bitbake-setup configuration file) and the meta layer with project recipes/machine/distro.

This change allows this kind of setup:

├── meta-my-project/ # the project layer
└── my-project.conf.json   # the bb-setup configuration file

by writing, in my-project.conf.json:

  "bitbake-setup": {
    "configurations": [{
      "bb-layers": [
        "{THISDIR}/meta-my-project"

Note: in this case meta-my-project is not present as a "source", so, not handled by bb-setup update/status. It is expected of the user to handle this on their own (is our case, a simple git workflow).

---
 bin/bitbake-setup     | 20 +++++++++++++++++---
 lib/bb/tests/setup.py | 17 +++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)
bin/bitbake-setup +17 -3
index 36a1bbd91..de83d780b 100755
@@ -114,10 +114,23 @@ def checkout_layers(layers, layerdir, d):
                 os.remove(symlink)
             os.symlink(os.path.relpath(t,layerdir),symlink)
 
-def setup_bitbake_build(bitbake_config, layerdir, builddir):
+def setup_bitbake_build(bitbake_config, layerdir, builddir, thisdir):
     def _setup_build_conf(layers, build_conf_dir):
         os.makedirs(build_conf_dir)
-        layers_s = "\n".join(["  {} \\".format(os.path.join(layerdir,l)) for l in layers])
+        layers_s = []
+        for l in layers:
+            if l.startswith("{THISDIR}/"):
+                if thisdir:
+                    l = l.format(THISDIR=thisdir)
+                else:
+                    raise Exception("Configuration is using {THISDIR} to specify " \
+                    "a layer path relative to itself. This can be done only " \
+                    "when the configuration is specified by its path on local " \
+                    "disk, not when it's in a registry or is fetched over http.")
+            if not os.path.isabs(l):
+                l = os.path.join(layerdir, l)
+            layers_s.append("  {} \\".format(l))
+        layers_s = "\n".join(layers_s)
         bblayers_conf = """BBLAYERS ?= " \\
 {}
   "
@@ -237,7 +250,8 @@ def update_build(config, confdir, builddir, layerdir, d):
             layer_config[k]["git-remote"] = v["git-remote"]
     checkout_layers(layer_config, layerdir, d)
     bitbake_config = config["bitbake-config"]
-    setup_bitbake_build(bitbake_config, layerdir, builddir)
+    thisdir = os.path.dirname(config["path"]) if config["type"] == 'local' else None
+    setup_bitbake_build(bitbake_config, layerdir, builddir, thisdir)
 
 def int_input(allowed_values):
     n = None
lib/bb/tests/setup.py +15 -2
index 2076613d9..747a9b733 100644
@@ -130,6 +130,12 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 "description": "Gizmo notemplate build configuration",
                 "bb-layers": ["layerC","layerD/meta-layer"],
                 "oe-fragments": ["test-fragment-2"]
+            },
+            {
+                "name": "gizmo-notemplate-with-thisdir",
+                "description": "Gizmo notemplate build configuration using THISDIR",
+                "bb-layers": ["layerC","layerD/meta-layer","{THISDIR}/layerE/meta-layer"],
+                "oe-fragments": ["test-fragment-2"]
             }
         ]
     },
@@ -174,7 +180,14 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             with open(os.path.join(bb_conf_path, 'bblayers.conf')) as f:
                 bblayers = f.read()
                 for l in bitbake_config["bb-layers"]:
-                    self.assertIn(os.path.join(buildpath, 'layers', l), bblayers)
+                    if l.startswith('{THISDIR}/'):
+                        thisdir_layer = os.path.join(
+                            os.path.dirname(json_config["path"]),
+                            l.removeprefix("{THISDIR}/"),
+                        )
+                        self.assertIn(thisdir_layer, bblayers)
+                    else:
+                        self.assertIn(os.path.join(buildpath, "layers", l), bblayers)
 
         for f in bitbake_config["oe-fragments"]:
             self.assertTrue(os.path.exists(os.path.join(bb_conf_path, f)))
@@ -235,7 +248,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
 
         # test-config-1 is tested as a registry config, test-config-2 as a local file
         test_configurations = {'test-config-1': {'cmdline': 'test-config-1', 'buildconfigs':('gadget','gizmo','gadget-notemplate','gizmo-notemplate')},
-                               'test-config-2': {'cmdline': os.path.join(self.registrypath,'config-2/test-config-2.conf.json'), 'buildconfigs': ('gadget','gizmo','gadget-notemplate','gizmo-notemplate') } }
+                               'test-config-2': {'cmdline': os.path.join(self.registrypath,'config-2/test-config-2.conf.json'), 'buildconfigs': ('gadget','gizmo','gadget-notemplate','gizmo-notemplate', 'gizmo-notemplate-with-thisdir') } }
         for cf, v in test_configurations.items():
             for c in v['buildconfigs']:
                 out = self.runbbsetup("init --non-interactive {} {}".format(v['cmdline'], c))
Signature · 1 line
2.39.5
#5 lore raw

PATCH 6/7 bitbake-setup: clarify that default answer to prompts is no

In reply to Alexander Kanavin

From: Paul Gortmaker <[email protected]>

It is common practice to put the default choice in upper case for yes/no interactive prompts, so that when people just hit enter, they know what they are getting. An example that linux users are probably familiar with is "sensors-detect" from the "lm-sensors" package.

Unify all the prompts to be the same and indicate that the default answer from hitting enter is a no with an upper case N. No functional changes.

---
 bin/bitbake-setup | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
bin/bitbake-setup +3 -3
index de83d780b..bb466d85b 100755
@@ -418,7 +418,7 @@ def init_config(settings, args, d):
 
     print("Initializing a build in\n    {}".format(builddir))
     if not args.non_interactive:
-        y_or_n = input('Continue? y/n: ')
+        y_or_n = input('Continue? (y/N): ')
         if y_or_n != 'y':
             exit()
         print()
@@ -623,7 +623,7 @@ def write_settings(top_dir, force_replace, non_interactive=True):
         print('A new settings file will be created in\n    {}\n'.format(settings_path))
         print('A common site.conf file will be created, please edit or replace before running builds\n    {}\n'.format(siteconfpath))
         if not non_interactive:
-            y_or_n = input('Bitbake-setup will be configured with the above settings in {}, y/n: '.format(top_dir))
+            y_or_n = input('Bitbake-setup will be configured with the above settings in {}, (y/N): '.format(top_dir))
             if y_or_n != 'y':
                 print("\nYou can run 'bitbake-setup install-settings' to edit them before setting up builds")
                 exit()
@@ -669,7 +669,7 @@ def write_global_settings(settings_path, force_replace, non_interactive=True):
         print('Top directory prefix (where all top level directories are created) set to\n    {}\n'.format(settings['default']['top-dir-prefix']))
         print('Top directory name (this is added to the top directory prefix to form a top directory where builds are set up) set to\n    {}\n'.format(settings['default']['top-dir-name']))
         if not non_interactive:
-            y_or_n = input('Write out the global settings as specified above (y/n)? ')
+            y_or_n = input('Write out the global settings as specified above (y/N)? ')
             if y_or_n != 'y':
                 print("\nYou can run 'bitbake-setup install-global-settings' to edit them before setting up builds")
                 exit()
Signature · 1 line
2.39.5
#6 lore raw

PATCH 7/7 bitbake: registry: make a separate configuration for poky with sstate mirror

In reply to Alexander Kanavin

From: Alexander Kanavin <[email protected]>

Using sstate mirror places much higher requirements on both network robustness and network bandwidth than just fetching source code. When the network doesn't meet those, the user experience can be very frustrating as errors can be cryptic and intermittent, or bitbake would just seemingly do nothing for a long time.

Let's make sstate an opt-in, and provide a caution for using it. When it does work, it works wonderfully and does accelerate builds significantly.

---
 .../configurations/poky-master.conf.json           | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
default-registry/configurations/poky-master.conf.json +11 -3
index 3f1299179..60531ba02 100644
@@ -53,10 +53,7 @@
     "bitbake-setup": {
         "configurations": [
         {
-            "name": "poky",
-            "description": "Poky - The Yocto Project testing distribution",
             "bb-layers": ["openembedded-core/meta","meta-yocto/meta-yocto-bsp","meta-yocto/meta-poky"],
-            "oe-fragments": ["core/yocto/sstate-mirror-cdn"],
             "oe-fragments-one-of": {
                 "machine": {
                     "description": "Target machines",
@@ -66,7 +63,18 @@
                     "description": "Distribution configuration variants",
                     "options" : ["distro/poky", "distro/poky-altcfg", "distro/poky-tiny"]
                 }
+            },
+            "configurations": [
+            {
+                "name": "poky",
+                "description": "Poky - The Yocto Project testing distribution"
+            },
+            {
+                "name": "poky-with-sstate",
+                "description": "Poky - The Yocto Project testing distribution with internet sstate acceleration. Use with caution as it requires a completely robust local network with sufficient bandwidth.",
+                "oe-fragments": ["core/yocto/sstate-mirror-cdn"]
             }
+            ]
         }
         ]
     },
Signature · 1 line
2.39.5