Open cgrindel opened 2 years ago
Ah yea, the only reason I didn't do a shell script before was because that seemed unnecessary, but yea this is a good reason
BTW a shell wrapper is not needed at all:
alias(
name = "buildozer",
actual = "@buildifier_prebuilt//:buildozer",
)
Then here is an example execution:
$ bazel run :buildozer -- 'print actual' //:buildozer
INFO: Invocation ID: 3f4494b3-882e-4c28-a33f-2e37ccb33baa
INFO: Analyzed target //:buildozer (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @buildifier_prebuilt~6.0.0.1//buildozer:buildozer up-to-date:
dist/bin/external/buildifier_prebuilt~6.0.0.1/buildozer/buildozer
INFO: Elapsed time: 0.192s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: dist/bin/external/buildifier_prebuilt~6.0.0.1/buildozer/buildozer 'print actual' //:buildozer
@buildifier_prebuilt//:buildozer
A wrapper is indeed not needed (even without the alias):
bazel run @buildifier_prebuilt//:buildozer print //:all
works for me.
Modifying files also work. So it looks like this issue can be closed?
So it looks like this issue can be closed?
I'm not sure. I get a similar (the same?) issues as OP. It seems like Buildozer doesn't find any of the targets I specify. Example:
$ # running using a compiled go binary:
$ ~/go/bin/buildozer 'print name' '//src/pyle_xc/fab/package_tester/...:*'
test_data_filegroup
device_data_filegroup
device_mapping_test
...
$ running using the bazel target
$ bazel run -- @buildifier_prebuilt//:buildozer 'print name' !$
bazel run -- @buildifier_prebuilt//:buildozer 'print name' '//src/pyle_xc/fab/package_tester/...:*'
INFO: Analyzed target @@buildifier_prebuilt~//:buildozer (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @@buildifier_prebuilt~//buildozer:buildozer up-to-date:
bazel-bin/external/buildifier_prebuilt~/buildozer/buildozer
INFO: Elapsed time: 0.476s, Critical Path: 0.18s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/external/buildifier_prebuilt~/buildozer/buildozer 'print name' '//src/pyle_xc/fab/package_tester/...:*'
$ # nothing printed :-(
I tried using an alias
as well as suggested a couple comments up. Same thing.
Thoughts?
Edit: trying on a different target set results in an error. Yay something new!
$ ~/go/bin/buildozer 'print name' '//:all'
python_requirements_lockfile
buildifier.check
buildifier.fix
buildozer
modules_map
gazelle_python_manifest
gazelle
$ bazel run //:buildozer -- 'print name' '//:all'
INFO: Analyzed target //:buildozer (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @@buildifier_prebuilt~//buildozer:buildozer up-to-date:
bazel-bin/external/buildifier_prebuilt~/buildozer/buildozer
INFO: Elapsed time: 0.789s, Critical Path: 0.18s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/external/buildifier_prebuilt~/buildozer/buildozer 'print name' //:all
/usr/local/google/home/dthor/.cache/bazel/_bazel_dthor/dbe74c4144b5c9a438d84a119652bef9/execroot/_main/bazel-out/k8-fastbuild/bin/external/buildifier_prebuilt~/buildozer/buildozer.runfiles/_main/BUILD: file not found or not readable
For you it's running inside the sandbox and not chdir into BUILD_WORKSPACE_DIRECTORY when it starts https://blog.aspect.build/bazel-can-write-to-the-source-folder.
Maybe you can create a repro setup? It does switch to the right place for us @ booking, but we mostly pass buildozer as a tool to other binaries and those make the chdir so we may not be seeing the issue.
Thanks @manuelnaranjo. I was able to get things working with the following:
sh_binary
targetI still think that the "right" way is to add a bash runner template for buildozer
- there's already one for buildifier
after all - but I don't consider it a super high priority.
The current README.md states that the following should work:
However, this will not work correctly. Bazel will execute the command in a sandbox, not the workspace. Hence,
buildozer
will never find any of the paths.A possible fix would be to provide a shell script that performs a
cd "${BUILD_WORKSPACE_DIRECTORY}"
and then executes thebuildozer
commands.NOTE: The
buildifier
would also benefit from this technique as today one must specify absolute paths forbuildifier
to find files and directories.