diff mbox series

[3/3] bitbake-setup: default top-dir to empty string

Message ID 20251111223325.2034322-3-adrian.freihofer@siemens.com
State New
Headers show
Series [1/3] bitbake-setup: remove unused imports | expand

Commit Message

AdrianF Nov. 11, 2025, 10:33 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Change the default for top-dir to be an empty string instead of
"bitbake-builds". This makes the build directory be created directly
under the specified top-dir-prefix (which defaults to the current working
directory).

This allows to do:
    mkdir -p ~/temp/bb-test
    cd ~/temp/bb-test
    bitbake-setup init
      ...
      setup-dir = poky-altcfg

ending up with the build directory at:
  ~/temp/bb-test/poky-altcfg/build

bitbake-selftest: improve tests for top-dir-name setting

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 bin/bitbake-setup     |  2 +-
 lib/bb/tests/setup.py | 19 +++++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

Comments

Alexander Kanavin Nov. 12, 2025, 5:56 a.m. UTC | #1
This I have to firmly say no to.

bitbake-setup doesn't just create setup directories under the top dir,
it also creates local settings, site.conf, downloads and bitbake cache
in it. This would put all of it in the current directory. Then users
realize they messed up, and need it elsewhere, and it's tricky to
clean up because some of it is hidden (.-prefixed). It's much much
better to create a single directory - top-dir-name, and put all of it
there.

There's also something rather confusing about setting top-dir-name to
'' so that it would not be created at all. If you really not want it,
it should be a separate boolean setting.

Alex

On Tue, 11 Nov 2025 at 23:34, Adrian Freihofer via
lists.openembedded.org
<adrian.freihofer=siemens.com@lists.openembedded.org> wrote:
>
> From: Adrian Freihofer <adrian.freihofer@siemens.com>
>
> Change the default for top-dir to be an empty string instead of
> "bitbake-builds". This makes the build directory be created directly
> under the specified top-dir-prefix (which defaults to the current working
> directory).
>
> This allows to do:
>     mkdir -p ~/temp/bb-test
>     cd ~/temp/bb-test
>     bitbake-setup init
>       ...
>       setup-dir = poky-altcfg
>
> ending up with the build directory at:
>   ~/temp/bb-test/poky-altcfg/build
>
> bitbake-selftest: improve tests for top-dir-name setting
>
> Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
> ---
>  bin/bitbake-setup     |  2 +-
>  lib/bb/tests/setup.py | 19 +++++++++++++------
>  2 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/bin/bitbake-setup b/bin/bitbake-setup
> index bda62f5f4..5a0ad599a 100755
> --- a/bin/bitbake-setup
> +++ b/bin/bitbake-setup
> @@ -871,7 +871,7 @@ def main():
>          builtin_settings = {}
>          builtin_settings['default'] = {
>                           'top-dir-prefix':os.getcwd(),
> -                         'top-dir-name':'bitbake-builds',
> +                         'top-dir-name':'',
>                           'registry':default_registry,
>                           }
>
> diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py
> index d761ee734..85bb33db4 100644
> --- a/lib/bb/tests/setup.py
> +++ b/lib/bb/tests/setup.py
> @@ -233,22 +233,28 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
>          if 'BBPATH' in os.environ:
>              del os.environ['BBPATH']
>
> +        TOP_DIR_NAME = 'bitbake-builds'
> +
>          # check that no arguments works
>          self.runbbsetup("")
>
>          # check that --help works
>          self.runbbsetup("--help")
>
> -        # check that the default top-dir-prefix is cwd before any settings are configured
> +        # check that the default top-dir-prefix is cwd and top-dir-name is empty before any settings are configured
>          out = self.runbbsetup("settings list")
>          self.assertIn("default top-dir-prefix {}".format(os.getcwd()), out[0])
> +        self.assertIn("default top-dir-name", out[0])
>
> -        # set up global location for top-dir-prefix
> +        # set up global location for top-dir-prefix and top-dir-name
>          out = self.runbbsetup("settings set --global default top-dir-prefix {}".format(self.tempdir))
>          settings_path = "{}/global-config".format(self.tempdir)
>          self.assertIn(settings_path, out[0])
>          self.assertIn("From section 'default' the setting 'top-dir-prefix' was changed to", out[0])
>          self.assertIn("Settings written to".format(settings_path), out[0])
> +        out = self.runbbsetup('settings set --global default top-dir-name "{}"'.format(TOP_DIR_NAME))
> +        self.assertIn("From section 'default' the setting 'top-dir-name' was changed to '{}'".format(TOP_DIR_NAME), out[0])
> +        self.assertIn("Settings written to".format(settings_path), out[0])
>          out = self.runbbsetup("settings set --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')))
>          self.assertIn("From section 'default' the setting 'dl-dir' was changed to", out[0])
>          self.assertIn("Settings written to".format(settings_path), out[0])
> @@ -256,7 +262,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
>          # check that writing settings works and then adjust them to point to
>          # test registry repo
>          out = self.runbbsetup("settings set default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath))
> -        settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir)
> +        settings_path = os.path.join(self.tempdir, TOP_DIR_NAME, "settings.conf")
>          self.assertIn(settings_path, out[0])
>          self.assertIn("From section 'default' the setting 'registry' was changed to", out[0])
>          self.assertIn("Settings written to".format(settings_path), out[0])
> @@ -264,6 +270,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
>          # check that listing settings works
>          out = self.runbbsetup("settings list")
>          self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0])
> +        self.assertIn("default top-dir-name {}".format(TOP_DIR_NAME), out[0])
>          self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0])
>          self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0])
>
> @@ -307,7 +314,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 = os.path.join(self.tempdir, TOP_DIR_NAME, '{}-{}'.format(cf, c))
>                  self.check_setupdir_files(setuppath, test_file_content)
>                  os.environ['BBPATH'] = os.path.join(setuppath, 'build')
>                  out = self.runbbsetup("status")
> @@ -329,7 +336,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 = os.path.join(self.tempdir, TOP_DIR_NAME, 'test-config-1-{}'.format(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 +359,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 = os.path.join(self.tempdir, TOP_DIR_NAME, 'test-config-1-{}'.format(c))
>              os.environ['BBPATH'] = os.path.join(setuppath, 'build')
>              out = self.runbbsetup("status")
>              self.assertIn("Configuration in {} has changed:".format(setuppath), out[0])
> --
> 2.51.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#18339): https://lists.openembedded.org/g/bitbake-devel/message/18339
> Mute This Topic: https://lists.openembedded.org/mt/116247252/1686489
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
AdrianF Nov. 12, 2025, 8:05 a.m. UTC | #2
Hi Alex

The workflow looks like this:

  mkdir top-dir
  cd top-dir
  bitbake-setup init

If top-dir is created by bitbake-setup, we get one useless level of directories.

We could argue that it must be used like that:

  mkdir top-dir
  bitbake-setup --top-dir=top-dir

But that's not what I would expect or prefer to type.


Maybe the logic should be:
  top-dir-prefix=""
  top-dir=.
?

Regards,
Adrian
Alexander Kanavin Nov. 12, 2025, 8:24 a.m. UTC | #3
You don’t create a top dir, you create only the prefix for it and then run
‘init’ from it. Think of it as unpacking a tarball. This allows running
init without having to create a top dir at all, and it would still do the
right thing by default.

If you prefer that top dir is the current dir, and not just the prefix, you
can tweak the settings but I maintain that should not be default for all.

Alex

On Wed 12. Nov 2025 at 9.05, Freihofer, Adrian <adrian.freihofer@siemens.com>
wrote:

> Hi Alex
>
> The workflow looks like this:
>
>   mkdir top-dir
>   cd top-dir
>   bitbake-setup init
>
> If top-dir is created by bitbake-setup, we get one useless level of
> directories.
>
> We could argue that it must be used like that:
>
>   mkdir top-dir
>   bitbake-setup --top-dir=top-dir
>
> But that's not what I would expect or prefer to type.
>
>
> Maybe the logic should be:
>   top-dir-prefix=""
>   top-dir=.
> ?
>
> Regards,
> Adrian
>
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index bda62f5f4..5a0ad599a 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -871,7 +871,7 @@  def main():
         builtin_settings = {}
         builtin_settings['default'] = {
                          'top-dir-prefix':os.getcwd(),
-                         'top-dir-name':'bitbake-builds',
+                         'top-dir-name':'',
                          'registry':default_registry,
                          }
 
diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py
index d761ee734..85bb33db4 100644
--- a/lib/bb/tests/setup.py
+++ b/lib/bb/tests/setup.py
@@ -233,22 +233,28 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         if 'BBPATH' in os.environ:
             del os.environ['BBPATH']
 
+        TOP_DIR_NAME = 'bitbake-builds'
+
         # check that no arguments works
         self.runbbsetup("")
 
         # check that --help works
         self.runbbsetup("--help")
 
-        # check that the default top-dir-prefix is cwd before any settings are configured
+        # check that the default top-dir-prefix is cwd and top-dir-name is empty before any settings are configured
         out = self.runbbsetup("settings list")
         self.assertIn("default top-dir-prefix {}".format(os.getcwd()), out[0])
+        self.assertIn("default top-dir-name", out[0])
 
-        # set up global location for top-dir-prefix
+        # set up global location for top-dir-prefix and top-dir-name
         out = self.runbbsetup("settings set --global default top-dir-prefix {}".format(self.tempdir))
         settings_path = "{}/global-config".format(self.tempdir)
         self.assertIn(settings_path, out[0])
         self.assertIn("From section 'default' the setting 'top-dir-prefix' was changed to", out[0])
         self.assertIn("Settings written to".format(settings_path), out[0])
+        out = self.runbbsetup('settings set --global default top-dir-name "{}"'.format(TOP_DIR_NAME))
+        self.assertIn("From section 'default' the setting 'top-dir-name' was changed to '{}'".format(TOP_DIR_NAME), out[0])
+        self.assertIn("Settings written to".format(settings_path), out[0])
         out = self.runbbsetup("settings set --global default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')))
         self.assertIn("From section 'default' the setting 'dl-dir' was changed to", out[0])
         self.assertIn("Settings written to".format(settings_path), out[0])
@@ -256,7 +262,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         # check that writing settings works and then adjust them to point to
         # test registry repo
         out = self.runbbsetup("settings set default registry 'git://{};protocol=file;branch=master;rev=master'".format(self.registrypath))
-        settings_path = "{}/bitbake-builds/settings.conf".format(self.tempdir)
+        settings_path = os.path.join(self.tempdir, TOP_DIR_NAME, "settings.conf")
         self.assertIn(settings_path, out[0])
         self.assertIn("From section 'default' the setting 'registry' was changed to", out[0])
         self.assertIn("Settings written to".format(settings_path), out[0])
@@ -264,6 +270,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
         # check that listing settings works
         out = self.runbbsetup("settings list")
         self.assertIn("default top-dir-prefix {}".format(self.tempdir), out[0])
+        self.assertIn("default top-dir-name {}".format(TOP_DIR_NAME), out[0])
         self.assertIn("default dl-dir {}".format(os.path.join(self.tempdir, 'downloads')), out[0])
         self.assertIn("default registry {}".format('git://{};protocol=file;branch=master;rev=master'.format(self.registrypath)), out[0])
 
@@ -307,7 +314,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 = os.path.join(self.tempdir, TOP_DIR_NAME, '{}-{}'.format(cf, c))
                 self.check_setupdir_files(setuppath, test_file_content)
                 os.environ['BBPATH'] = os.path.join(setuppath, 'build')
                 out = self.runbbsetup("status")
@@ -329,7 +336,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 = os.path.join(self.tempdir, TOP_DIR_NAME, 'test-config-1-{}'.format(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 +359,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 = os.path.join(self.tempdir, TOP_DIR_NAME, 'test-config-1-{}'.format(c))
             os.environ['BBPATH'] = os.path.join(setuppath, 'build')
             out = self.runbbsetup("status")
             self.assertIn("Configuration in {} has changed:".format(setuppath), out[0])