Skip to content

Commit

Permalink
Subtract protos from avoid_deps of apple_static_library
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 152416858
  • Loading branch information
c-parsons authored and hlopko committed Apr 7, 2017
1 parent edbeafe commit ee4c252
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ public void init(Builder builder) {
// TODO(ulfjack): Depending on objcProtoAspect from here is a layering violation.
ObjcProtoAspect objcProtoAspect = new ObjcProtoAspect();
builder.addNativeAspectClass(objcProtoAspect);
builder.addRuleDefinition(new AppleBinaryRule(objcProtoAspect));
builder.addRuleDefinition(new AppleStaticLibraryRule(objcProtoAspect));
builder.addRuleDefinition(new ObjcProtoLibraryRule(objcProtoAspect));

builder.addRuleDefinition(new AppleBinaryRule(objcProtoAspect));
builder.addRuleDefinition(new AppleCcToolchainRule());
builder.addRuleDefinition(new AppleStaticLibraryRule());
builder.addRuleDefinition(new AppleToolchain.RequiresXcodeConfigRule(toolsRepository));
builder.addRuleDefinition(new AppleWatch1ExtensionRule());
builder.addRuleDefinition(new AppleWatch2ExtensionRule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
Expand All @@ -36,6 +37,7 @@
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes;
import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key;

import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -79,6 +81,10 @@ public final ConfiguredTarget create(RuleContext ruleContext)
ImmutableListMultimap<BuildConfiguration, CcLinkParamsProvider> configToCcAvoidDepsMap =
ruleContext.getPrerequisitesByConfiguration(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME,
Mode.SPLIT, CcLinkParamsProvider.class);
Iterable<ObjcProtoProvider> avoidProtoProviders =
ruleContext.getPrerequisites(AppleStaticLibraryRule.AVOID_DEPS_ATTR_NAME, Mode.TARGET,
ObjcProtoProvider.class);
NestedSet<Artifact> protosToAvoid = protoArtifactsToAvoid(avoidProtoProviders);

Set<BuildConfiguration> childConfigurations = getChildConfigurations(ruleContext);

Expand All @@ -95,7 +101,7 @@ public final ConfiguredTarget create(RuleContext ruleContext)

for (BuildConfiguration childConfig : childConfigurations) {
ProtobufSupport protoSupport =
new ProtobufSupport(ruleContext, childConfig)
new ProtobufSupport(ruleContext, childConfig, protosToAvoid)
.registerGenerationActions()
.registerCompilationActions();

Expand Down Expand Up @@ -192,4 +198,15 @@ private Set<BuildConfiguration> getChildConfigurations(RuleContext ruleContext)

return configToProvider.keySet();
}

private static NestedSet<Artifact> protoArtifactsToAvoid(
Iterable<ObjcProtoProvider> avoidedProviders) {
NestedSetBuilder<Artifact> avoidArtifacts = NestedSetBuilder.stableOrder();
for (ObjcProtoProvider avoidProvider : avoidedProviders) {
for (NestedSet<Artifact> avoidProviderOutputGroup : avoidProvider.getProtoGroups()) {
avoidArtifacts.addTransitive(avoidProviderOutputGroup);
}
}
return avoidArtifacts.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
*/
public class AppleStaticLibraryRule implements RuleDefinition {

private final ObjcProtoAspect objcProtoAspect;

public AppleStaticLibraryRule(ObjcProtoAspect objcProtoAspect) {
this.objcProtoAspect = objcProtoAspect;
}

/**
* Template for the fat archive output (using Apple's "lipo" tool to combine .a archive files of
* multiple architectures).
Expand Down Expand Up @@ -80,7 +86,8 @@ <p>A list of targets which should not be included (nor their transitive dependen
.mandatoryNativeProviders(
ImmutableList.<Class<? extends TransitiveInfoProvider>>of(ObjcProvider.class))
.cfg(splitTransitionProvider)
.allowedFileTypes())
.allowedFileTypes()
.aspect(objcProtoAspect))
/*<!-- #BLAZE_RULE(apple_static_library).IMPLICIT_OUTPUTS -->
<ul>
<li><code><var>name</var>_lipo.a</code>: a 'lipo'ed archive file. All transitive
Expand Down

0 comments on commit ee4c252

Please sign in to comment.