Skip to content

Commit

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

Need to roll this back to roll back bazelbuild@56f2b2b, needed for b/123103413.

*** Original change description ***

C++: More CcLinkParams removal

This was rolled back from bazelbuild@2a01403 to make a different rollback easier. Nothing wrong with this CL.

RELNOTES:none
PiperOrigin-RevId: 230093848
  • Loading branch information
janakdr authored and weixiao-huang committed Jan 31, 2019
1 parent 22a32b8 commit ca6164a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.android;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand All @@ -34,11 +33,12 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.cpp.CcInfo;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.cpp.CppSemantics;
import com.google.devtools.build.lib.rules.cpp.LibraryToLinkWrapper;
import com.google.devtools.build.lib.rules.cpp.LinkerInput;
import com.google.devtools.build.lib.rules.nativedeps.NativeDepsHelper;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -68,15 +68,17 @@ public static NativeLibs fromLinkedNativeDeps(
String nativeDepsLibraryBasename = null;
for (Map.Entry<String, Collection<TransitiveInfoCollection>> entry :
getSplitDepsByArchitecture(ruleContext, depsAttributes).asMap().entrySet()) {
CcInfo ccInfo =
CcLinkParams linkParams =
AndroidCommon.getCcInfo(
entry.getValue(),
ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName()));
entry.getValue(),
ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName()))
.getCcLinkingInfo()
.getStaticModeParamsForDynamicLibrary();

Artifact nativeDepsLibrary =
NativeDepsHelper.linkAndroidNativeDepsIfPresent(
ruleContext,
ccInfo,
linkParams,
configurationMap.get(entry.getKey()),
toolchainsByCpu.get(entry.getKey()),
cppSemantics);
Expand All @@ -87,8 +89,7 @@ public static NativeLibs fromLinkedNativeDeps(
nativeDepsLibraryBasename = nativeDepsLibrary.getExecPath().getBaseName();
}
librariesBuilder.addAll(
filterUniqueSharedLibraries(
ruleContext, nativeDepsLibrary, ccInfo.getCcLinkingContext().getLibraries()));
filterUniqueSharedLibraries(ruleContext, nativeDepsLibrary, linkParams.getLibraries()));
NestedSet<Artifact> libraries = librariesBuilder.build();

if (!libraries.isEmpty()) {
Expand Down Expand Up @@ -245,33 +246,20 @@ private static Map<String, CcToolchainProvider> getToolchainsByCpu(RuleContext r
}

private static Iterable<Artifact> filterUniqueSharedLibraries(
RuleContext ruleContext, Artifact linkedLibrary, NestedSet<LibraryToLinkWrapper> libraries) {
RuleContext ruleContext, Artifact linkedLibrary, NestedSet<? extends LinkerInput> libraries) {
Map<String, Artifact> basenames = new HashMap<>();
Set<Artifact> artifacts = new HashSet<>();
if (linkedLibrary != null) {
basenames.put(linkedLibrary.getExecPath().getBaseName(), linkedLibrary);
}
for (LibraryToLinkWrapper linkerInput : libraries) {
if (linkerInput.getPicStaticLibrary() != null || linkerInput.getStaticLibrary() != null) {
for (LinkerInput linkerInput : libraries) {
String name = linkerInput.getArtifact().getFilename();
if (!(CppFileTypes.SHARED_LIBRARY.matches(name)
|| CppFileTypes.VERSIONED_SHARED_LIBRARY.matches(name))) {
// This is not a shared library and will not be loaded by Android, so skip it.
continue;
}
Artifact artifact = null;
if (linkerInput.getInterfaceLibrary() != null) {
if (linkerInput.getResolvedSymlinkInterfaceLibrary() != null) {
artifact = linkerInput.getResolvedSymlinkInterfaceLibrary();
} else {
artifact = linkerInput.getInterfaceLibrary();
}
} else {
if (linkerInput.getResolvedSymlinkDynamicLibrary() != null) {
artifact = linkerInput.getResolvedSymlinkDynamicLibrary();
} else {
artifact = linkerInput.getDynamicLibrary();
}
}
Preconditions.checkNotNull(artifact);

Artifact artifact = linkerInput.getOriginalLibraryArtifact();
if (!artifacts.add(artifact)) {
// We have already reached this library, e.g., through a different solib symlink.
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ public Artifact create(
private final Set<LinkerInput> objectFiles = new LinkedHashSet<>();
private final Set<Artifact> nonCodeInputs = new LinkedHashSet<>();
private final NestedSetBuilder<LibraryToLink> libraries = NestedSetBuilder.linkOrder();
private final NestedSetBuilder<LibraryToLinkWrapper> libraryToLinkWrappers =
NestedSetBuilder.linkOrder();
private NestedSet<Artifact> linkerFiles = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
private Artifact runtimeMiddleman;
private ArtifactCategory toolchainLibrariesType = null;
Expand Down Expand Up @@ -578,63 +576,8 @@ boolean canSplitCommandLine() {
}
}

private List<LibraryToLink> convertLibraryToLinkWrapperListToLibraryToLinkList(
NestedSet<LibraryToLinkWrapper> libraryToLinkWrappers) {
ImmutableList.Builder<LibraryToLink> librariesToLink = ImmutableList.builder();
for (LibraryToLinkWrapper libraryToLinkWrapper : libraryToLinkWrappers) {
LibraryToLink staticLibraryToLink =
libraryToLinkWrapper.getStaticLibrary() == null
? null
: libraryToLinkWrapper.getStaticLibraryToLink();
LibraryToLink picStaticLibraryToLink =
libraryToLinkWrapper.getPicStaticLibrary() == null
? null
: libraryToLinkWrapper.getPicStaticLibraryToLink();
LibraryToLink libraryToLinkToUse = null;
if (linkingMode == LinkingMode.STATIC) {
if (linkType.isDynamicLibrary()) {
if (picStaticLibraryToLink != null) {
libraryToLinkToUse = picStaticLibraryToLink;
} else if (staticLibraryToLink != null) {
libraryToLinkToUse = staticLibraryToLink;
}
} else {
if (staticLibraryToLink != null) {
libraryToLinkToUse = staticLibraryToLink;
} else if (picStaticLibraryToLink != null) {
libraryToLinkToUse = picStaticLibraryToLink;
}
}
}
if (libraryToLinkToUse == null) {
if (libraryToLinkWrapper.getInterfaceLibrary() != null) {
libraryToLinkToUse = libraryToLinkWrapper.getInterfaceLibraryToLink();
} else if (libraryToLinkWrapper.getDynamicLibrary() != null) {
libraryToLinkToUse = libraryToLinkWrapper.getDynamicLibraryToLink();
}
}
Preconditions.checkNotNull(libraryToLinkToUse);
checkLibrary(libraryToLinkToUse);
librariesToLink.add(libraryToLinkToUse);
}
return librariesToLink.build();
}

/** Builds the Action as configured and returns it. */
public CppLinkAction build() throws InterruptedException {
NestedSet<LibraryToLink> originalUniqueLibraries = null;

if (libraryToLinkWrappers.isEmpty()) {
originalUniqueLibraries = libraries.build();
} else {
Preconditions.checkState(libraries.isEmpty());
originalUniqueLibraries =
NestedSetBuilder.<LibraryToLink>linkOrder()
.addAll(
convertLibraryToLinkWrapperListToLibraryToLinkList(libraryToLinkWrappers.build()))
.build();
}

// Executable links do not have library identifiers.
boolean hasIdentifier = (libraryIdentifier != null);
boolean isExecutable = linkType.isExecutable();
Expand Down Expand Up @@ -687,6 +630,8 @@ public CppLinkAction build() throws InterruptedException {
includeLinkStaticInLtoIndexing
|| (linkingMode == Link.LinkingMode.DYNAMIC && !ltoCompilationContext.isEmpty());

NestedSet<LibraryToLink> originalUniqueLibraries = libraries.build();

PathFragment ltoOutputRootPrefix = null;
if (isLtoIndexing) {
Preconditions.checkState(allLtoArtifacts == null);
Expand Down Expand Up @@ -1371,7 +1316,6 @@ public CppLinkActionBuilder addLibrary(LibraryToLink input) {
* libraries.
*/
public CppLinkActionBuilder addLibraries(Iterable<LibraryToLink> inputs) {
Preconditions.checkState(libraryToLinkWrappers.isEmpty());
for (LibraryToLink input : inputs) {
checkLibrary(input);
if (input.isMustKeepDebug()) {
Expand All @@ -1382,17 +1326,6 @@ public CppLinkActionBuilder addLibraries(Iterable<LibraryToLink> inputs) {
return this;
}

public CppLinkActionBuilder addLibraryToLinkWrappers(Iterable<LibraryToLinkWrapper> inputs) {
Preconditions.checkState(libraries.isEmpty());
for (LibraryToLinkWrapper input : inputs) {
if (input.getMustKeepDebug()) {
mustKeepDebug = true;
}
}
this.libraryToLinkWrappers.addAll(inputs);
return this;
}

/**
* Sets the type of ELF file to be created (.a, .so, .lo, executable). The default is {@link
* LinkTargetType#STATIC_LIBRARY}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,6 @@ public static List<Artifact> getStaticModeParamsForExecutableLibraries(
return getStaticModeParamsForExecutableLibraries(fromCcLinkingInfo(ccLinkingInfo));
}

public static List<Artifact> getStaticModeParamsForDynamicLibraryLibraries(
CcLinkingContext ccLinkingContext) {
ImmutableList.Builder<Artifact> artifactListBuilder = ImmutableList.builder();
for (LibraryToLinkWrapper library : ccLinkingContext.getLibraries()) {
if (library.getPicStaticLibrary() != null) {
artifactListBuilder.add(library.getPicStaticLibrary());
} else if (library.getStaticLibrary() != null) {
artifactListBuilder.add(library.getStaticLibrary());
} else if (library.getInterfaceLibrary() != null) {
artifactListBuilder.add(library.getInterfaceLibrary());
} else {
artifactListBuilder.add(library.getDynamicLibrary());
}
}
return artifactListBuilder.build();
}

public NestedSet<LibraryToLinkWrapper> getLibraries() {
return libraries;
}
Expand Down Expand Up @@ -398,28 +381,16 @@ public Artifact getDynamicLibrary() {
return dynamicLibrary;
}

public Artifact getResolvedSymlinkDynamicLibrary() {
return resolvedSymlinkDynamicLibrary;
}

@Override
public Artifact getInterfaceLibrary() {
return interfaceLibrary;
}

public Artifact getResolvedSymlinkInterfaceLibrary() {
return resolvedSymlinkInterfaceLibrary;
}

@Override
public boolean getAlwayslink() {
return alwayslink;
}

public boolean getMustKeepDebug() {
return mustKeepDebug;
}

public static Builder builder() {
return new Builder();
}
Expand Down
Loading

0 comments on commit ca6164a

Please sign in to comment.