[PATCH] bitbake-setup: support --update-bb-conf on init and fix site.conf symlink for setup-dir == top-dir

"Daniel" <[email protected]> Mon, 29 Jun 2026 20:58:28 -0600
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <CANDCFSwD88aPfsKDqZE_SdybCn5xYBF1VpRqgwmhTEuJK=eLcQ@mail.gmail.com>
  Two fixes that work together to let "bitbake-setup init" preserve an
  existing bitbake build configuration (local.conf, bblayers.conf):

  1. Expose the existing update_bb_conf parameter through a new
     --update-bb-conf CLI flag on init, matching the semantics of
     "bitbake-setup update". This lets downstream projects re-run init
     (e.g. to refresh layers via --source-overrides) without losing
     their tracked conf files. The default remains "yes" for backward
     compatibility, so a fresh init is unaffected.

  2. Fix the site.conf symlink target when the setup directory is the
     same as the top directory. The target was always computed as
     setupdir/../site.conf, which only matches the actual site.conf
     location (top_dir/site.conf) when the setup directory is exactly
     one level below the top directory. When --setup-dir-name is given
     an absolute path equal to the top directory, the symlink ends up
     broken, which causes "diff -uNr" to fail with exit code 2 inside
     setup_bitbake_build(). That exception is raised before the
     update_bb_conf == 'no' branch can restore the original conf,
     defeating the new flag from #1. Prefer setupdir/site.conf when it
     exists, falling back to the previous behaviour otherwise.

  Together these changes make "bitbake-setup init --update-bb-conf=no"
  behave like Yocto's oe-init-build-env: the build environment is
  preserved across re-initializations.

  Signed-off-by: Daniel Chaves <[email protected]>
  ---
   bin/bitbake-setup | 9 +++++++--
   1 file changed, 7 insertions(+), 2 deletions(-)

  diff --git a/bin/bitbake-setup b/bin/bitbake-setup
  index 97ea08d..9a59a5a 100755
  --- a/bin/bitbake-setup
  +++ b/bin/bitbake-setup
  @@ -371,7 +371,10 @@ def setup_bitbake_build(bitbake_config,
layerdir, setupdir, thisdir, update_bb_c
       _prepend_passthrough_to_init_build_env(bitbake_builddir)

       siteconf_symlink = os.path.join(bitbake_confdir, "site.conf")
  -    siteconf = os.path.normpath(os.path.join(setupdir, '..', "site.conf"))
  +    if os.path.exists(os.path.join(setupdir, "site.conf")):
  +        siteconf = os.path.join(setupdir, "site.conf")
  +    else:
  +        siteconf = os.path.normpath(os.path.join(setupdir, '..',
"site.conf"))
       if os.path.lexists(siteconf_symlink):
           os.remove(siteconf_symlink)
       os.symlink(os.path.relpath(siteconf, bitbake_confdir), siteconf_symlink)
  @@ -870,7 +873,7 @@ def init_config(top_dir, settings, args):
       bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d)

       write_upstream_config(confdir, upstream_config)
  -    update_build(upstream_config, confdir, setupdir, layerdir, d,
update_bb_conf="yes", init_vscode=args.init_vscode)
  +    update_build(upstream_config, confdir, setupdir, layerdir, d,
update_bb_conf=args.update_bb_conf, init_vscode=args.init_vscode)

       bb.event.remove("bb.build.TaskProgress", None)

  @@ -1268,6 +1271,8 @@ def main():
                           help='Symlink local source into a build,
instead of getting it as prescribed by a configuration (useful for
local development).')
       parser_init.add_argument('--init-vscode',
action=argparse.BooleanOptionalAction,
default=bool(shutil.which('code')),
                           help='Generate VSCode workspace
configuration (default: %(default)s)')
  +    parser_init.add_argument('--update-bb-conf', choices=['prompt',
'yes', 'no'], default='yes',
  +                        help='Update bitbake configuration files
(bblayers.conf, local.conf) when re-initializing an existing setup
(default: %(default)s)')
       parser_init.set_defaults(func=init_config)

       parser_status = subparsers.add_parser('status', help='Check if
the setup needs to be synchronized with configuration')