Skip to content

Commit

Permalink
Remove "builtins" restriction on "flag" parameter to attr.label().
Browse files Browse the repository at this point in the history
Even though this is "deprecated", it made little sense to restrict this
paramter in "label" but allow it for "label_list" and
"label_keyed_string_dict", especially when it is necessary for many
rules to be migrated to Starlark.

PiperOrigin-RevId: 644729148
Change-Id: Ia4e2ea158b4a0f36074ec58cbfdc4e389d738ab2
  • Loading branch information
c-mita authored and Copybara-Service committed Jun 19, 2024
1 parent fb05e91 commit 9fc25dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.devtools.build.lib.packages.AttributeTransitionData;
import com.google.devtools.build.lib.packages.AttributeValueSource;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.BuiltinRestriction;
import com.google.devtools.build.lib.packages.BzlInitThreadContext;
import com.google.devtools.build.lib.packages.LabelConverter;
import com.google.devtools.build.lib.packages.Provider;
Expand Down Expand Up @@ -60,7 +59,6 @@
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkFunction;
import net.starlark.java.eval.StarlarkInt;
import net.starlark.java.eval.StarlarkList;
import net.starlark.java.eval.StarlarkThread;

/**
Expand Down Expand Up @@ -570,20 +568,11 @@ public Descriptor labelAttribute(
Object allowRules,
Object cfg,
Sequence<?> aspects,
Object flagsObject, // Sequence<String> expected
Sequence<?> flags,
StarlarkThread thread)
throws EvalException {
checkContext(thread, "attr.label()");

if (flagsObject != Starlark.UNBOUND) {
BuiltinRestriction.failIfCalledOutsideBuiltins(thread);
}
@SuppressWarnings("unchecked")
Sequence<String> flags =
flagsObject == Starlark.UNBOUND
? StarlarkList.immutableOf()
: ((Sequence<String>) flagsObject);

ImmutableAttributeFactory attribute =
createAttributeFactory(
BuildType.LABEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,10 @@ Descriptor stringAttribute(
doc = ASPECTS_ARG_DOC),
@Param(
name = FLAGS_ARG,
defaultValue = "unbound",
allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)},
defaultValue = "[]",
named = true,
positional = false,
documented = false,
doc = FLAGS_DOC)
},
useStarlarkThread = true)
Expand All @@ -419,7 +418,7 @@ Descriptor labelAttribute(
Object allowRules,
Object cfg,
Sequence<?> aspects,
Object flags, // Sequence<String> expected
Sequence<?> flags,
StarlarkThread thread)
throws EvalException;

Expand Down

0 comments on commit 9fc25dc

Please sign in to comment.