Skip to content

Commit

Permalink
Subtract resource-related provider values defined in avoid_deps from …
Browse files Browse the repository at this point in the history
…deps

--
MOS_MIGRATED_REVID=137329481
  • Loading branch information
c-parsons authored and laszlocsomor committed Oct 27, 2016
1 parent 738c892 commit 7d94f18
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
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.RuleConfiguredTargetBuilder;
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;
import com.google.devtools.build.lib.rules.apple.Platform.PlatformType;
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.HashSet;
import java.util.List;
import java.util.Set;

Expand All @@ -42,6 +48,32 @@
*/
public class AppleStaticLibrary implements RuleConfiguredTargetFactory {

/**
* Set of {@link ObjcProvider} keys whose values are subtracted by avoid_deps. Specifically, a
* value is propagated if present in the transitive "deps" but *not* present in the transitive
* "avoid_deps".
*/
private static final ImmutableSet<Key<?>> AVOID_DEPS_KEYS =
ImmutableSet.<Key<?>>of(
ObjcProvider.ASSET_CATALOG,
ObjcProvider.BUNDLE_FILE,
ObjcProvider.GENERAL_RESOURCE_DIR,
ObjcProvider.GENERAL_RESOURCE_FILE,
ObjcProvider.STORYBOARD,
ObjcProvider.STRINGS,
ObjcProvider.XCDATAMODEL,
ObjcProvider.XIB,
ObjcProvider.XCASSETS_DIR);

/**
* Set of {@link ObjcProvider} whose values are propagated regardless of avoid_deps.
*/
private static final ImmutableSet<Key<?>> PROPAGATE_REGARDLESS_KEYS =
ImmutableSet.<Key<?>>of(
ObjcProvider.SDK_DYLIB,
ObjcProvider.SDK_FRAMEWORK,
ObjcProvider.WEAK_SDK_FRAMEWORK);

@VisibleForTesting
static final String UNSUPPORTED_PLATFORM_TYPE_ERROR_FORMAT =
"Unsupported platform type \"%s\"";
Expand Down Expand Up @@ -98,7 +130,8 @@ public final ConfiguredTarget create(RuleContext ruleContext)
.validateAttributes();
ruleContext.assertNoErrors();

objcProviderBuilder.addTransitiveAndPropagate(common.getObjcProvider());
addTransitiveAndAvoid(objcProviderBuilder, common.getObjcProvider(),
configToAvoidDepsMap.get(childConfig));
}

AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
Expand All @@ -118,6 +151,28 @@ public final ConfiguredTarget create(RuleContext ruleContext)
targetBuilder.addProvider(ObjcProvider.class, objcProviderBuilder.build());
return targetBuilder.build();
}

private void addTransitiveAndAvoid(ObjcProvider.Builder objcProviderBuilder,
ObjcProvider provider, ImmutableList<ObjcProvider> avoidProviders) {
for (Key<?> key : PROPAGATE_REGARDLESS_KEYS) {
objcProviderBuilder.addTransitiveAndPropagate(key, provider);
}
for (Key<?> key : AVOID_DEPS_KEYS) {
addTransitiveAndAvoid(objcProviderBuilder, key, provider, avoidProviders);
}
}

private <T> void addTransitiveAndAvoid(ObjcProvider.Builder objcProviderBuilder, Key<T> key,
ObjcProvider provider, ImmutableList<ObjcProvider> avoidProviders) {
HashSet<T> avoidItemsSet = new HashSet<T>();
for (ObjcProvider avoidProvider : avoidProviders) {
avoidItemsSet.addAll(avoidProvider.getPropagable(key).toList());
}
NestedSet<T> items = provider.getPropagable(key);

objcProviderBuilder.addAll(key,
Iterables.filter(items.toList(), Predicates.not(Predicates.in(avoidItemsSet))));
}

private ObjcCommon common(
RuleContext ruleContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* files.
*/
public final class BundleableFile extends Value<BundleableFile> {

static final int EXECUTABLE_EXTERNAL_FILE_ATTRIBUTE = 0100755 << 16;
static final int DEFAULT_EXTERNAL_FILE_ATTRIBUTE = 0100644 << 16;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,20 @@ public <E> NestedSet<E> get(Key<E> key) {
}
return builder.build();
}

/**
* All artifacts, bundleable files, etc, that should be propagated to transitive dependers, of
* the type specified by {@code key}.
*/
@SuppressWarnings("unchecked")
public <E> NestedSet<E> getPropagable(Key<E> key) {
Preconditions.checkNotNull(key);
NestedSetBuilder<E> builder = new NestedSetBuilder<>(key.order);
if (items.containsKey(key)) {
builder.addTransitive((NestedSet<E>) items.get(key));
}
return builder.build();
}

/**
* Indicates whether {@code flag} is set on this provider.
Expand Down Expand Up @@ -559,7 +573,7 @@ public Builder addTransitiveAndPropagate(ObjcProvider provider) {
}
return this;
}

/**
* Add all keys and values from the given provider, but propagate any normally-propagated items
* only to direct dependers of this ObjcProvider.
Expand Down

0 comments on commit 7d94f18

Please sign in to comment.