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
(cherry picked from commit 9fc25dc)
  • Loading branch information
c-mita authored and hvadehra committed Sep 11, 2024
1 parent 9508979 commit a018135
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 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 All @@ -58,7 +57,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 @@ -512,20 +510,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 @@ -346,11 +346,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 @@ -365,7 +364,7 @@ Descriptor labelAttribute(
Object allowRules,
Object cfg,
Sequence<?> aspects,
Object flags, // Sequence<String> expected
Sequence<?> flags,
StarlarkThread thread)
throws EvalException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Descriptor labelAttribute(
Object allowRules,
Object cfg,
Sequence<?> aspects,
Object flags,
Sequence<?> flags,
StarlarkThread thread)
throws EvalException {
List<List<String>> allNameGroups = new ArrayList<>();
Expand Down

0 comments on commit a018135

Please sign in to comment.