Skip to content
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

bazel mod tidy fails when nothing changes #21651

Closed
tyler-french opened this issue Mar 12, 2024 · 12 comments
Closed

bazel mod tidy fails when nothing changes #21651

tyler-french opened this issue Mar 12, 2024 · 12 comments
Assignees
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@tyler-french
Copy link

tyler-french commented Mar 12, 2024

Description of the bug:

MODULE.bazel is correct, I then run bazel mod tidy and get an error:

% bazel mod --enable_bzlmod tidy       
ERROR: Unexpected error while running buildozer: Process exited with status 3:
. Type 'bazel help mod' for syntax and help.

Next, I mess up the formatting (but not the syntax), and run bazel mod tidy again, and it succeeds:

% bazel mod --enable_bzlmod tidy 

Next, I run it again, and Bazel crashes

% bazel mod --enable_bzlmod tidy
 checking cached actions
    Fetching repository @@bazel_tools; starting
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphValue$$Lambda/0x0000000800590400@11c76f5f' (requested by nodes 'com.google.devtools.build.lib.bazel.bzlmod.BazelModTidyValue$$Lambda/0x0000000800593800@5733c27d')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:550)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException: null value in entry: googleapis=null
        at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
        at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:54)
        at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:341)
        at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:450)
        at com.google.devtools.build.lib.bazel.bzlmod.Module.getRepoMappingWithBazelDepsOnly(Module.java:67)
        at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.getExtensionUsagesById(BazelDepGraphFunction.java:233)
        at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.compute(BazelDepGraphFunction.java:126)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
        ... 7 more

This will continue with all --enable_bzlmod builds until MODULE.bazel.lock is deleted

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

See description

Which operating system are you running Bazel on?

Linux AMD 64

What is the output of bazel info release?

% bazel info release Starting local Bazel server and connecting to it... INFO: Invocation ID: f7b2a282-a126-4ed2-9b9b-a7eab1906e22 release 7.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

Internal Uber codebase

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

https://github.com/bazelbuild/bazel/pull/21265/files

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@fmeum
Copy link
Collaborator

fmeum commented Mar 12, 2024

@Wyverald Looks like two separate bugs to me. I can fix the exit code behavior, but not sure what the stack trace is about.

@fmeum
Copy link
Collaborator

fmeum commented Mar 12, 2024

@tyler-french Could you share where Uber Bazel Extensions commands: is coming from? Is that a Bazel wrapper?

@fmeum
Copy link
Collaborator

fmeum commented Mar 12, 2024

@bazel-io fork 7.1.1

@tyler-french
Copy link
Author

tyler-french commented Mar 12, 2024

@tyler-french Could you share where Uber Bazel Extensions commands: is coming from? Is that a Bazel wrapper?

@fmeum This is just a bug in our wrapper, it is succeeding, just not recognizing mod as a command.

Let me remove this from the Bug

    known_cmds = {
        "analyze-profile", "aquery", "build", "canonicalize-flags", "clean",
        "coverage", "cquery", "dump", "fetch", "help", "info", "license",
        "mobile-install", "modquery", "print_action", "query", "run",
        "shutdown", "sync", "test", "version", "debug"
    }

fmeum added a commit to fmeum/bazel that referenced this issue Mar 12, 2024
@tyler-french
Copy link
Author

tyler-french commented Mar 12, 2024

Here's our MODULE.bazel file with many things redacted:

module(name = "go-code")

# Version Declarations

bazel_gazelle_version = "0.35.0"

...

# Bazel Modules
bazel_dep(name = "bazel_skylib", version = bazel_skylib_version)
bazel_dep(name = "com_google_googleapis", version = googleapis_revision, repo_name = "googleapis")
bazel_dep(name = "gazelle", version = bazel_gazelle_version, repo_name = "bazel_gazelle")
bazel_dep(name = "hermetic_cc_toolchain", version = hermetic_cc_toolchain_version)
bazel_dep(name = "platforms", version = platforms_version)
bazel_dep(name = "rules_go", version = rules_go_version, repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_proto", version = rules_proto_version)
bazel_dep(name = "rules_python", version = rules_python_version)
bazel_dep(name = "rules_python_gazelle_plugin", version = rules_python_version, repo_name = "com_github_bazelbuild_rules_python_gazelle")

# Overrides
# An archive_override is required because we can't patch the MODULE.bazel file using a single_version_override.
archive_override(
    module_name = "rules_go",
    ...
)

single_version_override(
    module_name = "gazelle",
    ...
)

archive_override(
    module_name = "com_google_googleapis",
    patches = [
        "//patches:googleapis_add_bzlmod_support.patch",  # https://github.com/googleapis/googleapis/pull/855
        "//patches:googleapis.patch",
    ],
    ...
)

###########################################
####### SDK/Toolchain Registrations #######
###########################################

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
    name = "go_sdk",
    patches = [
        ...
    ],
    sdks = {
        ...
    }
)
go_sdk.nogo(
    nogo = "//:default_nogo",
)
use_repo(go_sdk, "go_sdk")

toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")

# These C++ toolchains will only be considered when @zig_sdk//libc:flavor
# is set. That is usually done by providing a `--platforms=...` or by a
# transition.
register_toolchains(
    ...
)

# Repos and Extentions
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = True,
    is_default = True,
    python_version = python_version,
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "pip",
    python_version = python_version,
    requirements_lock = "//third_party/python:requirements.lock",
)

artifactory = use_extension("//third_party:artifactory.bzl", "artifactory")
use_repo(artifactory, "artifactory_urls")

###########################################
############ HTTP DEPENDENCIES ############
###########################################

...

switched_rules = use_extension("@googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages()
use_repo(switched_rules, "com_google_googleapis_imports")

###########################################
############# GO DEPENDENCIES #############
###########################################

# Load all go repos from the go.mod file.
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//src/code.uber.internal:go.mod")

# Similar to `gazelle update-repos`, apply default attributes to all go_deps.
go_deps.gazelle_default_attributes(
    build_extra_args = ["-go_naming_convention_external=go_default_library"],
    build_file_generation = "on",
    directives = [
        "gazelle:proto disable",
    ],
)

########################################################################
# BELOW are overrides for Go dependencies
# TODO(tfrench): this should automatically populated by https://github.com/bazelbuild/bazel-gazelle/pull/1677

...

# This is a minimal set of dependencies needed to build a few targets in Go Monorepo.
# Once WORKSPACE is removed, this will need to list all directly depended on Go Dependencies.
use_repo(
    go_deps,
    "com_github_gogo_protobuf",
    ...
)

@Wyverald Wyverald added P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests and removed untriaged labels Mar 12, 2024
@Wyverald Wyverald assigned Wyverald and fmeum and unassigned sgowroji and iancha1992 Mar 12, 2024
@fmeum
Copy link
Collaborator

fmeum commented Mar 12, 2024

One half of this is fixed by #21657.

@Wyverald Are you looking into the other failure or should I?

@Wyverald
Copy link
Member

sorry, I haven't had time yet (busy with some other stuff today). Will take a look in a bit if you can't get to it!

@fmeum
Copy link
Collaborator

fmeum commented Mar 12, 2024

I can reproduce this locally. What's quite interesting is that googleapis having a version set in bazel_dep despite being subject to a non-registry override is required for the crash.

It's likely that this regressed when I removed the name attribute from the lockfile. I can dig deeper and submit a fix.

copybara-service bot pushed a commit that referenced this issue Mar 12, 2024
Buildozer has a non-zero exit code if it didn't make any changes.

Work towards #21651

Closes #21657.

PiperOrigin-RevId: 615184752
Change-Id: Ib89928974e2cd014cec968193d35fd74e2d01261
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Mar 12, 2024
Buildozer has a non-zero exit code if it didn't make any changes.

Work towards bazelbuild#21651

Closes bazelbuild#21657.

PiperOrigin-RevId: 615184752
Change-Id: Ib89928974e2cd014cec968193d35fd74e2d01261
iancha1992 pushed a commit to iancha1992/bazel that referenced this issue Mar 12, 2024
Buildozer has a non-zero exit code if it didn't make any changes.

Work towards bazelbuild#21651

Closes bazelbuild#21657.

Commit
bazelbuild@98f29db

PiperOrigin-RevId: 615184752
Change-Id: Ib89928974e2cd014cec968193d35fd74e2d01261

Co-authored-by: Fabian Meumertzheim <[email protected]>
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Mar 14, 2024
* Fixes a crash when using a non-registry override with a specified version:

```
Caused by: java.lang.NullPointerException: null value in entry: foo=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
	at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:54)
	at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:345)
	at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:454)
	at com.google.devtools.build.lib.bazel.bzlmod.Module.getRepoMappingWithBazelDepsOnly(Module.java:67)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.getExtensionUsagesById(BazelDepGraphFunction.java:233)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.compute(BazelDepGraphFunction.java:126)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

* Fixes a crash for root modules with no extension usages:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.keySet()" because the return value of "com.google.common.collect.ImmutableMap.get(Object)" is null
	at com.google.devtools.build.lib.bazel.bzlmod.BazelModTidyFunction.compute(BazelModTidyFunction.java:85)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

Fixes bazelbuild#21651

Closes bazelbuild#21686.

PiperOrigin-RevId: 615826860
Change-Id: I22be3fd53d0dc97aec92afe3dc51a9d6b7e60c98
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Mar 14, 2024
* Fixes a crash when using a non-registry override with a specified version:

```
Caused by: java.lang.NullPointerException: null value in entry: foo=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
	at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:54)
	at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:345)
	at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:454)
	at com.google.devtools.build.lib.bazel.bzlmod.Module.getRepoMappingWithBazelDepsOnly(Module.java:67)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.getExtensionUsagesById(BazelDepGraphFunction.java:233)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.compute(BazelDepGraphFunction.java:126)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

* Fixes a crash for root modules with no extension usages:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.keySet()" because the return value of "com.google.common.collect.ImmutableMap.get(Object)" is null
	at com.google.devtools.build.lib.bazel.bzlmod.BazelModTidyFunction.compute(BazelModTidyFunction.java:85)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

Fixes bazelbuild#21651

Closes bazelbuild#21686.

PiperOrigin-RevId: 615826860
Change-Id: I22be3fd53d0dc97aec92afe3dc51a9d6b7e60c98
github-merge-queue bot pushed a commit that referenced this issue Mar 14, 2024
* Fixes a crash when using a non-registry override with a specified
version:

```
Caused by: java.lang.NullPointerException: null value in entry: foo=null
	at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
	at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:54)
	at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:345)
	at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:454)
	at com.google.devtools.build.lib.bazel.bzlmod.Module.getRepoMappingWithBazelDepsOnly(Module.java:67)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.getExtensionUsagesById(BazelDepGraphFunction.java:233)
	at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.compute(BazelDepGraphFunction.java:126)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

* Fixes a crash for root modules with no extension usages:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.keySet()" because the return value of "com.google.common.collect.ImmutableMap.get(Object)" is null
	at com.google.devtools.build.lib.bazel.bzlmod.BazelModTidyFunction.compute(BazelModTidyFunction.java:85)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:464)
```

Fixes #21651

Closes #21686.

Commit
77369dc

PiperOrigin-RevId: 615826860
Change-Id: I22be3fd53d0dc97aec92afe3dc51a9d6b7e60c98

Co-authored-by: Fabian Meumertzheim <[email protected]>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.1 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=7.1.1rc1. Thanks!

@stagnation
Copy link
Contributor

stagnation commented Apr 24, 2024

I hit this with 7.1.1
When trying to convert bb-deployments to use only bzlmod.
buildbarn/bb-deployments#136

$ bazel version
Bazelisk version: development
Starting local Bazel server and connecting to it...
Build label: 7.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Mar 21 18:08:37 2024 (1711044517)
Build timestamp: 1711044517
Build timestamp as int: 1711044517

bb-deployments $ bazel build //... 
Starting local Bazel server and connecting to it...
Computing main repo mapping:
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphValue$$Lambda/0x00000008004beb48@6c9547d' (requested by nodes 'Key{repoName=@@, rootModuleShouldSeeWorkspaceRepos=true}')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:550)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException: null value in entry: googletest=null
        at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:33)
        at com.google.common.collect.ImmutableMapEntry.<init>(ImmutableMapEntry.java:54)
        at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:341)
        at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:450)
        at com.google.devtools.build.lib.bazel.bzlmod.Module.getRepoMappingWithBazelDepsOnly(Module.java:67)
        at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.getExtensionUsagesById(BazelDepGraphFunction.java:233)
        at com.google.devtools.build.lib.bazel.bzlmod.BazelDepGraphFunction.compute(BazelDepGraphFunction.java:126)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
        ... 7 more

Twiddling a little bit with the module file it sometimes prints this warning:

WARNING: For repository 'googletest', the root module requires module version [email protected], but got [email protected] in the resolved dependency graph.

$ rg [email protected]
MODULE.bazel.lock
507:    "[email protected]": {
510:      "key": "[email protected]",
682:        "com_google_googletest": "[email protected]",
1661:        "com_google_googletest": "[email protected]",
2783:        "com_google_googletest": "[email protected]",
3447:        "com_google_googletest": "[email protected]",

@fmeum
Copy link
Collaborator

fmeum commented Apr 24, 2024

@stagnation Could you try deleting your lockfile once? If the lockfile was generated by pre-7.1.1 bazel mod tidy, you will still see the issue with 7.1.1.

@stagnation
Copy link
Contributor

stagnation commented Apr 24, 2024

Cheers, I guess that works or something similar. I just tried a build with last_green which kicked it just right to start working again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants