diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java index 5fa7eb85655..e895d07db9f 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory; import com.google.devtools.build.lib.analysis.config.HostTransition; import com.google.devtools.build.lib.analysis.config.StarlarkDefinedConfigTransition; @@ -35,8 +36,8 @@ import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.packages.SkylarkAspect; +import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier; import com.google.devtools.build.lib.packages.StarlarkCallbackHelper; -import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier; import com.google.devtools.build.lib.packages.Type; import com.google.devtools.build.lib.packages.Type.ConversionException; import com.google.devtools.build.lib.packages.Type.LabelClass; @@ -48,6 +49,7 @@ import com.google.devtools.build.lib.syntax.Module; import com.google.devtools.build.lib.syntax.Printer; import com.google.devtools.build.lib.syntax.Sequence; +import com.google.devtools.build.lib.syntax.SkylarkType; import com.google.devtools.build.lib.syntax.Starlark; import com.google.devtools.build.lib.syntax.StarlarkFunction; import com.google.devtools.build.lib.syntax.StarlarkThread; @@ -58,18 +60,16 @@ import javax.annotation.Nullable; /** - * A helper class to provide Attr module in Starlark. + * A helper class to provide Attr module in Skylark. * - *

It exposes functions (for example, 'attr.string', 'attr.label_list', etc.) to Starlark users. - * The functions are executed through reflection. As everywhere in Starlark, arguments are + *

It exposes functions (for example, 'attr.string', 'attr.label_list', etc.) to Skylark users. + * The functions are executed through reflection. As everywhere in Skylark, arguments are * type-checked with the signature and cannot be null. */ public final class SkylarkAttr implements SkylarkAttrApi { // Arguments - // TODO(adonovan): opt: this class does a lot of redundant hashtable lookups. - private static boolean containsNonNoneKey(Map arguments, String key) { return arguments.containsKey(key) && arguments.get(key) != Starlark.NONE; } @@ -82,7 +82,9 @@ private static void setAllowedFileTypes( builder.allowedFileTypes(FileTypeSet.NO_FILE); } else if (fileTypesObj instanceof Sequence) { ImmutableList arg = - ImmutableList.copyOf(Sequence.cast(fileTypesObj, String.class, "allow_files argument")); + ImmutableList.copyOf( + Sequence.castSkylarkListOrNoneToList( + fileTypesObj, String.class, "allow_files argument")); builder.allowedFileTypes(FileType.of(arg)); } else { throw new EvalException(null, attr + " should be a boolean or a string list"); @@ -93,7 +95,7 @@ private static ImmutableAttributeFactory createAttributeFactory( Type type, String doc, Map arguments, StarlarkThread thread) throws EvalException { // We use an empty name now so that we can set it later. - // This trick makes sense only in the context of Starlark (builtin rules should not use it). + // This trick makes sense only in the context of Skylark (builtin rules should not use it). return createAttributeFactory(type, doc, arguments, thread, ""); } @@ -144,11 +146,9 @@ private static Attribute.Builder createAttribute( } } - Object flagsArg = arguments.get(FLAGS_ARG); - if (flagsArg != null) { - for (String flag : Sequence.noneableCast(flagsArg, String.class, FLAGS_ARG)) { - builder.setPropertyFlag(flag); - } + for (String flag : + Sequence.castSkylarkListOrNoneToList(arguments.get(FLAGS_ARG), String.class, FLAGS_ARG)) { + builder.setPropertyFlag(flag); } if (containsNonNoneKey(arguments, MANDATORY_ARG) && (Boolean) arguments.get(MANDATORY_ARG)) { @@ -220,22 +220,21 @@ && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { Object ruleClassesObj = arguments.get(ALLOW_RULES_ARG); if (ruleClassesObj != null && ruleClassesObj != Starlark.NONE) { builder.allowedRuleClasses( - Sequence.cast( + Sequence.castSkylarkListOrNoneToList( ruleClassesObj, String.class, "allowed rule classes for attribute definition")); } - Object valuesArg = arguments.get(VALUES_ARG); - if (valuesArg != null) { - List values = Sequence.noneableCast(valuesArg, Object.class, VALUES_ARG); - if (!values.isEmpty()) { - builder.allowedValues(new AllowedValueSet(values)); - } + List values = + Sequence.castSkylarkListOrNoneToList(arguments.get(VALUES_ARG), Object.class, VALUES_ARG); + if (!Iterables.isEmpty(values)) { + builder.allowedValues(new AllowedValueSet(values)); } if (containsNonNoneKey(arguments, PROVIDERS_ARG)) { Object obj = arguments.get(PROVIDERS_ARG); - ImmutableList> providersList = - buildProviderPredicate(Sequence.cast(obj, Object.class, PROVIDERS_ARG), PROVIDERS_ARG); + SkylarkType.checkType(obj, Sequence.class, PROVIDERS_ARG); + ImmutableList> providersList = + buildProviderPredicate((Sequence) obj, PROVIDERS_ARG); // If there is at least one empty set, there is no restriction. if (providersList.stream().noneMatch(ImmutableSet::isEmpty)) { @@ -285,7 +284,10 @@ && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { if (containsNonNoneKey(arguments, ASPECTS_ARG)) { Object obj = arguments.get(ASPECTS_ARG); - for (SkylarkAspect aspect : Sequence.cast(obj, SkylarkAspect.class, "aspects")) { + SkylarkType.checkType(obj, Sequence.class, ASPECTS_ARG); + + List aspects = ((Sequence) obj).getContents(SkylarkAspect.class, "aspects"); + for (SkylarkAspect aspect : aspects) { aspect.attachToAttribute(builder); } } @@ -294,13 +296,13 @@ && containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { } /** - * Builds a list of sets of accepted providers from Starlark list {@code obj}. The list can either + * Builds a list of sets of accepted providers from Skylark list {@code obj}. The list can either * be a list of providers (in that case the result is a list with one set) or a list of lists of * providers (then the result is the list of sets). * * @param argumentName used in error messages. */ - static ImmutableList> buildProviderPredicate( + static ImmutableList> buildProviderPredicate( Sequence obj, String argumentName) throws EvalException { if (obj.isEmpty()) { return ImmutableList.of(); @@ -320,39 +322,39 @@ static ImmutableList> buildProviderPred } /** - * Returns true if {@code o} is a Starlark provider (either a declared provider or a legacy - * provider name. + * Returns true if {@code o} is a Skylark provider (either a declared provider or + * a legacy provider name. */ static boolean isProvider(Object o) { return o instanceof String || o instanceof Provider; } /** - * Converts Starlark identifiers of providers (either a string or a provider value) to their + * Converts Skylark identifiers of providers (either a string or a provider value) to their * internal representations. */ - static ImmutableSet getSkylarkProviderIdentifiers(Sequence list) + static ImmutableSet getSkylarkProviderIdentifiers(Sequence list) throws EvalException { - ImmutableList.Builder result = ImmutableList.builder(); + ImmutableList.Builder result = ImmutableList.builder(); for (Object obj : list) { if (obj instanceof String) { - result.add(StarlarkProviderIdentifier.forLegacy((String) obj)); + result.add(SkylarkProviderIdentifier.forLegacy((String) obj)); } else if (obj instanceof Provider) { Provider constructor = (Provider) obj; if (!constructor.isExported()) { throw new EvalException( null, "Providers should be top-level values in extension files that define them."); } - result.add(StarlarkProviderIdentifier.forKey(constructor.getKey())); + result.add(SkylarkProviderIdentifier.forKey(constructor.getKey())); } } return ImmutableSet.copyOf(result.build()); } - private static ImmutableList> getProvidersList( + private static ImmutableList> getProvidersList( Sequence skylarkList, String argumentName) throws EvalException { - ImmutableList.Builder> providersList = + ImmutableList.Builder> providersList = ImmutableList.builder(); String errorMsg = "Illegal argument: element in '%s' is of unexpected type. " + "Either all elements should be providers, " @@ -416,7 +418,7 @@ private static Descriptor createNonconfigurableAttrDescriptor( Preconditions.checkNotNull(maybeGetNonConfigurableReason(type), type); try { // We use an empty name now so that we can set it later. - // This trick makes sense only in the context of Starlark (builtin rules should not use it). + // This trick makes sense only in the context of Skylark (builtin rules should not use it). return new Descriptor( name, createAttribute(type, null, kwargs, thread, "") @@ -773,7 +775,7 @@ public Descriptor licenseAttribute( thread); } - /** A descriptor of an attribute defined in Starlark. */ + /** A descriptor of an attribute defined in Skylark. */ @AutoCodec public static final class Descriptor implements SkylarkAttrApi.Descriptor { private final ImmutableAttributeFactory attributeFactory; diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java index 5fc5bbf9fa4..dfb51397e79 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java @@ -264,17 +264,6 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl + "directory.") public boolean experimentalSiblingRepositoryLayout; - @Option( - name = "experimental_exec_groups", - defaultValue = "false", - documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, - effectTags = {OptionEffectTag.EXECUTION}, - metadataTags = {OptionMetadataTag.EXPERIMENTAL}, - help = - "If set to true, allows rule authors define and access multiple execution groups " - + "during rule definition. This work is ongoing.") - public boolean experimentalExecGroups; - @Option( name = "experimental_allow_tags_propagation", oldName = "incompatible_allow_tags_propagation", @@ -688,7 +677,6 @@ public StarlarkSemantics toSkylarkSemantics() { .experimentalRepoRemoteExec(experimentalRepoRemoteExec) .experimentalDisableExternalPackage(experimentalDisableExternalPackage) .experimentalSiblingRepositoryLayout(experimentalSiblingRepositoryLayout) - .experimentalExecGroups(experimentalExecGroups) .incompatibleApplicableLicenses(incompatibleApplicableLicenses) .incompatibleDepsetUnion(incompatibleDepsetUnion) .incompatibleDisableTargetProviderFields(incompatibleDisableTargetProviderFields) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java index b688d70c1bf..dca25cb3f83 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java @@ -20,13 +20,13 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; -import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; -import com.google.devtools.build.lib.syntax.Environment; +import com.google.devtools.build.lib.syntax.Dict; import com.google.devtools.build.lib.syntax.EvalException; -import com.google.devtools.build.lib.syntax.FuncallExpression; -import com.google.devtools.build.lib.syntax.SkylarkDict; -import com.google.devtools.build.lib.syntax.SkylarkList; -import com.google.devtools.build.lib.syntax.UserDefinedFunction; +import com.google.devtools.build.lib.syntax.Sequence; +import com.google.devtools.build.lib.syntax.StarlarkFunction; +import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier; +import com.google.devtools.build.lib.syntax.StarlarkThread; +import com.google.devtools.build.lib.syntax.StarlarkValue; /** * The "attr" module of the Build API. @@ -37,7 +37,7 @@ @SkylarkModule( name = "attr", namespace = true, - category = SkylarkModuleCategory.BUILTIN, + category = SkylarkModuleCategory.TOP_LEVEL_TYPE, doc = "This is a top-level module for defining the attribute schemas of a rule or aspect. Each " + "function returns an object representing the schema of a single attribute. These " @@ -48,10 +48,10 @@ + "

See the Rules page for more on " + "defining and " + "using attributes.") -public interface SkylarkAttrApi extends SkylarkValue { +public interface SkylarkAttrApi extends StarlarkValue { // dependency and output attributes - static final String LABEL_PARAGRAPH = + String LABEL_PARAGRAPH = "

This attribute contains Label values. If a string " + "is supplied in place of a Label, it will be converted using the " + "label constructor. The relative parts of the label " @@ -59,7 +59,7 @@ public interface SkylarkAttrApi extends SkylarkValue { + "instantiated target's package."; // attr.label, attr.label_list, attr.label_keyed_string_dict - static final String DEPENDENCY_ATTR_TEXT = + String DEPENDENCY_ATTR_TEXT = LABEL_PARAGRAPH + "

At analysis time (within the rule's implementation function), when retrieving the " + "attribute value from ctx.attr, labels are replaced by the corresponding " @@ -67,64 +67,64 @@ public interface SkylarkAttrApi extends SkylarkValue { + "providers of the currrent target's dependencies."; // attr.output, attr.output_list - static final String OUTPUT_ATTR_TEXT = + String OUTPUT_ATTR_TEXT = LABEL_PARAGRAPH + "

At analysis time, the corresponding File can " + "be retrieved using ctx.outputs."; - static final String ALLOW_FILES_ARG = "allow_files"; - static final String ALLOW_FILES_DOC = + String ALLOW_FILES_ARG = "allow_files"; + String ALLOW_FILES_DOC = "Whether File targets are allowed. Can be True, False " + "(default), or a list of file extensions that are allowed (for example, " + "[\".cc\", \".cpp\"])."; - static final String ALLOW_RULES_ARG = "allow_rules"; - static final String ALLOW_RULES_DOC = + String ALLOW_RULES_ARG = "allow_rules"; + String ALLOW_RULES_DOC = "Which rule targets (name of the classes) are allowed. This is deprecated (kept only for " + "compatibility), use providers instead."; - static final String ASPECTS_ARG = "aspects"; - static final String ASPECTS_ARG_DOC = + String ASPECTS_ARG = "aspects"; + String ASPECTS_ARG_DOC = "Aspects that should be applied to the dependency or dependencies specified by this " + "attribute."; - static final String CONFIGURATION_ARG = "cfg"; + String CONFIGURATION_ARG = "cfg"; // TODO(bazel-team): Update when new Skylark-based configuration framework is implemented. - static final String CONFIGURATION_DOC = + String CONFIGURATION_DOC = "Configuration of the attribute. It can be " + "either \"host\" or \"target\"."; - static final String DEFAULT_ARG = "default"; + String DEFAULT_ARG = "default"; // A trailing space is required because it's often prepended to other sentences - static final String DEFAULT_DOC = + String DEFAULT_DOC = "A default value to use if no value for this attribute is given when instantiating the rule."; - static final String DOC_ARG = "doc"; - static final String DOC_DOC = + String DOC_ARG = "doc"; + String DOC_DOC = "A description of the attribute that can be extracted by documentation generating tools."; - static final String EXECUTABLE_ARG = "executable"; - static final String EXECUTABLE_DOC = + String EXECUTABLE_ARG = "executable"; + String EXECUTABLE_DOC = "True if the dependency has to be executable. This means the label must refer to an " + "executable file, or to a rule that outputs an executable file. Access the label " + "with ctx.executable.<attribute_name>."; - static final String FLAGS_ARG = "flags"; - static final String FLAGS_DOC = "Deprecated, will be removed."; + String FLAGS_ARG = "flags"; + String FLAGS_DOC = "Deprecated, will be removed."; - static final String MANDATORY_ARG = "mandatory"; - static final String MANDATORY_DOC = + String MANDATORY_ARG = "mandatory"; + String MANDATORY_DOC = "If true, the value must be specified explicitly (even if it has a default)."; - static final String NON_EMPTY_ARG = "non_empty"; - static final String NON_EMPTY_DOC = + String NON_EMPTY_ARG = "non_empty"; + String NON_EMPTY_DOC = "True if the attribute must not be empty. Deprecated: Use allow_empty instead."; - static final String ALLOW_EMPTY_ARG = "allow_empty"; - static final String ALLOW_EMPTY_DOC = "True if the attribute can be empty."; + String ALLOW_EMPTY_ARG = "allow_empty"; + String ALLOW_EMPTY_DOC = "True if the attribute can be empty."; - static final String PROVIDERS_ARG = "providers"; - static final String PROVIDERS_DOC = + String PROVIDERS_ARG = "providers"; + String PROVIDERS_DOC = "The providers that must be given by any dependency appearing in this attribute." + "" + "

The format of this argument is a list of lists of providers -- *Info " @@ -134,11 +134,11 @@ public interface SkylarkAttrApi extends SkylarkValue { + "argument may also be a single-level list of providers, in which case it is wrapped in " + "an outer list with one element."; - static final String SINGLE_FILE_ARG = "single_file"; - static final String ALLOW_SINGLE_FILE_ARG = "allow_single_file"; + String SINGLE_FILE_ARG = "single_file"; + String ALLOW_SINGLE_FILE_ARG = "allow_single_file"; - static final String VALUES_ARG = "values"; - static final String VALUES_DOC = + String VALUES_ARG = "values"; + String VALUES_DOC = "The list of allowed values for the attribute. An error is raised if any other " + "value is given."; @@ -148,10 +148,7 @@ public interface SkylarkAttrApi extends SkylarkValue { parameters = { @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Integer.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Integer.class, defaultValue = "0", doc = DEFAULT_DOC, named = true, @@ -172,22 +169,20 @@ public interface SkylarkAttrApi extends SkylarkValue { positional = false), @Param( name = VALUES_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = Integer.class, defaultValue = "[]", doc = VALUES_DOC, named = true, positional = false) }, - useAst = true, - useEnvironment = true) + useStarlarkThread = true) Descriptor intAttribute( - Integer defaultInt, + Integer defaultValue, String doc, Boolean mandatory, - SkylarkList values, - FuncallExpression ast, - Environment env) + Sequence values, + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -196,9 +191,7 @@ Descriptor intAttribute( parameters = { @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = String.class), - }, + type = String.class, defaultValue = "''", doc = DEFAULT_DOC, named = true, @@ -219,27 +212,26 @@ Descriptor intAttribute( positional = false), @Param( name = VALUES_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, defaultValue = "[]", doc = VALUES_DOC, named = true, positional = false) }, - useAst = true, - useEnvironment = true) - public Descriptor stringAttribute( - String defaultString, + useStarlarkThread = true) + Descriptor stringAttribute( + String defaultValue, String doc, Boolean mandatory, - SkylarkList values, - FuncallExpression ast, - Environment env) + Sequence values, + StarlarkThread thread) throws EvalException; @SkylarkCallable( name = "label", - doc = "Creates a schema for a label attribute. This is a dependency attribute." + doc = + "Creates a schema for a label attribute. This is a dependency attribute." + DEPENDENCY_ATTR_TEXT + "

In addition to ordinary source files, this kind of attribute is often used to " + "refer to a tool -- for example, a compiler. Such tools are considered to be " @@ -257,7 +249,12 @@ public Descriptor stringAttribute( @ParamType(type = Label.class), @ParamType(type = String.class), @ParamType(type = LateBoundDefaultApi.class), - @ParamType(type = UserDefinedFunction.class) + // TODO(adonovan): remove StarlarkFunction. It's undocumented, + // unused by Google's .bzl files, and likely unused in Bazel. + // I suspect it is a vestige of a "computed defaults" feature + // that was never fully exposed to Starlark (or was since + // withdrawn). + @ParamType(type = StarlarkFunction.class) }, callbackEnabled = true, noneable = true, @@ -309,14 +306,14 @@ public Descriptor stringAttribute( doc = MANDATORY_DOC), @Param( name = PROVIDERS_ARG, - type = SkylarkList.class, + type = Sequence.class, defaultValue = "[]", named = true, positional = false, doc = PROVIDERS_DOC), @Param( name = ALLOW_RULES_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, noneable = true, defaultValue = "None", @@ -343,32 +340,34 @@ public Descriptor stringAttribute( positional = false, doc = CONFIGURATION_DOC - + " This parameter is required if executable is True."), + + " This parameter is required if executable is True " + + "to guard against accidentally building host tools in the " + + "target configuration. \"target\" has no semantic " + + "effect, so don't set it when executable is False " + + "unless it really helps clarify your intentions."), @Param( name = ASPECTS_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = SkylarkAspectApi.class, defaultValue = "[]", named = true, positional = false, doc = ASPECTS_ARG_DOC), }, - useAst = true, - useEnvironment = true) - public Descriptor labelAttribute( - Object defaultO, + useStarlarkThread = true) + Descriptor labelAttribute( + Object defaultValue, String doc, Boolean executable, Object allowFiles, Object allowSingleFile, Boolean mandatory, - SkylarkList providers, + Sequence providers, Object allowRules, Boolean singleFile, Object cfg, - SkylarkList aspects, - FuncallExpression ast, - Environment env) + Sequence aspects, + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -395,10 +394,8 @@ public Descriptor labelAttribute( named = true), @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = String.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Sequence.class, + generic1 = String.class, defaultValue = "[]", doc = DEFAULT_DOC, named = true, @@ -411,16 +408,14 @@ public Descriptor labelAttribute( named = true, positional = false) }, - useAst = true, - useEnvironment = true) - public Descriptor stringListAttribute( + useStarlarkThread = true) + Descriptor stringListAttribute( Boolean mandatory, Boolean nonEmpty, Boolean allowEmpty, - SkylarkList defaultList, + Sequence defaultValue, String doc, - FuncallExpression ast, - Environment env) + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -447,10 +442,8 @@ public Descriptor stringListAttribute( named = true), @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Integer.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Sequence.class, + generic1 = Integer.class, defaultValue = "[]", doc = DEFAULT_DOC, named = true, @@ -463,16 +456,14 @@ public Descriptor stringListAttribute( named = true, positional = false) }, - useAst = true, - useEnvironment = true) - public Descriptor intListAttribute( + useStarlarkThread = true) + Descriptor intListAttribute( Boolean mandatory, Boolean nonEmpty, Boolean allowEmpty, - SkylarkList defaultList, + Sequence defaultValue, String doc, - FuncallExpression ast, - Environment env) + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -490,8 +481,8 @@ public Descriptor intListAttribute( @Param( name = DEFAULT_ARG, allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Label.class), - @ParamType(type = UserDefinedFunction.class) + @ParamType(type = Sequence.class, generic1 = Label.class), + @ParamType(type = StarlarkFunction.class) }, callbackEnabled = true, defaultValue = "[]", @@ -518,7 +509,7 @@ public Descriptor intListAttribute( doc = ALLOW_FILES_DOC), @Param( name = ALLOW_RULES_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, noneable = true, defaultValue = "None", @@ -527,14 +518,14 @@ public Descriptor intListAttribute( doc = ALLOW_RULES_DOC), @Param( name = PROVIDERS_ARG, - type = SkylarkList.class, + type = Sequence.class, defaultValue = "[]", named = true, positional = false, doc = PROVIDERS_DOC), @Param( name = FLAGS_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, defaultValue = "[]", named = true, @@ -564,29 +555,27 @@ public Descriptor intListAttribute( doc = CONFIGURATION_DOC), @Param( name = ASPECTS_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = SkylarkAspectApi.class, defaultValue = "[]", named = true, positional = false, doc = ASPECTS_ARG_DOC), }, - useAst = true, - useEnvironment = true) - public Descriptor labelListAttribute( + useStarlarkThread = true) + Descriptor labelListAttribute( Boolean allowEmpty, - Object defaultList, + Object defaultValue, String doc, Object allowFiles, Object allowRules, - SkylarkList providers, - SkylarkList flags, + Sequence providers, + Sequence flags, Boolean mandatory, Boolean nonEmpty, Object cfg, - SkylarkList aspects, - FuncallExpression ast, - Environment env) + Sequence aspects, + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -605,8 +594,8 @@ public Descriptor labelListAttribute( @Param( name = DEFAULT_ARG, allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) + @ParamType(type = Dict.class), + @ParamType(type = StarlarkFunction.class) }, callbackEnabled = true, defaultValue = "{}", @@ -634,7 +623,7 @@ public Descriptor labelListAttribute( doc = ALLOW_FILES_DOC), @Param( name = ALLOW_RULES_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, noneable = true, defaultValue = "None", @@ -643,14 +632,14 @@ public Descriptor labelListAttribute( doc = ALLOW_RULES_DOC), @Param( name = PROVIDERS_ARG, - type = SkylarkList.class, + type = Sequence.class, defaultValue = "[]", named = true, positional = false, doc = PROVIDERS_DOC), @Param( name = FLAGS_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = String.class, defaultValue = "[]", named = true, @@ -680,29 +669,27 @@ public Descriptor labelListAttribute( doc = CONFIGURATION_DOC), @Param( name = ASPECTS_ARG, - type = SkylarkList.class, + type = Sequence.class, generic1 = SkylarkAspectApi.class, defaultValue = "[]", named = true, positional = false, doc = ASPECTS_ARG_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor labelKeyedStringDictAttribute( + useStarlarkThread = true) + Descriptor labelKeyedStringDictAttribute( Boolean allowEmpty, - Object defaultList, + Object defaultValue, String doc, Object allowFiles, Object allowRules, - SkylarkList providers, - SkylarkList flags, + Sequence providers, + Sequence flags, Boolean mandatory, Boolean nonEmpty, Object cfg, - SkylarkList aspects, - FuncallExpression ast, - Environment env) + Sequence aspects, + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -711,10 +698,7 @@ public Descriptor labelKeyedStringDictAttribute( parameters = { @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Boolean.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Boolean.class, defaultValue = "False", named = true, positional = false, @@ -734,31 +718,15 @@ public Descriptor labelKeyedStringDictAttribute( positional = false, doc = MANDATORY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor boolAttribute( - Boolean defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + useStarlarkThread = true) + Descriptor boolAttribute( + Boolean defaultValue, String doc, Boolean mandatory, StarlarkThread thread) throws EvalException; @SkylarkCallable( name = "output", - doc = - "Creates a schema for an output (label) attribute." - + OUTPUT_ATTR_TEXT, + doc = "Creates a schema for an output (label) attribute." + OUTPUT_ATTR_TEXT, parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Label.class), - @ParamType(type = UserDefinedFunction.class) - }, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = "default is deprecated for attr.output. Use " - + "Starlark macros to set the default for output and " - + "output_list attributes.

" + DEFAULT_DOC), @Param( name = DOC_ARG, type = String.class, @@ -774,17 +742,13 @@ public Descriptor boolAttribute( positional = false, doc = MANDATORY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor outputAttribute( - Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + useStarlarkThread = true) + Descriptor outputAttribute(String doc, Boolean mandatory, StarlarkThread thread) throws EvalException; @SkylarkCallable( name = "output_list", - doc = - "Creates a schema for a list-of-outputs attribute." - + OUTPUT_ATTR_TEXT, + doc = "Creates a schema for a list-of-outputs attribute." + OUTPUT_ATTR_TEXT, parameters = { @Param( name = ALLOW_EMPTY_ARG, @@ -792,19 +756,6 @@ public Descriptor outputAttribute( defaultValue = "True", doc = ALLOW_EMPTY_DOC, named = true), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Label.class), - @ParamType(type = UserDefinedFunction.class) - }, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = "default is deprecated for attr.output_list. Use " - + "Starlark macros to set the default for output and " - + "output_list attributes.

" + DEFAULT_DOC), @Param( name = DOC_ARG, type = String.class, @@ -827,16 +778,13 @@ public Descriptor outputAttribute( positional = false, doc = NON_EMPTY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor outputListAttribute( + useStarlarkThread = true) + Descriptor outputListAttribute( Boolean allowEmpty, - Object defaultList, String doc, Boolean mandatory, Boolean nonEmpty, - FuncallExpression ast, - Environment env) + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -853,10 +801,7 @@ public Descriptor outputListAttribute( named = true), @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Dict.class, named = true, positional = false, defaultValue = "{}", @@ -883,16 +828,14 @@ public Descriptor outputListAttribute( positional = false, doc = NON_EMPTY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor stringDictAttribute( + useStarlarkThread = true) + Descriptor stringDictAttribute( Boolean allowEmpty, - SkylarkDict defaultO, + Dict defaultValue, String doc, Boolean mandatory, Boolean nonEmpty, - FuncallExpression ast, - Environment env) + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -909,10 +852,7 @@ public Descriptor stringDictAttribute( named = true), @Param( name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) - }, + type = Dict.class, defaultValue = "{}", named = true, positional = false, @@ -939,16 +879,14 @@ public Descriptor stringDictAttribute( positional = false, doc = NON_EMPTY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor stringListDictAttribute( + useStarlarkThread = true) + Descriptor stringListDictAttribute( Boolean allowEmpty, - SkylarkDict defaultO, + Dict defaultValue, String doc, Boolean mandatory, Boolean nonEmpty, - FuncallExpression ast, - Environment env) + StarlarkThread thread) throws EvalException; @SkylarkCallable( @@ -979,20 +917,20 @@ public Descriptor stringListDictAttribute( positional = false, doc = MANDATORY_DOC) }, - useAst = true, - useEnvironment = true) - public Descriptor licenseAttribute( - Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + disableWithFlag = FlagIdentifier.INCOMPATIBLE_NO_ATTR_LICENSE, + useStarlarkThread = true) + Descriptor licenseAttribute( + Object defaultValue, String doc, Boolean mandatory, StarlarkThread thread) throws EvalException; /** An attribute descriptor. */ @SkylarkModule( name = "Attribute", - category = SkylarkModuleCategory.NONE, + category = SkylarkModuleCategory.BUILTIN, doc = "Representation of a definition of an attribute. Use the attr " + "module to create an Attribute. They are only for use with a " + "rule or an " + "aspect.") - public static interface Descriptor extends SkylarkValue {} + interface Descriptor extends StarlarkValue {} } diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java index d1b04ad3c22..41ef0d794f6 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java @@ -70,7 +70,6 @@ private FlagIdentifier() {} // uninstantiable public static final String EXPERIMENTAL_STARLARK_UNUSED_INPUTS_LIST = "experimental_starlark_unused_inputs_list"; public static final String EXPERIMENTAL_REPO_REMOTE_EXEC = "experimental_repo_remote_exec"; - public static final String EXPERIMENTAL_EXEC_GROUPS = "experimental_exec_groups"; public static final String INCOMPATIBLE_APPLICABLE_LICENSES = "incompatible_applicable_licenses"; public static final String INCOMPATIBLE_DISABLE_DEPSET_INPUTS = @@ -122,8 +121,6 @@ public boolean flagValue(String flag) { return experimentalStarlarkUnusedInputsList(); case FlagIdentifier.EXPERIMENTAL_REPO_REMOTE_EXEC: return experimentalRepoRemoteExec(); - case FlagIdentifier.EXPERIMENTAL_EXEC_GROUPS: - return experimentalExecGroups(); case FlagIdentifier.INCOMPATIBLE_APPLICABLE_LICENSES: return incompatibleApplicableLicenses(); case FlagIdentifier.INCOMPATIBLE_DISABLE_DEPSET_INPUTS: @@ -215,8 +212,6 @@ boolean isFeatureEnabledBasedOnTogglingFlags(String enablingFlag, String disabli public abstract boolean experimentalSiblingRepositoryLayout(); - public abstract boolean experimentalExecGroups(); - public abstract boolean incompatibleAlwaysCheckDepsetElements(); public abstract boolean incompatibleApplicableLicenses(); @@ -323,7 +318,6 @@ public static Builder builderWithDefaults() { .experimentalRepoRemoteExec(false) .experimentalDisableExternalPackage(false) .experimentalSiblingRepositoryLayout(false) - .experimentalExecGroups(false) .incompatibleAlwaysCheckDepsetElements(true) .incompatibleApplicableLicenses(false) .incompatibleDepsetUnion(true) @@ -392,8 +386,6 @@ public abstract static class Builder { public abstract Builder experimentalSiblingRepositoryLayout(boolean value); - public abstract Builder experimentalExecGroups(boolean value); - public abstract Builder incompatibleAlwaysCheckDepsetElements(boolean value); public abstract Builder incompatibleApplicableLicenses(boolean value); diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkAttrApi.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkAttrApi.java index 8de4003eeb9..762c1fe7910 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkAttrApi.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkAttrApi.java @@ -14,14 +14,20 @@ package com.google.devtools.build.skydoc.fakebuildapi; +import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.skylarkbuildapi.SkylarkAttrApi; -import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.syntax.Environment; +import com.google.devtools.build.lib.skylarkbuildapi.core.ProviderApi; +import com.google.devtools.build.lib.syntax.Dict; import com.google.devtools.build.lib.syntax.EvalException; -import com.google.devtools.build.lib.syntax.FuncallExpression; -import com.google.devtools.build.lib.syntax.SkylarkDict; -import com.google.devtools.build.lib.syntax.SkylarkList; -import com.google.devtools.build.skydoc.rendering.AttributeInfo.Type; +import com.google.devtools.build.lib.syntax.Module; +import com.google.devtools.build.lib.syntax.Printer; +import com.google.devtools.build.lib.syntax.Sequence; +import com.google.devtools.build.lib.syntax.StarlarkThread; +import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.AttributeType; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; /** * Fake implementation of {@link SkylarkAttrApi}. @@ -29,94 +35,255 @@ public class FakeSkylarkAttrApi implements SkylarkAttrApi { @Override - public Descriptor intAttribute(Integer defaultInt, String doc, Boolean mandatory, - SkylarkList values, FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.INT, doc, mandatory); + public Descriptor intAttribute( + Integer defaultInt, + String doc, + Boolean mandatory, + Sequence values, + StarlarkThread thread) + throws EvalException { + return new FakeDescriptor(AttributeType.INT, doc, mandatory, ImmutableList.of(), defaultInt); } @Override - public Descriptor stringAttribute(String defaultString, String doc, Boolean mandatory, - SkylarkList values, FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.STRING, doc, mandatory); + public Descriptor stringAttribute( + String defaultString, + String doc, + Boolean mandatory, + Sequence values, + StarlarkThread thread) + throws EvalException { + return new FakeDescriptor( + AttributeType.STRING, + doc, + mandatory, + ImmutableList.of(), + defaultString != null ? "\"" + defaultString + "\"" : null); } @Override - public Descriptor labelAttribute(Object defaultO, String doc, Boolean executable, - Object allowFiles, Object allowSingleFile, Boolean mandatory, SkylarkList providers, - Object allowRules, Boolean singleFile, Object cfg, SkylarkList aspects, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.LABEL, doc, mandatory); + public Descriptor labelAttribute( + Object defaultO, + String doc, + Boolean executable, + Object allowFiles, + Object allowSingleFile, + Boolean mandatory, + Sequence providers, + Object allowRules, + Boolean singleFile, + Object cfg, + Sequence aspects, + StarlarkThread thread) + throws EvalException { + List> allNameGroups = new ArrayList<>(); + if (providers != null) { + allNameGroups = allProviderNameGroups(providers, thread); + } + return new FakeDescriptor(AttributeType.LABEL, doc, mandatory, allNameGroups, defaultO); } @Override - public Descriptor stringListAttribute(Boolean mandatory, Boolean nonEmpty, Boolean allowEmpty, - SkylarkList defaultList, String doc, FuncallExpression ast, Environment env) + public Descriptor stringListAttribute( + Boolean mandatory, + Boolean nonEmpty, + Boolean allowEmpty, + Sequence defaultList, + String doc, + StarlarkThread thread) throws EvalException { - return new FakeDescriptor(Type.STRING_LIST, doc, mandatory); + return new FakeDescriptor( + AttributeType.STRING_LIST, doc, mandatory, ImmutableList.of(), defaultList); } @Override - public Descriptor intListAttribute(Boolean mandatory, Boolean nonEmpty, Boolean allowEmpty, - SkylarkList defaultList, String doc, FuncallExpression ast, Environment env) + public Descriptor intListAttribute( + Boolean mandatory, + Boolean nonEmpty, + Boolean allowEmpty, + Sequence defaultList, + String doc, + StarlarkThread thread) throws EvalException { - return new FakeDescriptor(Type.INT_LIST, doc, mandatory); + return new FakeDescriptor( + AttributeType.INT_LIST, doc, mandatory, ImmutableList.of(), defaultList); } @Override - public Descriptor labelListAttribute(Boolean allowEmpty, Object defaultList, String doc, - Object allowFiles, Object allowRules, SkylarkList providers, SkylarkList flags, - Boolean mandatory, Boolean nonEmpty, Object cfg, SkylarkList aspects, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.LABEL_LIST, doc, mandatory); + public Descriptor labelListAttribute( + Boolean allowEmpty, + Object defaultList, + String doc, + Object allowFiles, + Object allowRules, + Sequence providers, + Sequence flags, + Boolean mandatory, + Boolean nonEmpty, + Object cfg, + Sequence aspects, + StarlarkThread thread) + throws EvalException { + List> allNameGroups = new ArrayList<>(); + if (providers != null) { + allNameGroups = allProviderNameGroups(providers, thread); + } + return new FakeDescriptor(AttributeType.LABEL_LIST, doc, mandatory, allNameGroups, defaultList); } @Override - public Descriptor labelKeyedStringDictAttribute(Boolean allowEmpty, Object defaultList, - String doc, Object allowFiles, Object allowRules, SkylarkList providers, - SkylarkList flags, Boolean mandatory, Boolean nonEmpty, Object cfg, SkylarkList aspects, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.LABEL_STRING_DICT, doc, mandatory); + public Descriptor labelKeyedStringDictAttribute( + Boolean allowEmpty, + Object defaultList, + String doc, + Object allowFiles, + Object allowRules, + Sequence providers, + Sequence flags, + Boolean mandatory, + Boolean nonEmpty, + Object cfg, + Sequence aspects, + StarlarkThread thread) + throws EvalException { + List> allNameGroups = new ArrayList<>(); + if (providers != null) { + allNameGroups = allProviderNameGroups(providers, thread); + } + return new FakeDescriptor( + AttributeType.LABEL_STRING_DICT, doc, mandatory, allNameGroups, defaultList); } @Override - public Descriptor boolAttribute(Boolean defaultO, String doc, Boolean mandatory, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.BOOLEAN, doc, mandatory); + public Descriptor boolAttribute( + Boolean defaultO, String doc, Boolean mandatory, StarlarkThread thread) throws EvalException { + return new FakeDescriptor( + AttributeType.BOOLEAN, + doc, + mandatory, + ImmutableList.of(), + Boolean.TRUE.equals(defaultO) ? "True" : "False"); } @Override - public Descriptor outputAttribute(Object defaultO, String doc, Boolean mandatory, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.OUTPUT, doc, mandatory); + public Descriptor outputAttribute(String doc, Boolean mandatory, StarlarkThread thread) + throws EvalException { + return new FakeDescriptor(AttributeType.OUTPUT, doc, mandatory, ImmutableList.of(), ""); } @Override - public Descriptor outputListAttribute(Boolean allowEmpty, Object defaultList, String doc, - Boolean mandatory, Boolean nonEmpty, FuncallExpression ast, Environment env) + public Descriptor outputListAttribute( + Boolean allowEmpty, + String doc, + Boolean mandatory, + Boolean nonEmpty, + StarlarkThread thread) throws EvalException { - return new FakeDescriptor(Type.OUTPUT_LIST, doc, mandatory); + return new FakeDescriptor(AttributeType.OUTPUT_LIST, doc, mandatory, ImmutableList.of(), ""); } @Override - public Descriptor stringDictAttribute(Boolean allowEmpty, SkylarkDict defaultO, String doc, - Boolean mandatory, Boolean nonEmpty, FuncallExpression ast, Environment env) + public Descriptor stringDictAttribute( + Boolean allowEmpty, + Dict defaultO, + String doc, + Boolean mandatory, + Boolean nonEmpty, + StarlarkThread thread) throws EvalException { - return new FakeDescriptor(Type.STRING_DICT, doc, mandatory); + return new FakeDescriptor( + AttributeType.STRING_DICT, doc, mandatory, ImmutableList.of(), defaultO); } @Override - public Descriptor stringListDictAttribute(Boolean allowEmpty, SkylarkDict defaultO, - String doc, Boolean mandatory, Boolean nonEmpty, FuncallExpression ast, Environment env) + public Descriptor stringListDictAttribute( + Boolean allowEmpty, + Dict defaultO, + String doc, + Boolean mandatory, + Boolean nonEmpty, + StarlarkThread thread) throws EvalException { - return new FakeDescriptor(Type.STRING_LIST_DICT, doc, mandatory); + return new FakeDescriptor( + AttributeType.STRING_LIST_DICT, doc, mandatory, ImmutableList.of(), defaultO); } @Override - public Descriptor licenseAttribute(Object defaultO, String doc, Boolean mandatory, - FuncallExpression ast, Environment env) throws EvalException { - return new FakeDescriptor(Type.LICENSE, doc, mandatory); + public Descriptor licenseAttribute( + Object defaultO, String doc, Boolean mandatory, StarlarkThread thread) throws EvalException { + return new FakeDescriptor( + AttributeType.STRING_LIST, doc, mandatory, ImmutableList.of(), defaultO); } @Override - public void repr(SkylarkPrinter printer) {} + public void repr(Printer printer) {} + + /** + * Returns a list of provider name groups, given the value of a Starlark attribute's "providers" + * argument. + * + *

{@code providers} can either be a list of providers or a list of lists of providers, where + * each provider is represented by a ProviderApi or by a String. In the case of a single-level + * list, the whole list is considered a single group, while in the case of a double-level list, + * each of the inner lists is a separate group. + */ + private static List> allProviderNameGroups( + Sequence providers, StarlarkThread thread) { + + List> allNameGroups = new ArrayList<>(); + for (Object object : providers) { + List providerNameGroup; + if (object instanceof Sequence) { + Sequence group = (Sequence) object; + providerNameGroup = parseProviderGroup(group, thread); + allNameGroups.add(providerNameGroup); + } else { + providerNameGroup = parseProviderGroup(providers, thread); + allNameGroups.add(providerNameGroup); + break; + } + } + return allNameGroups; + } + + /** + * Returns the names of the providers in the given group. + * + *

Each item in the group may be either a {@link ProviderApi} or a {@code String} (representing + * a legacy provider). + */ + private static List parseProviderGroup(Sequence group, StarlarkThread thread) { + List providerNameGroup = new ArrayList<>(); + for (Object object : group) { + if (object instanceof ProviderApi) { + ProviderApi provider = (ProviderApi) object; + String providerName = providerName(provider, thread); + providerNameGroup.add(providerName); + } else if (object instanceof String) { + String legacyProvider = (String) object; + providerNameGroup.add(legacyProvider); + } + } + return providerNameGroup; + } + + /** + * Returns the name of {@code provider}. + * + *

{@code thread} contains a {@code Map} where the values are built-in objects + * or objects defined in the file and the keys are the names of these objects. If a {@code + * provider} is in the map, the name of the provider is set as the key of this object in {@code + * bindings}. If it is not in the map, the provider may be part of a module in the map and the + * name will be set to "Unknown Provider". + */ + private static String providerName(ProviderApi provider, StarlarkThread thread) { + Map bindings = + Module.ofInnermostEnclosingStarlarkFunction(thread).getTransitiveBindings(); + for (Entry envEntry : bindings.entrySet()) { + if (provider.equals(envEntry.getValue())) { + return envEntry.getKey(); + } + } + return "Unknown Provider"; + } } diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java index d3d2e050b3e..6a183e80328 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java @@ -139,7 +139,6 @@ private static StarlarkSemanticsOptions buildRandomOptions(Random rand) throws E "--incompatible_allow_tags_propagation=" + rand.nextBoolean(), // flag, Java names differ "--experimental_cc_shared_library=" + rand.nextBoolean(), "--experimental_repo_remote_exec=" + rand.nextBoolean(), - "--experimental_exec_groups=" + rand.nextBoolean(), "--incompatible_always_check_depset_elements=" + rand.nextBoolean(), "--incompatible_applicable_licenses=" + rand.nextBoolean(), "--incompatible_depset_for_libraries_to_link_getter=" + rand.nextBoolean(), @@ -194,7 +193,6 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) { .experimentalAllowTagsPropagation(rand.nextBoolean()) .experimentalCcSharedLibrary(rand.nextBoolean()) .experimentalRepoRemoteExec(rand.nextBoolean()) - .experimentalExecGroups(rand.nextBoolean()) .incompatibleAlwaysCheckDepsetElements(rand.nextBoolean()) .incompatibleApplicableLicenses(rand.nextBoolean()) .incompatibleDepsetForLibrariesToLinkGetter(rand.nextBoolean()) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java index f38571aa236..367341f5bb1 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import static com.google.devtools.build.lib.analysis.OutputGroupInfo.INTERNAL_SUFFIX; import static com.google.devtools.build.lib.packages.FunctionSplitTransitionWhitelist.WHITELIST_ATTRIBUTE_NAME; -import static org.junit.Assert.assertThrows; +import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; @@ -55,7 +55,7 @@ import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; import com.google.devtools.build.lib.skyframe.PackageFunction; import com.google.devtools.build.lib.skyframe.SkyFunctions; -import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction; +import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction; import com.google.devtools.build.lib.syntax.Depset; import com.google.devtools.build.lib.syntax.Sequence; import com.google.devtools.build.lib.syntax.Starlark; @@ -240,7 +240,7 @@ public void testMacroHasGeneratorAttributes() throws Exception { AttributeContainer withMacro = getContainerForTarget("macro_target"); assertThat(withMacro.getAttr("generator_name")).isEqualTo("macro_target"); assertThat(withMacro.getAttr("generator_function")).isEqualTo("macro"); - assertThat(withMacro.getAttr("generator_location")).isEqualTo("test/skylark/BUILD:3:11"); + assertThat(withMacro.getAttr("generator_location")).isEqualTo("test/skylark/BUILD:3:1"); // Attributes are only set when the rule was created by a macro AttributeContainer noMacro = getContainerForTarget("no_macro_target"); @@ -251,7 +251,7 @@ public void testMacroHasGeneratorAttributes() throws Exception { AttributeContainer nativeMacro = getContainerForTarget("native_macro_target_suffix"); assertThat(nativeMacro.getAttr("generator_name")).isEqualTo("native_macro_target"); assertThat(nativeMacro.getAttr("generator_function")).isEqualTo("native_macro"); - assertThat(nativeMacro.getAttr("generator_location")).isEqualTo("test/skylark/BUILD:5:18"); + assertThat(nativeMacro.getAttr("generator_location")).isEqualTo("test/skylark/BUILD:5:1"); AttributeContainer ccTarget = getContainerForTarget("cc_target"); assertThat(ccTarget.getAttr("generator_name")).isEqualTo(""); @@ -281,6 +281,36 @@ public void sanityCheckUserDefinedTestRule() throws Exception { getConfiguredTarget("//test/skylark:test_name"); } + @Test + public void testOutputGroups() throws Exception { + setSkylarkSemanticsOptions( + "--incompatible_disallow_struct_provider_syntax=false", + "--incompatible_no_target_output_group=false"); + scratch.file( + "test/skylark/extension.bzl", + "load('//myinfo:myinfo.bzl', 'MyInfo')", + "def _impl(ctx):", + " f = ctx.attr.dep.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", + " return [MyInfo(result = f),", + " OutputGroupInfo(my_group = f)]", + "my_rule = rule(implementation = _impl,", + " attrs = { 'dep' : attr.label() })"); + scratch.file( + "test/skylark/BUILD", + "load('//test/skylark:extension.bzl', 'my_rule')", + "cc_binary(name = 'lib', data = ['a.txt'])", + "my_rule(name='my', dep = ':lib')"); + NestedSet hiddenTopLevelArtifacts = + OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) + .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); + Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + assertThat(result.getSet(Artifact.class).toList()) + .containsExactlyElementsIn(hiddenTopLevelArtifacts.toList()); + assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group").toList()) + .containsExactlyElementsIn(hiddenTopLevelArtifacts.toList()); + } + @Test public void testOutputGroupsDeclaredProvider() throws Exception { scratch.file( @@ -378,6 +408,37 @@ public void testOutputGroupsAsDictionaryPipe() throws Exception { .containsExactlyElementsIn(hiddenTopLevelArtifacts.toList()); } + @Test + public void testOutputGroupsWithList() throws Exception { + scratch.file( + "test/skylark/extension.bzl", + "load('//myinfo:myinfo.bzl', 'MyInfo')", + "def _impl(ctx):", + " f = ctx.attr.dep.output_group('_hidden_top_level" + INTERNAL_SUFFIX + "')", + " g = f.to_list()", + " return [MyInfo(result = f),", + " OutputGroupInfo(my_group = g, my_empty_group = [])]", + "my_rule = rule(implementation = _impl,", + " attrs = { 'dep' : attr.label() })"); + scratch.file( + "test/skylark/BUILD", + "load('//test/skylark:extension.bzl', 'my_rule')", + "cc_binary(name = 'lib', data = ['a.txt'])", + "my_rule(name='my', dep = ':lib')"); + + setSkylarkSemanticsOptions("--incompatible_no_target_output_group=false"); + NestedSet hiddenTopLevelArtifacts = + OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) + .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); + ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); + Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + assertThat(result.getSet(Artifact.class).toList()) + .containsExactlyElementsIn(hiddenTopLevelArtifacts.toList()); + assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group").toList()) + .containsExactlyElementsIn(hiddenTopLevelArtifacts.toList()); + assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_empty_group").toList()).isEmpty(); + } + @Test public void testOutputGroupsDeclaredProviderWithList() throws Exception { scratch.file( @@ -1670,7 +1731,7 @@ public void testOutputsObjectOrphanExecutableReportError() throws Exception { reporter.removeHandler(failFastHandler); getConfiguredTarget("//test:xxx"); - assertContainsEvent("ERROR /workspace/test/BUILD:2:8: in my_rule rule //test:xxx: "); + assertContainsEvent("ERROR /workspace/test/BUILD:2:1: in my_rule rule //test:xxx: "); assertContainsEvent("The following files have no generating action:"); assertContainsEvent("test/xxx"); } @@ -1716,11 +1777,10 @@ public void testCustomAndDefaultExecutableReportsError() throws Exception { ); reporter.removeHandler(failFastHandler); getConfiguredTarget("//test:xxx"); - assertContainsEvent("ERROR /workspace/test/BUILD:2:8: in my_rule rule //test:xxx: "); - assertContainsEvent( - "/workspace/test/rule.bzl:5:23: The rule 'my_rule' both accesses " - + "'ctx.outputs.executable' and provides a different executable 'test/x.sh'. " - + "Do not use 'ctx.output.executable'."); + assertContainsEvent("ERROR /workspace/test/BUILD:2:1: in my_rule rule //test:xxx: "); + assertContainsEvent("/workspace/test/rule.bzl:5:12: The rule 'my_rule' both accesses " + + "'ctx.outputs.executable' and provides a different executable 'test/x.sh'. " + + "Do not use 'ctx.output.executable'."); } @@ -1795,7 +1855,7 @@ public void testOutputsObjectInDifferentRuleInaccessible() throws Exception { reporter.removeHandler(failFastHandler); getConfiguredTarget("//test:yyy"); - assertContainsEvent("ERROR /workspace/test/BUILD:3:12: in my_dep_rule rule //test:yyy: "); + assertContainsEvent("ERROR /workspace/test/BUILD:3:1: in my_dep_rule rule //test:yyy: "); assertContainsEvent("File \"/workspace/test/rule.bzl\", line 8, in _dep_impl"); assertContainsEvent("ctx.attr.dep[PInfo].outputs.executable"); assertContainsEvent("cannot access outputs of rule '//test:xxx' outside " @@ -1858,7 +1918,7 @@ public void testExecutableRuleWithNoExecutableReportsError() throws Exception { reporter.removeHandler(failFastHandler); getConfiguredTarget("//test:xxx"); - assertContainsEvent("ERROR /workspace/test/BUILD:2:8: in my_rule rule //test:xxx: "); + assertContainsEvent("ERROR /workspace/test/BUILD:2:1: in my_rule rule //test:xxx: "); assertContainsEvent("/rule.bzl:1:5: The rule 'my_rule' is executable. " + "It needs to create an executable File and pass it as the 'executable' " + "parameter to the DefaultInfo it returns."); @@ -1891,7 +1951,7 @@ public void testExecutableFromDifferentRuleIsForbidden() throws Exception { reporter.removeHandler(failFastHandler); getConfiguredTarget("//src:r_tools"); assertContainsEvent( - "/workspace/src/rulez.bzl:2:23: 'executable' provided by an executable" + "/workspace/src/rulez.bzl:2:12: 'executable' provided by an executable" + " rule 'r' should be created by the same rule."); } @@ -1911,16 +1971,10 @@ public void testFileAndDirectory() throws Exception { " 'out': 'foo/bar/baz',", " },", ")"); - scratch.file( - "BUILD", // - "load(':ext.bzl', 'extrule')", - "", - "extrule(", - " name = 'test'", - ")"); + scratch.file("BUILD", "load(':ext.bzl', 'extrule')", "", "extrule(", " name = 'test'", ")"); reporter.removeHandler(failFastHandler); getConfiguredTarget("//:test"); - assertContainsEvent("ERROR /workspace/BUILD:3:8: in extrule rule //:test:"); + assertContainsEvent("ERROR /workspace/BUILD:3:1: in extrule rule //:test:"); assertContainsEvent("he following directories were also declared as files:"); assertContainsEvent("foo/bar/baz"); } @@ -1958,6 +2012,25 @@ public void testEnvironmentConstraintsFromSkylarkRule() throws Exception { "//test/skylark:dep doesn't support expected environment: //buildenv/foo:default"); } + @Test + public void testNoTargetOutputGroup() throws Exception { + setSkylarkSemanticsOptions("--incompatible_no_target_output_group=true"); + scratch.file( + "test/skylark/extension.bzl", + "def _impl(ctx):", + " f = ctx.attr.dep.output_group()", + "my_rule = rule(implementation = _impl,", + " attrs = { 'dep' : attr.label() })"); + + checkError( + "test/skylark", + "r", + " (rule 'cc_binary') doesn't have provider 'output_group'", + "load('//test/skylark:extension.bzl', 'my_rule')", + "cc_binary(name = 'lib', data = ['a.txt'])", + "my_rule(name='r', dep = ':lib')"); + } + @Test public void testAnalysisFailureInfo() throws Exception { scratch.file( @@ -2980,14 +3053,14 @@ public final void initializeLookupFunctions() throws Exception { ImmutableMap skyFunctions = ((InMemoryMemoizingEvaluator) getSkyframeExecutor().getEvaluatorForTesting()) .getSkyFunctionsForTesting(); - StarlarkImportLookupFunction starlarkImportLookupFunction = - new StarlarkImportLookupFunction( + SkylarkImportLookupFunction skylarkImportLookupFunction = + new SkylarkImportLookupFunction( this.getRuleClassProvider(), this.getPackageFactory(), /*starlarkImportLookupValueCacheSize=*/ 2); - starlarkImportLookupFunction.resetCache(); + skylarkImportLookupFunction.resetCache(); ((PackageFunction) skyFunctions.get(SkyFunctions.PACKAGE)) - .setStarlarkImportLookupFunctionForInliningForTesting(starlarkImportLookupFunction); + .setSkylarkImportLookupFunctionForInliningForTesting(skylarkImportLookupFunction); } @Override diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylarkinterface/processor/testsources/EnablingAndDisablingFlag.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylarkinterface/processor/testsources/EnablingAndDisablingFlag.java index f115acfe159..27e3882bf67 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylarkinterface/processor/testsources/EnablingAndDisablingFlag.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylarkinterface/processor/testsources/EnablingAndDisablingFlag.java @@ -17,11 +17,12 @@ import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier; +import com.google.devtools.build.lib.syntax.StarlarkValue; /** * Test case for a SkylarkCallable method which has both enablingFlag and disablingFlag specified. */ -public class EnablingAndDisablingFlag { +public class EnablingAndDisablingFlag implements StarlarkValue { @SkylarkCallable( name = "someMethod", @@ -30,8 +31,8 @@ public class EnablingAndDisablingFlag { @Param(name = "one", type = String.class, named = true), @Param(name = "two", type = Integer.class, named = true), }, - enableOnlyWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES, - disableWithFlag = FlagIdentifier.INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES) + enableOnlyWithFlag = FlagIdentifier.INCOMPATIBLE_APPLICABLE_LICENSES, + disableWithFlag = FlagIdentifier.INCOMPATIBLE_APPLICABLE_LICENSES) public String someMethod(String one, Integer two) { return "foo"; }