-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): allow integration commands to resolve executables throug…
…h expansion Gives a tool built using `nodejs_binary` or `sh_binary`, the tool cannot be used as binary in an integration test command currently because: * Bazel location expansion does not respect the executable "FilesToRun" information of the binaries, and rather sees _all_ outputs, erroring that `$(locations X)` need to be used instead. See e.g. bazelbuild/bazel#11820) * The command is currently split by space and this decouples the Make funtion expression incorrectly into a broken expansion. e.g. `$(rootpath X)` will become `["$(rootpath", "X"]`). This commit fixes both things by relying on the Bazel `CommandHelper.java` class which handles the expansion of commands as expected, with similar semantics of a `genrule` as per `GenRuleBase.java`. This allows test authors to conveniently use a `nodejs_binary` or `sh_binary` as command binary because the `CommandHelper` knows exactly which targets provide executables or not. There is no good API for the plain Make expansion of a command itself, so we use a little trick (which is documented sufficiently in the code).
- Loading branch information
1 parent
c1dbbba
commit f35236e
Showing
5 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
bazel/integration/tests/external_command_script/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//bazel/integration:index.bzl", "integration_test") | ||
|
||
sh_binary( | ||
name = "external_script", | ||
srcs = ["external_script.sh"], | ||
) | ||
|
||
integration_test( | ||
name = "test", | ||
srcs = [], | ||
commands = [ | ||
"$(rootpath :external_script) First Second", | ||
], | ||
data = [":external_script"], | ||
) |
9 changes: 9 additions & 0 deletions
9
bazel/integration/tests/external_command_script/external_script.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if [[ "$1" != "First" ]]; then | ||
echo "First argument not matching: $1" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$2" != "Second" ]]; then | ||
echo "Second argument not matching: $2" | ||
exit 1 | ||
fi |