From 93ed7f114ee9be35f41eff5476963745baae4c12 Mon Sep 17 00:00:00 2001 From: Francois-Rene Rideau Date: Tue, 20 Oct 2015 15:39:33 +0000 Subject: Unify Skylark and BUILD lists Use SkylarkList everywhere rather than either List or GlobList. Keep a GlobList underneath a MutableList, where applicable. -- MOS_MIGRATED_REVID=105864035 --- .../devtools/build/docgen/skylark/SkylarkDoc.java | 11 +- .../build/lib/packages/PackageFactory.java | 53 +++-- .../devtools/build/lib/packages/RuleClass.java | 24 +- .../build/lib/packages/SkylarkNativeModule.java | 5 +- .../devtools/build/lib/rules/SkylarkAttr.java | 15 +- .../build/lib/rules/SkylarkRuleClassFunctions.java | 16 +- .../build/lib/rules/SkylarkRuleContext.java | 15 +- .../rules/SkylarkRuleImplementationFunctions.java | 22 +- .../build/lib/syntax/BinaryOperatorExpression.java | 42 +--- .../devtools/build/lib/syntax/BuiltinFunction.java | 4 - .../devtools/build/lib/syntax/Environment.java | 16 -- .../build/lib/syntax/FuncallExpression.java | 60 +---- .../build/lib/syntax/ListComprehension.java | 2 +- .../devtools/build/lib/syntax/ListLiteral.java | 6 +- .../devtools/build/lib/syntax/MethodLibrary.java | 246 ++++++--------------- .../devtools/build/lib/syntax/SkylarkList.java | 133 ++++++++++- .../lib/syntax/SkylarkSignatureProcessor.java | 26 +-- .../devtools/build/lib/syntax/SkylarkType.java | 41 ---- .../com/google/devtools/build/lib/syntax/Type.java | 14 +- 19 files changed, 313 insertions(+), 438 deletions(-) (limited to 'src/main/java/com/google') diff --git a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java index 6d0f904c45..941849d0a3 100644 --- a/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java +++ b/src/main/java/com/google/devtools/build/docgen/skylark/SkylarkDoc.java @@ -17,14 +17,13 @@ import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.FuncallExpression; import com.google.devtools.build.lib.syntax.Runtime.NoneType; import com.google.devtools.build.lib.syntax.SkylarkList; +import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; 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 com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor.HackHackEitherList; import java.util.Arrays; -import java.util.List; import java.util.Map; /** @@ -55,12 +54,12 @@ abstract class SkylarkDoc { return "string"; } else if (Map.class.isAssignableFrom(type)) { return "dict"; - } else if (Tuple.class.isAssignableFrom(type)) { + } else if (type.equals(Tuple.class)) { return "tuple"; - } else if (List.class.isAssignableFrom(type) || SkylarkList.class.isAssignableFrom(type) - || type == HackHackEitherList.class) { - // Annotated Java methods can return simple java.util.Lists (which get auto-converted). + } else if (type.equals(MutableList.class)) { return "list"; + } else if (type.equals(SkylarkList.class)) { + return "sequence"; } else if (type.equals(Void.TYPE) || type.equals(NoneType.class)) { return "None"; } else if (type.isAnnotationPresent(SkylarkModule.class)) { diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java index 7fcb29d5a6..11a9772121 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java @@ -51,10 +51,11 @@ import com.google.devtools.build.lib.syntax.Identifier; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.ParserInputSource; import com.google.devtools.build.lib.syntax.Runtime; +import com.google.devtools.build.lib.syntax.SkylarkList; +import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkSignature; import com.google.devtools.build.lib.syntax.SkylarkSignature.Param; import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor; -import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor.HackHackEitherList; import com.google.devtools.build.lib.syntax.Statement; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.syntax.Type.ConversionException; @@ -475,13 +476,13 @@ public final class PackageFactory { * @param async if true, start globs in the background but don't block on their completion. * Only use this for heuristic preloading. */ - @SkylarkSignature(name = "glob", objectType = Object.class, returnType = GlobList.class, + @SkylarkSignature(name = "glob", objectType = Object.class, returnType = SkylarkList.class, doc = "Returns a list of files that match glob search pattern", mandatoryPositionals = { - @Param(name = "include", type = HackHackEitherList.class, generic1 = String.class, + @Param(name = "include", type = SkylarkList.class, generic1 = String.class, doc = "a list of strings specifying patterns of files to include.")}, optionalPositionals = { - @Param(name = "exclude", type = HackHackEitherList.class, generic1 = String.class, + @Param(name = "exclude", type = SkylarkList.class, generic1 = String.class, defaultValue = "[]", doc = "a list of strings specifying patterns of files to exclude."), // TODO(bazel-team): migrate all existing code to use boolean instead? @@ -492,8 +493,8 @@ public final class PackageFactory { new BuiltinFunction.Factory("glob") { public BuiltinFunction create(final PackageContext originalContext, final boolean async) { return new BuiltinFunction("glob", this) { - public GlobList invoke( - Object include, Object exclude, Integer excludeDirectories, + public SkylarkList invoke( + SkylarkList include, SkylarkList exclude, Integer excludeDirectories, FuncallExpression ast, Environment env) throws EvalException, ConversionException, InterruptedException { return callGlob( @@ -503,7 +504,7 @@ public final class PackageFactory { } }; - static GlobList callGlob(@Nullable PackageContext originalContext, + static SkylarkList callGlob(@Nullable PackageContext originalContext, boolean async, Object include, Object exclude, boolean excludeDirs, FuncallExpression ast, Environment env) throws EvalException, ConversionException, InterruptedException { @@ -520,16 +521,18 @@ public final class PackageFactory { List includes = Type.STRING_LIST.convert(include, "'glob' argument"); List excludes = Type.STRING_LIST.convert(exclude, "'glob' argument"); + GlobList globList; if (async) { try { context.globber.runAsync(includes, excludes, excludeDirs); } catch (GlobCache.BadGlobException e) { // Ignore: errors will appear during the actual evaluation of the package. } - return GlobList.captureResults(includes, excludes, ImmutableList.of()); + globList = GlobList.captureResults(includes, excludes, ImmutableList.of()); } else { - return handleGlob(includes, excludes, excludeDirs, context, ast); + globList = handleGlob(includes, excludes, excludeDirs, context, ast); } + return new MutableList(globList, env); } /** @@ -621,20 +624,21 @@ public final class PackageFactory { @Param(name = "name", type = String.class, doc = "The name of the rule."), // Both parameter below are lists of label designators - @Param(name = "environments", type = HackHackEitherList.class, generic1 = Object.class, + @Param(name = "environments", type = SkylarkList.class, generic1 = Object.class, doc = "A list of Labels for the environments to be grouped, from the same package."), - @Param(name = "defaults", type = HackHackEitherList.class, generic1 = Object.class, + @Param(name = "defaults", type = SkylarkList.class, generic1 = Object.class, doc = "A list of Labels.")}, // TODO(bazel-team): document what that is documented = false, useLocation = true) private static final BuiltinFunction.Factory newEnvironmentGroupFunction = new BuiltinFunction.Factory("environment_group") { public BuiltinFunction create(final PackageContext context) { return new BuiltinFunction("environment_group", this) { - public Runtime.NoneType invoke(String name, Object environmentsO, Object defaultsO, + public Runtime.NoneType invoke( + String name, SkylarkList environmentsList, SkylarkList defaultsList, Location loc) throws EvalException, ConversionException { - List