This was originally reported by @siddharthab in bazelbuild/rules_go#1473. I've reproduced it and trimmed it down to a minimal test case.
Bazel crashes when a select expression is used on an attribute of a rule that is also an attribute of an aspect the rule uses. The crash looks like this:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'PACKAGE:' (requested by nodes ':hello')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:424)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:355)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: wrong type for attribute "pure" in go_binary rule //:hello
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:75)
at com.google.devtools.build.lib.packages.SkylarkDefinedAspect.lambda$getDefaultParametersExtractor$0(SkylarkDefinedAspect.java:207)
at com.google.devtools.build.lib.packages.Attribute$SkylarkRuleAspect.getAspect(Attribute.java:135)
at com.google.devtools.build.lib.packages.Attribute.getAspects(Attribute.java:2236)
at com.google.devtools.build.lib.packages.RuleClass.checkAspectAllowedValues(RuleClass.java:2066)
at com.google.devtools.build.lib.packages.RuleClass.createRule(RuleClass.java:1596)
at com.google.devtools.build.lib.packages.RuleFactory.createRule(RuleFactory.java:131)
at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:177)
at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:218)
at com.google.devtools.build.lib.analysis.skylark.SkylarkRuleClassFunctions$SkylarkRuleFunction.call(SkylarkRuleClassFunctions.java:956)
at com.google.devtools.build.lib.syntax.BaseFunction.callWithArgArray(BaseFunction.java:462)
at com.google.devtools.build.lib.syntax.BaseFunction.call(BaseFunction.java:440)
at com.google.devtools.build.lib.syntax.FuncallExpression.callFunction(FuncallExpression.java:854)
at com.google.devtools.build.lib.syntax.FuncallExpression.doEval(FuncallExpression.java:826)
at com.google.devtools.build.lib.syntax.Expression.eval(Expression.java:69)
at com.google.devtools.build.lib.syntax.Eval.execDispatch(Eval.java:180)
at com.google.devtools.build.lib.syntax.Eval.exec(Eval.java:162)
at com.google.devtools.build.lib.syntax.BuildFileAST.execTopLevelStatement(BuildFileAST.java:225)
at com.google.devtools.build.lib.syntax.BuildFileAST.exec(BuildFileAST.java:198)
at com.google.devtools.build.lib.packages.PackageFactory.evaluateBuildFile(PackageFactory.java:1659)
at com.google.devtools.build.lib.packages.PackageFactory.createPackageFromAst(PackageFactory.java:1298)
at com.google.devtools.build.lib.skyframe.PackageFunction.loadPackage(PackageFunction.java:1234)
at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:476)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:347)
... 4 more
Caused by: java.lang.ClassCastException: com.google.devtools.build.lib.packages.BuildType$SelectorList cannot be cast to java.lang.String
at com.google.devtools.build.lib.syntax.Type$StringType.cast(Type.java:385)
at com.google.devtools.build.lib.syntax.Type$StringType.cast(Type.java:382)
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:71)
... 27 more
java.lang.RuntimeException: Unrecoverable error while evaluating node 'PACKAGE:' (requested by nodes ':hello')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:424)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:355)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: wrong type for attribute "pure" in go_binary rule //:hello
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:75)
at com.google.devtools.build.lib.packages.SkylarkDefinedAspect.lambda$getDefaultParametersExtractor$0(SkylarkDefinedAspect.java:207)
at com.google.devtools.build.lib.packages.Attribute$SkylarkRuleAspect.getAspect(Attribute.java:135)
at com.google.devtools.build.lib.packages.Attribute.getAspects(Attribute.java:2236)
at com.google.devtools.build.lib.packages.RuleClass.checkAspectAllowedValues(RuleClass.java:2066)
at com.google.devtools.build.lib.packages.RuleClass.createRule(RuleClass.java:1596)
at com.google.devtools.build.lib.packages.RuleFactory.createRule(RuleFactory.java:131)
at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:177)
at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:218)
at com.google.devtools.build.lib.analysis.skylark.SkylarkRuleClassFunctions$SkylarkRuleFunction.call(SkylarkRuleClassFunctions.java:956)
at com.google.devtools.build.lib.syntax.BaseFunction.callWithArgArray(BaseFunction.java:462)
at com.google.devtools.build.lib.syntax.BaseFunction.call(BaseFunction.java:440)
at com.google.devtools.build.lib.syntax.FuncallExpression.callFunction(FuncallExpression.java:854)
at com.google.devtools.build.lib.syntax.FuncallExpression.doEval(FuncallExpression.java:826)
at com.google.devtools.build.lib.syntax.Expression.eval(Expression.java:69)
at com.google.devtools.build.lib.syntax.Eval.execDispatch(Eval.java:180)
at com.google.devtools.build.lib.syntax.Eval.exec(Eval.java:162)
at com.google.devtools.build.lib.syntax.BuildFileAST.execTopLevelStatement(BuildFileAST.java:225)
at com.google.devtools.build.lib.syntax.BuildFileAST.exec(BuildFileAST.java:198)
at com.google.devtools.build.lib.packages.PackageFactory.evaluateBuildFile(PackageFactory.java:1659)
at com.google.devtools.build.lib.packages.PackageFactory.createPackageFromAst(PackageFactory.java:1298)
at com.google.devtools.build.lib.skyframe.PackageFunction.loadPackage(PackageFunction.java:1234)
at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:476)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:347)
... 4 more
Caused by: java.lang.ClassCastException: com.google.devtools.build.lib.packages.BuildType$SelectorList cannot be cast to java.lang.String
at com.google.devtools.build.lib.syntax.Type$StringType.cast(Type.java:385)
at com.google.devtools.build.lib.syntax.Type$StringType.cast(Type.java:382)
at com.google.devtools.build.lib.packages.AbstractAttributeMapper.get(AbstractAttributeMapper.java:71)
... 27 more
Minimal test case is below. The key is that pure is an aspect attribute, and it's a scalar string value.
# BUILD.bazel
load("//:def.bzl", "go_binary")
go_binary(
name = "hello",
srcs = ["hello.go"],
pure = select({"//conditions:default": "auto"}),
)
# def.bzl
def _go_archive_aspect_impl(ctx):
return []
go_archive_aspect = aspect(
_go_archive_aspect_impl,
attrs = {
"pure": attr.string(values = [
"on",
"off",
"auto",
]),
},
)
def _go_binary_impl(ctx):
return []
go_binary = rule(
_go_binary_impl,
attrs = {
"srcs": attr.label_list(allow_files = [".go"]),
"deps": attr.label_list(aspects = [go_archive_aspect]),
"pure": attr.string(
values = [
"on",
"off",
"auto",
],
default = "auto",
),
},
)
Debian GNU/Linux buster/sid (Rodete)
bazel info release?release 0.13.0
Any idea if or when this might be fixed? We had to resort to a somewhat ugly workaround, and it'd be nice if this worked more like we'd expect.
Re-routing to the configurability team.
I'm looking into it...
I have a pending change that turns the crash into a proper error. So strictly speaking it'll fix this bug.
But I understand there's also the desire to properly support aspect parameters + select(). That's unfortunately more involved since aspect definitions read their attributes values in places before it's possible to know what the select() will resolve to. So it'll take a deeper refactoring of aspects to make that work. I'm going to consider that a separate issue.
Most helpful comment
I have a pending change that turns the crash into a proper error. So strictly speaking it'll fix this bug.
But I understand there's also the desire to properly support aspect parameters + select(). That's unfortunately more involved since aspect definitions read their attributes values in places before it's possible to know what the select() will resolve to. So it'll take a deeper refactoring of aspects to make that work. I'm going to consider that a separate issue.