rules_jvm_external
rules_jvm_external copied to clipboard
Pinning artifacts on Windows does not work?
Windows 10 Bazel 1.2.1 rules_jvm_external 3.0 and 2.10 were tried.
I have a small project that uses rules_jvm_external. If I run bazel build //...
Then everything works fine with just Coursier But when trying to pin the jars by running bazel run @maven//:pin
I get the following error:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\USER_NAME> cd C:\PROJECT_LOCATION
PS C:\PROJECT_LOCATION> bazel run @maven//:pin
Starting local Bazel server and connecting to it...
INFO: Analyzed target @maven//:pin (1 packages loaded, 1 target configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base C:/users/USER_NAME/_bazel_USER_NAME/x2wgegak/sandbox
INFO: Elapsed time: 583.469s, Critical Path: 0.04s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
FATAL: ExecuteProgram(C:\users\USER_NAME\_bazel_USER_NAME\x2wgegak\external\maven\pin) failed: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("C:\users\USER_NAME\_bazel_USER_NAME\x2wgegak\external\maven\pin"): %1 is not a valid Win32 application.
(error: 193)
PS C:\PROJECT_LOCATION>
If i go look at the pin file that was created, I can see that it is a shell script:
#!/usr/bin/env bash
set -euo pipefail
readonly maven_install_json_loc=$BUILD_WORKSPACE_DIRECTORY/maven_install.json
readonly execution_root=$(bazel info execution_root)
readonly workspace_name=$(basename $execution_root)
cat <<"RULES_JVM_EXTERNAL_EOF" | python -m json.tool > $maven_install_json_loc
<THE EXPECTED OUTPUT IS HERE>
RULES_JVM_EXTERNAL_EOF
if [ "False" = "True" ]; then
echo "Successfully pinned resolved artifacts for @maven, $maven_install_json_loc is now up-to-date."
else
echo "Successfully pinned resolved artifacts for @maven in $maven_install_json_loc." \
"This file should be checked in your version control system."
echo
echo "Next, please update your WORKSPACE file by adding the maven_install_json attribute" \
"and loading pinned_maven_install from @maven//:defs.bzl".
echo
echo "For example:"
echo
cat <<EOF
=============================================================
maven_install(
artifacts = # ...,
repositories = # ...,
maven_install_json = "@$workspace_name//:maven_install.json",
)
load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
=============================================================
EOF
echo
echo "To update maven_install.json, run this command to re-pin the unpinned repository:"
echo
echo " bazel run @unpinned_maven//:pin"
fi
echo
From here, I can manually copy the section <THE EXPECTED OUTPUT IS HERE>
and then create the file maven_install.json
and paste the output in. Then if i do a normal bazel build the pined jars are used as expected. So everything works except the creating of the json file.
Thank you,
PS My apologies if this should have been a stackoverflow question instead of a github issue.
I think the fix here is to write the pin bash script as a batch script for proper portability. Unfortunately, this is where I need help, as I don't primarily work with Windows. Happy to take a PR to make pinning work on Windows.
where does this shell script get generated exactly?