bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.98k stars 4.03k forks source link

Crash in vendor subcommand #23521

Open criemen opened 1 week ago

criemen commented 1 week ago

Description of the bug:

 criemen@Corneliuss-MBP  ~/repos/semmle-code   main ±  bazel vendor --vendor_dir=vendor_src //...
Starting local Bazel server and connecting to it...
INFO: Invocation ID: a3f127d2-153b-400d-8a1e-55c75c5d6396
Loading: 1 packages loaded
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@@WORKSPACE.bazel' (requested by nodes '[/private/var/tmp/_bazel_criemen/267ec2c545f0139b2caed9502387afe1]/[external/WORKSPACE.bazel]')
        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.ClassCastException: class com.google.devtools.build.lib.packages.InputFile cannot be cast to class com.google.devtools.build.lib.packages.Rule (com.google.devtools.build.lib.packages.InputFile and com.google.devtools.build.lib.packages.Rule are in unnamed module of loader 'app')
        at com.google.devtools.build.lib.packages.Package.getRule(Package.java:615)
        at com.google.devtools.build.lib.repository.ExternalPackageHelper$ExternalPackageRuleExtractor.processAndShouldContinue(ExternalPackageHelper.java:144)
        at com.google.devtools.build.lib.repository.ExternalPackageHelper.iterateWorkspaceFragments(ExternalPackageHelper.java:118)
        at com.google.devtools.build.lib.repository.ExternalPackageHelper.getRuleByName(ExternalPackageHelper.java:52)
        at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.getRepoRuleFromWorkspace(RepositoryDelegatorFunction.java:475)
        at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.getRepositoryRule(RepositoryDelegatorFunction.java:360)
        at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:154)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
        ... 7 more

Presumably some symlink or something in our source root messes up the vendor subcommand - it shouldn't crash with an exception though.

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.

No response

Which operating system are you running Bazel on?

MacOS

What is the output of bazel info release?

development

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

5f5d70b6c4d2fb1a889479569107f1692239e8a7 via bazelisk (it's a commit from the 7.4.0 branch)

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

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

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 commented 1 week ago

@meteorcloudy

meteorcloudy commented 1 week ago

REPOSITORY_DIRECTORY:@@WORKSPACE.bazel

This looks very weird, do you actually have a repo called WORKSPACE.bazel somehow? Can you provide a minimal reproducible case?

criemen commented 1 week ago

do you actually have a repo called WORKSPACE.bazel somehow?

No, unless one of our transitive dependencies has one (that'd be weird though).

Can you provide a minimal reproducible case?

Not anytime soon, but if you're fine with waiting then I'll get back to you eventually.

moroten commented 16 hours ago

After running bazel vendor, I got stuck with the same error when running bazel test using Bazel 7.3.1: java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@@WORKSPACE' (requested by nodes '[/<redacted>/e9607a41d9]/[external/WORKSPACE]')

moroten commented 16 hours ago

The crash loop does not get resolved by bazel clean --expunge, only by removing the vendor directory.

I can reproduce it by running

touch WORKSPACE
mkdir vendor
ln -s $(bazel info output_base)/external vendor/bazel-external
bazel test ...
moroten commented 16 hours ago

Duplicates #22740