Skip to contentSkip to conversation

bitbake-setup: Tell the user what to do if they don't like the top dir

PATCH New Alexander Kanavin 1 participant 3 messages Nov 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 bitbake-setup: Tell the user what to do if they don't like the top dir

From: "Joshua Watt via lists.openembedded.org" <[email protected]>

If the top level directory look new (e.g. doesn't contain a site.conf file), then instruct the user on how to choose a different directory if they desire. This should help clarify what bitbake-setup is about to do and how to change it if desired.

Changed the wording and order of the two possibilities: changing the settings comes first.

---
 bin/bitbake-setup | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
bin/bitbake-setup +11 -2
index ca0517924..cbcd637b2 100755
@@ -697,7 +697,16 @@ def create_siteconf(top_dir, non_interactive, settings):
     if os.path.exists(siteconfpath):
         print('A site.conf file already exists. Please remove it if you would like to replace it with a default one')
     else:
-        print('A common site.conf file will be created, please edit or replace before running builds\n    {}\n'.format(siteconfpath))
+        print(f'{top_dir} looks like a new top directory. If you would like to use a different directory, answer "n" below and either:')
+        print('\t1) Change the default bitbake-setup settings:')
+        print('\t\tbitbake-setup settings set default top-level-prefix <PATH>')
+        print('\t\tbitbake-setup settings set default top-level-name <NAME>')
+        print('\t2) Pass one or more options on the command line to change the top level directory in that invocation only:')
+        print('\t\tbitbake-setup --setting default top-dir-prefix <PATH> ...')
+        print('\t\tbitbake-setup --setting default top-dir-name <NAME> ...')
+        print()
+
+        print('A common site.conf file will be created, please check it is correct before running builds\n    {}\n'.format(siteconfpath))
         if not non_interactive:
             y_or_n = input('Proceed? (y/N): ')
             if y_or_n != 'y':
@@ -947,7 +956,7 @@ def main():
             settings_func(top_dir, all_settings, args)
             return
 
-        print('Bitbake-setup is using {} as top directory ("bitbake-setup settings --help" shows how to change it).\n'.format(top_dir, global_settings_path(args)))
+        print('Bitbake-setup is using {} as top directory.\n'.format(top_dir, global_settings_path(args)))
 
         if args.func == init_config:
             init_config(top_dir, all_settings, args)
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/3 bitbake-setup: Allow setup-dir-name to be specified in JSON (and use that in the default registry)

From: "Joshua Watt via lists.openembedded.org" <[email protected]>

Enables the JSON file to specify the preferred name of the setup directory with a 'setup-dir-name' key. This key can have variable expansions in the same format as python string.Template strings (which matches the shell variable expansion rules).

Variables that can be expanded are any fragment configuration prompted by the user (e.g. the keys in "oe-fragments-one-of"), or "$name" to use the name of the configuration (e.g. the .conf.json file).

default-registry: Change default setup dir

Uses the template mechanism to provide shorter setup-dir names by default. Specifically, the machine names are no longer part of the setup path since they are intended to be changed without needing a new setup directory.

Further tweaks by Alex:
- $name support is not actually implemented (as far as I see)
- add fallbacks to the full name if the short name already exists in the filesystem or there's a setting that forces full names
- add documentation for the setup dir entry in configs and the setting to ignore it
- adjust the schema
- adjust the selftest to include the feature and test for it

---
 bin/bitbake-setup                             | 16 ++++++++
 .../configurations/oe-nodistro.conf.json      |  1 +
 .../configurations/poky-master.conf.json      |  1 +
 .../bitbake-user-manual-environment-setup.rst | 39 +++++++++++++++++++
 lib/bb/tests/setup.py                         | 15 ++++---
 setup-schema/bitbake-setup.schema.json        |  4 ++
 6 files changed, 71 insertions(+), 5 deletions(-)
bin/bitbake-setup +16 -0
index cbcd637b2..b331eac53 100755
@@ -19,6 +19,7 @@ import copy
 import textwrap
 import signal
 import functools
+import string
 
 default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry")
 
@@ -492,6 +493,20 @@ def init_config(top_dir, settings, args):
         setup_dir_name = args.setup_dir_name
     else:
         setup_dir_name = "{}-{}".format(upstream_config['name']," ".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_"))
+        if 'setup-dir-name' in upstream_config['bitbake-config']:
+            mapping = {
+                    k: v.replace(" ", "-").replace("/", "_")
+                    for k, v in upstream_config['bitbake-config']['oe-fragment-choices'].items()
+            }
+            config_setup_dir_name = string.Template(upstream_config['bitbake-config']['setup-dir-name']).substitute(mapping)
+            config_setup_dir = os.path.join(top_dir, config_setup_dir_name)
+            if os.path.exists(config_setup_dir):
+                print("Setup directory {} (as suggested by configuration) already exists, using the full name instead.\n".format(config_setup_dir))
+            elif settings['default']['use-full-setup-dir-name'] != 'no':
+                print("Using the full setup directory name instead of {} suggested by configuration, as set in the settings.\n".format(config_setup_dir))
+            else:
+                setup_dir_name = config_setup_dir_name
+
         if not args.non_interactive:
             n = input(f"Enter setup directory name: [{setup_dir_name}] ")
             if n:
@@ -935,6 +950,7 @@ def main():
                          'top-dir-prefix':os.getcwd(),
                          'top-dir-name':'bitbake-builds',
                          'registry':default_registry,
+                         'use-full-setup-dir-name':'no',
                          }
 
         global_settings = load_settings(global_settings_path(args))
default-registry/configurations/oe-nodistro.conf.json +1 -0
index 9cd11a218..70ae6d364 100644
@@ -40,6 +40,7 @@
         {
             "name": "nodistro",
             "description": "OpenEmbedded 'nodistro'",
+            "setup-dir-name": "oe-nodistro",
             "bb-layers": ["openembedded-core/meta"],
             "oe-fragments-one-of": {
                 "machine": {
default-registry/configurations/poky-master.conf.json +1 -0
index 9b63ea5f0..81e0e47f0 100644
@@ -50,6 +50,7 @@
         "configurations": [
         {
             "bb-layers": ["openembedded-core/meta","meta-yocto/meta-yocto-bsp","meta-yocto/meta-poky"],
+            "setup-dir-name": "poky-master-$distro",
             "oe-fragments-one-of": {
                 "machine": {
                     "description": "Target machines",
doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst +39 -0
index dd8d08877..8a90e33e8 100644
@@ -504,6 +504,7 @@ A valid settings file would for example be:
    top-dir-name = bitbake-builds
    registry = /path/to/bitbake/default-registry
    dl-dir = /path/to/bitbake-setup-downloads
+   use-full-setup-dir-name = yes
 
 Settings and their values can be listed and modified with the ``bitbake-setup
 settings`` command. See the :ref:`ref-bbsetup-command-settings` section for
@@ -597,6 +598,17 @@ BitBake builds, so that there is a single directory containing a copy of
 everything needed to set up and run a BitBake build offline in a reproducible
 manner.
 
+.. _ref-bbsetup-setting-use-full-setup-dir-name:
+
+``use-full-setup-dir-name``
+---------------------------
+
+The :ref:`ref-bbsetup-setting-use-full-setup-dir-name` setting, if set to ``yes``
+will override the suggestions for the :term:`Setup` directory name made by
+``setup-dir-name`` entries in :term:`Generic Configuration` files. This
+will make the directory names longer, but fully specific: they will contain
+all selections made during initialization.
+
 .. _ref-bbsetup-section-config-reference:
 
 Generic Configuration Files Reference
@@ -802,6 +814,33 @@ They contain the following sections:
       See https://docs.yoctoproject.org/dev/ref-manual/fragments.html for
       more information of OpenEmbedded configuration fragments.
 
+   -  ``setup-dir-name`` (*optional*): a suggestion for the :term:`Setup`
+      directory name. Bitbake-setup will use it, unless it already exists, or
+      the :ref:`ref-bbsetup-setting-use-full-setup-dir-name` setting is set
+      to ``yes`` (in those cases, it will fall back to the built-in full name,
+      containing the full set of choices made during initialization).
+
+      This key can have variable expansions in the same format as python
+      string.Template strings (which matches the shell variable expansion rules):
+      https://docs.python.org/3/library/string.html#template-strings-strings .
+
+      Variables that can be expanded are any fragment configuration prompted
+      by the user (e.g. the keys in "oe-fragments-one-of")::
+
+            {
+                ...
+                "oe-fragments-one-of": {
+                    "machine": {
+                        "description": "Target machines",
+                        "options" : ["machine/gadget", "machine/gizmo"]
+                    }
+                },
+                "setup-dir-name": "somebuild-$machine"
+                ...
+            }
+
+      would expand to ``somebuild-machine_gadget``.
+
 Generic Configuration Examples
 ------------------------------
 
lib/bb/tests/setup.py +10 -5
index 27b9f288a..8b6d8bce6 100644
@@ -118,7 +118,8 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 "name": "gizmo",
                 "description": "Gizmo configuration",
                 "oe-template": "test-configuration-gizmo",
-                "oe-fragments": ["test-fragment-2"]
+                "oe-fragments": ["test-fragment-2"],
+                "setup-dir-name": "this-is-a-custom-gizmo-build"
             },
             {
                 "name": "gizmo-env-passthrough",
@@ -227,6 +228,10 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             self.assertTrue('BUILD_SERVER' in init_build_env)
             # a more throrough test could be to initialize a bitbake build-env, export FOO to the shell environment, set the env-passthrough on it and finally check against 'bitbake-getvar FOO'
 
+    def get_setup_path(self, cf, c):
+        if c == 'gizmo':
+            return os.path.join(self.tempdir, 'bitbake-builds', 'this-is-a-custom-gizmo-build')
+        return os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c))
 
     def test_setup(self):
         # unset BBPATH to ensure tests run in isolation from the existing bitbake environment
@@ -307,7 +312,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         for cf, v in test_configurations.items():
             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))
+                setuppath = self.get_setup_path(cf, c)
                 self.check_setupdir_files(setuppath, test_file_content)
                 os.environ['BBPATH'] = os.path.join(setuppath, 'build')
                 out = self.runbbsetup("status")
@@ -329,7 +334,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                   'gizmo-env-passthrough',
                   'gizmo-no-fragment',
                   'gadget-notemplate', 'gizmo-notemplate'):
-            setuppath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c))
+            setuppath = self.get_setup_path('test-config-1', c)
             os.environ['BBPATH'] = os.path.join(setuppath, 'build')
             out = self.runbbsetup("status")
             self.assertIn("Layer repository file://{} checked out into {}/layers/test-repo updated revision master from".format(self.testrepopath, setuppath), out[0])
@@ -352,7 +357,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                   'gizmo-env-passthrough',
                   'gizmo-no-fragment',
                   'gadget-notemplate', 'gizmo-notemplate'):
-            setuppath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c))
+            setuppath = self.get_setup_path('test-config-1', c)
             os.environ['BBPATH'] = os.path.join(setuppath, 'build')
             out = self.runbbsetup("status")
             self.assertIn("Configuration in {} has changed:".format(setuppath), out[0])
@@ -385,7 +390,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                   'gizmo-env-passthrough',
                   'gizmo-no-fragment',
                   'gadget-notemplate', 'gizmo-notemplate'):
-            setuppath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c))
+            setuppath = self.get_setup_path('test-config-1', c)
             os.environ['BBPATH'] = os.path.join(setuppath, 'build')
             # write something in local.conf and bblayers.conf
             for f in ["local.conf", "bblayers.conf"]:
setup-schema/bitbake-setup.schema.json +4 -0
index 7030f1d6d..027ba2568 100644
@@ -96,6 +96,10 @@
                                 "items": {
                                     "type": "string"
                                 }
+                            },
+                            "setup-dir-name": {
+                                "type": "string",
+                                "description": "A suggestion for the setup directory name, $-prefixed keys from oe-fragments-one-of will be substituted with user selections."
                             }
                         },
                         "additionalProperties": false
Signature · 1 line
2.39.5
#2 lore raw

PATCH 3/3 bitbake-setup: add information about enabling fragments to toolcfg.conf, tool output and written-out README

In reply to Alexander Kanavin

From: Alexander Kanavin <[email protected]>

Also adjust the order of those pieces to be more logical, and tweak the newlines so that each item is separated by a single newline from the previous and next ones.

---
 bin/bitbake-setup | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
bin/bitbake-setup +15 -3
index b331eac53..a8da10e4f 100755
@@ -259,6 +259,12 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c
     shell = "bash"
     fragments = bitbake_config.get("oe-fragments", []) + sorted(bitbake_config.get("oe-fragment-choices",{}).values())
     if fragments:
+        toolcfg_file = os.path.join(bitbake_builddir,'conf/toolcfg.conf')
+        toolcfg_comment = """# Run 'bitbake-config-build enable-fragment <fragment-name>' to enable additional fragments
+# or replace built-in ones (e.g. machine/<name> or distro/<name> to change MACHINE or DISTRO).
+"""
+        with open(toolcfg_file, 'w') as f:
+            f.write(toolcfg_comment)
         bb.process.run("{} -c '. {} && bitbake-config-build enable-fragment {}'".format(shell, init_script, " ".join(fragments)))
 
     if os.path.exists(backup_bitbake_confdir):
@@ -287,23 +293,29 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c
         print('Applying upstream bitbake configuration changes')
         print(f'Leaving the previous configuration in {backup_bitbake_confdir}')
 
-    print("This bitbake configuration provides:\n    {}\n".format(bitbake_config["description"]))
+    fragment_note = "Run 'bitbake-config-build enable-fragment <fragment-name>' to enable additional fragments or replace built-in ones (e.g. machine/<name> or distro/<name> to change MACHINE or DISTRO)."
+
     readme = """{}\n\nAdditional information is in {} and {}\n
-Source the environment using '. {}' to run builds from the command line.
+Source the environment using '. {}' to run builds from the command line.\n
+{}\n
 The bitbake configuration files (local.conf, bblayers.conf and more) can be found in {}/conf
 """.format(
         bitbake_config["description"],
         os.path.join(bitbake_builddir,'conf/conf-summary.txt'),
         os.path.join(bitbake_builddir,'conf/conf-notes.txt'),
         init_script,
+        fragment_note,
         bitbake_builddir
         )
     readme_file = os.path.join(bitbake_builddir, "README")
     with open(readme_file, 'w') as f:
         f.write(readme)
+
+    print("This bitbake configuration provides:\n    {}\n".format(bitbake_config["description"]))
     print("Usage instructions and additional information are in\n     {}\n".format(readme_file))
+    print("To run builds, source the environment using\n    . {}\n".format(init_script))
+    print("{}\n".format(fragment_note))
     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    . {}".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