diff options
author | shreyax <shreyax@google.com> | 2017-03-30 23:11:27 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2017-03-31 17:12:48 +0200 |
commit | 5d2f57b6f970c1bfae0dcee23a3981cdcf5af45f (patch) | |
tree | f22d8b42db16fdcc59cf455fc885bc7a937cdc05 /src/main/java/com | |
parent | 93e3eeadc24197c62a12fc843db319cb58d98d84 (diff) |
Use ImmutableList.Builder and ImmutableListMultimap.Builder to create the outputFiles and outputFileMap objects in Rule.
RELNOTES: None.
PiperOrigin-RevId: 151764143
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/Rule.java | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java index e1607e96d8..246ff07550 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; @@ -476,16 +475,21 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide throws LabelSyntaxException, InterruptedException { Preconditions.checkState(outputFiles == null); // Order is important here: implicit before explicit - outputFiles = Lists.newArrayList(); - outputFileMap = LinkedListMultimap.create(); - populateImplicitOutputFiles(eventHandler, pkgBuilder); - populateExplicitOutputFiles(eventHandler); - outputFiles = ImmutableList.copyOf(outputFiles); - outputFileMap = ImmutableListMultimap.copyOf(outputFileMap); + ImmutableList.Builder<OutputFile> outputFilesBuilder = ImmutableList.builder(); + ImmutableListMultimap.Builder<String, OutputFile> outputFileMapBuilder = + ImmutableListMultimap.builder(); + populateImplicitOutputFiles(eventHandler, pkgBuilder, outputFilesBuilder); + populateExplicitOutputFiles(eventHandler, outputFilesBuilder, outputFileMapBuilder); + outputFiles = outputFilesBuilder.build(); + outputFileMap = outputFileMapBuilder.build(); } // Explicit output files are user-specified attributes of type OUTPUT. - private void populateExplicitOutputFiles(EventHandler eventHandler) throws LabelSyntaxException { + private void populateExplicitOutputFiles( + EventHandler eventHandler, + ImmutableList.Builder<OutputFile> outputFilesBuilder, + ImmutableListMultimap.Builder<String, OutputFile> outputFileMapBuilder) + throws LabelSyntaxException { NonconfigurableAttributeMapper nonConfigurableAttributes = NonconfigurableAttributeMapper.of(this); for (Attribute attribute : ruleClass.getAttributes()) { @@ -494,27 +498,31 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide if (type == BuildType.OUTPUT) { Label outputLabel = nonConfigurableAttributes.get(name, BuildType.OUTPUT); if (outputLabel != null) { - addLabelOutput(attribute, outputLabel, eventHandler); + addLabelOutput( + attribute, outputLabel, eventHandler, outputFilesBuilder, outputFileMapBuilder); } } else if (type == BuildType.OUTPUT_LIST) { for (Label label : nonConfigurableAttributes.get(name, BuildType.OUTPUT_LIST)) { - addLabelOutput(attribute, label, eventHandler); + addLabelOutput(attribute, label, eventHandler, outputFilesBuilder, outputFileMapBuilder); } } } } /** - * Implicit output files come from rule-specific patterns, and are a function - * of the rule's "name", "srcs", and other attributes. + * Implicit output files come from rule-specific patterns, and are a function of the rule's + * "name", "srcs", and other attributes. */ - private void populateImplicitOutputFiles(EventHandler eventHandler, Package.Builder pkgBuilder) + private void populateImplicitOutputFiles( + EventHandler eventHandler, + Package.Builder pkgBuilder, + ImmutableList.Builder<OutputFile> outputFilesBuilder) throws InterruptedException { try { RawAttributeMapper attributeMap = RawAttributeMapper.of(this); for (String out : implicitOutputsFunction.getImplicitOutputs(attributeMap)) { try { - addOutputFile(pkgBuilder.createLabel(out), eventHandler); + addOutputFile(pkgBuilder.createLabel(out), eventHandler, outputFilesBuilder); } catch (LabelSyntaxException e) { reportError( "illegal output file name '" @@ -531,7 +539,12 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide } } - private void addLabelOutput(Attribute attribute, Label label, EventHandler eventHandler) + private void addLabelOutput( + Attribute attribute, + Label label, + EventHandler eventHandler, + ImmutableList.Builder<OutputFile> outputFilesBuilder, + ImmutableListMultimap.Builder<String, OutputFile> outputFileMapBuilder) throws LabelSyntaxException { if (!label.getPackageIdentifier().equals(pkg.getPackageIdentifier())) { throw new IllegalStateException("Label for attribute " + attribute @@ -542,11 +555,14 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide if (label.getName().equals(".")) { throw new LabelSyntaxException("output file name can't be equal '.'"); } - OutputFile outputFile = addOutputFile(label, eventHandler); - outputFileMap.put(attribute.getName(), outputFile); + OutputFile outputFile = addOutputFile(label, eventHandler, outputFilesBuilder); + outputFileMapBuilder.put(attribute.getName(), outputFile); } - private OutputFile addOutputFile(Label label, EventHandler eventHandler) { + private OutputFile addOutputFile( + Label label, + EventHandler eventHandler, + ImmutableList.Builder<OutputFile> outputFilesBuilder) { if (label.getName().equals(getName())) { // TODO(bazel-team): for now (23 Apr 2008) this is just a warning. After // June 1st we should make it an error. @@ -554,7 +570,7 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide + "another name for the rule", eventHandler); } OutputFile outputFile = new OutputFile(pkg, label, this); - outputFiles.add(outputFile); + outputFilesBuilder.add(outputFile); return outputFile; } |