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. Signed-off-by: Jaipaul Cheernam <[email protected]> --- scripts/install-buildtools | 41 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/scripts/install-buildtools b/scripts/install-buildtools index b9c008a2ec..3525d8f7af 100755 --- a/scripts/install-buildtools +++ b/scripts/install-buildtools @@ -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") -- 2.34.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#238847): https://lists.openembedded.org/g/openembedded-core/message/238847 Mute This Topic: https://lists.openembedded.org/mt/119814299/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
