diff options
author | janakr <janakr@google.com> | 2018-03-24 14:32:02 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-24 14:33:07 -0700 |
commit | 738a2edcf811f9cc90e492f192f0d5cafcf93951 (patch) | |
tree | 7aab56ea915c5b1a0f060d6a879298fd70d6320b /src/main/java/com/google/devtools/build/lib | |
parent | 56cf9699acdb7df0beed16e251ee6a68b011bb96 (diff) |
@AutoCodec SkylarkCustomCommandLine. Includes hack to work around b/76233103.
PiperOrigin-RevId: 190349968
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkCustomCommandLine.java | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkCustomCommandLine.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkCustomCommandLine.java index 38ba7216a9..d08be014ee 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkCustomCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkCustomCommandLine.java @@ -26,6 +26,8 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.events.NullEventHandler; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.syntax.BaseFunction; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; @@ -39,6 +41,7 @@ import java.util.List; import javax.annotation.Nullable; /** Supports ctx.actions.args() from Skylark. */ +@AutoCodec class SkylarkCustomCommandLine extends CommandLine { private final SkylarkSemantics skylarkSemantics; private final EventHandler eventHandler; @@ -47,6 +50,7 @@ class SkylarkCustomCommandLine extends CommandLine { private static final Joiner LINE_JOINER = Joiner.on("\n").skipNulls(); private static final Joiner FIELD_JOINER = Joiner.on(": ").skipNulls(); + @AutoCodec static final class VectorArg { private static Interner<VectorArg> interner = BlazeInterners.newStrongInterner(); @@ -57,7 +61,7 @@ class SkylarkCustomCommandLine extends CommandLine { private final boolean hasMapFn; private final boolean hasLocation; - VectorArg( + private VectorArg( boolean isNestedSet, boolean hasFormat, boolean hasBeforeEach, @@ -72,18 +76,30 @@ class SkylarkCustomCommandLine extends CommandLine { this.hasLocation = hasLocation; } + @AutoCodec.VisibleForSerialization + @AutoCodec.Instantiator + static VectorArg create( + boolean isNestedSet, + boolean hasFormat, + boolean hasBeforeEach, + boolean hasJoinWith, + boolean hasMapFn, + boolean hasLocation) { + return interner.intern( + new VectorArg(isNestedSet, hasFormat, hasBeforeEach, hasJoinWith, hasMapFn, hasLocation)); + } + private static void push(ImmutableList.Builder<Object> arguments, Builder arg) { boolean wantsLocation = arg.format != null || arg.mapFn != null; boolean hasLocation = arg.location != null && wantsLocation; VectorArg vectorArg = - new VectorArg( + VectorArg.create( arg.nestedSet != null, arg.format != null, arg.beforeEach != null, arg.joinWith != null, arg.mapFn != null, hasLocation); - vectorArg = interner.intern(vectorArg); arguments.add(vectorArg); if (vectorArg.isNestedSet) { arguments.add(arg.nestedSet); @@ -257,6 +273,7 @@ class SkylarkCustomCommandLine extends CommandLine { } } + @AutoCodec static final class ScalarArg { private static Interner<ScalarArg> interner = BlazeInterners.newStrongInterner(); @@ -264,17 +281,22 @@ class SkylarkCustomCommandLine extends CommandLine { private final boolean hasMapFn; private final boolean hasLocation; - public ScalarArg(boolean hasFormat, boolean hasMapFn, boolean hasLocation) { + private ScalarArg(boolean hasFormat, boolean hasMapFn, boolean hasLocation) { this.hasFormat = hasFormat; this.hasMapFn = hasMapFn; this.hasLocation = hasLocation; } + @AutoCodec.VisibleForSerialization + @AutoCodec.Instantiator + static ScalarArg create(boolean hasFormat, boolean hasMapFn, boolean hasLocation) { + return interner.intern(new ScalarArg(hasFormat, hasMapFn, hasLocation)); + } + private static void push(ImmutableList.Builder<Object> arguments, Builder arg) { boolean wantsLocation = arg.format != null || arg.mapFn != null; boolean hasLocation = arg.location != null && wantsLocation; - ScalarArg scalarArg = new ScalarArg(arg.format != null, arg.mapFn != null, hasLocation); - scalarArg = interner.intern(scalarArg); + ScalarArg scalarArg = ScalarArg.create(arg.format != null, arg.mapFn != null, hasLocation); arguments.add(scalarArg); arguments.add(arg.object); if (hasLocation) { @@ -380,14 +402,24 @@ class SkylarkCustomCommandLine extends CommandLine { } SkylarkCustomCommandLine build() { - return new SkylarkCustomCommandLine(this); + return new SkylarkCustomCommandLine(skylarkSemantics, eventHandler, arguments.build()); } } - SkylarkCustomCommandLine(Builder builder) { - this.arguments = builder.arguments.build(); - this.skylarkSemantics = builder.skylarkSemantics; - this.eventHandler = builder.eventHandler; + @AutoCodec.VisibleForSerialization + @AutoCodec.Instantiator + SkylarkCustomCommandLine(SkylarkSemantics skylarkSemantics, ImmutableList<Object> arguments) { + // TODO(b/76233103): fix this. + this(skylarkSemantics, NullEventHandler.INSTANCE, arguments); + } + + private SkylarkCustomCommandLine( + SkylarkSemantics skylarkSemantics, + EventHandler eventHandler, + ImmutableList<Object> arguments) { + this.skylarkSemantics = skylarkSemantics; + this.eventHandler = eventHandler; + this.arguments = arguments; } @Override |