-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bazel mod tidy
#20483
Add bazel mod tidy
#20483
Conversation
ebabd9e
to
389e53c
Compare
@aherrmann @cgrindel in case you want to give this an early try The CI failure does appear to be a flake. |
@fmeum Thanks! I gave it a quick shot on rules_nixpkgs_core and it seems to be working there. (I tested removing a |
f3fc1fe
to
8039efa
Compare
@meteorcloudy @Wyverald I resolved all conflicts and also fixed a bug in the buildozer module that resulted in a platform-dependent lockfile entry. |
.equals(FailureDetails.ExternalDeps.Code.INVALID_EXTENSION_IMPORT)) { | ||
throw new BazelModTidyFunctionException(e, SkyFunctionException.Transience.PERSISTENT); | ||
} | ||
// This is an error bazel mod tidy can fix, so don't fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this actually work? last time I checked, we can't actually recover from errors in any Skyframe node evaluation. So even if we don't throw anything here, the evaluation would end in error (presumably at ModCommand.java:234)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand this, we can't recover in a SkyFunction, but here we perform a top-level evaluation (implicitly in keep going mode: https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java;l=2262;drc=0e1dd2afc8dfe69033abbc7852bb23bd0a9237f6). The individual values will still be marked as failed, but we should be able to extract the individual exceptions in this way. There is a test case covering this case, but if I misunderstood how this works it might of course not catch every issue due to the inherent non-determinism of Skyframe evaluation order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! I think the 'implicitly in keep-going mode' bit is crucial. But it still surprises me a bit that the whole evaluation doesn't end up in error (even though we can go through all the failed nodes). Anyhow, this is definitely not blocking the whole PR, especially as you do have a test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it still surprises me a bit that the whole evaluation doesn't end up in error (even though we can go through all the failed nodes).
You are right, that is indeed surprising. Maybe this is because the nodes we actually requested did not fail themselves and we are in "keep going" mode? It would be nice to get confirmation on this.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModTidyFunction.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionContext.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
if (modTidyValue.lockfileMode().equals(LockfileMode.UPDATE)) { | ||
// We cannot safely rerun Skyframe evaluation here to pick up the updated module file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part seems rather tricky so I'd just like to flag it so I can think about it more. My immediate reaction was that we should just trigger whatever mechanism we have for detecting diffs/dirtiness (there seem to be quite a few of those... DiffAwareness, DirtinessChecker, etc). But some half-hearted digging revealed that it might be even hackier than what you're doing here. So I'd like to come back later with a clearer head and review this part more carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with this approach based on @lberki's comments on the design doc. I don't know whether triggering any of the diff awareness logic directly could help work around the various file system caches.
Another argument in favor of the current approach is that it could be fully dropped with the proposed new lockfile format: The lockfile wouldn't change at all if only imports are changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another argument in favor of the current approach is that it could be fully dropped with the proposed new lockfile format: The lockfile wouldn't change at all if only imports are changed.
To confirm, this is because we send out the lockfile event (or whatever it's called...) before we check the validity of use_repo
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how your question relates to the quote (did you mean to respond on the thread about Skyframe evaluation failing?). The fixup events are emitted before we check the validity of use_repo
, which is indeed crucial, as otherwise we would exit the SkyFunction with a failure before we learn of the fixup command. However, this was already necessary before this PR, simply to show the user-facing warning before running into the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good, good -- nevermind the quote, not important :)
1fdcced
to
d644e21
Compare
@fmeum Can you please resolve the conflict? |
Done! |
I resolved the new conflict. |
The remaining failure looks like a flake, but a retry didn't fix it. |
@bazel-io fork 7.1.0 |
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes bazelbuild#20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit RELNOTES: The new `bazel mod tidy` subcommand automatically updates `use_repo` calls in the `MODULE.bazel` file for extensions that use `module_ctx.extension_metadata`. Closes #20483. PiperOrigin-RevId: 605021386 Change-Id: Idb1f22c51e126328b9efd6a5a6d6f89d77b9308d Closes #21241
The changes in this PR have been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=last_rc. |
Thanks! I repeated my test from above. diff --git a/core/MODULE.bazel b/core/MODULE.bazel
index 52953ec..5202e78 100644
--- a/core/MODULE.bazel
+++ b/core/MODULE.bazel
@@ -9,7 +9,7 @@ bazel_dep(name = "bazel_skylib", version = "1.0.3")
nix_repo = use_extension("//extensions:repository.bzl", "nix_repo")
nix_repo.github(
name = "nixpkgs",
- tag = "22.11",
sha256 = "ddc3428d9e1a381b7476750ac4dbea7a42885cbbe6e1af44b21d6447c9609a6f",
+ tag = "22.11",
)
use_repo(nix_repo, "nixpkgs") Is that intentional? IIRC this did not happen when I last tested it and the proposal only speaks about |
This is a result of buildifier formatting the module file, which is a side effect of running buildozer on it. Since buildozer by default only reformats if it made any changes, the |
Implements https://docs.google.com/document/d/13LbK_1WhA4la0eH7yISjnMvXs2cKFXD-adKPu0i0RK0/edit
RELNOTES: The new
bazel mod tidy
subcommand automatically updatesuse_repo
calls in theMODULE.bazel
file for extensions that usemodule_ctx.extension_metadata
.