bazelbuild / bazel

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

Cquery crashing on recursive target pattern #6939

Closed Globegitter closed 3 years ago

Globegitter commented 5 years ago

Description of the problem / feature request:

I was just testing out cquery in a case where we are using query but could use knowledge about our configuration, specifically the define flags and when running this in our monorepo I am getting an exception.

This is the query I am running

bazel cquery --config=ci --noannounce_rc --keep_going --define environment=dev --test_arg=something --universe_scope=//... 'kind('\''.*_binary|app_layer|jsonnet_to_json|k8s_object|.*_image.*|_run_all'\'', rdeps(set(//app:file.jsonnet), //...)) except attr('\''tags'\'', '\''manual'\'', //...)'

And then I am getting following exception 3 times:

Internal error thrown during build. Printing stack trace: java.lang.IllegalStateException: java.lang.IllegalStateException: Root /home/markus/Projects/github.com/path/core in repository @ could not be found in the graph.
    at com.google.devtools.build.lib.cmdline.TargetPattern.evalAdaptedForAsync(TargetPattern.java:187)
    at com.google.devtools.build.lib.query2.ConfiguredTargetQueryEnvironment.getTargetsMatchingPattern(ConfiguredTargetQueryEnvironment.java:230)
    at com.google.devtools.build.lib.query2.engine.TargetLiteral.eval(TargetLiteral.java:71)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.eval(AbstractQueryEnvironment.java:129)
    at com.google.devtools.build.lib.query2.engine.AllRdepsFunction.eval(AllRdepsFunction.java:88)
    at com.google.devtools.build.lib.query2.engine.RdepsFunction.lambda$evalWithBoundedDepth$0(RdepsFunction.java:104)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.lambda$transformAsync$0(AbstractQueryEnvironment.java:188)
    at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:210)
    at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:199)
    at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:111)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:398)
    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1024)
    at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:670)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.addListener(AbstractFuture.java:105)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment$QueryTaskFutureImpl.addListener(AbstractQueryEnvironment.java:78)
    at com.google.common.util.concurrent.AbstractTransformFuture.create(AbstractTransformFuture.java:40)
    at com.google.common.util.concurrent.Futures.transformAsync(Futures.java:634)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.transformAsync(AbstractQueryEnvironment.java:186)
    at com.google.devtools.build.lib.query2.engine.RdepsFunction.evalWithBoundedDepth(RdepsFunction.java:107)
    at com.google.devtools.build.lib.query2.engine.RdepsFunction.eval(RdepsFunction.java:72)
    at com.google.devtools.build.lib.query2.engine.FunctionExpression.eval(FunctionExpression.java:50)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.eval(AbstractQueryEnvironment.java:129)
    at com.google.devtools.build.lib.query2.engine.RegexFilterExpression.eval(RegexFilterExpression.java:70)
    at com.google.devtools.build.lib.query2.engine.FunctionExpression.eval(FunctionExpression.java:50)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.eval(AbstractQueryEnvironment.java:129)
    at com.google.devtools.build.lib.query2.engine.QueryUtil.evalAll(QueryUtil.java:127)
    at com.google.devtools.build.lib.query2.engine.BinaryOperatorExpression.evalMinus(BinaryOperatorExpression.java:104)
    at com.google.devtools.build.lib.query2.engine.BinaryOperatorExpression.eval(BinaryOperatorExpression.java:67)
    at com.google.devtools.build.lib.query2.engine.AbstractQueryEnvironment.eval(AbstractQueryEnvironment.java:129)
    at com.google.devtools.build.lib.query2.AbstractBlazeQueryEnvironment.evalTopLevelInternal(AbstractBlazeQueryEnvironment.java:105)
    at com.google.devtools.build.lib.query2.AbstractBlazeQueryEnvironment.evaluateQuery(AbstractBlazeQueryEnvironment.java:144)
    at com.google.devtools.build.lib.query2.PostAnalysisQueryEnvironment.evaluateQuery(PostAnalysisQueryEnvironment.java:157)
    at com.google.devtools.build.lib.buildtool.PostAnalysisQueryBuildTool.doPostAnalysisQuery(PostAnalysisQueryBuildTool.java:124)
    at com.google.devtools.build.lib.buildtool.PostAnalysisQueryBuildTool.postProcessAnalysisResult(PostAnalysisQueryBuildTool.java:65)
    at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:156)
    at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:253)
    at com.google.devtools.build.lib.runtime.commands.CqueryCommand.exec(CqueryCommand.java:121)
    at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:477)
    at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:205)
    at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:749)
    at com.google.devtools.build.lib.server.GrpcServerImpl.access$1600(GrpcServerImpl.java:103)
    at com.google.devtools.build.lib.server.GrpcServerImpl$2.lambda$run$0(GrpcServerImpl.java:818)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Root /home/markus/Projects/github.com/ecosia/core in repository @ could not be found in the graph.
    at com.google.common.base.Preconditions.checkState(Preconditions.java:823)
    at com.google.devtools.build.lib.skyframe.RecursivePkgValueRootPackageExtractor.getPackagesFromRoots(RecursivePkgValueRootPackageExtractor.java:52)
    at com.google.devtools.build.lib.skyframe.GraphBackedRecursivePackageProvider.getPackagesUnderDirectory(GraphBackedRecursivePackageProvider.java:223)
    at com.google.devtools.build.lib.skyframe.RecursivePackageProviderBackedTargetPatternResolver.findTargetsBeneathDirectoryAsyncImpl(RecursivePackageProviderBackedTargetPatternResolver.java:261)
    at com.google.devtools.build.lib.skyframe.RecursivePackageProviderBackedTargetPatternResolver.findTargetsBeneathDirectory(RecursivePackageProviderBackedTargetPatternResolver.java:206)
    at com.google.devtools.build.lib.cmdline.TargetPattern$TargetsBelowDirectory.eval(TargetPattern.java:578)
    at com.google.devtools.build.lib.cmdline.TargetPattern.evalAdaptedForAsync(TargetPattern.java:177)
    ... 44 more

Unfortunately I can not provide a minimal reproducible example because I am not sure what the error is based on this exception and I can not make our repo public.

What operating system are you running Bazel on?

Elementary OS 5.0 (Ubuntu 18.04)

What's the output of bazel info release?

release 0.21.0rc2

Have you found anything relevant by searching the web?

No.

janakdr commented 5 years ago

Just to confirm, /home/markus/Projects/github.com/ecosia/core is the root of your repo?

juliexxia commented 5 years ago

For a little more context on Janak's question - I can repro this crash by setting --universe_scope to something that isn't a superset of the targets I'm querying. We should be able to fail gracefully in those cases instead of crashing. Do you think that could be what's happening here?

Globegitter commented 5 years ago

@janakdr It is the root indeed. @juliexxia Hmm, in my case it should be a superset but I will test again asap to confirm.

juliexxia commented 3 years ago

(Context: I'm moving on from Bazel on friday and spending some time triaging all bugs assigned to me before unassigning myself)

Since we haven't heard in a while I'm closing this issue but feel free to reopen if you're still having issues.