install-buildtools: make SDK name configurable via --sdk-name
PATCH 1/1 install-buildtools: make SDK name configurable via --sdk-name
The environment setup script installed by a buildtools tarball is named environment-setup-<arch>-<sdk-name>-linux. The script hardcodes "pokysdk" for this component, so any distro that ships buildtools under a different SDK name gets a FileNotFoundError after an otherwise successful install.
Add --sdk-name to let callers specify the SDK name. Defaults to "pokysdk" so all existing usage is unaffected. Invalid values (empty string or a value containing path separators) are rejected early with a clear error. A friendly error message is also emitted when the resolved path does not exist, pointing the user at the --sdk-name option as the likely cause.
--- scripts/install-buildtools | 41 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-)
scripts/install-buildtools +30 -11
@@ -113,6 +113,14 @@ def remove_quotes(var): return var +def sdk_name_arg(value): + if not value.strip(): + raise argparse.ArgumentTypeError("SDK name is empty") + if os.path.basename(value) != value: + raise argparse.ArgumentTypeError("SDK name must not contain path separators") + return value + + def main(): global DEFAULT_INSTALL_DIR global DEFAULT_BASE_URL
@@ -175,6 +183,12 @@ def main(): default=True, action='store_true') group.add_argument('-n', '--no-check', help='disable checksum validation', dest="check", action='store_false') + parser.add_argument('--sdk-name', + type=sdk_name_arg, + help='SDK name used in the environment setup script ' + '(e.g. "customsdk" for environment-setup-<arch>-customsdk-linux). ' + 'Defaults to "pokysdk".', + default='pokysdk') parser.add_argument('-D', '--debug', help='enable debug output', action='store_true') parser.add_argument('-q', '--quiet', help='print only errors',
@@ -305,17 +319,22 @@ def main(): # Setup the environment logger.info("Setting up the environment") regex = re.compile(r'^(?P<export>export )?(?P<env_var>[A-Z_]+)=(?P<env_val>.+)$') - with open("%s/environment-setup-%s-pokysdk-linux" % - (install_dir, arch), 'rb') as f: - for line in f: - match = regex.search(line.decode('utf-8')) - logger.debug("export regex: %s" % match) - if match: - env_var = match.group('env_var') - logger.debug("env_var: %s" % env_var) - env_val = remove_quotes(match.group('env_val')) - logger.debug("env_val: %s" % env_val) - os.environ[env_var] = env_val + env_setup_script = os.path.join(install_dir, "environment-setup-%s-%s-linux" % (arch, args.sdk_name)) + try: + with open(env_setup_script, 'rb') as f: + for line in f: + match = regex.search(line.decode('utf-8')) + logger.debug("export regex: %s" % match) + if match: + env_var = match.group('env_var') + logger.debug("env_var: %s" % env_var) + env_val = remove_quotes(match.group('env_val')) + logger.debug("env_val: %s" % env_val) + os.environ[env_var] = env_val + except FileNotFoundError: + logger.error("Environment setup script not found: %s" % env_setup_script) + logger.error("Check that --sdk-name '%s' matches the installed SDK name." % args.sdk_name) + return 1 # Test installation logger.info("Testing installation")
Signature · 1 line
2.34.1
Quoted 11 lines · Jaipaul Cheernam via lists.openembedded.org
The environment setup script installed by a buildtools tarball is named environment-setup-<arch>-<sdk-name>-linux. The script hardcodes "pokysdk" for this component, so any distro that ships buildtools under a different SDK name gets a FileNotFoundError after an otherwise successful install.
Add --sdk-name to let callers specify the SDK name. Defaults to "pokysdk" so all existing usage is unaffected. Invalid values (empty string or a value containing path separators) are rejected early with a clear error. A friendly error message is also emitted when the resolved path does not exist, pointing the user at the --sdk-name option as the likely cause.
Quoted 4 lines
Signed-off-by Jaipaul Cheernam <[email protected]>---
scripts/install-buildtools | 41 ++++++++++++++++++++++++++++----------1 file changed, 30 insertions(+), 11 deletions(-)
Given we're installing this and there should be only one of them, perhaps we should just use glob.glob to find the name? We could error if more than one is found?
Cheers,
Richard
PATCH v2 1/1 install-buildtools: auto-discover environment setup script via glob
In reply to Jaipaul CheernamThe environment setup script installed by a buildtools tarball is named environment-setup-<arch>-<sdk-name>-linux. The script previously hardcoded "pokysdk" for this component, so any distro that ships buildtools under a different SDK name gets a FileNotFoundError after an otherwise successful install.
Use glob.glob() to discover the environment setup script by pattern matching on environment-setup-<arch>-*-linux in the install directory. Since a buildtools install should produce exactly one such script, error out if zero or more than one match is found.
--- scripts/install-buildtools | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/install-buildtools +12 -2
@@ -33,6 +33,7 @@ # import argparse +import glob import logging import os import platform
@@ -305,8 +306,17 @@ def main(): # Setup the environment logger.info("Setting up the environment") regex = re.compile(r'^(?P<export>export )?(?P<env_var>[A-Z_]+)=(?P<env_val>.+)$') - with open("%s/environment-setup-%s-pokysdk-linux" % - (install_dir, arch), 'rb') as f: + pattern = os.path.join(install_dir, "environment-setup-%s-*-linux" % arch) + matches = glob.glob(pattern) + if len(matches) == 0: + logger.error("No environment setup script matching %s" % pattern) + return 1 + if len(matches) > 1: + logger.error("Multiple environment setup scripts found: %s" + % " ".join(matches)) + return 1 + logger.debug("Using environment setup script: %s" % matches[0]) + with open(matches[0], 'rb') as f: for line in f: match = regex.search(line.decode('utf-8')) logger.debug("export regex: %s" % match)
Signature · 1 line
2.34.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [OE-core] [PATCH v2] install-buildtools: auto-discover environment setup script via glob
Hi ,
Please let me know feedback on below patch .
Regards,
Jaipaul
________________________________
From: [email protected] <[email protected]> on behalf of Jaipaul Cheernam via lists.openembedded.org <[email protected]>
Sent: Tuesday, June 16, 2026 12:57 PM
To: [email protected] <[email protected]>
Cc: Jaipaul Cheernam <[email protected]>
Subject: [OE-core] [PATCH v2] install-buildtools: auto-discover environment setup script via glob
The environment setup script installed by a buildtools tarball is named environment-setup-<arch>-<sdk-name>-linux. The script previously hardcoded "pokysdk" for this component, so any distro that ships buildtools under a different SDK name gets a FileNotFoundError after an otherwise successful install.
Use glob.glob() to discover the environment setup script by pattern matching on environment-setup-<arch>-*-linux in the install directory. Since a buildtools install should produce exactly one such script, error out if zero or more than one match is found.
--- scripts/install-buildtools | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/install-buildtools +12 -2
@@ -33,6 +33,7 @@ # import argparse +import glob import logging import os import platform
@@ -305,8 +306,17 @@ def main(): # Setup the environment logger.info("Setting up the environment") regex = re.compile(r'^(?P<export>export )?(?P<env_var>[A-Z_]+)=(?P<env_val>.+)$') - with open("%s/environment-setup-%s-pokysdk-linux" % - (install_dir, arch), 'rb') as f: + pattern = os.path.join(install_dir, "environment-setup-%s-*-linux" % arch) + matches = glob.glob(pattern) + if len(matches) == 0: + logger.error("No environment setup script matching %s" % pattern) + return 1 + if len(matches) > 1: + logger.error("Multiple environment setup scripts found: %s" + % " ".join(matches)) + return 1 + logger.debug("Using environment setup script: %s" % matches[0]) + with open(matches[0], 'rb') as f: for line in f: match = regex.search(line.decode('utf-8')) logger.debug("export regex: %s" % match)
--
2.34.1