diff options
author | 2017-08-07 21:41:25 +0200 | |
---|---|---|
committer | 2017-08-08 13:02:44 +0200 | |
commit | bd36e5f77c4c891132cb7578779946fa89c394ec (patch) | |
tree | dddad4d732cbd1e0bb0ac1fb1f0e497df8e18915 /src/main/java/com/google/devtools | |
parent | 67b1736235dcf4d57dd9fb2c8900f83f5ec83f51 (diff) |
Rollforward of "Framework dependency subtraction uses runfiles path instead of full artifact path"
RELNOTES: None.
PiperOrigin-RevId: 164496520
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 790854a4c8..51a3c435fa 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -609,27 +609,30 @@ public final class ObjcProvider extends Info { * @param avoidCcProviders cc providers which contain the dependency subtrees to subtract */ // TODO(b/19795062): Investigate subtraction generalized to NestedSet. + @SuppressWarnings("unchecked") // Due to depending on Key types, when the keys map erases type. public ObjcProvider subtractSubtrees(Iterable<ObjcProvider> avoidObjcProviders, Iterable<CcLinkParamsProvider> avoidCcProviders) { // LIBRARY and CC_LIBRARY need to be special cased for objc-cc interop. - // A library which is a dependency of a cc_library may be present in all or any of + // A library which is a dependency of a cc_library may be present in all or any of // three possible locations (and may be duplicated!): // 1. ObjcProvider.LIBRARY // 2. ObjcProvider.CC_LIBRARY // 3. CcLinkParamsProvider->LibraryToLink->getArtifact() // TODO(cpeyser): Clean up objc-cc interop. - HashSet<Artifact> avoidLibrariesSet = new HashSet<>(); + HashSet<PathFragment> avoidLibrariesSet = new HashSet<>(); for (CcLinkParamsProvider linkProvider : avoidCcProviders) { NestedSet<LibraryToLink> librariesToLink = linkProvider.getCcLinkParams(true, false).getLibraries(); for (LibraryToLink libraryToLink : librariesToLink.toList()) { - avoidLibrariesSet.add(libraryToLink.getArtifact()); + avoidLibrariesSet.add(libraryToLink.getArtifact().getRunfilesPath()); } } for (ObjcProvider avoidProvider : avoidObjcProviders) { - avoidLibrariesSet.addAll(avoidProvider.getCcLibraries()); + for (Artifact ccLibrary : avoidProvider.getCcLibraries()) { + avoidLibrariesSet.add(ccLibrary.getRunfilesPath()); + } for (Artifact libraryToAvoid : avoidProvider.getPropagable(LIBRARY)) { - avoidLibrariesSet.add(libraryToAvoid); + avoidLibrariesSet.add(libraryToAvoid.getRunfilesPath()); } } ObjcProvider.Builder objcProviderBuilder = new ObjcProvider.Builder(); @@ -638,10 +641,12 @@ public final class ObjcProvider extends Info { addTransitiveAndFilter(objcProviderBuilder, CC_LIBRARY, ccLibraryNotYetLinked(avoidLibrariesSet)); } else if (key == LIBRARY) { - addTransitiveAndFilter(objcProviderBuilder, LIBRARY, - notContainedIn(avoidLibrariesSet)); + addTransitiveAndFilter(objcProviderBuilder, LIBRARY, notContainedIn(avoidLibrariesSet)); } else if (NON_SUBTRACTABLE_KEYS.contains(key)) { addTransitiveAndAvoid(objcProviderBuilder, key, ImmutableList.<ObjcProvider>of()); + } else if (key.getType() == Artifact.class) { + addTransitiveAndAvoidArtifacts(objcProviderBuilder, ((Key<Artifact>) key), + avoidObjcProviders); } else { addTransitiveAndAvoid(objcProviderBuilder, key, avoidObjcProviders); } @@ -650,27 +655,28 @@ public final class ObjcProvider extends Info { } /** - * Returns a predicate which returns true for a given artifact if the artifact is not contained - * in a given set. + * Returns a predicate which returns true for a given artifact if the artifact's runfiles path + * is not contained in the given set. * - * @param linkedLibraryArtifacts if a given artifact is present in this set, the predicate will - * return false + * @param runfilesPaths if a given artifact has runfiles path present in this set, the predicate + * will return false */ private static Predicate<Artifact> notContainedIn( - final HashSet<Artifact> linkedLibraryArtifacts) { - return libraryToLink -> !linkedLibraryArtifacts.contains(libraryToLink); + final HashSet<PathFragment> runfilesPaths) { + return libraryToLink -> !runfilesPaths.contains(libraryToLink.getRunfilesPath()); } /** - * Returns a predicate which returns true for a given {@link LibraryToLink} if the library - * artifact is not contained in a given set. + * Returns a predicate which returns true for a given {@link LibraryToLink} if the library's + * runfiles path is not contained in the given set. * - * @param linkedLibraryArtifacts if a given library's artifact is present in this set, the - * predicate will return false + * @param runfilesPaths if a given library has runfiles path present in this set, the predicate + * will return false */ private static Predicate<LibraryToLink> ccLibraryNotYetLinked( - final HashSet<Artifact> linkedLibraryArtifacts) { - return libraryToLink -> !linkedLibraryArtifacts.contains(libraryToLink.getArtifact()); + final HashSet<PathFragment> runfilesPaths) { + return libraryToLink -> !runfilesPaths.contains( + libraryToLink.getArtifact().getRunfilesPath()); } @SuppressWarnings("unchecked") @@ -694,6 +700,19 @@ public final class ObjcProvider extends Info { } } + private void addTransitiveAndAvoidArtifacts(ObjcProvider.Builder objcProviderBuilder, + Key<Artifact> key, Iterable<ObjcProvider> avoidProviders) { + // Artifacts to avoid may be in a different configuration and thus a different + // root directory, hence only the path fragment after the root directory is compared. + HashSet<PathFragment> avoidPathsSet = new HashSet<>(); + for (ObjcProvider avoidProvider : avoidProviders) { + for (Artifact artifact : avoidProvider.getPropagable(key)) { + avoidPathsSet.add(artifact.getRunfilesPath()); + } + } + addTransitiveAndFilter(objcProviderBuilder, key, notContainedIn(avoidPathsSet)); + } + @SuppressWarnings("unchecked") private <T> void addTransitiveAndAvoid(ObjcProvider.Builder objcProviderBuilder, Key<T> key, Iterable<ObjcProvider> avoidProviders) { |