Skip to content

Commit

Permalink
C++: Removes calls to setCcLinkparamsStore of CcLinkingInfo.Builder
Browse files Browse the repository at this point in the history
This is in preparation for deleting CcLinkParamsStore. Not all calls to
setCcLinkparamsStore have been removed in this CL.

RELNOTES:none
PiperOrigin-RevId: 205998687
  • Loading branch information
oquenchil authored and Copybara-Service committed Jul 25, 2018
1 parent e1ed9f5 commit 16dde0d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
Expand All @@ -42,9 +44,6 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
Expand Down Expand Up @@ -562,20 +561,19 @@ public void addProviders(
Artifact gensrcJar,
RuleConfiguredTargetBuilder ruleBuilder) {
// TODO(plf): Figure out whether we can remove support for C++ dependencies in Bazel.
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
ccLinkingInfoBuilder.setCcLinkParamsStore(
new CcLinkParamsStore(
new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(
javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH),
JavaCcLinkParamsProvider.TO_LINK_PARAMS,
CcLinkParamsStore.TO_LINK_PARAMS);
}
}));
ruleBuilder.addNativeDeclaredProvider(ccLinkingInfoBuilder.build());
ImmutableList<? extends TransitiveInfoCollection> deps =
javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH);
ImmutableList<CcLinkingInfo> ccLinkingInfos =
ImmutableList.<CcLinkingInfo>builder()
.addAll(AnalysisUtils.getProviders(deps, CcLinkingInfo.PROVIDER))
.addAll(
Streams.stream(AnalysisUtils.getProviders(deps, JavaCcLinkParamsProvider.class))
.map(JavaCcLinkParamsProvider::getCcLinkingInfo)
.collect(ImmutableList.toImmutableList()))
.build();

// TODO(plf): return empty CcLinkingInfo.
ruleBuilder.addNativeDeclaredProvider(CcLinkingInfo.merge(ccLinkingInfos));
}

// TODO(dmarting): simplify that logic when we remove the legacy Bazel java_test behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ParamFileInfo;
import com.google.devtools.build.lib.actions.ParameterFile;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
Expand All @@ -40,9 +42,6 @@
import com.google.devtools.build.lib.cmdline.Label;
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.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.python.PyCcLinkParamsProvider;
import com.google.devtools.build.lib.rules.python.PyCommon;
Expand Down Expand Up @@ -365,18 +364,16 @@ private static String getPythonBinary(
@Override
public CcLinkingInfo buildCcLinkingInfoProvider(
Iterable<? extends TransitiveInfoCollection> deps) {
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
AbstractCcLinkParamsStore ccLinkParamsStore =
new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(
deps, CcLinkParamsStore.TO_LINK_PARAMS, PyCcLinkParamsProvider.TO_LINK_PARAMS);
}
};
ImmutableList<CcLinkingInfo> ccLinkingInfos =
ImmutableList.<CcLinkingInfo>builder()
.addAll(AnalysisUtils.getProviders(deps, CcLinkingInfo.PROVIDER))
.addAll(
Streams.stream(AnalysisUtils.getProviders(deps, PyCcLinkParamsProvider.PROVIDER))
.map(PyCcLinkParamsProvider::getCcLinkingInfo)
.collect(ImmutableList.toImmutableList()))
.build();

// TODO(plf): return empty CcLinkingInfo.
ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore));
return ccLinkingInfoBuilder.build();
return CcLinkingInfo.merge(ccLinkingInfos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
Expand Down Expand Up @@ -45,9 +46,8 @@
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.android.ZipFilterBuilder.CheckHashMismatchMode;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.ClasspathConfiguredFragment;
import com.google.devtools.build.lib.rules.java.JavaCcLinkParamsProvider;
import com.google.devtools.build.lib.rules.java.JavaCommon;
Expand Down Expand Up @@ -795,28 +795,39 @@ public boolean isNeverLink() {
return asNeverLink;
}

public AbstractCcLinkParamsStore getCcLinkParamsStore() {
return getCcLinkParamsStore(
public CcLinkingInfo getCcLinkingInfo() {
return getCcLinkingInfo(
javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH), ImmutableList.<String>of());
}

public static AbstractCcLinkParamsStore getCcLinkParamsStore(
public static CcLinkingInfo getCcLinkingInfo(
final Iterable<? extends TransitiveInfoCollection> deps, final Collection<String> linkOpts) {
return new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
builder.addTransitiveTargets(
deps,
// Link in Java-specific C++ code in the transitive closure
JavaCcLinkParamsProvider.TO_LINK_PARAMS,
// Link in Android-specific C++ code (e.g., android_libraries) in the transitive closure
AndroidCcLinkParamsProvider.TO_LINK_PARAMS,
// Link in non-language-specific C++ code in the transitive closure
CcLinkParamsStore.TO_LINK_PARAMS);
builder.addLinkOpts(linkOpts);
}
};

CcLinkParams linkOptsParams = CcLinkParams.builder().addLinkOpts(linkOpts).build();
CcLinkingInfo linkOptsProvider =
CcLinkingInfo.Builder.create()
.setStaticModeParamsForDynamicLibrary(linkOptsParams)
.setStaticModeParamsForExecutable(linkOptsParams)
.setDynamicModeParamsForDynamicLibrary(linkOptsParams)
.setDynamicModeParamsForExecutable(linkOptsParams)
.build();

ImmutableList<CcLinkingInfo> ccLinkingInfos =
ImmutableList.<CcLinkingInfo>builder()
.add(linkOptsProvider)
.addAll(
Streams.stream(AnalysisUtils.getProviders(deps, JavaCcLinkParamsProvider.class))
.map(JavaCcLinkParamsProvider::getCcLinkingInfo)
.collect(ImmutableList.toImmutableList()))
.addAll(
Streams.stream(
AnalysisUtils.getProviders(deps, AndroidCcLinkParamsProvider.PROVIDER))
.map(AndroidCcLinkParamsProvider::getLinkParams)
.collect(ImmutableList.toImmutableList()))
.addAll(AnalysisUtils.getProviders(deps, CcLinkingInfo.PROVIDER))
.build();

return CcLinkingInfo.merge(ccLinkingInfos);
}

/** Returns {@link AndroidConfiguration} in given context. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidAaptVersion;
import com.google.devtools.build.lib.rules.android.AndroidLibraryAarInfo.Aar;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.JavaCommon;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider;
Expand Down Expand Up @@ -246,12 +244,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
.add(
JavaSourceInfoProvider.class,
JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes, javaSemantics))
.addNativeDeclaredProvider(
new AndroidCcLinkParamsProvider(
CcLinkingInfo.Builder.create()
.setCcLinkParamsStore(
new CcLinkParamsStore(androidCommon.getCcLinkParamsStore()))
.build()))
.addNativeDeclaredProvider(androidCommon.getCcLinkingInfo())
.addNativeDeclaredProvider(new ProguardSpecProvider(transitiveProguardConfigs))
.addNativeDeclaredProvider(
new AndroidProguardInfo(proguardLibrary.collectLocalProguardSpecs()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public static NativeLibs fromLinkedNativeDeps(
for (Map.Entry<String, Collection<TransitiveInfoCollection>> entry :
getSplitDepsByArchitecture(ruleContext, depsAttributes).asMap().entrySet()) {
CcLinkParams linkParams =
AndroidCommon.getCcLinkParamsStore(
AndroidCommon.getCcLinkingInfo(
entry.getValue(),
ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName()))
.get(/* linkingStatically */ true, /* linkShared */ true);
.getStaticModeParamsForDynamicLibrary();

Artifact nativeDepsLibrary =
NativeDepsHelper.linkAndroidNativeDepsIfPresent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,26 @@ public CcDynamicLibrariesForRuntime getCcDynamicLibrariesForRuntime() {
/** A Builder for {@link CcLinkingInfo}. */
public static class Builder {
CcLinkParamsStore ccLinkParamsStore;
CcLinkParams staticModeParamsForDynamicLibrary;
CcLinkParams staticModeParamsForExecutable;
CcLinkParams dynamicModeParamsForDynamicLibrary;
CcLinkParams dynamicModeParamsForExecutable;
CcRunfiles ccRunfiles;
CcDynamicLibrariesForRuntime ccDynamicLibrariesForRuntime;

public static CcLinkingInfo.Builder create() {
return new CcLinkingInfo.Builder();
}

@Deprecated
// TODO(b/111781390): Use individual setters for each flavor of CcLinkParams. Not all callsites
// are being refactored at once. Work in progress.
public Builder setCcLinkParamsStore(CcLinkParamsStore ccLinkParamsStore) {
Preconditions.checkState(this.ccLinkParamsStore == null);
Preconditions.checkState(this.staticModeParamsForDynamicLibrary == null);
Preconditions.checkState(this.staticModeParamsForExecutable == null);
Preconditions.checkState(this.dynamicModeParamsForDynamicLibrary == null);
Preconditions.checkState(this.dynamicModeParamsForExecutable == null);
this.ccLinkParamsStore = ccLinkParamsStore;
return this;
}
Expand All @@ -213,7 +224,47 @@ public Builder setCcDynamicLibrariesForRuntime(
return this;
}

public Builder setStaticModeParamsForDynamicLibrary(CcLinkParams ccLinkParams) {
Preconditions.checkState(
this.staticModeParamsForDynamicLibrary == null && ccLinkParamsStore == null);
this.staticModeParamsForDynamicLibrary = ccLinkParams;
return this;
}

public Builder setStaticModeParamsForExecutable(CcLinkParams ccLinkParams) {
Preconditions.checkState(
this.staticModeParamsForExecutable == null && ccLinkParamsStore == null);
this.staticModeParamsForExecutable = ccLinkParams;
return this;
}

public Builder setDynamicModeParamsForDynamicLibrary(CcLinkParams ccLinkParams) {
Preconditions.checkState(
this.dynamicModeParamsForDynamicLibrary == null && ccLinkParamsStore == null);
this.dynamicModeParamsForDynamicLibrary = ccLinkParams;
return this;
}

public Builder setDynamicModeParamsForExecutable(CcLinkParams ccLinkParams) {
Preconditions.checkState(
this.dynamicModeParamsForExecutable == null && ccLinkParamsStore == null);
this.dynamicModeParamsForExecutable = ccLinkParams;
return this;
}

public CcLinkingInfo build() {
if (ccLinkParamsStore == null) {
Preconditions.checkNotNull(staticModeParamsForDynamicLibrary);
Preconditions.checkNotNull(staticModeParamsForExecutable);
Preconditions.checkNotNull(dynamicModeParamsForDynamicLibrary);
Preconditions.checkNotNull(dynamicModeParamsForExecutable);
ccLinkParamsStore =
new CcLinkParamsStore(
staticModeParamsForDynamicLibrary,
staticModeParamsForExecutable,
dynamicModeParamsForDynamicLibrary,
dynamicModeParamsForExecutable);
}
return new CcLinkingInfo(ccLinkParamsStore, ccRunfiles, ccDynamicLibrariesForRuntime);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package com.google.devtools.build.lib.rules.java.proto;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
import com.google.devtools.build.lib.rules.java.JavaCcLinkParamsProvider;
import java.util.ArrayList;
Expand Down Expand Up @@ -51,19 +49,16 @@ public static JavaCcLinkParamsProvider createCcLinkParamsStore(
.getTransitiveInfoProviderMap()
.getProvider(JavaCcLinkParamsProvider.class));
}
CcLinkingInfo.Builder builder = CcLinkingInfo.Builder.create();
builder.setCcLinkParamsStore(
new CcLinkParamsStore(
new AbstractCcLinkParamsStore() {
@Override
protected void collect(
CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
for (JavaCcLinkParamsProvider provider : providers) {
builder.add(provider.getCcLinkingInfo().getCcLinkParamsStore());
}
builder.addTransitiveTargets(protoRuntimes);
}
}));
return new JavaCcLinkParamsProvider(builder.build());
ImmutableList<CcLinkingInfo> ccLinkingInfos =
ImmutableList.<CcLinkingInfo>builder()
.addAll(
providers
.stream()
.map(JavaCcLinkParamsProvider::getCcLinkingInfo)
.collect(ImmutableList.toImmutableList()))
.addAll(AnalysisUtils.getProviders(protoRuntimes, CcLinkingInfo.PROVIDER))
.build();

return new JavaCcLinkParamsProvider(CcLinkingInfo.merge(ccLinkingInfos));
}
}

0 comments on commit 16dde0d

Please sign in to comment.