aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
index 04ff209823..cbc308e631 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java
@@ -18,11 +18,11 @@ import com.google.devtools.build.lib.packages.Type.ConversionException;
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.SkylarkBuiltin;
-import com.google.devtools.build.lib.syntax.SkylarkBuiltin.Param;
import com.google.devtools.build.lib.syntax.SkylarkFunction;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkModule;
+import com.google.devtools.build.lib.syntax.SkylarkSignature;
+import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
import java.util.Map;
@@ -36,44 +36,51 @@ import java.util.Map;
+ "Extra helper functions:")
public class SkylarkNativeModule {
- @SkylarkBuiltin(name = "glob", objectType = SkylarkNativeModule.class,
+ @SkylarkSignature(name = "glob", objectType = SkylarkNativeModule.class,
+ returnType = SkylarkList.class,
doc = "Glob returns a list of every file in the current package that:<ul>\n"
+ "<li>Matches at least one pattern in <code>include</code>.</li>\n"
+ "<li>Does not match any of the patterns in <code>exclude</code> "
+ "(default <code>[]</code>).</li></ul>\n"
+ "If the <code>exclude_directories</code> argument is enabled (set to <code>1</code>), "
+ "files of type directory will be omitted from the results (default <code>1</code>).",
- mandatoryParams = {
+ mandatoryPositionals = {
@Param(name = "includes", type = SkylarkList.class, generic1 = String.class,
- doc = "The list of glob patterns to include.")},
- optionalParams = {
+ defaultValue = "[]", doc = "The list of glob patterns to include.")},
+ optionalPositionals = {
@Param(name = "excludes", type = SkylarkList.class, generic1 = String.class,
- doc = "The list of glob patterns to exclude."),
- @Param(name = "exclude_directories", type = Integer.class,
- doc = "A flag whether to exclude directories or not.")})
+ defaultValue = "[]", doc = "The list of glob patterns to exclude."),
+ // TODO(bazel-team): accept booleans as well as integers? (and eventually migrate?)
+ @Param(name = "exclude_directories", type = Integer.class, defaultValue = "1",
+ doc = "A flag whether to exclude directories or not.")},
+ useAst = true, useEnvironment = true)
private static final SkylarkFunction glob = new SkylarkFunction("glob") {
- @Override
- public Object call(Map<String, Object> kwargs, FuncallExpression ast, Environment env)
- throws EvalException, ConversionException, InterruptedException {
- return PackageFactory.callGlob(null, false, ast, env, new Object[] {
- kwargs.get("includes"),
- kwargs.get("excludes"),
- kwargs.get("exclude_directories")
- });
- }
- };
+ @Override
+ public Object call(Map<String, Object> kwargs, FuncallExpression ast, Environment env)
+ throws EvalException, ConversionException, InterruptedException {
+ return PackageFactory.callGlob(null, false, ast, env, new Object[] {
+ kwargs.get("includes"),
+ kwargs.get("excludes"),
+ kwargs.get("exclude_directories")
+ });
+ }
+ };
- @SkylarkBuiltin(name = "package_group", objectType = SkylarkNativeModule.class,
+ @SkylarkSignature(name = "package_group", objectType = SkylarkNativeModule.class,
+ returnType = Environment.NoneType.class,
doc = "This function defines a set of packages and assigns a label to the group. "
+ "The label can be referenced in <code>visibility</code> attributes.",
- mandatoryParams = {
+ mandatoryNamedOnly = {
@Param(name = "name", type = String.class,
doc = "A unique name for this rule.")},
- optionalParams = {
+ optionalNamedOnly = {
@Param(name = "packages", type = SkylarkList.class, generic1 = String.class,
+ defaultValue = "[]",
doc = "A complete enumeration of packages in this group."),
@Param(name = "includes", type = SkylarkList.class, generic1 = String.class,
- doc = "Other package groups that are included in this one.")})
+ defaultValue = "[]",
+ doc = "Other package groups that are included in this one.")},
+ useAst = true, useEnvironment = true)
private static final SkylarkFunction packageGroup = new SkylarkFunction("package_group") {
@Override
public Object call(Map<String, Object> kwargs, FuncallExpression ast, Environment env)
@@ -86,19 +93,23 @@ public class SkylarkNativeModule {
}
};
- @SkylarkBuiltin(name = "exports_files", objectType = SkylarkNativeModule.class,
+ @SkylarkSignature(name = "exports_files", objectType = SkylarkNativeModule.class,
+ returnType = Environment.NoneType.class,
doc = "Specifies a list of files belonging to this package that are exported to other "
+ "packages but not otherwise mentioned.",
- mandatoryParams = {
+ mandatoryPositionals = {
@Param(name = "srcs", type = SkylarkList.class, generic1 = String.class,
doc = "The list of files to export.")},
- optionalParams = {
- @Param(name = "visibility", type = SkylarkList.class, generic1 = String.class,
+ optionalPositionals = {
+ // TODO(bazel-team): make it possible to express the precise type ListOf(LabelDesignator)
+ @Param(name = "visibility", type = SkylarkList.class,
+ noneable = true,
doc = "A visibility declaration can to be specified. The files will be visible to the "
+ "targets specified. If no visibility is specified, the files will be visible to "
+ "every package."),
- @Param(name = "licenses", type = SkylarkList.class, generic1 = String.class,
- doc = "Lincenses to be specified.")})
+ @Param(name = "licenses", type = SkylarkList.class, generic1 = String.class, noneable = true,
+ doc = "Licenses to be specified.")},
+ useAst = true, useEnvironment = true)
private static final SkylarkFunction exportsFiles = new SkylarkFunction("exports_files") {
@Override
public Object call(Map<String, Object> kwargs, FuncallExpression ast, Environment env)