Hi,

I was trying to install the buildtools by using the scripts/install-buildtools script, however the call fails. The issue I found seems a bit weird, as IMHO the script would always fail, hence I am not sure whether it's really an issue or I am misusing the script. Anyway, I am using the script from the openembedded-core - OpenEmbedded Core layer repository, commit 41390f52.

The command executed:
./scripts/install-buildtools --debug --without-extended-buildtools --directory ./build-tools --base-url https://downloads.yoctoproject.org/releases/yocto --release yocto-4.0.14 --installer-version 4.0.14
The command fails and its output is given in [1].

Now, I dug a bit deeper and found two potential issues (if they are even issues, I am not sure anymore).

1. First one is in here. Basically, while environment variables are read from build-tools/environment-setup-x86_64-pokysdk-linux (see [2] for its content), some of them are read with double quotes (e.g. PATH) and as such written in os.environ (here), which makes them not correctly used later on. Some come without quotes and are fine to be used (e.g., PKG_CONFIG_LIBDIR). A solution to this problem is removing the double quotes from envvar if present in the envvar, e.g., ENVVAR="foo" becomes ENVVAR=foo and as such is written in os.environ.

2. Another issue I found is related to this line. If the command is called with --directory, as in my case, the function starts_with will always fail because which_tool will never start with install_dir. The only case where this is not an issue is in when --directory is omitted, since INSTALL_DIR is used in that case and its a full path already. A solution is also simple, we can just check if install_dir is in which_tool, instead of whether which_tool starts with install_dir.

Now my question is am I misunderstanding something or am I misusing the install-buildtools script somehow? If this is really an issue I'd be more than glad to provide a patch.

Cheers
Aleksandar

[1]
DEBUG: milestone regex: None
INFO: Fetching buildtools installer
INFO: Fetching buildtools installer checksum
DEBUG: checksum regex match: <re.Match object; span=(0, 113), match='62e811c2f1a91f6d2d5e07ee3031af9bff58c15f515ff5968>
DEBUG: checksum: 62e811c2f1a91f6d2d5e07ee3031af9bff58c15f515ff59688bf39f1f8a4341d
DEBUG: path: None
DEBUG: filename: x86_64-buildtools-nativesdk-standalone-4.0.14.sh
INFO: Checksum success
INFO: Making installer executable
DEBUG: os.stat_result(st_mode=33252, st_ino=2376165, st_dev=2080, st_nlink=1, st_uid=1000, st_gid=1000, st_size=29509071, st_atime=1702587153, st_mtime=1699048064, st_ctime=1702587153)
Build tools installer version 4.0.14
====================================
You are about to install the SDK to "/home/anikolic/git/openembedded-core/build-tools". Proceed [Y/n]? Y
Extracting SDK...........done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /home/anikolic/git/openembedded-core/build-tools/environment-setup-x86_64-pokysdk-linux
INFO: Setting up the environment
DEBUG: export regex: <re.Match object; span=(0, 361), match='export PATH="/home/anikolic/git/openembedded-core>
DEBUG: env_var: PATH
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/usr/bin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/usr/sbin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/bin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/sbin:$PATH"
DEBUG: export regex: <re.Match object; span=(0, 109), match='export OECORE_NATIVE_SYSROOT="/home/anikolic/git/>
DEBUG: env_var: OECORE_NATIVE_SYSROOT
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux"
DEBUG: export regex: <re.Match object; span=(0, 136), match='export GIT_SSL_CAINFO="/home/anikolic/git/openemb>
DEBUG: env_var: GIT_SSL_CAINFO
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
DEBUG: export regex: <re.Match object; span=(0, 135), match='export SSL_CERT_FILE="/home/anikolic/git/openembe>
DEBUG: env_var: SSL_CERT_FILE
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
DEBUG: export regex: <re.Match object; span=(0, 140), match='export REQUESTS_CA_BUNDLE="/home/anikolic/git/ope>
DEBUG: env_var: REQUESTS_CA_BUNDLE
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
DEBUG: export regex: <re.Match object; span=(0, 136), match='export CURL_CA_BUNDLE="/home/anikolic/git/openemb>
DEBUG: env_var: CURL_CA_BUNDLE
DEBUG: env_val: "/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
DEBUG: export regex: <re.Match object; span=(0, 80), match='HOST_PKG_PATH=$(command -p pkg-config --variable=>
DEBUG: env_var: HOST_PKG_PATH
DEBUG: env_val: $(command -p pkg-config --variable=pc_path pkg-config 2>/dev/null)
DEBUG: export regex: <re.Match object; span=(0, 280), match='export PKG_CONFIG_LIBDIR=/home/anikolic/git/opene>
DEBUG: env_var: PKG_CONFIG_LIBDIR
DEBUG: env_val: /home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux//usr/lib/pkgconfig:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux//usr/share/pkgconfig:${HOST_PKG_PATH:-/usr/lib/pkgconfig:/usr/share/pkgconfig}DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
DEBUG: export regex: None
INFO: Testing installation
DEBUG: extended regex: None
DEBUG: install_dir: ./build-tools
DEBUG: cmd: ['/usr/bin/which', 'tar']
DEBUG: tool: tar
DEBUG: proc.args: ['/usr/bin/which', 'tar']
DEBUG: proc.communicate(): output b''
DEBUG: proc.communicate(): errors None
DEBUG: which tar:
ERROR: Something went wrong: tar not found in ./build-tools
ERROR: Something went wrong: installation failed
[2]
export PATH="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/usr/bin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/usr/sbin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/bin:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/sbin:$PATH"
export OECORE_NATIVE_SYSROOT="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux"
export GIT_SSL_CAINFO="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
export SSL_CERT_FILE="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
export REQUESTS_CA_BUNDLE="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
export CURL_CA_BUNDLE="/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux/etc/ssl/certs/ca-certificates.crt"
HOST_PKG_PATH=$(command -p pkg-config --variable=pc_path pkg-config 2>/dev/null)
export PKG_CONFIG_LIBDIR=/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux//usr/lib/pkgconfig:/home/anikolic/git/openembedded-core/build-tools/sysroots/x86_64-pokysdk-linux//usr/share/pkgconfig:${HOST_PKG_PATH:-/usr/lib/pkgconfig:/usr/share/pkgconfig}
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
        for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
                . $envfile
        done
fi
# We have to unset this else it can confuse oe-selftest and other tools
# which may also use the overlapping namespace.
unset OECORE_NATIVE_SYSROOT