bitbake: bitbake-setup: add 'install-buildtools' command

This basically calls install-buildtools from oe-core/poky, but
it ensures via command line parameters that the installation
location is stable and the downloads are preserved for reproducibility:

$ bin/bitbake-setup install-buildtools
Loading settings from /home/alex/bitbake-builds/bitbake-setup.conf

======
Buildtools archive is downloaded into /home/alex/bitbake-builds/yocto-master-testing/buildtools-downloads/20250319141333 and its content installed into /home/alex/bitbake-builds/yocto-master-testing/buildtools

... (output from install-buildtools script)
======

It also detects when buildtools are already installed, and will direct
users what to do:
======
alex@Zen2:/srv/work/alex/bitbake$ bin/bitbake-setup install-buildtools
Loading settings from /home/alex/bitbake-builds/bitbake-setup.conf

Buildtools are already installed in /home/alex/bitbake-builds/yocto-master-testing/buildtools.
If you wish to use them, you need to source the the environment setup script e.g.
$ . /home/alex/bitbake-builds/yocto-master-testing/buildtools/environment-setup-x86_64-pokysdk-linux
You can also re-run bitbake-setup install-buildtools with --force option to force a reinstallation
======

This commits includes fixes by Gyorgy Sarvari <skandigraun@gmail.com>
https://github.com/kanavin/bitbake/pull/2

(Bitbake rev: 3fe3096847046110c72b23fce37fb4a459b1d748)

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Alexander Kanavin 2025-09-29 14:56:09 +02:00 committed by Richard Purdie
parent a66c929a6a
commit 266379f0be
2 changed files with 46 additions and 0 deletions

View File

@ -16,6 +16,8 @@ import stat
import tempfile
import configparser
import datetime
import glob
import subprocess
default_registry = 'git://github.com/kanavin/bitbake-setup-configurations.git;protocol=https;branch=main;rev=main'
@ -554,6 +556,25 @@ def list_configs(settings, args, d):
json.dump(json_data, f, sort_keys=True, indent=4)
print("Available configurations written into {}".format(args.write_json))
def install_buildtools(settings, args, d):
buildtools_install_dir = os.path.join(args.build_dir, 'buildtools')
if os.path.exists(buildtools_install_dir):
if not args.force:
print("Buildtools are already installed in {}.".format(buildtools_install_dir))
env_scripts = glob.glob(os.path.join(buildtools_install_dir, 'environment-setup-*'))
if env_scripts:
print("If you wish to use them, you need to source the environment setup script e.g.")
for s in env_scripts:
print("$ . {}".format(s))
print("You can also re-run bitbake-setup install-buildtools with --force option to force a reinstallation.")
return
shutil.rmtree(buildtools_install_dir)
install_buildtools = os.path.join(args.build_dir, 'layers/oe-scripts/install-buildtools')
buildtools_download_dir = os.path.join(args.build_dir, 'buildtools-downloads/{}'.format(time.strftime("%Y%m%d%H%M%S")))
print("Buildtools archive is downloaded into {} and its content installed into {}".format(buildtools_download_dir, buildtools_install_dir))
subprocess.check_call("{} -d {} --downloads-directory {}".format(install_buildtools, buildtools_install_dir, buildtools_download_dir), shell=True)
def default_settings_path(top_dir):
return os.path.join(top_dir, 'bitbake-setup.conf')
@ -739,6 +760,11 @@ def main():
add_build_dir_arg(parser_update)
parser_update.set_defaults(func=build_update)
parser_install_buildtools = subparsers.add_parser('install-buildtools', help='Install buildtools which can help fulfil missing or incorrect dependencies on the host machine')
add_build_dir_arg(parser_install_buildtools)
parser_install_buildtools.add_argument('--force', action='store_true', help='Force a reinstall of buildtools over the previous installation.')
parser_install_buildtools.set_defaults(func=install_buildtools)
parser_install_settings = subparsers.add_parser('install-settings', help='Write a settings file with default values into the top level directory (contains the location of build configuration registry, downloads directory and other settings specific to a top directory)')
add_top_dir_arg(parser_install_settings)
parser_install_settings.set_defaults(func=write_settings)

View File

@ -49,6 +49,21 @@ with open(os.path.join(builddir, 'init-build-env'), 'w') as f:
"""
self.add_file_to_testrepo('scripts/oe-setup-build', oesetupbuild, script=True)
installbuildtools = """#!/usr/bin/env python3
import getopt
import sys
import os
opts, args = getopt.getopt(sys.argv[1:], "d:", ["downloads-directory="])
for option, value in opts:
if option == '-d':
installdir = value
print("Buildtools installed into {}".format(installdir))
os.makedirs(installdir)
"""
self.add_file_to_testrepo('scripts/install-buildtools', installbuildtools, script=True)
bitbakeconfigbuild = """#!/usr/bin/env python3
import os
import sys
@ -224,6 +239,11 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
out = self.runbbsetup("update")
self.assertIn("Configuration in {} has not changed".format(buildpath), out[0])
# install buildtools
out = self.runbbsetup("install-buildtools")
self.assertIn("Buildtools installed into", out[0])
self.assertTrue(os.path.exists(os.path.join(buildpath, 'buildtools')))
# change a file in the test layer repo, make a new commit and
# test that status/update correctly report the change and update the config
prev_test_file_content = test_file_content