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

Crash when using subrules in aspects that uses to a bool_flag #23282

Closed
jacky8hyf opened this issue Aug 12, 2024 · 3 comments
Closed

Crash when using subrules in aspects that uses to a bool_flag #23282

jacky8hyf opened this issue Aug 12, 2024 · 3 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug

Comments

@jacky8hyf
Copy link

Description of the bug:

Bazel crashes when using subrules in aspects that uses to a bool_flag

Which category does this issue belong to?

Configurability, Rules API

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

# a.bzl
def _print_label_impl(subrule_ctx, *, _should_print):
    pass

_print_label = subrule(
    implementation = _print_label_impl,
    attrs = {
        "_should_print": attr.label(default = "//:debug_print_label"),
    },
)

def _print_label_aspect_impl(_target, _ctx):
    _print_label()
    return []

_print_label_aspect = aspect(
    implementation = _print_label_aspect_impl,
    subrules = [_print_label],
)

def _myrule_impl(ctx):
    return DefaultInfo(files = depset(ctx.files.src))

myrule = rule(
    implementation = _myrule_impl,
    attrs = {
        "src": attr.label(
            allow_files = True,
            aspects = [_print_label_aspect],
        ),
    },
)
# BUILD.bazel
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load(":a.bzl", "myrule")

bool_flag(
    name = "debug_print_label",
    build_setting_default = False,
    visibility = ["//build/kernel:__subpackages__"],
)

filegroup(
    name = "file",
    srcs = ["a.bzl"]
)

myrule(
    name = "ok",
    src = ":file"
)

and an empty MODULE.bazel file.

Then

$ bazel build //:ok  --experimental_rule_extension_api --//:debug_print_label
Starting local Bazel server and connecting to it...
Analyzing: target //:ok (1 packages loaded, 0 targets configured)
    currently loading: @@bazel_tools//tools
[0 / 1] checking cached actions
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node '//:file#//:a.bzl%_print_label_aspect ConfiguredTargetKey{label=//:file, config=BuildConfigurationKey[4cc7959eb23e0d30c542520c40bc7e2d5c65d1105b5d1458ef83c5b1bb5b10ae]} {}' (requested by nodes 'ConfiguredTargetKey{label=//:ok, config=BuildConfigurationKey[4cc7959eb23e0d30c542520c40bc7e2d5c65d1105b5d1458ef83c5b1bb5b10ae]}')
	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$RunnableExecuteAction.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: net.starlark.java.eval.Starlark$UncheckedEvalException: NullPointerException thrown during Starlark evaluation (//:file)
	at <starlark>._print_label(<builtin>:0)
	at <starlark>._print_label_aspect_impl(/mnt/sdc/android/tmpdir2/a.bzl:12)
Caused by: java.lang.NullPointerException: Attribute $//:a.bzl%_print_label%_should_print does not exist
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:1010)
	at com.google.devtools.build.lib.packages.RuleClass.getAttributeByName(RuleClass.java:2055)
	at com.google.devtools.build.lib.analysis.starlark.StarlarkSubrule.call(StarlarkSubrule.java:143)
	at net.starlark.java.eval.StarlarkCallable.fastcall(StarlarkCallable.java:86)
	at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
	at net.starlark.java.eval.Eval.evalCall(Eval.java:682)
	at net.starlark.java.eval.Eval.eval(Eval.java:497)
	at net.starlark.java.eval.Eval.exec(Eval.java:271)
	at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
	at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
	at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:179)
	at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
	at com.google.devtools.build.lib.skyframe.StarlarkAspectFactory.create(StarlarkAspectFactory.java:64)
	at com.google.devtools.build.lib.analysis.ConfiguredTargetFactory.createAspect(ConfiguredTargetFactory.java:611)
	at com.google.devtools.build.lib.skyframe.AspectFunction.createAspect(AspectFunction.java:778)
	at com.google.devtools.build.lib.skyframe.AspectFunction.compute(AspectFunction.java:366)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.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)

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 7.3.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 ?

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?

This only happens when using subrules. If I put the attrs in the aspect directly, then it would work properly.

def _print_label_aspect_impl(_target, _ctx):
    return []

_print_label_aspect = aspect(
    implementation = _print_label_aspect_impl,
    attrs = {
        "_should_print": attr.label(default = "//:debug_print_label"),
    },
)

def _myrule_impl(ctx):
    return DefaultInfo(files = depset(ctx.files.src))

myrule = rule(
    implementation = _myrule_impl,
    attrs = {
        "src": attr.label(
            allow_files = True,
            aspects = [_print_label_aspect],
        ),
    },
)
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts labels Aug 12, 2024
@comius comius added P2 We'll consider working on this in future. (Assignee optional) and removed team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged labels Aug 26, 2024
@hvadehra
Copy link
Member

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Aug 27, 2024
@iancha1992
Copy link
Member

@bazel-io fork 7.4.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Aug 27, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Aug 27, 2024
Fixes bazelbuild#23282

PiperOrigin-RevId: 667946340
Change-Id: Icac6c4e4c695e5b580c13e9aa9cd7cee608b8e3b
github-merge-queue bot pushed a commit that referenced this issue Aug 28, 2024
Fixes #23282

PiperOrigin-RevId: 667946340
Change-Id: Icac6c4e4c695e5b580c13e9aa9cd7cee608b8e3b

Commit
1f216b1

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: bug
Projects
None yet
Development

No branches or pull requests

7 participants