diff options
author | plf <plf@google.com> | 2018-04-20 03:13:25 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-20 03:14:27 -0700 |
commit | 1cf50a8696234fda143f5afccbb7023ac2b54e19 (patch) | |
tree | 19936b207b7b759a5dd3e1c46f2ed31c66aeb02a /src | |
parent | dc4a3278739023cb39c66b9b017fe84d60094734 (diff) |
C++: Wraps CcRunfilesInfo inside CcLinkingInfo.
This simplifies the exposure to Skylark. It also helps by not forcing us to expose to Skylark providers that may eventually be deleted.
RELNOTES:none
PiperOrigin-RevId: 193645766
Diffstat (limited to 'src')
4 files changed, 55 insertions, 32 deletions
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 62d0bff944..ef4cc9ed16 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 @@ -317,6 +317,14 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { } NestedSet<Artifact> filesToBuild = filesBuilder.build(); + List<Artifact> instrumentedObjectFiles = new ArrayList<>(); + instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(false)); + instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(true)); + InstrumentedFilesProvider instrumentedFilesProvider = + common.getInstrumentedFilesProvider( + instrumentedObjectFiles, /* withBaselineCoverage= */ true); + CppHelper.maybeAddStaticLinkMarkerProvider(targetBuilder, ruleContext); + Runfiles staticRunfiles = collectRunfiles( ruleContext, @@ -336,17 +344,12 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { addDynamicRuntimeInputArtifactsToRunfiles, false); - List<Artifact> instrumentedObjectFiles = new ArrayList<>(); - instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(false)); - instrumentedObjectFiles.addAll(compilationInfo.getCcCompilationOutputs().getObjectFiles(true)); - InstrumentedFilesProvider instrumentedFilesProvider = - common.getInstrumentedFilesProvider(instrumentedObjectFiles, /*withBaselineCoverage=*/true); - CppHelper.maybeAddStaticLinkMarkerProvider(targetBuilder, ruleContext); - targetBuilder .setFilesToBuild(filesToBuild) .addProviders(compilationInfo.getProviders()) .addProviders(linkingInfo.getProviders()) + .addNativeDeclaredProvider( + overrideRunfilesProvider(staticRunfiles, sharedRunfiles, linkingInfo)) .addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME, new CcSkylarkApiProvider()) .addOutputGroups( CcCommon.mergeOutputGroups( @@ -354,8 +357,6 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { .addProvider(InstrumentedFilesProvider.class, instrumentedFilesProvider) .addProvider( RunfilesProvider.class, RunfilesProvider.withData(staticRunfiles, sharedRunfiles)) - // Remove this? - .addNativeDeclaredProvider(new CcRunfilesInfo(staticRunfiles, sharedRunfiles)) .addOutputGroup( OutputGroupInfo.HIDDEN_TOP_LEVEL, collectHiddenTopLevelArtifacts( @@ -366,6 +367,17 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { ruleContext, compilationInfo.getCcCompilationOutputs())); } + private static CcLinkingInfo overrideRunfilesProvider( + Runfiles staticRunfiles, Runfiles sharedRunfiles, LinkingInfo linkingInfo) { + CcLinkingInfo ccLinkingInfo = + (CcLinkingInfo) linkingInfo.getProviders().getProvider(CcLinkingInfo.PROVIDER.getKey()); + CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); + ccLinkingInfoBuilder.setCcLinkParamsInfo(ccLinkingInfo.getCcLinkParamsInfo()); + ccLinkingInfoBuilder.setCcRunfilesInfo(new CcRunfilesInfo(staticRunfiles, sharedRunfiles)); + + return ccLinkingInfoBuilder.build(); + } + private static NestedSet<Artifact> collectHiddenTopLevelArtifacts( RuleContext ruleContext, CcToolchainProvider toolchain, 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 6a9bab624d..a1fe50ba50 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 @@ -521,21 +521,16 @@ public final class CcLinkingHelper { .build(); } - Runfiles cppStaticRunfiles = collectCppRunfiles(ccLinkingOutputs, true); - Runfiles cppSharedRunfiles = collectCppRunfiles(ccLinkingOutputs, false); - - // By very careful when adding new providers here - it can potentially affect a lot of rules. - // We should consider merging most of these providers into a single provider. - TransitiveInfoProviderMapBuilder providers = - new TransitiveInfoProviderMapBuilder() - .put(new CcRunfilesInfo(cppStaticRunfiles, cppSharedRunfiles)); - Map<String, NestedSet<Artifact>> outputGroups = new TreeMap<>(); if (shouldAddLinkerOutputArtifacts(ruleContext, ccOutputs)) { addLinkerOutputArtifacts(outputGroups, ccOutputs); } + // Be very careful when adding new providers here - it can potentially affect a lot of rules. + // We should consider merging most of these providers into a single provider. + TransitiveInfoProviderMapBuilder providers = new TransitiveInfoProviderMapBuilder(); + // TODO(bazel-team): Maybe we can infer these from other data at the places where they are // used. if (emitCcNativeLibrariesProvider) { @@ -544,6 +539,13 @@ public final class CcLinkingHelper { providers.put( collectExecutionDynamicLibraryArtifacts(ccLinkingOutputs.getExecutionDynamicLibraries())); + Runfiles cppStaticRunfiles = collectCppRunfiles(ccLinkingOutputs, true); + Runfiles cppSharedRunfiles = collectCppRunfiles(ccLinkingOutputs, false); + + CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); + ccLinkingInfoBuilder.setCcRunfilesInfo( + new CcRunfilesInfo(cppStaticRunfiles, cppSharedRunfiles)); + CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class); boolean forcePic = cppConfiguration.forcePic(); if (emitCcSpecificLinkParamsProvider) { @@ -551,12 +553,11 @@ public final class CcLinkingHelper { new CcSpecificLinkParamsProvider( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); } else { - CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); ccLinkingInfoBuilder.setCcLinkParamsInfo( new CcLinkParamsInfo( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); - providers.put(ccLinkingInfoBuilder.build()); } + providers.put(ccLinkingInfoBuilder.build()); return new LinkingInfo( providers.build(), outputGroups, ccLinkingOutputs, originalLinkingOutputs); } 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 2b25eae46d..f0b5a0faca 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 @@ -40,21 +40,28 @@ public final class CcLinkingInfo extends NativeInfo { new NativeProvider<CcLinkingInfo>(CcLinkingInfo.class, "CcLinkingInfo") {}; private final CcLinkParamsInfo ccLinkParamsInfo; + private final CcRunfilesInfo ccRunfilesInfo; @AutoCodec.Instantiator @VisibleForSerialization - CcLinkingInfo(CcLinkParamsInfo ccLinkParamsInfo) { + CcLinkingInfo(CcLinkParamsInfo ccLinkParamsInfo, CcRunfilesInfo ccRunfilesInfo) { super(PROVIDER); this.ccLinkParamsInfo = ccLinkParamsInfo; + this.ccRunfilesInfo = ccRunfilesInfo; } public CcLinkParamsInfo getCcLinkParamsInfo() { return ccLinkParamsInfo; } + public CcRunfilesInfo getCcRunfilesInfo() { + return ccRunfilesInfo; + } + /** A Builder for {@link CcLinkingInfo}. */ public static class Builder { CcLinkParamsInfo ccLinkParamsInfo; + CcRunfilesInfo ccRunfilesInfo; public static CcLinkingInfo.Builder create() { return new CcLinkingInfo.Builder(); @@ -66,8 +73,14 @@ public final class CcLinkingInfo extends NativeInfo { return this; } + public Builder setCcRunfilesInfo(CcRunfilesInfo ccRunfilesInfo) { + Preconditions.checkState(this.ccRunfilesInfo == null); + this.ccRunfilesInfo = ccRunfilesInfo; + return this; + } + public CcLinkingInfo build() { - return new CcLinkingInfo(ccLinkParamsInfo); + return new CcLinkingInfo(ccLinkParamsInfo, ccRunfilesInfo); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfilesInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfilesInfo.java index d88431ee31..c6c8d3580f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfilesInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfilesInfo.java @@ -18,8 +18,6 @@ import com.google.common.base.Function; import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.packages.NativeInfo; -import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; /** @@ -30,16 +28,13 @@ import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; */ @Immutable @AutoCodec -public final class CcRunfilesInfo extends NativeInfo { - public static final NativeProvider<CcRunfilesInfo> PROVIDER = - new NativeProvider<CcRunfilesInfo>(CcRunfilesInfo.class, "CcRunfilesInfo") {}; +public final class CcRunfilesInfo { private final Runfiles staticRunfiles; private final Runfiles sharedRunfiles; @AutoCodec.Instantiator public CcRunfilesInfo(Runfiles staticRunfiles, Runfiles sharedRunfiles) { - super(PROVIDER); this.staticRunfiles = staticRunfiles; this.sharedRunfiles = sharedRunfiles; } @@ -58,8 +53,9 @@ public final class CcRunfilesInfo extends NativeInfo { */ public static final Function<TransitiveInfoCollection, Runfiles> STATIC_RUNFILES = input -> { - CcRunfilesInfo provider = input.get(CcRunfilesInfo.PROVIDER); - return provider == null ? Runfiles.EMPTY : provider.getStaticRunfiles(); + CcLinkingInfo provider = input.get(CcLinkingInfo.PROVIDER); + CcRunfilesInfo ccRunfilesInfo = provider == null ? null : provider.getCcRunfilesInfo(); + return ccRunfilesInfo == null ? Runfiles.EMPTY : ccRunfilesInfo.getStaticRunfiles(); }; /** @@ -68,8 +64,9 @@ public final class CcRunfilesInfo extends NativeInfo { */ public static final Function<TransitiveInfoCollection, Runfiles> SHARED_RUNFILES = input -> { - CcRunfilesInfo provider = input.get(CcRunfilesInfo.PROVIDER); - return provider == null ? Runfiles.EMPTY : provider.getSharedRunfiles(); + CcLinkingInfo provider = input.get(CcLinkingInfo.PROVIDER); + CcRunfilesInfo ccRunfilesInfo = provider == null ? null : provider.getCcRunfilesInfo(); + return ccRunfilesInfo == null ? Runfiles.EMPTY : ccRunfilesInfo.getSharedRunfiles(); }; /** |