diff options
Diffstat (limited to 'src/main/java/com/google')
6 files changed, 1002 insertions, 890 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index a70778d4bf..13ad5af5b8 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -426,6 +426,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec", + "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java index 423fab890a..a7ecf893e9 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java @@ -22,7 +22,6 @@ import com.google.common.collect.Iterables; import com.google.devtools.build.lib.analysis.config.HostTransition; import com.google.devtools.build.lib.analysis.config.transitions.PatchTransition; import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition; -import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.Attribute.AllowedValueSet; @@ -35,13 +34,8 @@ 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.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skylarkinterface.Param; -import com.google.devtools.build.lib.skylarkinterface.ParamType; -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.skylarkbuildapi.SkylarkAttrApi; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; -import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; @@ -69,83 +63,10 @@ import javax.annotation.Nullable; * The functions are executed through reflection. As everywhere in Skylark, arguments are * type-checked with the signature and cannot be null. */ -@SkylarkModule( - name = "attr", - namespace = true, - category = SkylarkModuleCategory.BUILTIN, - doc = - "Module for creating new attributes. " - + "They are only for use with <a href=\"globals.html#rule\">rule</a> or " - + "<a href=\"globals.html#aspect\">aspect</a>. " - + "<a href=\"https://github.com/bazelbuild/examples/tree/master/rules/" - + "attributes/printer.bzl\">See example of use</a>." -) -public final class SkylarkAttr implements SkylarkValue { +public final class SkylarkAttr implements SkylarkAttrApi { // Arguments - private static final String ALLOW_FILES_ARG = "allow_files"; - private static final 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, <code>[\".cc\", \".cpp\"]</code>)."; - - private static final String ALLOW_RULES_ARG = "allow_rules"; - private static final String ALLOW_RULES_DOC = - "Which rule targets (name of the classes) are allowed. This is deprecated (kept only for " - + "compatibility), use providers instead."; - - private static final String ASPECTS_ARG = "aspects"; - private static final String ASPECTS_ARG_DOC = - "Aspects that should be applied to the dependency or dependencies specified by this " - + "attribute."; - - private static final String CONFIGURATION_ARG = "cfg"; - private static final String CONFIGURATION_DOC = - "<a href=\"../rules.$DOC_EXT#configurations\">Configuration</a> of the attribute. It can be " - + "either <code>\"data\"</code>, <code>\"host\"</code>, or <code>\"target\"</code>."; - - private static final String DEFAULT_ARG = "default"; - // A trailing space is required because it's often prepended to other sentences - private static final String DEFAULT_DOC = "The default value of the attribute. "; - - private static final String DOC_ARG = "doc"; - private static final String DOC_DOC = - "A description of the attribute that can be extracted by documentation generating tools."; - - private static final String EXECUTABLE_ARG = "executable"; - private static final String EXECUTABLE_DOC = - "True if the label 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 <code>ctx.executable.<attribute_name></code>."; - - private static final String FLAGS_ARG = "flags"; - private static final String FLAGS_DOC = "Deprecated, will be removed."; - - private static final String MANDATORY_ARG = "mandatory"; - private static final String MANDATORY_DOC = "True if the value must be explicitly specified."; - - private static final String NON_EMPTY_ARG = "non_empty"; - private static final String NON_EMPTY_DOC = - "True if the attribute must not be empty. Deprecated: Use allow_empty instead."; - - private static final String ALLOW_EMPTY_ARG = "allow_empty"; - private static final String ALLOW_EMPTY_DOC = "True if the attribute can be empty."; - - private static final String PROVIDERS_ARG = "providers"; - private static final String PROVIDERS_DOC = - "Mandatory providers list. It should be either a list of providers, or a " - + "list of lists of providers. Every dependency should provide ALL providers " - + "from at least ONE of these lists. A single list of providers will be " - + "automatically converted to a list containing one list of providers."; - - private static final String SINGLE_FILE_ARG = "single_file"; - private static final String ALLOW_SINGLE_FILE_ARG = "allow_single_file"; - - private static final String VALUES_ARG = "values"; - private static final String VALUES_DOC = - "The list of allowed values for the attribute. An error is raised if any other " - + "value is given."; - private static boolean containsNonNoneKey(SkylarkDict<String, Object> arguments, String key) { return arguments.containsKey(key) && arguments.get(key) != Runtime.NONE; } @@ -471,50 +392,7 @@ public final class SkylarkAttr implements SkylarkValue { printer.append("<attr>"); } - @SkylarkCallable( - name = "int", - doc = "Creates an attribute of type int.", - parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Integer.class), - @ParamType(type = UserDefinedFunction.class) - }, - defaultValue = "0", - doc = DEFAULT_DOC, - named = true, - positional = false - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = MANDATORY_DOC, - named = true, - positional = false - ), - @Param( - name = VALUES_ARG, - type = SkylarkList.class, - generic1 = Integer.class, - defaultValue = "[]", - doc = VALUES_DOC, - named = true, - positional = false - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor intAttribute( Integer defaultInt, String doc, @@ -534,49 +412,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "string", - doc = "Creates an attribute of type <a href=\"string.html\">string</a>.", - parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = String.class), - }, - defaultValue = "''", - doc = DEFAULT_DOC, - named = true, - positional = false - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = MANDATORY_DOC, - named = true, - positional = false - ), - @Param( - name = VALUES_ARG, - type = SkylarkList.class, - generic1 = String.class, - defaultValue = "[]", - doc = VALUES_DOC, - named = true, - positional = false - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor stringAttribute( String defaultString, String doc, @@ -595,128 +431,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "label", - doc = - "Creates an attribute of type <a href=\"Target.html\">Target</a> which is the target " - + "referred to by the label. " - + "It is the only way to specify a dependency to another target. " - + "If you need a dependency that the user cannot overwrite, " - + "<a href=\"../rules.$DOC_EXT#private-attributes\">make the attribute private</a>.", - parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Label.class), - @ParamType(type = String.class), - @ParamType(type = SkylarkLateBoundDefault.class), - @ParamType(type = UserDefinedFunction.class) - }, - callbackEnabled = true, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = - DEFAULT_DOC - + "Use a string or the <a href=\"globals.html#Label\"><code>Label</code></a> " - + "function to specify a default value, for example, " - + "<code>attr.label(default = \"//a:b\")</code>." - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = EXECUTABLE_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = EXECUTABLE_DOC - ), - @Param( - name = ALLOW_FILES_ARG, - defaultValue = "None", - named = true, - positional = false, - noneable = true, - doc = ALLOW_FILES_DOC - ), - @Param( - name = ALLOW_SINGLE_FILE_ARG, - defaultValue = "None", - named = true, - positional = false, - noneable = true, - doc = - "This is similar to <code>allow_files</code>, with the restriction that the label must " - + "correspond to a single <a href=\"File.html\">File</a>. " - + "Access it through <code>ctx.file.<attribute_name></code>." - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ), - @Param( - name = PROVIDERS_ARG, - type = SkylarkList.class, - defaultValue = "[]", - named = true, - positional = false, - doc = PROVIDERS_DOC - ), - @Param( - name = ALLOW_RULES_ARG, - type = SkylarkList.class, - generic1 = String.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = ALLOW_RULES_DOC - ), - @Param( - name = SINGLE_FILE_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = - "Deprecated: Use <code>allow_single_file</code> instead. " - + "If True, the label must correspond to a single <a href=\"File.html\">File</a>. " - + "Access it through <code>ctx.file.<attribute_name></code>." - ), - @Param( - name = CONFIGURATION_ARG, - type = Object.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = CONFIGURATION_DOC + " This parameter is required if <code>executable</code> is True." - ), - @Param( - name = ASPECTS_ARG, - type = SkylarkList.class, - generic1 = SkylarkAspect.class, - defaultValue = "[]", - named = true, - positional = false, - doc = ASPECTS_ARG_DOC - ), - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor labelAttribute( Object defaultO, String doc, @@ -768,56 +483,7 @@ public final class SkylarkAttr implements SkylarkValue { } } - @SkylarkCallable( - name = "string_list", - doc = - "Creates an attribute which is a <a href=\"list.html\">list</a> of " - + "<a href=\"string.html\">strings</a>.", - parameters = { - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = MANDATORY_DOC, - named = true - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = NON_EMPTY_DOC, - named = true - ), - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = String.class), - @ParamType(type = UserDefinedFunction.class) - }, - defaultValue = "[]", - doc = DEFAULT_DOC, - named = true, - positional = false - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor stringListAttribute( Boolean mandatory, Boolean nonEmpty, @@ -845,54 +511,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "int_list", - doc = "Creates an attribute which is a <a href=\"list.html\">list</a> of ints.", - parameters = { - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = MANDATORY_DOC, - named = true - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - doc = NON_EMPTY_DOC, - named = true - ), - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Integer.class), - @ParamType(type = UserDefinedFunction.class) - }, - defaultValue = "[]", - doc = DEFAULT_DOC, - named = true, - positional = false - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor intListAttribute( Boolean mandatory, Boolean nonEmpty, @@ -920,117 +539,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "label_list", - doc = - "Creates an attribute which is a <a href=\"list.html\">list</a> of type " - + "<a href=\"Target.html\">Target</a> which are specified by the labels in the list. " - + "See <a href=\"attr.html#label\">label</a> for more information.", - parameters = { - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Label.class), - @ParamType(type = UserDefinedFunction.class) - }, - callbackEnabled = true, - defaultValue = "[]", - named = true, - positional = false, - doc = - DEFAULT_DOC - + "Use strings or the <a href=\"globals.html#Label\"><code>Label</code></a> " - + "function to specify default values, for example, " - + "<code>attr.label_list(default = [\"//a:b\", \"//a:c\"])</code>." - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = ALLOW_FILES_ARG, // bool or FileType filter - defaultValue = "None", - named = true, - positional = false, - noneable = true, - doc = ALLOW_FILES_DOC - ), - @Param( - name = ALLOW_RULES_ARG, - type = SkylarkList.class, - generic1 = String.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = ALLOW_RULES_DOC - ), - @Param( - name = PROVIDERS_ARG, - type = SkylarkList.class, - defaultValue = "[]", - named = true, - positional = false, - doc = PROVIDERS_DOC - ), - @Param( - name = FLAGS_ARG, - type = SkylarkList.class, - generic1 = String.class, - defaultValue = "[]", - named = true, - positional = false, - doc = FLAGS_DOC - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = NON_EMPTY_DOC - ), - @Param( - name = CONFIGURATION_ARG, - type = Object.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = CONFIGURATION_DOC - ), - @Param( - name = ASPECTS_ARG, - type = SkylarkList.class, - generic1 = SkylarkAspect.class, - defaultValue = "[]", - named = true, - positional = false, - doc = ASPECTS_ARG_DOC - ), - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor labelListAttribute( Boolean allowEmpty, Object defaultList, @@ -1079,119 +588,7 @@ public final class SkylarkAttr implements SkylarkValue { } } - @SkylarkCallable( - name = "label_keyed_string_dict", - doc = - "Creates an attribute which is a <a href=\"dict.html\">dict</a>. Its keys are type " - + "<a href=\"Target.html\">Target</a> and are specified by the label keys of the " - + "input dict. Its values are <a href=\"string.html\">strings</a>. See " - + "<a href=\"attr.html#label\">label</a> for more information.", - parameters = { - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) - }, - callbackEnabled = true, - defaultValue = "{}", - named = true, - positional = false, - doc = - DEFAULT_DOC - + "Use strings or the <a href=\"globals.html#Label\"><code>Label</code></a> " - + "function to specify default values, for example, " - + "<code>attr.label_keyed_string_dict(default = " - + "{\"//a:b\": \"value\", \"//a:c\": \"string\"})</code>." - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = ALLOW_FILES_ARG, // bool or FileType filter - defaultValue = "None", - named = true, - positional = false, - noneable = true, - doc = ALLOW_FILES_DOC - ), - @Param( - name = ALLOW_RULES_ARG, - type = SkylarkList.class, - generic1 = String.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = ALLOW_RULES_DOC - ), - @Param( - name = PROVIDERS_ARG, - type = SkylarkList.class, - defaultValue = "[]", - named = true, - positional = false, - doc = PROVIDERS_DOC - ), - @Param( - name = FLAGS_ARG, - type = SkylarkList.class, - generic1 = String.class, - defaultValue = "[]", - named = true, - positional = false, - doc = FLAGS_DOC - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = NON_EMPTY_DOC - ), - @Param( - name = CONFIGURATION_ARG, - type = Object.class, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = CONFIGURATION_DOC - ), - @Param( - name = ASPECTS_ARG, - type = SkylarkList.class, - generic1 = SkylarkAspect.class, - defaultValue = "[]", - named = true, - positional = false, - doc = ASPECTS_ARG_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor labelKeyedStringDictAttribute( Boolean allowEmpty, Object defaultList, @@ -1241,41 +638,7 @@ public final class SkylarkAttr implements SkylarkValue { } } - @SkylarkCallable( - name = "bool", - doc = "Creates an attribute of type bool.", - parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Boolean.class), - @ParamType(type = UserDefinedFunction.class) - }, - defaultValue = "False", - named = true, - positional = false, - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor boolAttribute( Boolean defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) throws EvalException { @@ -1288,45 +651,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "output", - doc = - "Creates an attribute of type output. " - + "The user provides a file name (string) and the rule must create an action that " - + "generates the file.", - parameters = { - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = Label.class), - @ParamType(type = UserDefinedFunction.class) - }, - noneable = true, - defaultValue = "None", - named = true, - positional = false, - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor outputAttribute( Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) throws EvalException { @@ -1339,59 +664,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "output_list", - doc = - "Creates an attribute which is a <a href=\"list.html\">list</a> of outputs. " - + "See <a href=\"attr.html#output\">output</a> for more information.", - parameters = { - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkList.class, generic1 = Label.class), - @ParamType(type = UserDefinedFunction.class) - }, - generic1 = Label.class, - defaultValue = "[]", - named = true, - positional = false, - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = NON_EMPTY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor outputListAttribute( Boolean allowEmpty, SkylarkList defaultList, @@ -1419,58 +692,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "string_dict", - doc = - "Creates an attribute of type <a href=\"dict.html\">dict</a>, mapping from " - + "<a href=\"string.html\">string</a> to <a href=\"string.html\">string</a>.", - parameters = { - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) - }, - named = true, - positional = false, - defaultValue = "{}", - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - named = true, - positional = false, - defaultValue = "False", - doc = MANDATORY_DOC - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = NON_EMPTY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor stringDictAttribute( Boolean allowEmpty, SkylarkDict<?, ?> defaultO, @@ -1498,59 +720,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "string_list_dict", - doc = - "Creates an attribute of type <a href=\"dict.html\">dict</a>, mapping from " - + "<a href=\"string.html\">string</a> to <a href=\"list.html\">list</a> of " - + "<a href=\"string.html\">string</a>.", - parameters = { - @Param( - name = ALLOW_EMPTY_ARG, - type = Boolean.class, - defaultValue = "True", - doc = ALLOW_EMPTY_DOC, - named = true - ), - @Param( - name = DEFAULT_ARG, - allowedTypes = { - @ParamType(type = SkylarkDict.class), - @ParamType(type = UserDefinedFunction.class) - }, - defaultValue = "{}", - named = true, - positional = false, - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ), - @Param( - name = NON_EMPTY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = NON_EMPTY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor stringListDictAttribute( Boolean allowEmpty, SkylarkDict<?, ?> defaultO, @@ -1578,40 +748,7 @@ public final class SkylarkAttr implements SkylarkValue { env); } - @SkylarkCallable( - name = "license", - doc = "Creates an attribute of type license.", - // TODO(bazel-team): Implement proper license support for Skylark. - parameters = { - // TODO(bazel-team): ensure this is the correct default value - @Param( - name = DEFAULT_ARG, - defaultValue = "None", - noneable = true, - named = true, - positional = false, - doc = DEFAULT_DOC - ), - @Param( - name = DOC_ARG, - type = String.class, - defaultValue = "''", - doc = DOC_DOC, - named = true, - positional = false - ), - @Param( - name = MANDATORY_ARG, - type = Boolean.class, - defaultValue = "False", - named = true, - positional = false, - doc = MANDATORY_DOC - ) - }, - useAst = true, - useEnvironment = true - ) + @Override public Descriptor licenseAttribute( Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) throws EvalException { @@ -1625,17 +762,8 @@ public final class SkylarkAttr implements SkylarkValue { } /** A descriptor of an attribute defined in Skylark. */ - @SkylarkModule( - name = "Attribute", - category = SkylarkModuleCategory.NONE, - doc = - "Representation of a definition of an attribute. Use the <a href=\"attr.html\">attr</a> " - + "module to create an Attribute. They are only for use with a " - + "<a href=\"globals.html#rule\">rule</a> or an " - + "<a href=\"globals.html#aspect\">aspect</a>." - ) @AutoCodec - public static final class Descriptor implements SkylarkValue { + public static final class Descriptor implements SkylarkAttrApi.Descriptor { private final ImmutableAttributeFactory attributeFactory; private final String name; diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java index b8fed99cf9..a39d69db5e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java @@ -16,9 +16,9 @@ package com.google.devtools.build.lib.packages; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.skylarkbuildapi.SkylarkAspectApi; 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.EvalException; /** Represents an aspect which can be attached to a skylark-defined rule attribute. */ @@ -30,7 +30,7 @@ import com.google.devtools.build.lib.syntax.EvalException; + "documentation of the aspect function</a> or the " + "<a href=\"../aspects.md\">introduction to Aspects</a>." ) -public interface SkylarkAspect extends SkylarkValue { +public interface SkylarkAspect extends SkylarkAspectApi { /** * Attaches this aspect to an attribute. diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD index 492daee57e..b441d201b3 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD @@ -22,6 +22,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib:events", "//src/main/java/com/google/devtools/build/lib:skylarkinterface", "//src/main/java/com/google/devtools/build/lib:syntax", + "//src/main/java/com/google/devtools/build/lib/cmdline", "//third_party:guava", "//third_party:jsr305", ], diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAspectApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAspectApi.java new file mode 100644 index 0000000000..30e4127c3b --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAspectApi.java @@ -0,0 +1,22 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi; + +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; + +/** The interface for skylark-defined aspects in the Build API. */ +public interface SkylarkAspectApi extends SkylarkValue { + // TODO(cparsons): Migrate this API from the Bazel-specific implementation. +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java new file mode 100644 index 0000000000..5c3c3a4292 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkAttrApi.java @@ -0,0 +1,960 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi; + +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skylarkinterface.Param; +import com.google.devtools.build.lib.skylarkinterface.ParamType; +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.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; + +/** + * The "attr" module of the Build API. + * + * <p>It exposes functions (for example, 'attr.string', 'attr.label_list', etc.) to Skylark users + * for creating attribute definitions. + */ +@SkylarkModule( + name = "attr", + namespace = true, + category = SkylarkModuleCategory.BUILTIN, + doc = + "Module for creating new attributes. " + + "They are only for use with <a href=\"globals.html#rule\">rule</a> or " + + "<a href=\"globals.html#aspect\">aspect</a>. " + + "<a href=\"https://github.com/bazelbuild/examples/tree/master/rules/" + + "attributes/printer.bzl\">See example of use</a>.") +public interface SkylarkAttrApi extends SkylarkValue { + + static final String ALLOW_FILES_ARG = "allow_files"; + static final 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, <code>[\".cc\", \".cpp\"]</code>)."; + + static final String ALLOW_RULES_ARG = "allow_rules"; + static final 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 = + "Aspects that should be applied to the dependency or dependencies specified by this " + + "attribute."; + + static final String CONFIGURATION_ARG = "cfg"; + static final String CONFIGURATION_DOC = + "<a href=\"../rules.$DOC_EXT#configurations\">Configuration</a> of the attribute. It can be " + + "either <code>\"data\"</code>, <code>\"host\"</code>, or <code>\"target\"</code>."; + + static final String DEFAULT_ARG = "default"; + // A trailing space is required because it's often prepended to other sentences + static final String DEFAULT_DOC = "The default value of the attribute. "; + + static final String DOC_ARG = "doc"; + static final 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 = + "True if the label 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 <code>ctx.executable.<attribute_name></code>."; + + static final String FLAGS_ARG = "flags"; + static final String FLAGS_DOC = "Deprecated, will be removed."; + + static final String MANDATORY_ARG = "mandatory"; + static final String MANDATORY_DOC = "True if the value must be explicitly specified."; + + static final String NON_EMPTY_ARG = "non_empty"; + static final 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."; + + static final String PROVIDERS_ARG = "providers"; + static final String PROVIDERS_DOC = + "Mandatory providers list. It should be either a list of providers, or a " + + "list of lists of providers. Every dependency should provide ALL providers " + + "from at least ONE of these lists. A single list of providers will be " + + "automatically converted to a list containing one list of providers."; + + static final String SINGLE_FILE_ARG = "single_file"; + static final String ALLOW_SINGLE_FILE_ARG = "allow_single_file"; + + static final String VALUES_ARG = "values"; + static final String VALUES_DOC = + "The list of allowed values for the attribute. An error is raised if any other " + + "value is given."; + + @SkylarkCallable( + name = "int", + doc = "Creates an attribute of type int.", + parameters = { + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = Integer.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "0", + doc = DEFAULT_DOC, + named = true, + positional = false), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = MANDATORY_DOC, + named = true, + positional = false), + @Param( + name = VALUES_ARG, + type = SkylarkList.class, + generic1 = Integer.class, + defaultValue = "[]", + doc = VALUES_DOC, + named = true, + positional = false) + }, + useAst = true, + useEnvironment = true) + Descriptor intAttribute( + Integer defaultInt, + String doc, + Boolean mandatory, + SkylarkList<?> values, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "string", + doc = "Creates an attribute of type <a href=\"string.html\">string</a>.", + parameters = { + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = String.class), + }, + defaultValue = "''", + doc = DEFAULT_DOC, + named = true, + positional = false), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = MANDATORY_DOC, + named = true, + positional = false), + @Param( + name = VALUES_ARG, + type = SkylarkList.class, + generic1 = String.class, + defaultValue = "[]", + doc = VALUES_DOC, + named = true, + positional = false) + }, + useAst = true, + useEnvironment = true) + public Descriptor stringAttribute( + String defaultString, + String doc, + Boolean mandatory, + SkylarkList<?> values, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "label", + doc = + "Creates an attribute of type <a href=\"Target.html\">Target</a> which is the target " + + "referred to by the label. " + + "It is the only way to specify a dependency to another target. " + + "If you need a dependency that the user cannot overwrite, " + + "<a href=\"../rules.$DOC_EXT#private-attributes\">make the attribute private</a>.", + parameters = { + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = Label.class), + @ParamType(type = String.class), + @ParamType(type = LateBoundDefaultApi.class), + @ParamType(type = UserDefinedFunction.class) + }, + callbackEnabled = true, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = + DEFAULT_DOC + + "Use a string or the <a href=\"globals.html#Label\"><code>Label</code></a> " + + "function to specify a default value, for example, " + + "<code>attr.label(default = \"//a:b\")</code>."), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = EXECUTABLE_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = EXECUTABLE_DOC), + @Param( + name = ALLOW_FILES_ARG, + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = ALLOW_FILES_DOC), + @Param( + name = ALLOW_SINGLE_FILE_ARG, + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = + "This is similar to <code>allow_files</code>, with the restriction that the label " + + "must correspond to a single <a href=\"File.html\">File</a>. " + + "Access it through <code>ctx.file.<attribute_name></code>."), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC), + @Param( + name = PROVIDERS_ARG, + type = SkylarkList.class, + defaultValue = "[]", + named = true, + positional = false, + doc = PROVIDERS_DOC), + @Param( + name = ALLOW_RULES_ARG, + type = SkylarkList.class, + generic1 = String.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = ALLOW_RULES_DOC), + @Param( + name = SINGLE_FILE_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = + "Deprecated: Use <code>allow_single_file</code> instead. " + + "If True, the label must correspond to a single " + + "<a href=\"File.html\">File</a>. " + + "Access it through <code>ctx.file.<attribute_name></code>."), + @Param( + name = CONFIGURATION_ARG, + type = Object.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = + CONFIGURATION_DOC + + " This parameter is required if <code>executable</code> is True."), + @Param( + name = ASPECTS_ARG, + type = SkylarkList.class, + generic1 = SkylarkAspectApi.class, + defaultValue = "[]", + named = true, + positional = false, + doc = ASPECTS_ARG_DOC), + }, + useAst = true, + useEnvironment = true) + 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; + + @SkylarkCallable( + name = "string_list", + doc = + "Creates an attribute which is a <a href=\"list.html\">list</a> of " + + "<a href=\"string.html\">strings</a>.", + parameters = { + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = MANDATORY_DOC, + named = true), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = NON_EMPTY_DOC, + named = true), + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkList.class, generic1 = String.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "[]", + doc = DEFAULT_DOC, + named = true, + positional = false), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false) + }, + useAst = true, + useEnvironment = true) + public Descriptor stringListAttribute( + Boolean mandatory, + Boolean nonEmpty, + Boolean allowEmpty, + SkylarkList<?> defaultList, + String doc, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "int_list", + doc = "Creates an attribute which is a <a href=\"list.html\">list</a> of ints.", + parameters = { + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = MANDATORY_DOC, + named = true), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + doc = NON_EMPTY_DOC, + named = true), + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkList.class, generic1 = Integer.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "[]", + doc = DEFAULT_DOC, + named = true, + positional = false), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false) + }, + useAst = true, + useEnvironment = true) + public Descriptor intListAttribute( + Boolean mandatory, + Boolean nonEmpty, + Boolean allowEmpty, + SkylarkList<?> defaultList, + String doc, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "label_list", + doc = + "Creates an attribute which is a <a href=\"list.html\">list</a> of type " + + "<a href=\"Target.html\">Target</a> which are specified by the labels in the list. " + + "See <a href=\"attr.html#label\">label</a> for more information.", + parameters = { + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkList.class, generic1 = Label.class), + @ParamType(type = UserDefinedFunction.class) + }, + callbackEnabled = true, + defaultValue = "[]", + named = true, + positional = false, + doc = + DEFAULT_DOC + + "Use strings or the <a href=\"globals.html#Label\"><code>Label</code></a> " + + "function to specify default values, for example, " + + "<code>attr.label_list(default = [\"//a:b\", \"//a:c\"])</code>."), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = ALLOW_FILES_ARG, // bool or FileType filter + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = ALLOW_FILES_DOC), + @Param( + name = ALLOW_RULES_ARG, + type = SkylarkList.class, + generic1 = String.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = ALLOW_RULES_DOC), + @Param( + name = PROVIDERS_ARG, + type = SkylarkList.class, + defaultValue = "[]", + named = true, + positional = false, + doc = PROVIDERS_DOC), + @Param( + name = FLAGS_ARG, + type = SkylarkList.class, + generic1 = String.class, + defaultValue = "[]", + named = true, + positional = false, + doc = FLAGS_DOC), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = NON_EMPTY_DOC), + @Param( + name = CONFIGURATION_ARG, + type = Object.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = CONFIGURATION_DOC), + @Param( + name = ASPECTS_ARG, + type = SkylarkList.class, + generic1 = SkylarkAspectApi.class, + defaultValue = "[]", + named = true, + positional = false, + doc = ASPECTS_ARG_DOC), + }, + useAst = true, + useEnvironment = true) + 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; + + @SkylarkCallable( + name = "label_keyed_string_dict", + doc = + "Creates an attribute which is a <a href=\"dict.html\">dict</a>. Its keys are type " + + "<a href=\"Target.html\">Target</a> and are specified by the label keys of the " + + "input dict. Its values are <a href=\"string.html\">strings</a>. See " + + "<a href=\"attr.html#label\">label</a> for more information.", + parameters = { + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkDict.class), + @ParamType(type = UserDefinedFunction.class) + }, + callbackEnabled = true, + defaultValue = "{}", + named = true, + positional = false, + doc = + DEFAULT_DOC + + "Use strings or the <a href=\"globals.html#Label\"><code>Label</code></a> " + + "function to specify default values, for example, " + + "<code>attr.label_keyed_string_dict(default = " + + "{\"//a:b\": \"value\", \"//a:c\": \"string\"})</code>."), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = ALLOW_FILES_ARG, // bool or FileType filter + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = ALLOW_FILES_DOC), + @Param( + name = ALLOW_RULES_ARG, + type = SkylarkList.class, + generic1 = String.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = ALLOW_RULES_DOC), + @Param( + name = PROVIDERS_ARG, + type = SkylarkList.class, + defaultValue = "[]", + named = true, + positional = false, + doc = PROVIDERS_DOC), + @Param( + name = FLAGS_ARG, + type = SkylarkList.class, + generic1 = String.class, + defaultValue = "[]", + named = true, + positional = false, + doc = FLAGS_DOC), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = NON_EMPTY_DOC), + @Param( + name = CONFIGURATION_ARG, + type = Object.class, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = CONFIGURATION_DOC), + @Param( + name = ASPECTS_ARG, + type = SkylarkList.class, + generic1 = SkylarkAspectApi.class, + defaultValue = "[]", + named = true, + positional = false, + doc = ASPECTS_ARG_DOC) + }, + useAst = true, + useEnvironment = true) + 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; + + @SkylarkCallable( + name = "bool", + doc = "Creates an attribute of type bool.", + parameters = { + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = Boolean.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "False", + named = true, + positional = false, + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor boolAttribute( + Boolean defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + throws EvalException; + + @SkylarkCallable( + name = "output", + doc = + "Creates an attribute of type output. " + + "The user provides a file name (string) and the rule must create an action that " + + "generates the file.", + parameters = { + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = Label.class), + @ParamType(type = UserDefinedFunction.class) + }, + noneable = true, + defaultValue = "None", + named = true, + positional = false, + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor outputAttribute( + Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + throws EvalException; + + @SkylarkCallable( + name = "output_list", + doc = + "Creates an attribute which is a <a href=\"list.html\">list</a> of outputs. " + + "See <a href=\"attr.html#output\">output</a> for more information.", + parameters = { + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkList.class, generic1 = Label.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "[]", + named = true, + positional = false, + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = NON_EMPTY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor outputListAttribute( + Boolean allowEmpty, + SkylarkList defaultList, + String doc, + Boolean mandatory, + Boolean nonEmpty, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "string_dict", + doc = + "Creates an attribute of type <a href=\"dict.html\">dict</a>, mapping from " + + "<a href=\"string.html\">string</a> to <a href=\"string.html\">string</a>.", + parameters = { + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkDict.class), + @ParamType(type = UserDefinedFunction.class) + }, + named = true, + positional = false, + defaultValue = "{}", + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + named = true, + positional = false, + defaultValue = "False", + doc = MANDATORY_DOC), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = NON_EMPTY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor stringDictAttribute( + Boolean allowEmpty, + SkylarkDict<?, ?> defaultO, + String doc, + Boolean mandatory, + Boolean nonEmpty, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "string_list_dict", + doc = + "Creates an attribute of type <a href=\"dict.html\">dict</a>, mapping from " + + "<a href=\"string.html\">string</a> to <a href=\"list.html\">list</a> of " + + "<a href=\"string.html\">string</a>.", + parameters = { + @Param( + name = ALLOW_EMPTY_ARG, + type = Boolean.class, + defaultValue = "True", + doc = ALLOW_EMPTY_DOC, + named = true), + @Param( + name = DEFAULT_ARG, + allowedTypes = { + @ParamType(type = SkylarkDict.class), + @ParamType(type = UserDefinedFunction.class) + }, + defaultValue = "{}", + named = true, + positional = false, + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC), + @Param( + name = NON_EMPTY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = NON_EMPTY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor stringListDictAttribute( + Boolean allowEmpty, + SkylarkDict<?, ?> defaultO, + String doc, + Boolean mandatory, + Boolean nonEmpty, + FuncallExpression ast, + Environment env) + throws EvalException; + + @SkylarkCallable( + name = "license", + doc = "Creates an attribute of type license.", + // TODO(bazel-team): Implement proper license support for Skylark. + parameters = { + // TODO(bazel-team): ensure this is the correct default value + @Param( + name = DEFAULT_ARG, + defaultValue = "None", + noneable = true, + named = true, + positional = false, + doc = DEFAULT_DOC), + @Param( + name = DOC_ARG, + type = String.class, + defaultValue = "''", + doc = DOC_DOC, + named = true, + positional = false), + @Param( + name = MANDATORY_ARG, + type = Boolean.class, + defaultValue = "False", + named = true, + positional = false, + doc = MANDATORY_DOC) + }, + useAst = true, + useEnvironment = true) + public Descriptor licenseAttribute( + Object defaultO, String doc, Boolean mandatory, FuncallExpression ast, Environment env) + throws EvalException; + + /** An attribute descriptor. */ + @SkylarkModule( + name = "Attribute", + category = SkylarkModuleCategory.NONE, + doc = + "Representation of a definition of an attribute. Use the <a href=\"attr.html\">attr</a> " + + "module to create an Attribute. They are only for use with a " + + "<a href=\"globals.html#rule\">rule</a> or an " + + "<a href=\"globals.html#aspect\">aspect</a>.") + public static interface Descriptor extends SkylarkValue {} +} |