aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-07-25 15:00:14 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-25 15:02:02 -0700
commit1ed89aa24c91248fc062477250d5188940a848de (patch)
tree52dd5f464cedcc69f7576a3897cad89e0aba3b27 /src/main
parent03bd99d4a4a6ae51b45907fc4b8677eeafe1d6c8 (diff)
Automated rollback of commit 16dde0de06a3a4157a13e7e7264afeb6a50b2dde.
*** Reason for rollback *** Crash (see linked bug). PiperOrigin-RevId: 206060905
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java27
-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.java9
-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.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JplCcLinkParams.java29
7 files changed, 79 insertions, 124 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 2837ae63c8..6f2fbff664 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -21,9 +21,7 @@ import com.google.common.base.Optional;
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;
@@ -44,6 +42,9 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
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;
@@ -561,19 +562,20 @@ public class BazelJavaSemantics implements JavaSemantics {
Artifact gensrcJar,
RuleConfiguredTargetBuilder ruleBuilder) {
// TODO(plf): Figure out whether we can remove support for C++ dependencies in Bazel.
- 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));
+ 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());
}
// TODO(dmarting): simplify that logic when we remove the legacy Bazel java_test behavior.
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
index 9a71ae9f55..51fe643793 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
@@ -18,11 +18,9 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1;
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;
@@ -42,6 +40,9 @@ import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.In
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;
@@ -364,16 +365,18 @@ public class BazelPythonSemantics implements PythonSemantics {
@Override
public CcLinkingInfo buildCcLinkingInfoProvider(
Iterable<? extends TransitiveInfoCollection> deps) {
- 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();
-
+ 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);
+ }
+ };
// TODO(plf): return empty CcLinkingInfo.
- return CcLinkingInfo.merge(ccLinkingInfos);
+ ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore));
+ return ccLinkingInfoBuilder.build();
}
}
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 af205eb4d9..5703def576 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,7 +16,6 @@ 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,8 +45,9 @@ import com.google.devtools.build.lib.packages.Rule;
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.CcLinkingInfo;
+import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
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;
@@ -795,39 +795,28 @@ public class AndroidCommon {
return asNeverLink;
}
- public CcLinkingInfo getCcLinkingInfo() {
- return getCcLinkingInfo(
+ public AbstractCcLinkParamsStore getCcLinkParamsStore() {
+ return getCcLinkParamsStore(
javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH), ImmutableList.<String>of());
}
- public static CcLinkingInfo getCcLinkingInfo(
+ public static AbstractCcLinkParamsStore getCcLinkParamsStore(
final Iterable<? extends TransitiveInfoCollection> deps, final Collection<String> 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);
+ 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);
+ }
+ };
}
/** 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 50d69dc9ab..19262c7ce8 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,6 +30,8 @@ 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;
@@ -244,7 +246,12 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory {
.add(
JavaSourceInfoProvider.class,
JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes, javaSemantics))
- .addNativeDeclaredProvider(androidCommon.getCcLinkingInfo())
+ .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 0df0d333b2..6bea350871 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.getCcLinkingInfo(
+ AndroidCommon.getCcLinkParamsStore(
entry.getValue(),
ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName()))
- .getStaticModeParamsForDynamicLibrary();
+ .get(/* linkingStatically */ true, /* linkShared */ true);
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 7acd2631d0..a8a27515af 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
@@ -187,10 +187,6 @@ 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;
@@ -198,15 +194,8 @@ 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 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;
}
@@ -224,47 +213,7 @@ 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 09aeecc79c..68f7222d46 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,10 +15,12 @@
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;
@@ -49,16 +51,19 @@ public class JplCcLinkParams {
.getTransitiveInfoProviderMap()
.getProvider(JavaCcLinkParamsProvider.class));
}
- 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));
+ 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());
}
}