2
0
Fork 0
mirror of https://github.com/bazelbuild/bazel-skylib synced 2024-11-27 05:43:25 +00:00

Use more portable #!/usr/bin/env bash shebang instead of hardcoded /bin/bash. (#329)

This commit is contained in:
Yesudeep Mangalapilly 2021-10-25 06:12:41 -07:00 committed by GitHub
parent 506c17293e
commit 8e923ca4b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 21 additions and 21 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #

View file

@ -18,7 +18,7 @@ load("//lib:new_sets.bzl", "sets")
def _empty_test_impl(ctx): def _empty_test_impl(ctx):
extension = ".bat" if ctx.attr.is_windows else ".sh" extension = ".bat" if ctx.attr.is_windows else ".sh"
content = "exit 0" if ctx.attr.is_windows else "#!/bin/bash\nexit 0" content = "exit 0" if ctx.attr.is_windows else "#!/usr/bin/env bash\nexit 0"
executable = ctx.actions.declare_file(ctx.label.name + extension) executable = ctx.actions.declare_file(ctx.label.name + extension)
ctx.actions.write( ctx.actions.write(
output = executable, output = executable,

View file

@ -86,7 +86,7 @@ if %ERRORLEVEL% neq 0 (
test_bin = ctx.actions.declare_file(ctx.label.name + "-test.sh") test_bin = ctx.actions.declare_file(ctx.label.name + "-test.sh")
ctx.actions.write( ctx.actions.write(
output = test_bin, output = test_bin,
content = r"""#!/bin/bash content = r"""#!/usr/bin/env bash
set -euo pipefail set -euo pipefail
F1="{file1}" F1="{file1}"
F2="{file2}" F2="{file2}"

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #

View file

@ -169,5 +169,5 @@ copy_file(
genrule( genrule(
name = "gen", name = "gen",
outs = ["b.txt"], outs = ["b.txt"],
cmd = "echo -e '#!/bin/bash\necho potato' > $@", cmd = "echo -e '#!/usr/bin/env bash\necho potato' > $@",
) )

View file

@ -1,2 +1,2 @@
#!/bin/bash #!/usr/bin/env bash
echo aaa echo aaa

View file

@ -1,2 +1,2 @@
#!/bin/bash #!/usr/bin/env bash
echo aaa echo aaa

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #
@ -42,25 +42,25 @@ source "$(rlocation bazel_skylib/tests/unittest.bash)" \
function test_copy_src() { function test_copy_src() {
cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out.txt)" >"$TEST_log" cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out.txt)" >"$TEST_log"
expect_log '^#!/bin/bash$' expect_log '^#!/usr/bin/env bash$'
expect_log '^echo aaa$' expect_log '^echo aaa$'
} }
function test_copy_src_symlink() { function test_copy_src_symlink() {
cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out-symlink.txt)" >"$TEST_log" cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out-symlink.txt)" >"$TEST_log"
expect_log '^#!/bin/bash$' expect_log '^#!/usr/bin/env bash$'
expect_log '^echo aaa$' expect_log '^echo aaa$'
} }
function test_copy_gen() { function test_copy_gen() {
cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out.txt)" >"$TEST_log" cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out.txt)" >"$TEST_log"
expect_log '^#!/bin/bash$' expect_log '^#!/usr/bin/env bash$'
expect_log '^echo potato$' expect_log '^echo potato$'
} }
function test_copy_gen_symlink() { function test_copy_gen_symlink() {
cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out-symlink.txt)" >"$TEST_log" cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out-symlink.txt)" >"$TEST_log"
expect_log '^#!/bin/bash$' expect_log '^#!/usr/bin/env bash$'
expect_log '^echo potato$' expect_log '^echo potato$'
} }

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #

View file

@ -82,7 +82,7 @@ write_file(
"@echo>>%OUT% ENV_PATH_CMD=(%ENV_PATH_CMD%)", "@echo>>%OUT% ENV_PATH_CMD=(%ENV_PATH_CMD%)",
], ],
"//conditions:default": [ "//conditions:default": [
"#!/bin/bash", "#!/usr/bin/env bash",
"echo > \"$OUT\" \"arg1=($1)\"", "echo > \"$OUT\" \"arg1=($1)\"",
"echo >> \"$OUT\" \"arg2=($2)\"", "echo >> \"$OUT\" \"arg2=($2)\"",
"echo >> \"$OUT\" \"ENV_LOCATION=($ENV_LOCATION)\"", "echo >> \"$OUT\" \"ENV_LOCATION=($ENV_LOCATION)\"",

View file

@ -69,7 +69,7 @@ def _shell_args_test_gen_impl(ctx):
"back`echo q`uote", "back`echo q`uote",
] ]
script_content = "\n".join([ script_content = "\n".join([
"#!/bin/bash", "#!/usr/bin/env bash",
"myarray=" + shell.array_literal(args), "myarray=" + shell.array_literal(args),
'output=$(echo "${myarray[@]}")', 'output=$(echo "${myarray[@]}")',
# For logging: # For logging:

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# #
# Copyright 2015 The Bazel Authors. All rights reserved. # Copyright 2015 The Bazel Authors. All rights reserved.
# #
@ -21,7 +21,7 @@
# A typical test suite looks like so: # A typical test suite looks like so:
# #
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
# #!/bin/bash # #!/usr/bin/env bash
# #
# source path/to/unittest.bash || exit 1 # source path/to/unittest.bash || exit 1
# #

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #

View file

@ -113,7 +113,7 @@ write_file(
name = "write_nonempty_bin", name = "write_nonempty_bin",
out = "out/nonempty.sh", out = "out/nonempty.sh",
content = [ content = [
"#!/bin/bash", "#!/usr/bin/env bash",
"echo potato", "echo potato",
], ],
is_executable = True, is_executable = True,

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2019 The Bazel Authors. All rights reserved. # Copyright 2019 The Bazel Authors. All rights reserved.
# #