aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/objc
diff options
context:
space:
mode:
authorGravatar kaipi <kaipi@google.com>2017-04-28 18:44:48 +0200
committerGravatar Vladimir Moskva <vladmos@google.com>2017-04-30 23:11:04 +0200
commitac85cf9294c68743800ab71a22d66c1f3d1823c2 (patch)
tree0fb0490635348c41f95712ccb13a1c7c1ff52d60 /src/main/java/com/google/devtools/build/lib/rules/objc
parent5038016e6573962d2554fcf9c10faa0cca8714e2 (diff)
Refactor to extract the collection of portable proto filters.
PiperOrigin-RevId: 154549379
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchBinarySupport.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java34
6 files changed, 48 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
index fbc8d62307..bf0acf7d43 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
@@ -109,13 +109,15 @@ public class AppleStaticLibrary implements RuleConfiguredTargetFactory {
Map<String, NestedSet<Artifact>> outputGroupCollector = new TreeMap<>();
for (BuildConfiguration childConfig : childConfigurations) {
+ Iterable<ObjcProtoProvider> objcProtoProviders = objcProtoProvidersMap.get(childConfig);
ProtobufSupport protoSupport =
new ProtobufSupport(
ruleContext,
childConfig,
protosToAvoid,
ImmutableList.<ProtoSourcesProvider>of(),
- objcProtoProvidersMap.get(childConfig))
+ objcProtoProviders,
+ ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders))
.registerGenerationActions()
.registerCompilationActions();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
index 131e5b9499..94e721ae54 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java
@@ -94,7 +94,8 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory
ruleContext,
ruleContext.getConfiguration(),
ImmutableList.<ProtoSourcesProvider>of(),
- objcProtoProviders)
+ objcProtoProviders,
+ ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders))
.registerGenerationActions()
.registerCompilationActions();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
index 9320702459..255ff0c0c7 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosTest.java
@@ -93,7 +93,8 @@ public final class IosTest implements RuleConfiguredTargetFactory {
ruleContext,
ruleContext.getConfiguration(),
ImmutableList.<ProtoSourcesProvider>of(),
- objcProtoProviders)
+ objcProtoProviders,
+ ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders))
.registerGenerationActions()
.registerCompilationActions();
Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchBinarySupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchBinarySupport.java
index 977dd298c7..140779a625 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchBinarySupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/MultiArchBinarySupport.java
@@ -195,6 +195,7 @@ public class MultiArchBinarySupport {
for (BuildConfiguration childConfig : childConfigurationsAndToolchains.keySet()) {
Optional<ObjcProvider> protosObjcProvider;
+ Iterable<ObjcProtoProvider> objcProtoProviders = objcProtoProvidersMap.get(childConfig);
if (ObjcRuleClasses.objcConfiguration(ruleContext).enableAppleBinaryNativeProtos()) {
ProtobufSupport protoSupport =
new ProtobufSupport(
@@ -202,7 +203,8 @@ public class MultiArchBinarySupport {
childConfig,
protosToAvoid,
ImmutableList.<ProtoSourcesProvider>of(),
- objcProtoProvidersMap.get(childConfig))
+ objcProtoProviders,
+ ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders))
.registerGenerationActions()
.registerCompilationActions();
protosObjcProvider = protoSupport.getObjcProvider();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
index 6b2ba5a76e..55fbba932f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
@@ -20,6 +20,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
@@ -58,7 +59,11 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory {
ProtobufSupport protoSupport =
new ProtobufSupport(
- ruleContext, ruleContext.getConfiguration(), protoProviders, objcProtoProviders)
+ ruleContext,
+ ruleContext.getConfiguration(),
+ protoProviders,
+ objcProtoProviders,
+ getPortableProtoFilters(ruleContext, objcProtoProviders))
.registerGenerationActions()
.addFilesToBuild(filesToBuild);
@@ -74,6 +79,18 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory {
.build();
}
+ private static NestedSet<Artifact> getPortableProtoFilters(
+ RuleContext ruleContext, Iterable<ObjcProtoProvider> objcProtoProviders) {
+ ProtoAttributes attributes = new ProtoAttributes(ruleContext);
+ NestedSetBuilder<Artifact> portableProtoFilters = NestedSetBuilder.stableOrder();
+
+ portableProtoFilters.addTransitive(
+ ProtobufSupport.getTransitivePortableProtoFilters(objcProtoProviders));
+ portableProtoFilters.addAll(attributes.getPortableProtoFilters());
+
+ return portableProtoFilters.build();
+ }
+
private ConfiguredTarget createProtocolBuffers2Target(RuleContext ruleContext)
throws InterruptedException, RuleErrorException {
NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.stableOrder();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
index 8141fa1d4d..b1e1caecea 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtobufSupport.java
@@ -73,6 +73,7 @@ final class ProtobufSupport {
private final IntermediateArtifacts intermediateArtifacts;
private final Set<Artifact> dylibHandledProtos;
private final Iterable<ObjcProtoProvider> objcProtoProviders;
+ private final NestedSet<Artifact> portableProtoFilters;
// Each entry of this map represents a generation action and a compilation action. The input set
// are dependencies of the output set. The output set is always a subset of, or the same set as,
@@ -106,13 +107,15 @@ final class ProtobufSupport {
RuleContext ruleContext,
BuildConfiguration buildConfiguration,
Iterable<ProtoSourcesProvider> protoProviders,
- Iterable<ObjcProtoProvider> objcProtoProviders) {
+ Iterable<ObjcProtoProvider> objcProtoProviders,
+ NestedSet<Artifact> portableProtoFilters) {
this(
ruleContext,
buildConfiguration,
NestedSetBuilder.<Artifact>stableOrder().build(),
protoProviders,
- objcProtoProviders);
+ objcProtoProviders,
+ portableProtoFilters);
}
/**
@@ -135,12 +138,14 @@ final class ProtobufSupport {
BuildConfiguration buildConfiguration,
NestedSet<Artifact> dylibHandledProtos,
Iterable<ProtoSourcesProvider> protoProviders,
- Iterable<ObjcProtoProvider> objcProtoProviders) {
+ Iterable<ObjcProtoProvider> objcProtoProviders,
+ NestedSet<Artifact> portableProtoFilters) {
this.ruleContext = ruleContext;
this.buildConfiguration = buildConfiguration;
this.attributes = new ProtoAttributes(ruleContext);
this.dylibHandledProtos = dylibHandledProtos.toSet();
this.objcProtoProviders = objcProtoProviders;
+ this.portableProtoFilters = portableProtoFilters;
this.intermediateArtifacts =
ObjcRuleClasses.intermediateArtifacts(ruleContext, buildConfiguration);
this.inputsToOutputsMap = getInputsToOutputsMap(attributes, protoProviders, objcProtoProviders);
@@ -319,15 +324,6 @@ final class ProtobufSupport {
return Optional.of(xcodeProviderBuilder.build());
}
- private NestedSet<Artifact> getPortableProtoFilters() {
- NestedSetBuilder<Artifact> portableProtoFilters = NestedSetBuilder.stableOrder();
- for (ObjcProtoProvider objcProtoProvider : objcProtoProviders) {
- portableProtoFilters.addTransitive(objcProtoProvider.getPortableProtoFilters());
- }
- portableProtoFilters.addAll(attributes.getPortableProtoFilters());
- return portableProtoFilters.build();
- }
-
private NestedSet<Artifact> getProtobufHeaders() {
NestedSetBuilder<Artifact> protobufHeaders = NestedSetBuilder.stableOrder();
for (ObjcProtoProvider objcProtoProvider : objcProtoProviders) {
@@ -511,7 +507,7 @@ final class ProtobufSupport {
.setMnemonic("GenObjcBundledProtos")
.addInput(attributes.getProtoCompiler())
.addInputs(attributes.getProtoCompilerSupport())
- .addTransitiveInputs(getPortableProtoFilters())
+ .addTransitiveInputs(portableProtoFilters)
.addInput(protoInputsFile)
.addInputs(inputProtos)
.addOutputs(getGeneratedProtoOutputs(outputProtos, HEADER_SUFFIX))
@@ -546,7 +542,7 @@ final class ProtobufSupport {
.add(getGenfilesPathString())
.add("--proto-root-dir")
.add(".")
- .addBeforeEachExecPath("--config", getPortableProtoFilters())
+ .addBeforeEachExecPath("--config", portableProtoFilters)
.build();
}
@@ -592,4 +588,14 @@ final class ProtobufSupport {
.attributes()
.isAttributeValueExplicitlySpecified(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR);
}
+
+ // Returns the transitive portable proto filter files from a list of ObjcProtoProviders.
+ public static NestedSet<Artifact> getTransitivePortableProtoFilters(
+ Iterable<ObjcProtoProvider> objcProtoProviders) {
+ NestedSetBuilder<Artifact> portableProtoFilters = NestedSetBuilder.stableOrder();
+ for (ObjcProtoProvider objcProtoProvider : objcProtoProviders) {
+ portableProtoFilters.addTransitive(objcProtoProvider.getPortableProtoFilters());
+ }
+ return portableProtoFilters.build();
+ }
}