Skip to content

Bash is not necessarily in /bin/bash #250

Closed
@Kernald

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions