From 6b3e482e010f5e256f43013f661ed9f67a723784 Mon Sep 17 00:00:00 2001 From: plf Date: Tue, 15 May 2018 06:04:34 -0700 Subject: [PATCH] C++: Deletes CcLinkParamsInfo This class is not necessary anymore. We can use CcLinkParamsStoreImpl directly which has been renamed to CcLinkParamsStore. RELNOTES:none PiperOrigin-RevId: 196656488 --- .../bazel/rules/java/BazelJavaSemantics.java | 10 +- .../rules/python/BazelPythonSemantics.java | 4 +- .../android/AndroidCcLinkParamsProvider.java | 10 +- .../lib/rules/android/AndroidCommon.java | 10 +- .../rules/cpp/AbstractCcLinkParamsStore.java | 128 +++++++++++++ .../build/lib/rules/cpp/CcLibrary.java | 2 +- .../build/lib/rules/cpp/CcLinkParams.java | 43 ++--- .../build/lib/rules/cpp/CcLinkParamsInfo.java | 80 -------- .../lib/rules/cpp/CcLinkParamsStore.java | 179 ++++++------------ .../build/lib/rules/cpp/CcLinkingHelper.java | 12 +- .../build/lib/rules/cpp/CcLinkingInfo.java | 20 +- .../lib/rules/cpp/CcSkylarkApiProvider.java | 8 +- .../cpp/CcSpecificLinkParamsProvider.java | 13 +- .../rules/java/JavaCcLinkParamsProvider.java | 14 +- .../lib/rules/java/proto/JplCcLinkParams.java | 10 +- .../build/lib/rules/objc/ObjcCommon.java | 12 +- .../build/lib/rules/objc/ObjcLibrary.java | 6 +- .../objc/ObjcLibraryCcLinkParamsStore.java | 6 +- .../build/lib/rules/objc/ObjcProvider.java | 10 +- .../build/lib/rules/python/PyBinary.java | 20 +- .../rules/python/PyCcLinkParamsProvider.java | 10 +- .../build/lib/rules/python/PyLibrary.java | 24 +-- .../lib/rules/python/PythonSemantics.java | 4 +- .../cpp/CcImportConfiguredTargetTest.java | 36 ++-- .../cpp/CcLibraryConfiguredTargetTest.java | 14 +- 25 files changed, 331 insertions(+), 354 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/AbstractCcLinkParamsStore.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsInfo.java 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 bcc9ea817b6952..4d95e444309404 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 @@ -42,8 +42,8 @@ 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.CcLinkParamsInfo; 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; @@ -568,16 +568,16 @@ public void addProviders( RuleConfiguredTargetBuilder ruleBuilder) { // TODO(plf): Figure out whether we can remove support for C++ dependencies in Bazel. CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); - ccLinkingInfoBuilder.setCcLinkParamsInfo( - new CcLinkParamsInfo( - new CcLinkParamsStore() { + 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, - CcLinkParamsInfo.TO_LINK_PARAMS); + CcLinkParamsStore.TO_LINK_PARAMS); } })); ruleBuilder.addNativeDeclaredProvider(ccLinkingInfoBuilder.build()); 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 eeaf5f24f69965..a2269fbecb5df7 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 @@ -39,7 +39,7 @@ 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.CcLinkParamsStore; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.python.PyCommon; import com.google.devtools.build.lib.rules.python.PythonConfiguration; import com.google.devtools.build.lib.rules.python.PythonSemantics; @@ -128,7 +128,7 @@ public Artifact getPythonTemplateMainArtifact(RuleContext ruleContext, Artifact public Artifact createExecutable( RuleContext ruleContext, PyCommon common, - CcLinkParamsStore ccLinkParamsStore, + AbstractCcLinkParamsStore ccLinkParamsStore, NestedSet imports) throws InterruptedException { String main = common.determineMainExecutableSource(/*withWorkspaceName=*/ true); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCcLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCcLinkParamsProvider.java index 0e21694bdcc0c6..405e68bd968cc5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCcLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCcLinkParamsProvider.java @@ -18,20 +18,20 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl; /** A target that provides C++ libraries to be linked into Android targets. */ @AutoValue @Immutable public abstract class AndroidCcLinkParamsProvider implements TransitiveInfoProvider { - public static AndroidCcLinkParamsProvider create(CcLinkParamsStore store) { - return new AutoValue_AndroidCcLinkParamsProvider(new CcLinkParamsStoreImpl(store)); + public static AndroidCcLinkParamsProvider create(AbstractCcLinkParamsStore store) { + return new AutoValue_AndroidCcLinkParamsProvider(new CcLinkParamsStore(store)); } - public abstract CcLinkParamsStore getLinkParams(); + public abstract AbstractCcLinkParamsStore getLinkParams(); - public static final Function TO_LINK_PARAMS = + public static final Function TO_LINK_PARAMS = (TransitiveInfoCollection input) -> { AndroidCcLinkParamsProvider provider = input.getProvider(AndroidCcLinkParamsProvider.class); return provider == null ? null : provider.getLinkParams(); 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 42147be65896ae..1ebd4abd9fa469 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 @@ -44,8 +44,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.CcLinkParamsInfo; 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; @@ -800,14 +800,14 @@ public boolean isNeverLink() { return asNeverLink; } - public CcLinkParamsStore getCcLinkParamsStore() { + public AbstractCcLinkParamsStore getCcLinkParamsStore() { return getCcLinkParamsStore( javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH), ImmutableList.of()); } - public static CcLinkParamsStore getCcLinkParamsStore( + public static AbstractCcLinkParamsStore getCcLinkParamsStore( final Iterable deps, final Collection linkOpts) { - return new CcLinkParamsStore() { + return new AbstractCcLinkParamsStore() { @Override protected void collect( CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { @@ -818,7 +818,7 @@ protected void collect( // 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 - CcLinkParamsInfo.TO_LINK_PARAMS); + CcLinkParamsStore.TO_LINK_PARAMS); builder.addLinkOpts(linkOpts); } }; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/AbstractCcLinkParamsStore.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/AbstractCcLinkParamsStore.java new file mode 100644 index 00000000000000..2849d55e0caa0a --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/AbstractCcLinkParamsStore.java @@ -0,0 +1,128 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.rules.cpp; + +import com.google.common.base.Preconditions; +import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; + +/** + * A cache of C link parameters. + * + *

The cache holds instances of {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} for + * combinations of linkingStatically and linkShared. If a requested value is not available in the + * cache, it is computed and then stored. + * + *

Typically this class is used on targets that may be linked in as C libraries as in the + * following example: + * + *

+ * class SomeTarget implements CcLinkParamsStore {
+ *   private final AbstractCcLinkParamsStore ccLinkParamsStore = new AbstractCcLinkParamsStore() {
+ *     @Override
+ *     protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
+ *                            boolean linkShared) {
+ *       builder.add[...]
+ *     }
+ *   };
+ *
+ *   @Override
+ *   public CcLinkParams getCcLinkParams(boolean linkingStatically, boolean linkShared) {
+ *     return ccLinkParamsStore.get(linkingStatically, linkShared);
+ *   }
+ * }
+ * 
+ */ +public abstract class AbstractCcLinkParamsStore { + protected CcLinkParams staticSharedParams; + protected CcLinkParams staticNoSharedParams; + protected CcLinkParams noStaticSharedParams; + protected CcLinkParams noStaticNoSharedParams; + + private CcLinkParams compute(boolean linkingStatically, boolean linkShared) { + CcLinkParams.Builder builder = CcLinkParams.builder(linkingStatically, linkShared); + collect(builder, linkingStatically, linkShared); + return builder.build(); + } + + /** + * Returns {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} for a combination of + * parameters. + * + *

The {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} instance is computed lazily + * and cached. + */ + public synchronized CcLinkParams get(boolean linkingStatically, boolean linkShared) { + CcLinkParams result = lookup(linkingStatically, linkShared); + if (result == null) { + result = compute(linkingStatically, linkShared); + put(linkingStatically, linkShared, result); + } + return result; + } + + private CcLinkParams lookup(boolean linkingStatically, boolean linkShared) { + if (linkingStatically) { + return linkShared ? staticSharedParams : staticNoSharedParams; + } else { + return linkShared ? noStaticSharedParams : noStaticNoSharedParams; + } + } + + private void put(boolean linkingStatically, boolean linkShared, CcLinkParams params) { + Preconditions.checkNotNull(params); + if (linkingStatically) { + if (linkShared) { + staticSharedParams = params; + } else { + staticNoSharedParams = params; + } + } else { + if (linkShared) { + noStaticSharedParams = params; + } else { + noStaticNoSharedParams = params; + } + } + } + + /** + * Hook for building the actual link params. + * + *

Users should override this method and call methods of the builder to + * set up the actual CcLinkParams objects. + * + *

Implementations of this method must not fail or try to report errors on the + * configured target. + */ + protected abstract void collect(CcLinkParams.Builder builder, boolean linkingStatically, + boolean linkShared); + + @AutoCodec + @VisibleForSerialization + static class EmptyCcLinkParamsStore extends AbstractCcLinkParamsStore { + public static final ObjectCodec CODEC = + new AbstractCcLinkParamsStore_EmptyCcLinkParamsStore_AutoCodec(); + + @Override + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {} + } + + /** An empty CcLinkParamStore. */ + public static final AbstractCcLinkParamsStore EMPTY = new EmptyCcLinkParamsStore(); +} + diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index 77d4f1ef6f55da..245af2ee1460fc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -374,7 +374,7 @@ private static CcLinkingInfo overrideRunfilesProvider( CcLinkingInfo ccLinkingInfo = (CcLinkingInfo) linkingInfo.getProviders().getProvider(CcLinkingInfo.PROVIDER.getKey()); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); - ccLinkingInfoBuilder.setCcLinkParamsInfo(ccLinkingInfo.getCcLinkParamsInfo()); + ccLinkingInfoBuilder.setCcLinkParamsStore(ccLinkingInfo.getCcLinkParamsStore()); ccLinkingInfoBuilder.setCcExecutionDynamicLibrariesInfo( ccLinkingInfo.getCcExecutionDynamicLibrariesInfo()); ccLinkingInfoBuilder.setCcRunfiles(new CcRunfiles(staticRunfiles, sharedRunfiles)); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java index 4ad7a1b030dc73..294ebe9f5aaba6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java @@ -218,7 +218,7 @@ public CcLinkParams build() { nonCodeInputs); } - public boolean add(CcLinkParamsStore store) { + public boolean add(AbstractCcLinkParamsStore store) { if (store != null) { CcLinkParams args = store.get(linkingStatically, linkShared); addTransitiveArgs(args); @@ -239,14 +239,17 @@ public Builder addTransitiveTargets(Iterable /** * Includes link parameters from a dependency target. * - *

The target should implement {@link CcLinkParamsInfo}. If it does not, - * the method does not do anything. + *

The target should implement {@link CcLinkParamsStore}. If it does not, the method does not + * do anything. */ public Builder addTransitiveTarget(TransitiveInfoCollection target) { CcLinkingInfo ccLinkingInfo = target.get(CcLinkingInfo.PROVIDER); - CcLinkParamsInfo ccLinkParamsInfo = - ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo(); - return addTransitiveProvider(ccLinkParamsInfo); + CcLinkParamsStore ccLinkParamsStore = + ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsStore(); + if (ccLinkParamsStore != null) { + add(ccLinkParamsStore); + } + return this; } /** @@ -255,14 +258,16 @@ public Builder addTransitiveTarget(TransitiveInfoCollection target) { * added. */ @SafeVarargs - public final Builder addTransitiveTarget(TransitiveInfoCollection target, - Function firstMapping, + public final Builder addTransitiveTarget( + TransitiveInfoCollection target, + Function firstMapping, @SuppressWarnings("unchecked") // Java arrays don't preserve generic arguments. - Function... remainingMappings) { + Function... remainingMappings) { if (add(firstMapping.apply(target))) { return this; } - for (Function mapping : remainingMappings) { + for (Function mapping : + remainingMappings) { if (add(mapping.apply(target))) { return this; } @@ -270,16 +275,6 @@ public final Builder addTransitiveTarget(TransitiveInfoCollection target, return this; } - /** - * Includes link parameters from a CcLinkParamsInfo provider. - */ - public Builder addTransitiveProvider(CcLinkParamsInfo provider) { - if (provider != null) { - add(provider.getCcLinkParamsStore()); - } - return this; - } - /** * Includes link parameters from the given targets. Each target is checked for the given * mappings in the order specified, and the first mapping that returns a non-null result is @@ -288,9 +283,9 @@ public Builder addTransitiveProvider(CcLinkParamsInfo provider) { @SafeVarargs public final Builder addTransitiveTargets( Iterable targets, - Function firstMapping, - @SuppressWarnings("unchecked") // Java arrays don't preserve generic arguments. - Function... remainingMappings) { + Function firstMapping, + @SuppressWarnings("unchecked") // Java arrays don't preserve generic arguments. + Function... remainingMappings) { for (TransitiveInfoCollection target : targets) { addTransitiveTarget(target, firstMapping, remainingMappings); } @@ -387,7 +382,7 @@ public Builder addNonCodeInputs(Iterable nonCodeInputs) { public Builder addCcLibrary(RuleContext context) { addTransitiveTargets( context.getPrerequisites("deps", Mode.TARGET), - CcLinkParamsInfo.TO_LINK_PARAMS, + CcLinkParamsStore.TO_LINK_PARAMS, CcSpecificLinkParamsProvider.TO_LINK_PARAMS); return this; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsInfo.java deleted file mode 100644 index 1727e8385eea2a..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsInfo.java +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.cpp; - -import com.google.common.base.Function; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; - -/** A target that provides C linker parameters. */ -@Immutable -@AutoCodec -public final class CcLinkParamsInfo { - public static final Function TO_LINK_PARAMS = - input -> { - // ... then try Skylark. - CcLinkingInfo provider = input.get(CcLinkingInfo.PROVIDER); - CcLinkParamsInfo ccLinkParamsInfo = - provider == null ? null : provider.getCcLinkParamsInfo(); - if (ccLinkParamsInfo != null) { - return ccLinkParamsInfo.getCcLinkParamsStore(); - } - return null; - }; - - private final CcLinkParamsStoreImpl store; - - @AutoCodec.Instantiator - public CcLinkParamsInfo(CcLinkParamsStore store) { - this.store = new CcLinkParamsStoreImpl(store); - } - - @AutoCodec - @VisibleForSerialization - static class CcLinkParamsInfoCollection extends CcLinkParamsStore { - private final Iterable providers; - - CcLinkParamsInfoCollection(Iterable providers) { - this.providers = providers; - } - - @Override - protected void collect( - CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { - for (CcLinkParamsInfo provider : providers) { - builder.add(provider.getCcLinkParamsStore()); - } - } - } - - public static CcLinkParamsInfo merge(final Iterable providers) { - return new CcLinkParamsInfo(new CcLinkParamsInfoCollection(providers)); - } - - /** Returns the link params store. */ - public CcLinkParamsStore getCcLinkParamsStore() { - return store; - } - - /** - * Returns link parameters given static / shared linking settings. - */ - public CcLinkParams getCcLinkParams(boolean linkingStatically, boolean linkShared) { - return store.get(linkingStatically, linkShared); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsStore.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsStore.java index 0ef882882e2346..f93943e1b6df36 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsStore.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParamsStore.java @@ -14,147 +14,78 @@ package com.google.devtools.build.lib.rules.cpp; -import com.google.common.base.Preconditions; +import com.google.common.base.Function; +import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; -/** - * A cache of C link parameters. - * - *

The cache holds instances of {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} for - * combinations of linkingStatically and linkShared. If a requested value is not available in the - * cache, it is computed and then stored. - * - *

Typically this class is used on targets that may be linked in as C libraries as in the - * following example: - * - *

- * class SomeTarget implements CcLinkParamsInfo {
- *   private final CcLinkParamsStore ccLinkParamsStore = new CcLinkParamsStore() {
- *     @Override
- *     protected void collect(CcLinkParams.Builder builder, boolean linkingStatically,
- *                            boolean linkShared) {
- *       builder.add[...]
- *     }
- *   };
- *
- *   @Override
- *   public CcLinkParams getCcLinkParams(boolean linkingStatically, boolean linkShared) {
- *     return ccLinkParamsStore.get(linkingStatically, linkShared);
- *   }
- * }
- * 
- */ -public abstract class CcLinkParamsStore { - private CcLinkParams staticSharedParams; - private CcLinkParams staticNoSharedParams; - private CcLinkParams noStaticSharedParams; - private CcLinkParams noStaticNoSharedParams; +/** An implementation class for the AbstractCcLinkParamsStore. */ +@AutoCodec +public final class CcLinkParamsStore extends AbstractCcLinkParamsStore { + public static final ObjectCodec CODEC = + new CcLinkParamsStore_AutoCodec(); + public static final Function TO_LINK_PARAMS = + input -> { + // ... then try Skylark. + CcLinkingInfo provider = input.get(CcLinkingInfo.PROVIDER); + return provider == null ? null : provider.getCcLinkParamsStore(); + }; - private CcLinkParams compute(boolean linkingStatically, boolean linkShared) { - CcLinkParams.Builder builder = CcLinkParams.builder(linkingStatically, linkShared); - collect(builder, linkingStatically, linkShared); - return builder.build(); - } - - /** - * Returns {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} for a combination of - * parameters. - * - *

The {@link com.google.devtools.build.lib.rules.cpp.CcLinkParams} instance is computed lazily - * and cached. - */ - public synchronized CcLinkParams get(boolean linkingStatically, boolean linkShared) { - CcLinkParams result = lookup(linkingStatically, linkShared); - if (result == null) { - result = compute(linkingStatically, linkShared); - put(linkingStatically, linkShared, result); - } - return result; - } + @AutoCodec + @VisibleForSerialization + static class CcLinkParamsInfoCollection extends AbstractCcLinkParamsStore { + private final Iterable + ccLinkParamStores; - private CcLinkParams lookup(boolean linkingStatically, boolean linkShared) { - if (linkingStatically) { - return linkShared ? staticSharedParams : staticNoSharedParams; - } else { - return linkShared ? noStaticSharedParams : noStaticNoSharedParams; + CcLinkParamsInfoCollection( + Iterable ccLinkParamStores) { + this.ccLinkParamStores = ccLinkParamStores; } - } - private void put(boolean linkingStatically, boolean linkShared, CcLinkParams params) { - Preconditions.checkNotNull(params); - if (linkingStatically) { - if (linkShared) { - staticSharedParams = params; - } else { - staticNoSharedParams = params; - } - } else { - if (linkShared) { - noStaticSharedParams = params; - } else { - noStaticNoSharedParams = params; + @Override + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { + for (com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore ccLinkParamsStore : + ccLinkParamStores) { + builder.add(ccLinkParamsStore); } } } - /** - * Hook for building the actual link params. - * - *

Users should override this method and call methods of the builder to - * set up the actual CcLinkParams objects. - * - *

Implementations of this method must not fail or try to report errors on the - * configured target. - */ - protected abstract void collect(CcLinkParams.Builder builder, boolean linkingStatically, - boolean linkShared); + public CcLinkParamsStore(AbstractCcLinkParamsStore store) { + this( + store.get(true, true), + store.get(true, false), + store.get(false, true), + store.get(false, false)); + } - @AutoCodec @VisibleForSerialization - static class EmptyCcLinkParamsStore extends CcLinkParamsStore { - public static final ObjectCodec CODEC = - new CcLinkParamsStore_EmptyCcLinkParamsStore_AutoCodec(); - - @Override - protected void collect( - CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {} + @AutoCodec.Instantiator + CcLinkParamsStore( + CcLinkParams staticSharedParams, + CcLinkParams staticNoSharedParams, + CcLinkParams noStaticSharedParams, + CcLinkParams noStaticNoSharedParams) { + super.staticSharedParams = staticSharedParams; + super.staticNoSharedParams = staticNoSharedParams; + super.noStaticSharedParams = noStaticSharedParams; + super.noStaticNoSharedParams = noStaticNoSharedParams; } - /** An empty CcLinkParamStore. */ - public static final CcLinkParamsStore EMPTY = new EmptyCcLinkParamsStore(); - - /** An implementation class for the CcLinkParamsStore. */ - @AutoCodec - public static final class CcLinkParamsStoreImpl extends CcLinkParamsStore { - public static final ObjectCodec CODEC = - new CcLinkParamsStore_CcLinkParamsStoreImpl_AutoCodec(); - - public CcLinkParamsStoreImpl(CcLinkParamsStore store) { - this( - store.get(true, true), - store.get(true, false), - store.get(false, true), - store.get(false, false)); - } + public static com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore merge( + final Iterable providers) { + return new com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore( + new CcLinkParamsInfoCollection(providers)); + } - @VisibleForSerialization - @AutoCodec.Instantiator - CcLinkParamsStoreImpl( - CcLinkParams staticSharedParams, - CcLinkParams staticNoSharedParams, - CcLinkParams noStaticSharedParams, - CcLinkParams noStaticNoSharedParams) { - super.staticSharedParams = staticSharedParams; - super.staticNoSharedParams = staticNoSharedParams; - super.noStaticSharedParams = noStaticSharedParams; - super.noStaticNoSharedParams = noStaticNoSharedParams; - } + @Override + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {} - @Override - protected void collect( - CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {} + /** Returns link parameters given static / shared linking settings. */ + public CcLinkParams getCcLinkParams(boolean linkingStatically, boolean linkShared) { + return get(linkingStatically, linkShared); } } - diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index e794eb5b633870..23abb5b4c8adda 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java @@ -381,7 +381,7 @@ public CcLinkingHelper enableCcNativeLibrariesProvider() { /** * This adds the {@link CcSpecificLinkParamsProvider} to the providers created by this class. - * Otherwise the result will contain an instance of {@link CcLinkParamsInfo}. + * Otherwise the result will contain an instance of {@link CcLinkParamsStore}. */ public CcLinkingHelper enableCcSpecificLinkParamsProvider() { this.emitCcSpecificLinkParamsProvider = true; @@ -551,8 +551,8 @@ public LinkingInfo link(CcCompilationOutputs ccOutputs, CcCompilationContext ccC new CcSpecificLinkParamsProvider( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } else { - ccLinkingInfoBuilder.setCcLinkParamsInfo( - new CcLinkParamsInfo( + ccLinkingInfoBuilder.setCcLinkParamsStore( + new CcLinkParamsStore( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } providers.put(ccLinkingInfoBuilder.build()); @@ -633,17 +633,17 @@ private Runfiles collectCppRunfiles( return builder.build(); } - private CcLinkParamsStore createCcLinkParamsStore( + private AbstractCcLinkParamsStore createCcLinkParamsStore( final CcLinkingOutputs ccLinkingOutputs, final CcCompilationContext ccCompilationContext, final boolean forcePic) { - return new CcLinkParamsStore() { + return new AbstractCcLinkParamsStore() { @Override protected void collect( CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { builder.addLinkstamps(linkstamps.build(), ccCompilationContext); builder.addTransitiveTargets( - deps, CcLinkParamsInfo.TO_LINK_PARAMS, CcSpecificLinkParamsProvider.TO_LINK_PARAMS); + deps, CcLinkParamsStore.TO_LINK_PARAMS, CcSpecificLinkParamsProvider.TO_LINK_PARAMS); if (!neverlink) { builder.addLibraries( ccLinkingOutputs.getPreferredLibraries( 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 4edbdf97bbd23b..a331e7025eb2c6 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 @@ -36,24 +36,24 @@ public final class CcLinkingInfo extends NativeInfo { public static final NativeProvider PROVIDER = new NativeProvider(CcLinkingInfo.class, "CcLinkingInfo") {}; - private final CcLinkParamsInfo ccLinkParamsInfo; + private final CcLinkParamsStore ccLinkParamsStore; private final CcRunfiles ccRunfiles; private final CcExecutionDynamicLibrariesInfo ccExecutionDynamicLibrariesInfo; @AutoCodec.Instantiator @VisibleForSerialization CcLinkingInfo( - CcLinkParamsInfo ccLinkParamsInfo, + CcLinkParamsStore ccLinkParamsStore, CcRunfiles ccRunfiles, CcExecutionDynamicLibrariesInfo ccExecutionDynamicLibrariesInfo) { super(PROVIDER); - this.ccLinkParamsInfo = ccLinkParamsInfo; + this.ccLinkParamsStore = ccLinkParamsStore; this.ccRunfiles = ccRunfiles; this.ccExecutionDynamicLibrariesInfo = ccExecutionDynamicLibrariesInfo; } - public CcLinkParamsInfo getCcLinkParamsInfo() { - return ccLinkParamsInfo; + public CcLinkParamsStore getCcLinkParamsStore() { + return ccLinkParamsStore; } public CcRunfiles getCcRunfiles() { @@ -66,7 +66,7 @@ public CcExecutionDynamicLibrariesInfo getCcExecutionDynamicLibrariesInfo() { /** A Builder for {@link CcLinkingInfo}. */ public static class Builder { - CcLinkParamsInfo ccLinkParamsInfo; + CcLinkParamsStore ccLinkParamsStore; CcRunfiles ccRunfiles; CcExecutionDynamicLibrariesInfo ccExecutionDynamicLibrariesInfo; @@ -74,9 +74,9 @@ public static CcLinkingInfo.Builder create() { return new CcLinkingInfo.Builder(); } - public Builder setCcLinkParamsInfo(CcLinkParamsInfo ccLinkParamsInfo) { - Preconditions.checkState(this.ccLinkParamsInfo == null); - this.ccLinkParamsInfo = ccLinkParamsInfo; + public Builder setCcLinkParamsStore(CcLinkParamsStore ccLinkParamsStore) { + Preconditions.checkState(this.ccLinkParamsStore == null); + this.ccLinkParamsStore = ccLinkParamsStore; return this; } @@ -94,7 +94,7 @@ public Builder setCcExecutionDynamicLibrariesInfo( } public CcLinkingInfo build() { - return new CcLinkingInfo(ccLinkParamsInfo, ccRunfiles, ccExecutionDynamicLibrariesInfo); + return new CcLinkingInfo(ccLinkParamsStore, ccRunfiles, ccExecutionDynamicLibrariesInfo); } } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java index 88c959de223e1f..7a0aa933633d50 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java @@ -66,8 +66,8 @@ public NestedSet getTransitiveHeaders() { public NestedSet getLibraries() { NestedSetBuilder libs = NestedSetBuilder.linkOrder(); CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER); - CcLinkParamsInfo ccLinkParams = - ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo(); + CcLinkParamsStore ccLinkParams = + ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsStore(); if (ccLinkParams == null) { return libs.build(); } @@ -87,8 +87,8 @@ public NestedSet getLibraries() { + "(possibly empty but never None)") public ImmutableList getLinkopts() { CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER); - CcLinkParamsInfo ccLinkParams = - ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsInfo(); + CcLinkParamsStore ccLinkParams = + ccLinkingInfo == null ? null : ccLinkingInfo.getCcLinkParamsStore(); if (ccLinkParams == null) { return ImmutableList.of(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java index 54ec8f966c3488..2c6edfcf6037e1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSpecificLinkParamsProvider.java @@ -18,7 +18,6 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; /** @@ -28,23 +27,23 @@ @Immutable @AutoCodec public final class CcSpecificLinkParamsProvider implements TransitiveInfoProvider { - private final CcLinkParamsStoreImpl store; + private final CcLinkParamsStore store; - CcSpecificLinkParamsProvider(CcLinkParamsStore store) { - this(new CcLinkParamsStoreImpl(store)); + CcSpecificLinkParamsProvider(AbstractCcLinkParamsStore store) { + this(new CcLinkParamsStore(store)); } @AutoCodec.VisibleForSerialization @AutoCodec.Instantiator - CcSpecificLinkParamsProvider(CcLinkParamsStoreImpl store) { + CcSpecificLinkParamsProvider(CcLinkParamsStore store) { this.store = store; } - public CcLinkParamsStore getLinkParams() { + public AbstractCcLinkParamsStore getLinkParams() { return store; } - public static final Function TO_LINK_PARAMS = + public static final Function TO_LINK_PARAMS = input -> { CcSpecificLinkParamsProvider provider = input.getProvider(CcSpecificLinkParamsProvider.class); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCcLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCcLinkParamsProvider.java index f8d73c71356ed3..1d9ff5a3c330cb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCcLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCcLinkParamsProvider.java @@ -18,31 +18,31 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; /** A target that provides C++ libraries to be linked into Java targets. */ @Immutable @AutoCodec public final class JavaCcLinkParamsProvider implements TransitiveInfoProvider { - private final CcLinkParamsStoreImpl store; + private final CcLinkParamsStore store; - public JavaCcLinkParamsProvider(CcLinkParamsStore store) { - this(new CcLinkParamsStoreImpl(store)); + public JavaCcLinkParamsProvider(AbstractCcLinkParamsStore store) { + this(new CcLinkParamsStore(store)); } @AutoCodec.VisibleForSerialization @AutoCodec.Instantiator - JavaCcLinkParamsProvider(CcLinkParamsStoreImpl store) { + JavaCcLinkParamsProvider(CcLinkParamsStore store) { this.store = store; } - public CcLinkParamsStore getLinkParams() { + public AbstractCcLinkParamsStore getLinkParams() { return store; } - public static final Function TO_LINK_PARAMS = + public static final Function TO_LINK_PARAMS = input -> { JavaCcLinkParamsProvider provider = input.getProvider(JavaCcLinkParamsProvider.class); return provider == null ? null : provider.getLinkParams(); 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 f8e48dbe4a3374..b5a67af82569c5 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 @@ -18,8 +18,8 @@ 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.java.JavaCcLinkParamsProvider; import java.util.ArrayList; import java.util.List; @@ -30,7 +30,7 @@ public class JplCcLinkParams { /** - * Creates a CcLinkParamsInfo based on 'deps' and an explicit list of proto runtimes, in the + * Creates a CcLinkParamsStore based on 'deps' and an explicit list of proto runtimes, in the * context of a java_xxx_proto_library and its aspects. * * @param ruleContext used to extract 'deps'. the 'deps' are expected to provide @@ -41,7 +41,7 @@ public class JplCcLinkParams { */ public static JavaCcLinkParamsProvider createCcLinkParamsStore( final RuleContext ruleContext, final ImmutableList protoRuntimes) { - List stores = new ArrayList<>(); + List stores = new ArrayList<>(); for (TransitiveInfoCollection t : ruleContext.getPrerequisites("deps", RuleConfiguredTarget.Mode.TARGET)) { stores.add(t.getProvider(JavaProtoLibraryAspectProvider.class) @@ -50,11 +50,11 @@ public static JavaCcLinkParamsProvider createCcLinkParamsStore( .getLinkParams()); } return new JavaCcLinkParamsProvider( - new CcLinkParamsStore() { + new AbstractCcLinkParamsStore() { @Override protected void collect( CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { - for (CcLinkParamsStore store : stores) { + for (AbstractCcLinkParamsStore store : stores) { builder.add(store); } builder.addTransitiveTargets(protoRuntimes); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java index f5a441ebd4b60b..b4d0bac3607d2f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java @@ -70,7 +70,7 @@ import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParams; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; +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.cpp.CppFileTypes; import com.google.devtools.build.lib.rules.cpp.CppModuleMap; @@ -172,7 +172,7 @@ static class Builder { private Optional linkedBinary = Optional.absent(); private Optional linkmapFile = Optional.absent(); private Iterable depCcHeaderProviders = ImmutableList.of(); - private Iterable depCcLinkProviders = ImmutableList.of(); + private Iterable depCcLinkProviders = ImmutableList.of(); /** * Builder for {@link ObjcCommon} obtaining both attribute data and configuration data from @@ -261,15 +261,15 @@ Builder addDeps(List deps) { ImmutableList.Builder propagatedObjcDeps = ImmutableList.builder(); ImmutableList.Builder cppDeps = ImmutableList.builder(); - ImmutableList.Builder cppDepLinkParams = - ImmutableList.builder(); + ImmutableList.Builder cppDepLinkParams = + ImmutableList.builder(); for (ConfiguredTargetAndData dep : deps) { ConfiguredTarget depCT = dep.getConfiguredTarget(); addAnyProviders(propagatedObjcDeps, depCT, ObjcProvider.SKYLARK_CONSTRUCTOR); addAnyProviders(cppDeps, depCT, CcCompilationInfo.PROVIDER); if (isCcLibrary(dep)) { - cppDepLinkParams.add(depCT.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo()); + cppDepLinkParams.add(depCT.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore()); CcCompilationContext ccCompilationContext = depCT.get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); addDefines(ccCompilationContext.getDefines()); @@ -463,7 +463,7 @@ ObjcCommon build() { objcProvider.addAll(DEFINE, headerProvider.getDefines()); textualHeaders.addAll(headerProvider.getTextualHdrs()); } - for (CcLinkParamsInfo linkProvider : depCcLinkProviders) { + for (CcLinkParamsStore linkProvider : depCcLinkProviders) { CcLinkParams params = linkProvider.getCcLinkParams(true, false); ImmutableList linkOpts = params.flattenedLinkopts(); ImmutableSet.Builder frameworkLinkOpts = new ImmutableSet.Builder<>(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java index 979ae10212c3ab..cd1793139b929e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibrary.java @@ -26,7 +26,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; +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.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.syntax.Type; @@ -109,8 +109,8 @@ public ConfiguredTarget create(RuleContext ruleContext) ccCompilationInfoBuilder.setCcCompilationContext(ccCompilationContext); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); - ccLinkingInfoBuilder.setCcLinkParamsInfo( - new CcLinkParamsInfo(new ObjcLibraryCcLinkParamsStore(common))); + ccLinkingInfoBuilder.setCcLinkParamsStore( + new CcLinkParamsStore(new ObjcLibraryCcLinkParamsStore(common))); return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addNativeDeclaredProvider(common.getObjcProvider()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryCcLinkParamsStore.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryCcLinkParamsStore.java index d0d46b08e98e1e..a97ba8403d03d8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryCcLinkParamsStore.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryCcLinkParamsStore.java @@ -17,17 +17,17 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.ArtifactCategory; 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.LinkerInputs; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.vfs.FileSystemUtils; /** - * A {@link CcLinkParamsStore} to be propagated to dependent cc_{library, binary} targets. + * A {@link AbstractCcLinkParamsStore} to be propagated to dependent cc_{library, binary} targets. */ -class ObjcLibraryCcLinkParamsStore extends CcLinkParamsStore { +class ObjcLibraryCcLinkParamsStore extends AbstractCcLinkParamsStore { private final ObjcCommon common; diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 5998b72f45fe89..127e5030a984cc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -33,7 +33,7 @@ import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.NativeProvider.WithLegacySkylarkName; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; +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.cpp.CppModuleMap; import com.google.devtools.build.lib.rules.cpp.LinkerInputs; @@ -950,16 +950,16 @@ public ObjcProvider subtractSubtrees( // three possible locations (and may be duplicated!): // 1. ObjcProvider.LIBRARY // 2. ObjcProvider.CC_LIBRARY - // 3. CcLinkParamsInfo->LibraryToLink->getArtifact() + // 3. CcLinkParamsStore->LibraryToLink->getArtifact() // TODO(cpeyser): Clean up objc-cc interop. HashSet avoidLibrariesSet = new HashSet<>(); for (CcLinkingInfo linkProvider : avoidCcProviders) { - CcLinkParamsInfo ccLinkParamsInfo = linkProvider.getCcLinkParamsInfo(); - if (ccLinkParamsInfo == null) { + CcLinkParamsStore ccLinkParamsStore = linkProvider.getCcLinkParamsStore(); + if (ccLinkParamsStore == null) { continue; } NestedSet librariesToLink = - ccLinkParamsInfo.getCcLinkParams(true, false).getLibraries(); + ccLinkParamsStore.getCcLinkParams(true, false).getLibraries(); for (LibraryToLink libraryToLink : librariesToLink.toList()) { avoidLibrariesSet.add(libraryToLink.getArtifact().getRunfilesPath()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java index 21b38c255aa5fb..41e19c497cc20a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java @@ -24,9 +24,9 @@ import com.google.devtools.build.lib.analysis.RunfilesSupport; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.collect.nestedset.NestedSet; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier; import com.google.devtools.build.lib.rules.cpp.CcLinkParams; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo; import com.google.devtools.build.lib.syntax.Type; @@ -60,7 +60,7 @@ public ConfiguredTarget create(RuleContext ruleContext) static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics, PyCommon common) throws InterruptedException { ruleContext.initConfigurationMakeVariableContext(new CcFlagsSupplier(ruleContext)); - CcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext); + AbstractCcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext); List srcs = common.validateSrcs(); List allOutputs = @@ -125,7 +125,7 @@ static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics.postInitBinary(ruleContext, runfilesSupport, common); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); - ccLinkingInfoBuilder.setCcLinkParamsInfo(new CcLinkParamsInfo(ccLinkParamsStore)); + ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore)); return builder .setFilesToBuild(common.getFilesToBuild()) @@ -156,14 +156,16 @@ private static Runfiles collectCommonRunfiles(RuleContext ruleContext, PyCommon return builder.build(); } - private static CcLinkParamsStore initializeCcLinkParamStore(final RuleContext ruleContext) { - return new CcLinkParamsStore() { + private static AbstractCcLinkParamsStore initializeCcLinkParamStore( + final RuleContext ruleContext) { + return new AbstractCcLinkParamsStore() { @Override - protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, - boolean linkShared) { - builder.addTransitiveTargets(ruleContext.getPrerequisites("deps", Mode.TARGET), + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { + builder.addTransitiveTargets( + ruleContext.getPrerequisites("deps", Mode.TARGET), PyCcLinkParamsProvider.TO_LINK_PARAMS, - CcLinkParamsInfo.TO_LINK_PARAMS); + CcLinkParamsStore.TO_LINK_PARAMS); } }; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCcLinkParamsProvider.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCcLinkParamsProvider.java index 45dc9af18b8547..8a270ac30694e7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCcLinkParamsProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCcLinkParamsProvider.java @@ -17,25 +17,25 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore.CcLinkParamsStoreImpl; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; /** A target that provides C++ libraries to be linked into Python targets. */ @Immutable @AutoCodec public final class PyCcLinkParamsProvider implements TransitiveInfoProvider { - private final CcLinkParamsStoreImpl store; + private final CcLinkParamsStore store; - public PyCcLinkParamsProvider(CcLinkParamsStoreImpl store) { + public PyCcLinkParamsProvider(CcLinkParamsStore store) { this.store = store; } - public CcLinkParamsStore getLinkParams() { + public AbstractCcLinkParamsStore getLinkParams() { return store; } - public static final Function TO_LINK_PARAMS = + public static final Function TO_LINK_PARAMS = input -> { PyCcLinkParamsProvider provider = input.getProvider(PyCcLinkParamsProvider.class); return provider == null ? null : provider.getLinkParams(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java index 4a51a4f07dd92c..e40a1ab9788266 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java @@ -25,8 +25,8 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; +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.CcLinkParamsInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo; import com.google.devtools.build.lib.vfs.PathFragment; @@ -64,15 +64,17 @@ public ConfiguredTarget create(final RuleContext ruleContext) NestedSetBuilder.wrap(Order.STABLE_ORDER, allOutputs); common.addPyExtraActionPseudoAction(); - CcLinkParamsStore ccLinkParamsStore = new CcLinkParamsStore() { - @Override - protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, - boolean linkShared) { - builder.addTransitiveTargets(ruleContext.getPrerequisites("deps", Mode.TARGET), - PyCcLinkParamsProvider.TO_LINK_PARAMS, - CcLinkParamsInfo.TO_LINK_PARAMS); - } - }; + AbstractCcLinkParamsStore ccLinkParamsStore = + new AbstractCcLinkParamsStore() { + @Override + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { + builder.addTransitiveTargets( + ruleContext.getPrerequisites("deps", Mode.TARGET), + PyCcLinkParamsProvider.TO_LINK_PARAMS, + CcLinkParamsStore.TO_LINK_PARAMS); + } + }; NestedSet imports = common.collectImports(ruleContext, semantics); if (ruleContext.hasErrors()) { @@ -93,7 +95,7 @@ protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, common.addCommonTransitiveInfoProviders(builder, semantics, filesToBuild); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); - ccLinkingInfoBuilder.setCcLinkParamsInfo(new CcLinkParamsInfo(ccLinkParamsStore)); + ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore(ccLinkParamsStore)); return builder .setFilesToBuild(filesToBuild) diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java index df73f88e58a26f..ee282cbe001872 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java @@ -19,7 +19,7 @@ import com.google.devtools.build.lib.analysis.RunfilesSupport; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore; +import com.google.devtools.build.lib.rules.cpp.AbstractCcLinkParamsStore; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Collection; import java.util.List; @@ -72,7 +72,7 @@ Collection precompiledPythonFiles( Artifact createExecutable( RuleContext ruleContext, PyCommon common, - CcLinkParamsStore ccLinkParamsStore, + AbstractCcLinkParamsStore ccLinkParamsStore, NestedSet imports) throws InterruptedException; diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java index 1e096b4ff7dbf6..a8463060096920 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java @@ -121,7 +121,7 @@ public void testCcImportWithStaticLibrary() throws Exception { LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, false) .getLibraries()); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); @@ -130,7 +130,7 @@ public void testCcImportWithStaticLibrary() throws Exception { LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, true) .getLibraries()); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); @@ -139,7 +139,7 @@ public void testCcImportWithStaticLibrary() throws Exception { LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(true, false) .getLibraries()); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); @@ -148,7 +148,7 @@ public void testCcImportWithStaticLibrary() throws Exception { LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(true, true) .getLibraries()); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); @@ -161,7 +161,7 @@ public void testCcImportWithSharedLibrary() throws Exception { scratchConfiguredTarget( "a", "foo", "cc_import(name = 'foo', shared_library = 'libfoo.so')"); CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); Iterable executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -169,7 +169,7 @@ public void testCcImportWithSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -177,7 +177,7 @@ public void testCcImportWithSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -185,7 +185,7 @@ public void testCcImportWithSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -203,7 +203,7 @@ public void testCcImportWithInterfaceSharedLibrary() throws Exception { "cc_import(name = 'foo', shared_library = 'libfoo.so'," + " interface_library = 'libfoo.ifso')"); CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); Iterable executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); @@ -211,7 +211,7 @@ public void testCcImportWithInterfaceSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); @@ -219,7 +219,7 @@ public void testCcImportWithInterfaceSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); @@ -227,7 +227,7 @@ public void testCcImportWithInterfaceSharedLibrary() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); @@ -244,7 +244,7 @@ public void testCcImportWithBothStaticAndSharedLibraries() throws Exception { "foo", "cc_import(name = 'foo', static_library = 'libfoo.a', shared_library = 'libfoo.so')"); CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); Iterable executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -252,7 +252,7 @@ public void testCcImportWithBothStaticAndSharedLibraries() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); @@ -260,14 +260,14 @@ public void testCcImportWithBothStaticAndSharedLibraries() throws Exception { .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); assertThat(artifactsToStrings(executionDynamicLibraries)).isEmpty(); ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(true, true); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); @@ -282,7 +282,7 @@ public void testCcImportWithAlwaysLinkStaticLibrary() throws Exception { LibraryToLink libraryToLink = target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, false) .getLibraries() .toList() @@ -299,7 +299,7 @@ public void testCcImportSystemProvidedIsTrue() throws Exception { "foo", "cc_import(name = 'foo', interface_library = 'libfoo.ifso', system_provided = 1)"); CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo().getCcLinkParams(false, false); + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); Iterable executionDynamicLibraries = ccLinkParams.getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.ifso"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index d860ba6d03969a..fc5b87bfdc4e47 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -242,7 +242,7 @@ public void testEmptyLinkopts() throws Exception { assertThat( hello .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, false) .getLinkopts() .isEmpty()) @@ -1239,7 +1239,7 @@ public void addStaticLibraryToStaticSharedLinkParamsWhenBuilding() throws Except LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(true, true) .getLibraries()); assertThat(artifactsToStrings(libraries)).contains("bin a/libfoo.a"); @@ -1255,7 +1255,7 @@ public void dontAddStaticLibraryToStaticSharedLinkParamsWhenWrappingSameLibraryI LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(true, true) .getLibraries()); assertThat(artifactsToStrings(libraries)).doesNotContain("bin a/libfoo.a"); @@ -1272,7 +1272,7 @@ public void onlyAddOneWrappedLibraryWithSameLibraryIdentifierToLinkParams() thro LinkerInputs.toNonSolibArtifacts( target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(true, true) .getLibraries()); assertThat(artifactsToStrings(libraries)).doesNotContain("src a/libfoo.so"); @@ -1291,7 +1291,7 @@ public void testCcLinkParamsHasExecutionDynamicLibraries() throws Exception { Iterable libraries = target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, true) .getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).doesNotContain("bin a/libfoo.ifso"); @@ -1306,7 +1306,7 @@ public void testCcLinkParamsHasExecutionDynamicLibrariesWithoutCopyFeature() thr Iterable libraries = target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, true) .getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).doesNotContain("bin _solib_k8/liba_Slibfoo.ifso"); @@ -1322,7 +1322,7 @@ public void testCcLinkParamsDoNotHasExecutionDynamicLibraries() throws Exception Iterable libraries = target .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsInfo() + .getCcLinkParamsStore() .getCcLinkParams(false, true) .getExecutionDynamicLibraries(); assertThat(artifactsToStrings(libraries)).isEmpty();