Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash is not necessarily in /bin/bash #250

Open
Kernald opened this issue Jul 26, 2024 · 0 comments
Open

Bash is not necessarily in /bin/bash #250

Kernald opened this issue Jul 26, 2024 · 0 comments

Comments

@Kernald
Copy link

Kernald commented Jul 26, 2024

In this helper:

for tool in ["aapt", "aapt2", "aidl", "zipalign"]:
native.genrule(
name = tool + "_runner",
srcs = [],
outs = [tool + "_runner.sh"],
cmd = "\n".join([
"cat > $@ << 'EOF'",
"#!/bin/bash",
"set -eu",
# The tools under build-tools/VERSION require the libraries under
# build-tools/VERSION/lib, so we can't simply depend on them as a
# file like we do with aapt.
# On Windows however we can use these binaries directly because
# there's no runfiles support so Bazel just creates a junction to
# {SDK}/build-tools.
"SDK=$${0}.runfiles/%s" % name,
# If $${SDK} is not a directory, it means that this tool is running
# from a runfiles directory, in the case of
# android_instrumentation_test. Hence, use the androidsdk
# that's already present in the runfiles of the current context.
"if [[ ! -d $${SDK} ]] ; then",
" SDK=$$(pwd)/../%s" % name,
"fi",
"tool=$${SDK}/build-tools/%s/%s" % (build_tools_directory, tool),
"exec env LD_LIBRARY_PATH=$${SDK}/build-tools/%s/lib64 $$tool $$*" % build_tools_directory,
"EOF\n",
]),
)

Bash is hard-coded in /bin/bash, which is not portable - e.g. NixOS doesn't have it there. Relying on e.g. /usr/bin/env bash instead would be more portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant