Skip to content

Commit

Permalink
Automated rollback of commit 47705ca.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Breakages in Blaze nightly, []

There are antipatterns in the depo "cc_library(srcs = ["a.so"]); cc_binary("a.so", linkstatic=1)", which should be cleand up firsts.

*** Original change description ***

Stop providing CcNativeLibraryInfo-s in cc_library and use data from ccLinkingInfo.

cc_library provides all the data needed by other targets in CcLinkingContext.

With this change CcNativeLibraryInfo is provided only by cc_binary.

PiperOrigin-RevId: 378592930
  • Loading branch information
comius authored and copybara-github committed Jun 10, 2021
1 parent 4c63c62 commit 517951a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,6 @@ private static NestedSet<LibraryToLink> collectTransitiveCcNativeLibraries(
builder.addAll(libraries);
for (CcInfo dep : ruleContext.getPrerequisites("deps", CcInfo.PROVIDER)) {
builder.addTransitive(dep.getCcNativeLibraryInfo().getTransitiveCcNativeLibraries());
builder.addTransitive(dep.getCcLinkingContext().getLibraries());
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ public static void init(
linkingHelper.buildCcLinkingContextFromLibrariesToLink(
neverLink ? ImmutableList.of() : libraryToLinks,
compilationInfo.getCcCompilationContext());
CcNativeLibraryInfo ccNativeLibraryInfo =
CppHelper.collectNativeCcLibraries(ruleContext.getPrerequisites("deps"), libraryToLinks);

/*
* We always generate a static library, even if there aren't any source files.
Expand Down Expand Up @@ -496,6 +498,7 @@ public static void init(
.setCcDebugInfoContext(
CppHelper.mergeCcDebugInfoContexts(
compilationInfo.getCcCompilationOutputs(), ccInfosFromDeps))
.setCcNativeLibraryInfo(ccNativeLibraryInfo)
.build())
.addOutputGroups(
CcCommon.mergeOutputGroups(ImmutableList.of(currentOutputGroups, outputGroups.build())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,16 @@ public static boolean useInterfaceSharedLibraries(
&& cppConfiguration.getUseInterfaceSharedLibraries();
}

public static CcNativeLibraryInfo collectNativeCcLibraries(
List<? extends TransitiveInfoCollection> deps, List<LibraryToLink> libraries) {
NestedSetBuilder<LibraryToLink> result = NestedSetBuilder.linkOrder();
result.addAll(libraries);
for (CcInfo dep : AnalysisUtils.getProviders(deps, CcInfo.PROVIDER)) {
result.addTransitive(dep.getCcNativeLibraryInfo().getTransitiveCcNativeLibraries());
}
return new CcNativeLibraryInfo(result.build());
}

static boolean useToolchainResolution(RuleContext ruleContext) {
CppOptions cppOptions =
Preconditions.checkNotNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.cpp.CcCommon;
import com.google.devtools.build.lib.rules.cpp.CcInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkingContext;
import com.google.devtools.build.lib.rules.cpp.CcNativeLibraryInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
Expand Down Expand Up @@ -733,14 +732,14 @@ public static Collection<Artifact> collectNativeLibraries(
NestedSet<LibraryToLink> linkerInputs =
NestedSetBuilder.fromNestedSets(
Streams.concat(
AnalysisUtils.getProviders(deps, JavaInfo.PROVIDER).stream()
.map(JavaInfo::getTransitiveNativeLibraries),
AnalysisUtils.getProviders(deps, CcInfo.PROVIDER).stream()
JavaInfo.getProvidersFromListOfTargets(JavaCcInfoProvider.class, deps)
.stream()
.map(JavaCcInfoProvider::getCcInfo)
.map(CcInfo::getCcNativeLibraryInfo)
.map(CcNativeLibraryInfo::getTransitiveCcNativeLibraries),
AnalysisUtils.getProviders(deps, CcInfo.PROVIDER).stream()
.map(CcInfo::getCcLinkingContext)
.map(CcLinkingContext::getLibraries))
.map(CcInfo::getCcNativeLibraryInfo)
.map(CcNativeLibraryInfo::getTransitiveCcNativeLibraries))
.collect(toImmutableList()))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,9 @@ public NestedSet<Artifact> getTransitiveOnlyRuntimeJars() {

/** Returns the transitive set of CC native libraries required by the target. */
public NestedSet<LibraryToLink> getTransitiveNativeLibraries() {
JavaCcInfoProvider javaCcInfo = getProvider(JavaCcInfoProvider.class);
if (javaCcInfo == null) {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}
CcInfo ccInfo = javaCcInfo.getCcInfo();
return NestedSetBuilder.fromNestedSet(
ccInfo.getCcNativeLibraryInfo().getTransitiveCcNativeLibraries())
.addTransitive(ccInfo.getCcLinkingContext().getLibraries())
.build();
return getProviderAsNestedSet(
JavaCcInfoProvider.class,
x -> x.getCcInfo().getCcNativeLibraryInfo().getTransitiveCcNativeLibraries());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ public void testFilesToBuild() throws Exception {
.containsExactly(archive, implSharedObject, implInterfaceSharedObject);
assertThat(
LibraryToLink.getDynamicLibrariesForLinking(
hello.get(CcInfo.PROVIDER).getCcLinkingContext().getLibraries()))
hello
.get(CcInfo.PROVIDER)
.getCcNativeLibraryInfo()
.getTransitiveCcNativeLibraries()))
.containsExactly(implInterfaceSharedObjectLink);
assertThat(
hello
Expand Down Expand Up @@ -267,7 +270,10 @@ public void testFilesToBuildWithInterfaceSharedObjects() throws Exception {
.containsExactly(archive, sharedObject, implSharedObject);
assertThat(
LibraryToLink.getDynamicLibrariesForLinking(
hello.get(CcInfo.PROVIDER).getCcLinkingContext().getLibraries()))
hello
.get(CcInfo.PROVIDER)
.getCcNativeLibraryInfo()
.getTransitiveCcNativeLibraries()))
.containsExactly(sharedObjectLink);
assertThat(
hello
Expand Down

0 comments on commit 517951a

Please sign in to comment.