Windows fixes for buildifier check, fix and test#89
Windows fixes for buildifier check, fix and test#89peakschris wants to merge 1 commit intokeith:mainfrom
Conversation
|
any way we can verify the previous failure on CI? |
|
@keith @cgrindel I've merged #90 here. Please would you run this CI? Expected results: How should we handle the linux failure? change the test to ignore that failure and raise an extra defect? Thanks, Chris |
|
Started CI |
|
@keith thank you. Results as expected. Would to like me to disable the two failing cases for non-windows? |
|
Looks like it failed on Linux but not windows? Maybe misunderstanding what you expected? |
|
I added new cases within my new test for: buildifier invoke (norunfiles) - passes windows & linux The linux failures are demonstrating existing problems (or limitations), and are not addressed by this PR. If you agree, I can I open a new defect and disable these two cases on linux for now. Most people won't hit these as no runfiles on linux is uncommon. I won't have time to work on these. Cheers, Chris |
|
I just approved CI. |
|
@cgrindel could you rerun this one? |
|
Awesome! Windows & Linux are clean... Mac seems to be waiting on a runner... What are next steps with this PR? |
| data = [ | ||
| "//tests/unittest", | ||
| "@bazel_tools//tools/bash/runfiles", | ||
| "//:WORKSPACE", |
There was a problem hiding this comment.
Can you explain why you are exporting the WORKSPACE and including it in this test? If it is to create a workspace for the test, it is better to create a new WORKSPACE that refers to the parent using local_repository.
There was a problem hiding this comment.
@cgrindel sorry for the delay, if you look at runner.bat.template line 24, we need to find the absolute path to the workspace directory (it is available through envvar during bazel run, but not bazel test), and there is no good way in bat/bazel to do this other than looking at the target of a symlink. Exporting and depending on WORKSPACE gives us this symlink. Any other file in root folder of workspace would also be fine.
There was a problem hiding this comment.
Are you trying to find the root of a test workspace? I would expect a buildifier test to create a workspace, execute buildifier, and then verify the changes. I don't believe that any of that requires access to this repository's WORKSPACE file.
There was a problem hiding this comment.
buildifier_test already has sandbox escape mechanism, implemented as the 'sandbox' and 'workspace' attributes to buildifier_test macro. This is documented here:
, and is one of the things that this PR fixes on windows.There was a problem hiding this comment.
Perhaps, I am not familiar enough with this use case. I will defer to @keith.
|
I was about to work on a fix but found out you already did it. May I ask what remains to be done here? |
This applies Windows fixes proposed by: keith#89
Currently, `buildifier` targets don't work out of the box on Windows - credits to Ofek for reporting. Sadly, it turns out that two separate attempts have already been made to remedy this: 1. In the upstream `bazelbuild/buildtools` (`go` source, but `workspace` suitable): bazelbuild/buildtools#1230 (merged) 2. `keith/buildifier-prebuilt` (`bzlmod` suitable, providing slightly outdated `go` binaries published by `bazelbuild/buildtools`): keith/buildifier-prebuilt#89 (well tested, but pending CI feedback... for months!) Inspired by Tony's [tips](https://datadoghq.atlassian.net/browse/ABLD-174?focusedCommentId=2644283), the present change proposes the "least intrusive" change so that: - we don't need to start a third effort (rules, `.bash` and `.bat` scripts), - we benefit from the validated and merged upstream behavior, - we don't depend on the goodwill of `keith/buildifier-prebuilt` to publish the version `8.2.1` of the binaries (nor subsequent versions), - we don't have to manage a complex patch, but instead simply inhibit the upstream lines that we do not need, given `buildifier` implementations are provided by `multitool` again. In short, this change combines the best of both worlds through a simple indirection made possible by the configurability of upstream rules which, unlike `keith/buildifier-prebuilt`, allow us to define which implementation of `buildifier` to use.
Currently, `buildifier` targets don't work out of the box on Windows - credits to Ofek for reporting. Sadly, it turns out that two separate attempts have already been made to remedy this: 1. In the upstream `bazelbuild/buildtools` (`go` source, but `workspace` suitable): bazelbuild/buildtools#1230 (merged) 2. `keith/buildifier-prebuilt` (`bzlmod` suitable, providing slightly outdated `go` binaries published by `bazelbuild/buildtools`): keith/buildifier-prebuilt#89 (well tested, but pending CI feedback... for months!) Inspired by Tony's [tips](https://datadoghq.atlassian.net/browse/ABLD-174?focusedCommentId=2644283), the present change proposes the "least intrusive" change so that: - we don't need to start a third effort (rules, `.bash` and `.bat` scripts), - we benefit from the validated and merged upstream behavior, - we don't depend on the goodwill of `keith/buildifier-prebuilt` to publish the version `8.2.1` of the binaries (nor subsequent versions), - we don't have to manage a complex patch, but instead simply inhibit the upstream lines that we do not need, given `buildifier` implementations are provided by `multitool` again. In short, this change combines the best of both worlds through a simple indirection made possible by the configurability of upstream rules which, unlike `keith/buildifier-prebuilt`, allow us to define which implementation of `buildifier` to use.
### Motivation Currently, `buildifier` targets don't work out of the box on Windows - credits to @ofek for reporting. Sadly, it turns out that two separate attempts have already been made to remedy this: 1. In the upstream `bazelbuild/buildtools` (`go` source, but only `workspace`-suitable): bazelbuild/buildtools#1230 (merged) 2. `keith/buildifier-prebuilt` (`bzlmod`-suitable, and providing -slightly outdated- `go` binaries published by `bazelbuild/buildtools`): keith/buildifier-prebuilt#89 (well tested, but pending CI feedback... for months!) ### What does this PR do? Inspired by some of @aiuto's [tips](https://datadoghq.atlassian.net/browse/ABLD-174?focusedCommentId=2644283): > [1.b.] instead of pointing to the toolchain type defined in buildifier_prebuilt, point to buildifier via multitools. > [2.a.] revert prebuilt_buildtools.json to 5fd6373 The present change proposes the "least intrusive" change so that: - we don't need to start a third effort (own rules, `.bash` and `.bat` scripts), - we benefit from the validated and merged upstream behavior, - we don't depend on the goodwill of `keith/buildifier-prebuilt` to publish the version `8.2.1` of the binaries (nor subsequent versions), - we don't have to manage a complex patch, but instead simply inhibit the upstream lines that we do not need, given `buildifier` implementations are provided by `multitool` (again). In short, this change combines the best of both worlds through a simple indirection made possible by the configurability of upstream rules which, unlike `keith/buildifier-prebuilt`, allow us to define which implementation of `buildifier` to use. ### Describe how you validated your changes I used another branch to verify this works under Windows as well: https://github.com/DataDog/datadog-agent/blob/026042234ee811fd1641a2417893c08008860186/.gitlab/bazel/build-deps.yaml#L39
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two disinct community efforts wrt runner script templates, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts like for Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - bazelbuild#1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
This change aims at making `buildtools/buildifier` more modular and easier to consume by enabling use of prebuilt binaries without pulling in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates. Today, `buildifier/BUILD.bazel` exposes two different sets of rules: - exports for runner script templates (`runner.bash.template`, `runner.bat.template`) as well as `README.md`, - `go` build & `sh` test rules which require external repos (`rules_go`, `rules_shell`) even for consumers who don't need to build the `buildifier` binary. It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream `bazelbuild/buildtools` and the derived `keith/buildifier-prebuilt` (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows support: - #1230 - keith/buildifier-prebuilt#89 (open for a year) Intended benefits of this change: - decoupling: by moving `go_binary` and `sh_test` targets into `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer requires `rules_go` nor `rules_shell`, - flexibility: users can either build binaries from source (via `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g. via `multitool`) while still consuming the same upstream runner script templates, - backward compatibility: aliases keep `//buildifier:buildifier*` working by delegating to `//buildifier/cmd:buildifier*`.
|
One point that might be missing is the handling of ++ characters in bzlmod case which I think would still be failing after this patch. Though given that this one goes on for 18 months+ it would be great to merge as is and then add ++ handling as a minor patch on top of this one as a separate issue (trivial powershell or some not so trivial workarounds without powershell). @keith , @cgrindel , would it be possible to re-trigger CI and if all great to merge this one? |
|
rebased in order to get it to run again |
@keith, thanks a lot - this is now all green. Anything else left to do on this PR or is it ready to be merged? |

This PR includes fixes to support check, fix and test on Windows. Fixes #88
Tested with bazel 7.2.1 and both --noenable_runfiles and --enable_runfiles
All validations performed with --windows_enable_symlinks enabled
for buildifier.test to work, I used the following config. I could not get test to work without specifying workspace and no_sandbox.