aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules
diff options
context:
space:
mode:
authorGravatar plf <plf@google.com>2018-08-06 03:05:29 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-06 03:07:21 -0700
commit7a3e39fc20f1fba810d8023ff1608e39f501492a (patch)
tree1b72979d65a670d0bd1c5b4aa459314a5e82e76b /src/main/java/com/google/devtools/build/lib/rules
parentad7b61286e29364d6c7e386f218c6c3b0530bfdc (diff)
C++: Removes calls to setCcLinkparamsStore of CcLinkingInfo.Builder
This is in preparation for deleting CcLinkParamsStore. Not all calls to setCcLinkparamsStore have been removed in this CL. RELNOTES:none PiperOrigin-RevId: 207516944
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java78
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java29
5 files changed, 110 insertions, 62 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
index cc5c0d3fb8..b8dce663d3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.rules.android;
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;
@@ -46,9 +47,8 @@ import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.
import com.google.devtools.build.lib.packages.TriState;
import com.google.devtools.build.lib.rules.android.DataBinding.DataBindingContext;
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;
@@ -809,28 +809,39 @@ public class AndroidCommon {
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. */
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
index 54e7683d07..fc2b5e28aa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java
@@ -30,8 +30,6 @@ import com.google.devtools.build.lib.packages.BuildType;
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;
@@ -271,15 +269,11 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
.addNativeDeclaredProvider(
new AndroidNativeLibsInfo(
AndroidCommon.collectTransitiveNativeLibs(ruleContext).build()))
+ .addNativeDeclaredProvider(
+ new AndroidCcLinkParamsProvider(androidCommon.getCcLinkingInfo()))
.add(
JavaSourceInfoProvider.class,
JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes, javaSemantics))
- .addNativeDeclaredProvider(
- new AndroidCcLinkParamsProvider(
- CcLinkingInfo.Builder.create()
- .setCcLinkParamsStore(
- new CcLinkParamsStore(androidCommon.getCcLinkParamsStore()))
- .build()))
.addNativeDeclaredProvider(new ProguardSpecProvider(transitiveProguardConfigs))
.addNativeDeclaredProvider(
new AndroidProguardInfo(proguardLibrary.collectLocalProguardSpecs()))
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
index 6bea350871..0df0d333b2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
@@ -68,10 +68,10 @@ public final class NativeLibs {
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(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
index 4157930c5c..123a824302 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
@@ -86,22 +86,19 @@ public final class CcLinkingInfo extends NativeInfo implements CcLinkingInfoApi
CcLinkParams dynamicModeParamsForExecutable = (CcLinkParams) nullIfNone(args[i++]);
CcRunfiles ccRunfiles = (CcRunfiles) nullIfNone(args[i++]);
CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create();
- if (staticModeParamsForDynamicLibrary != null) {
- if (staticModeParamsForExecutable == null
- || dynamicModeParamsForDynamicLibrary == null
- || dynamicModeParamsForExecutable == null) {
- throw new EvalException(
- loc,
- "Every CcLinkParams parameter must be passed to CcLinkingInfo "
- + "if one of them is passed.");
- }
- ccLinkingInfoBuilder.setCcLinkParamsStore(
- new CcLinkParamsStore(
- staticModeParamsForDynamicLibrary,
- staticModeParamsForExecutable,
- dynamicModeParamsForDynamicLibrary,
- dynamicModeParamsForExecutable));
+ if (staticModeParamsForDynamicLibrary == null
+ || staticModeParamsForExecutable == null
+ || dynamicModeParamsForDynamicLibrary == null
+ || dynamicModeParamsForExecutable == null) {
+ throw new EvalException(
+ loc, "Every CcLinkParams parameter must be passed to CcLinkingInfo.");
}
+ ccLinkingInfoBuilder.setCcLinkParamsStore(
+ new CcLinkParamsStore(
+ staticModeParamsForDynamicLibrary,
+ staticModeParamsForExecutable,
+ dynamicModeParamsForDynamicLibrary,
+ dynamicModeParamsForExecutable));
// TODO(plf): The CcDynamicLibrariesForRuntime provider can be removed perhaps. Do not
// add to the API until we know for sure. The CcRunfiles provider is already in the API
// at the time of this comment (cl/200184914). Perhaps it can be removed but Skylark rules
@@ -187,6 +184,10 @@ public final class CcLinkingInfo extends NativeInfo implements CcLinkingInfoApi
/** A Builder for {@link CcLinkingInfo}. */
public static class Builder {
CcLinkParamsStore ccLinkParamsStore;
+ CcLinkParams staticModeParamsForDynamicLibrary;
+ CcLinkParams staticModeParamsForExecutable;
+ CcLinkParams dynamicModeParamsForDynamicLibrary;
+ CcLinkParams dynamicModeParamsForExecutable;
CcRunfiles ccRunfiles;
CcDynamicLibrariesForRuntime ccDynamicLibrariesForRuntime;
@@ -194,8 +195,15 @@ public final class CcLinkingInfo extends NativeInfo implements CcLinkingInfoApi
return new CcLinkingInfo.Builder();
}
+ @Deprecated
+ // TODO(b/111781390): Use individual setters for each flavor of CcLinkParams. Not all call sites
+ // 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;
}
@@ -213,7 +221,47 @@ public final class CcLinkingInfo extends NativeInfo implements CcLinkingInfoApi
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);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java
index 68f7222d46..09aeecc79c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java
@@ -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;
@@ -51,19 +49,16 @@ public class JplCcLinkParams {
.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));
}
}