From d753ad59fde12d4dd01c52f9dc5a41e635caf2d5 Mon Sep 17 00:00:00 2001 From: plf Date: Mon, 14 May 2018 06:48:48 -0700 Subject: C++: Renames CcCompilationContextInfo to CcCompilationContext Since it's not a provider, it doesn't need the Info suffix anymore. RELNOTES:none PiperOrigin-RevId: 196498526 --- .../lib/bazel/rules/cpp/BazelCppSemantics.java | 6 +- .../devtools/build/lib/rules/cpp/CcBinary.java | 27 +- .../devtools/build/lib/rules/cpp/CcCommon.java | 16 +- .../build/lib/rules/cpp/CcCompilationContext.java | 949 ++++++++++++++++++++ .../lib/rules/cpp/CcCompilationContextInfo.java | 955 --------------------- .../build/lib/rules/cpp/CcCompilationHelper.java | 169 ++-- .../build/lib/rules/cpp/CcCompilationInfo.java | 37 +- .../devtools/build/lib/rules/cpp/CcImport.java | 3 +- .../devtools/build/lib/rules/cpp/CcLibrary.java | 3 +- .../devtools/build/lib/rules/cpp/CcLinkParams.java | 4 +- .../build/lib/rules/cpp/CcLinkingHelper.java | 15 +- .../build/lib/rules/cpp/CcSkylarkApiProvider.java | 50 +- .../devtools/build/lib/rules/cpp/CcToolchain.java | 11 +- .../build/lib/rules/cpp/CcToolchainProvider.java | 14 +- .../build/lib/rules/cpp/CompileBuildVariables.java | 6 +- .../build/lib/rules/cpp/CppCompileAction.java | 83 +- .../lib/rules/cpp/CppCompileActionBuilder.java | 28 +- .../build/lib/rules/cpp/CppConfiguration.java | 2 +- .../devtools/build/lib/rules/cpp/CppHelper.java | 19 +- .../devtools/build/lib/rules/cpp/CppSemantics.java | 6 +- .../build/lib/rules/cpp/FakeCppCompileAction.java | 4 +- .../devtools/build/lib/rules/cpp/FdoSupport.java | 12 +- .../build/lib/rules/cpp/LipoContextProvider.java | 12 +- .../build/lib/rules/cpp/proto/CcProtoAspect.java | 2 +- .../build/lib/rules/objc/CompilationSupport.java | 18 +- .../devtools/build/lib/rules/objc/ObjcCommon.java | 25 +- .../build/lib/rules/objc/ObjcCppSemantics.java | 14 +- .../devtools/build/lib/rules/objc/ObjcLibrary.java | 8 +- .../lib/runtime/commands/PrintActionCommand.java | 2 +- .../google/devtools/build/lib/rules/AliasTest.java | 2 +- .../devtools/build/lib/rules/cpp/CcCommonTest.java | 41 +- .../rules/cpp/CcImportConfiguredTargetTest.java | 2 +- .../rules/cpp/CcLibraryConfiguredTargetTest.java | 25 +- .../lib/rules/cpp/CcToolchainProviderTest.java | 4 +- .../build/lib/rules/cpp/MockCppSemantics.java | 4 +- .../lib/rules/cpp/proto/CcProtoLibraryTest.java | 22 +- 36 files changed, 1279 insertions(+), 1321 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppSemantics.java index ca1842fb72..75e67c2ee9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppSemantics.java @@ -20,7 +20,7 @@ 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.AspectLegalCppSemantics; -import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode; @@ -50,8 +50,8 @@ public class BazelCppSemantics implements AspectLegalCppSemantics { } @Override - public void setupCcCompilationContextInfo( - RuleContext ruleContext, CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder) {} + public void setupCcCompilationContext( + RuleContext ruleContext, CcCompilationContext.Builder ccCompilationContextBuilder) {} @Override public NestedSet getAdditionalPrunableIncludes() { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index 62cbb5232c..22dfdbd283 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -99,7 +99,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CcToolchainProvider toolchain, CcLinkingOutputs linkingOutputs, CcLinkingOutputs ccLibraryLinkingOutputs, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, Link.LinkingMode linkingMode, NestedSet filesToBuild, Iterable fakeLinkerInputs, @@ -153,12 +153,12 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { sourcesBuilder.add(cppSource.getSource()); } builder.addSymlinksToArtifacts(sourcesBuilder.build()); - builder.addSymlinksToArtifacts(ccCompilationContextInfo.getDeclaredIncludeSrcs()); + builder.addSymlinksToArtifacts(ccCompilationContext.getDeclaredIncludeSrcs()); // Add additional files that are referenced from the compile command, like module maps // or header modules. - builder.addSymlinksToArtifacts(ccCompilationContextInfo.getAdditionalInputs()); + builder.addSymlinksToArtifacts(ccCompilationContext.getAdditionalInputs()); builder.addSymlinksToArtifacts( - ccCompilationContextInfo.getTransitiveModules(usePic(context, toolchain))); + ccCompilationContext.getTransitiveModules(usePic(context, toolchain))); } return builder.build(); } @@ -238,8 +238,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .setFake(fake) .addPrecompiledFiles(precompiledFiles); CompilationInfo compilationInfo = compilationHelper.compile(); - CcCompilationContextInfo ccCompilationContextInfo = - compilationInfo.getCcCompilationContextInfo(); + CcCompilationContext ccCompilationContext = compilationInfo.getCcCompilationContext(); CcCompilationOutputs ccCompilationOutputs = compilationInfo.getCcCompilationOutputs(); // We currently only want link the dynamic library generated for test code separately. @@ -274,7 +273,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .enableInterfaceSharedObjects(); linkingHelper.setStaticLinkType(LinkTargetType.STATIC_LIBRARY); ccLinkingOutputs = - linkingHelper.link(ccCompilationOutputs, ccCompilationContextInfo).getCcLinkingOutputs(); + linkingHelper.link(ccCompilationOutputs, ccCompilationContext).getCcLinkingOutputs(); } CcLinkParams linkParams = @@ -293,7 +292,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { precompiledFiles, ccCompilationOutputs, ccLinkingOutputs, - ccCompilationContextInfo.getTransitiveCompilationPrerequisites(), + ccCompilationContext.getTransitiveCompilationPrerequisites(), fake, binary, linkParams, @@ -474,7 +473,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { ccToolchain, linkingOutputs, ccLinkingOutputs, - ccCompilationContextInfo, + ccCompilationContext, linkingMode, filesToBuild, fakeLinkerInputs, @@ -500,7 +499,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { ruleBuilder, filesToBuild, ccCompilationOutputs, - ccCompilationContextInfo, + ccCompilationContext, linkingOutputs, dwoArtifacts, transitiveLipoInfo, @@ -549,7 +548,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .addProvider( LipoContextProvider.class, new LipoContextProvider( - ccCompilationContextInfo, + ccCompilationContext, ImmutableMap.copyOf(scannableMap), ImmutableMap.copyOf(sourceFileMap))) .addProvider(CppLinkAction.Context.class, linkContext) @@ -879,7 +878,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { RuleConfiguredTargetBuilder builder, NestedSet filesToBuild, CcCompilationOutputs ccCompilationOutputs, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, CcLinkingOutputs linkingOutputs, DwoArtifactsCollector dwoArtifacts, TransitiveLipoInfoProvider transitiveLipoInfo, @@ -899,7 +898,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CppHelper.usePicForDynamicLibraries(ruleContext, toolchain)); CcCompilationInfo.Builder ccCompilationInfoBuilder = CcCompilationInfo.Builder.create(); - ccCompilationInfoBuilder.setCcCompilationContextInfo(ccCompilationContextInfo); + ccCompilationInfoBuilder.setCcCompilationContext(ccCompilationContext); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); ccLinkingInfoBuilder.setCcExecutionDynamicLibrariesInfo( @@ -931,7 +930,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, headerTokens) .addOutputGroup( OutputGroupInfo.COMPILATION_PREREQUISITES, - CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContextInfo)); + CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContext)); CppHelper.maybeAddStaticLinkMarkerProvider(builder, ruleContext); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index e85c538ca9..4d6cb3a72b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -598,11 +598,11 @@ public final class CcCommon { /** Collects compilation prerequisite artifacts. */ static NestedSet collectCompilationPrerequisites( - RuleContext ruleContext, CcCompilationContextInfo ccCompilationContextInfo) { - // TODO(bazel-team): Use ccCompilationContextInfo.getCompilationPrerequisites() instead; note + RuleContext ruleContext, CcCompilationContext ccCompilationContext) { + // TODO(bazel-team): Use ccCompilationContext.getCompilationPrerequisites() instead; note // that this // will - // need cleaning up the prerequisites, as the {@code CcCompilationContextInfo} currently + // need cleaning up the prerequisites, as the {@code CcCompilationContext} currently // collects them // transitively (to get transitive headers), but source files are not transitive compilation // prerequisites. @@ -615,10 +615,10 @@ public final class CcCommon { provider.getFilesToBuild(), SourceCategory.CC_AND_OBJC.getSourceTypes())); } } - prerequisites.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); - prerequisites.addTransitive(ccCompilationContextInfo.getAdditionalInputs()); - prerequisites.addTransitive(ccCompilationContextInfo.getTransitiveModules(true)); - prerequisites.addTransitive(ccCompilationContextInfo.getTransitiveModules(false)); + prerequisites.addTransitive(ccCompilationContext.getDeclaredIncludeSrcs()); + prerequisites.addTransitive(ccCompilationContext.getAdditionalInputs()); + prerequisites.addTransitive(ccCompilationContext.getTransitiveModules(true)); + prerequisites.addTransitive(ccCompilationContext.getTransitiveModules(false)); return prerequisites.build(); } @@ -777,7 +777,7 @@ public final class CcCommon { unsupportedFeaturesBuilder.add(CppRuleClasses.PARSE_HEADERS); unsupportedFeaturesBuilder.add(CppRuleClasses.PREPROCESS_HEADERS); } - if (toolchain.getCcCompilationContextInfo().getCppModuleMap() == null) { + if (toolchain.getCcCompilationContext().getCppModuleMap() == null) { unsupportedFeaturesBuilder.add(CppRuleClasses.MODULE_MAPS); } if (enableStaticLinkCppRuntimesFeature(requestedFeatures, unsupportedFeatures, toolchain)) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java new file mode 100644 index 0000000000..6df4ff1a8f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContext.java @@ -0,0 +1,949 @@ +// 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.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.devtools.build.lib.actions.ActionOwner; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.MiddlemanFactory; +import com.google.devtools.build.lib.analysis.RuleContext; +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.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.rules.cpp.CppHelper.PregreppedHeader; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; +import com.google.devtools.build.lib.vfs.PathFragment; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +/** + * Immutable store of information needed for C++ compilation that is aggregated across dependencies. + */ +@Immutable +@AutoCodec +@SkylarkModule( + name = "cc_compilation_context", + documented = false, + category = SkylarkModuleCategory.PROVIDER, + doc = + "Immutable store of information needed for C++ compilation that is aggregated across " + + "dependencies." +) +// TODO(b/77669139): Rename to CcCompilationContext. +public final class CcCompilationContext { + /** An empty {@code CcCompilationContext}. */ + public static final CcCompilationContext EMPTY = new Builder(null).build(); + + private final CommandLineCcCompilationContext commandLineCcCompilationContext; + + private final NestedSet declaredIncludeDirs; + private final NestedSet declaredIncludeWarnDirs; + private final NestedSet declaredIncludeSrcs; + + /** + * Module maps from direct dependencies. + */ + private final NestedSet directModuleMaps; + + /** Non-code mandatory compilation inputs. */ + private final NestedSet nonCodeInputs; + + private final NestedSet pregreppedHdrs; + + private final ModuleInfo moduleInfo; + private final ModuleInfo picModuleInfo; + + private final CppModuleMap cppModuleMap; + private final CppModuleMap verificationModuleMap; + + private final boolean propagateModuleMapAsActionInput; + + // Derived from depsContexts. + private final ImmutableSet compilationPrerequisites; + + @AutoCodec.Instantiator + @VisibleForSerialization + CcCompilationContext( + CommandLineCcCompilationContext commandLineCcCompilationContext, + ImmutableSet compilationPrerequisites, + NestedSet declaredIncludeDirs, + NestedSet declaredIncludeWarnDirs, + NestedSet declaredIncludeSrcs, + NestedSet pregreppedHdrs, + NestedSet nonCodeInputs, + ModuleInfo moduleInfo, + ModuleInfo picModuleInfo, + NestedSet directModuleMaps, + CppModuleMap cppModuleMap, + @Nullable CppModuleMap verificationModuleMap, + boolean propagateModuleMapAsActionInput) { + Preconditions.checkNotNull(commandLineCcCompilationContext); + this.commandLineCcCompilationContext = commandLineCcCompilationContext; + this.declaredIncludeDirs = declaredIncludeDirs; + this.declaredIncludeWarnDirs = declaredIncludeWarnDirs; + this.declaredIncludeSrcs = declaredIncludeSrcs; + this.directModuleMaps = directModuleMaps; + this.pregreppedHdrs = pregreppedHdrs; + this.moduleInfo = moduleInfo; + this.picModuleInfo = picModuleInfo; + this.cppModuleMap = cppModuleMap; + this.nonCodeInputs = nonCodeInputs; + this.verificationModuleMap = verificationModuleMap; + this.compilationPrerequisites = compilationPrerequisites; + this.propagateModuleMapAsActionInput = propagateModuleMapAsActionInput; + } + + /** + * Returns the transitive compilation prerequisites consolidated into middlemen prerequisites, or + * an empty set if there are no prerequisites. + * + *

Transitive compilation prerequisites are the prerequisites that will be needed by all + * reverse dependencies; note that these do specifically not include any compilation prerequisites + * that are only needed by the rule itself (for example, compiled source files from the {@code + * srcs} attribute). + * + *

To reduce the number of edges in the action graph, we express the dependency on compilation + * prerequisites as a transitive dependency via a middleman. After they have been accumulated + * (using {@link Builder#addCompilationPrerequisites(Iterable)}, {@link + * Builder#mergeDependentCcCompilationContext(CcCompilationContext)}, and {@link + * Builder#mergeDependentCcCompilationContexts(Iterable)}, they are consolidated into a single + * middleman Artifact when {@link Builder#build()} is called. + * + *

The returned set can be empty if there are no prerequisites. Usually it contains a single + * middleman, but if LIPO is used there can be two. + */ + public ImmutableSet getTransitiveCompilationPrerequisites() { + return compilationPrerequisites; + } + + /** + * Returns the immutable list of include directories to be added with "-I" + * (possibly empty but never null). This includes the include dirs from the + * transitive deps closure of the target. This list does not contain + * duplicates. All fragments are either absolute or relative to the exec root + * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). + */ + public ImmutableList getIncludeDirs() { + return commandLineCcCompilationContext.includeDirs; + } + + /** + * Returns the immutable list of include directories to be added with + * "-iquote" (possibly empty but never null). This includes the include dirs + * from the transitive deps closure of the target. This list does not contain + * duplicates. All fragments are either absolute or relative to the exec root + * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). + */ + public ImmutableList getQuoteIncludeDirs() { + return commandLineCcCompilationContext.quoteIncludeDirs; + } + + /** + * Returns the immutable list of include directories to be added with + * "-isystem" (possibly empty but never null). This includes the include dirs + * from the transitive deps closure of the target. This list does not contain + * duplicates. All fragments are either absolute or relative to the exec root + * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). + */ + public ImmutableList getSystemIncludeDirs() { + return commandLineCcCompilationContext.systemIncludeDirs; + } + + /** + * Returns the immutable set of declared include directories, relative to a "-I" or "-iquote" + * directory" (possibly empty but never null). + */ + public NestedSet getDeclaredIncludeDirs() { + return declaredIncludeDirs; + } + + /** + * Returns the immutable set of include directories, relative to a "-I" or "-iquote" directory", + * from which inclusion will produce a warning (possibly empty but never null). + */ + public NestedSet getDeclaredIncludeWarnDirs() { + return declaredIncludeWarnDirs; + } + + /** + * Returns the immutable set of headers that have been declared in the {@code srcs} or {@code + * hdrs} attribute (possibly empty but never null). + */ + public NestedSet getDeclaredIncludeSrcs() { + return declaredIncludeSrcs; + } + + /** Returns headers given as textual_hdrs in this target. */ + public ImmutableSet getTextualHdrs() { + return moduleInfo.textualHeaders; + } + + /** + * Returns the immutable pairs of (header file, pregrepped header file). The value artifacts + * (pregrepped header file) are generated by {@link ExtractInclusionAction}. + */ + NestedSet getPregreppedHeaders() { + return pregreppedHdrs; + } + + public NestedSet getTransitiveModules(boolean usePic) { + return usePic ? picModuleInfo.transitiveModules : moduleInfo.transitiveModules; + } + + public Collection getUsedModules( + boolean usePic, Set usedHeaders) { + return usePic + ? picModuleInfo.getUsedModules(usedHeaders) + : moduleInfo.getUsedModules(usedHeaders); + } + + /** + * Returns the immutable set of additional transitive inputs needed for + * compilation, like C++ module map artifacts. + */ + public NestedSet getAdditionalInputs() { + NestedSetBuilder builder = NestedSetBuilder.stableOrder(); + builder.addTransitive(directModuleMaps); + builder.addTransitive(nonCodeInputs); + if (cppModuleMap != null && propagateModuleMapAsActionInput) { + builder.add(cppModuleMap.getArtifact()); + } + return builder.build(); + } + + /** + * @return modules maps from direct dependencies. + */ + public NestedSet getDirectModuleMaps() { + return directModuleMaps; + } + + /** + * @return all declared headers of the current module if the current target + * is compiled as a module. + */ + protected Set getHeaderModuleSrcs() { + return new ImmutableSet.Builder() + .addAll(moduleInfo.modularHeaders) + .addAll(moduleInfo.textualHeaders) + .build(); + } + + /** + * Returns the set of defines needed to compile this target (possibly empty + * but never null). This includes definitions from the transitive deps closure + * for the target. The order of the returned collection is deterministic. + */ + public ImmutableList getDefines() { + return commandLineCcCompilationContext.defines; + } + + /** + * Returns a {@code CcCompilationContext} that is based on a given {@code CcCompilationContext} + * but returns empty sets for {@link #getDeclaredIncludeDirs()} and {@link + * #getDeclaredIncludeWarnDirs()}. + */ + public static CcCompilationContext disallowUndeclaredHeaders( + CcCompilationContext ccCompilationContext) { + return new CcCompilationContext( + ccCompilationContext.commandLineCcCompilationContext, + ccCompilationContext.compilationPrerequisites, + NestedSetBuilder.emptySet(Order.STABLE_ORDER), + NestedSetBuilder.emptySet(Order.STABLE_ORDER), + ccCompilationContext.declaredIncludeSrcs, + ccCompilationContext.pregreppedHdrs, + ccCompilationContext.nonCodeInputs, + ccCompilationContext.moduleInfo, + ccCompilationContext.picModuleInfo, + ccCompilationContext.directModuleMaps, + ccCompilationContext.cppModuleMap, + ccCompilationContext.verificationModuleMap, + ccCompilationContext.propagateModuleMapAsActionInput); + } + + /** + * Returns the context for a LIPO compile action. This uses the include dirs and defines of the + * library, but the declared inclusion dirs/srcs from both the library and the owner binary. + * + *

TODO(bazel-team): this might make every LIPO target have an unnecessary large set of + * inclusion dirs/srcs. The correct behavior would be to merge only the contexts of actual + * referred targets (as listed in .imports file). + * + *

Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, {@link + * #getDeclaredIncludeWarnDirs()}, and {@link #getDeclaredIncludeSrcs()}) needs to use the union + * of the contexts of the involved source files. + * + *

For include and define command line flags ({@link #getIncludeDirs()} {@link + * #getQuoteIncludeDirs()}, {@link #getSystemIncludeDirs()}, and {@link #getDefines()}) LIPO + * compilations use the same values as non-LIPO compilation. + * + *

Include scanning is not handled by this method. See {@code + * IncludeScannable#getAuxiliaryScannables()} instead. + * + * @param ownerCcCompilationContext the {@code CcCompilationContext} of the owner binary + * @param libCcCompilationContext the {@code CcCompilationContext} of the library + */ + public static CcCompilationContext mergeForLipo( + CcCompilationContext ownerCcCompilationContext, + CcCompilationContext libCcCompilationContext) { + ImmutableSet.Builder prerequisites = ImmutableSet.builder(); + prerequisites.addAll(ownerCcCompilationContext.compilationPrerequisites); + prerequisites.addAll(libCcCompilationContext.compilationPrerequisites); + ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); + moduleInfo.merge(ownerCcCompilationContext.moduleInfo); + moduleInfo.merge(libCcCompilationContext.moduleInfo); + ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); + picModuleInfo.merge(ownerCcCompilationContext.picModuleInfo); + picModuleInfo.merge(libCcCompilationContext.picModuleInfo); + return new CcCompilationContext( + libCcCompilationContext.commandLineCcCompilationContext, + prerequisites.build(), + mergeSets( + ownerCcCompilationContext.declaredIncludeDirs, + libCcCompilationContext.declaredIncludeDirs), + mergeSets( + ownerCcCompilationContext.declaredIncludeWarnDirs, + libCcCompilationContext.declaredIncludeWarnDirs), + mergeSets( + ownerCcCompilationContext.declaredIncludeSrcs, + libCcCompilationContext.declaredIncludeSrcs), + mergeSets(ownerCcCompilationContext.pregreppedHdrs, libCcCompilationContext.pregreppedHdrs), + mergeSets(ownerCcCompilationContext.nonCodeInputs, libCcCompilationContext.nonCodeInputs), + moduleInfo.build(), + picModuleInfo.build(), + mergeSets( + ownerCcCompilationContext.directModuleMaps, libCcCompilationContext.directModuleMaps), + libCcCompilationContext.cppModuleMap, + libCcCompilationContext.verificationModuleMap, + libCcCompilationContext.propagateModuleMapAsActionInput); + } + + /** + * Return a nested set containing all elements from {@code s1} and {@code s2}. + */ + private static NestedSet mergeSets(NestedSet s1, NestedSet s2) { + NestedSetBuilder builder = NestedSetBuilder.stableOrder(); + builder.addTransitive(s1); + builder.addTransitive(s2); + return builder.build(); + } + + /** @return the C++ module map of the owner. */ + public CppModuleMap getCppModuleMap() { + return cppModuleMap; + } + + /** @return the C++ module map of the owner. */ + public CppModuleMap getVerificationModuleMap() { + return verificationModuleMap; + } + + /** + * The parts of the {@code CcCompilationContext} that influence the command line of compilation + * actions. + */ + @Immutable + @AutoCodec + @VisibleForSerialization + static class CommandLineCcCompilationContext { + private final ImmutableList includeDirs; + private final ImmutableList quoteIncludeDirs; + private final ImmutableList systemIncludeDirs; + private final ImmutableList defines; + + CommandLineCcCompilationContext( + ImmutableList includeDirs, + ImmutableList quoteIncludeDirs, + ImmutableList systemIncludeDirs, + ImmutableList defines) { + this.includeDirs = includeDirs; + this.quoteIncludeDirs = quoteIncludeDirs; + this.systemIncludeDirs = systemIncludeDirs; + this.defines = defines; + } + } + + /** Builder class for {@link CcCompilationContext}. */ + public static class Builder { + private String purpose; + private final Set compilationPrerequisites = new LinkedHashSet<>(); + private final Set includeDirs = new LinkedHashSet<>(); + private final Set quoteIncludeDirs = new LinkedHashSet<>(); + private final Set systemIncludeDirs = new LinkedHashSet<>(); + private final NestedSetBuilder declaredIncludeDirs = + NestedSetBuilder.stableOrder(); + private final NestedSetBuilder declaredIncludeWarnDirs = + NestedSetBuilder.stableOrder(); + private final NestedSetBuilder declaredIncludeSrcs = + NestedSetBuilder.stableOrder(); + private final NestedSetBuilder pregreppedHdrs = + NestedSetBuilder.stableOrder(); + private final NestedSetBuilder nonCodeInputs = NestedSetBuilder.stableOrder(); + private final ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); + private final ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); + private final NestedSetBuilder directModuleMaps = NestedSetBuilder.stableOrder(); + private final Set defines = new LinkedHashSet<>(); + private CppModuleMap cppModuleMap; + private CppModuleMap verificationModuleMap; + private boolean propagateModuleMapAsActionInput = true; + + /** The rule that owns the context */ + private final RuleContext ruleContext; + + /** Creates a new builder for a {@link CcCompilationContext} instance. */ + public Builder(RuleContext ruleContext) { + this.ruleContext = ruleContext; + } + + /** + * Overrides the purpose of this context. This is useful if a Target needs more than one + * CcCompilationContext. (The purpose is used to construct the name of the prerequisites + * middleman for the context, and all artifacts for a given Target must have distinct names.) + * + * @param purpose must be a string which is suitable for use as a filename. A single rule may + * have many middlemen with distinct purposes. + * @see MiddlemanFactory#createErrorPropagatingMiddleman + */ + public Builder setPurpose(String purpose) { + this.purpose = purpose; + return this; + } + + public String getPurpose() { + return purpose; + } + + /** + * Merges the {@link CcCompilationContext} of a dependency into this one by adding the contents + * of all of its attributes. + */ + public Builder mergeDependentCcCompilationContext( + CcCompilationContext otherCcCompilationContext) { + Preconditions.checkNotNull(otherCcCompilationContext); + compilationPrerequisites.addAll( + otherCcCompilationContext.getTransitiveCompilationPrerequisites()); + includeDirs.addAll(otherCcCompilationContext.getIncludeDirs()); + quoteIncludeDirs.addAll(otherCcCompilationContext.getQuoteIncludeDirs()); + systemIncludeDirs.addAll(otherCcCompilationContext.getSystemIncludeDirs()); + declaredIncludeDirs.addTransitive(otherCcCompilationContext.getDeclaredIncludeDirs()); + declaredIncludeWarnDirs.addTransitive(otherCcCompilationContext.getDeclaredIncludeWarnDirs()); + declaredIncludeSrcs.addTransitive(otherCcCompilationContext.getDeclaredIncludeSrcs()); + pregreppedHdrs.addTransitive(otherCcCompilationContext.getPregreppedHeaders()); + moduleInfo.addTransitive(otherCcCompilationContext.moduleInfo); + picModuleInfo.addTransitive(otherCcCompilationContext.picModuleInfo); + nonCodeInputs.addTransitive(otherCcCompilationContext.nonCodeInputs); + + // All module maps of direct dependencies are inputs to the current compile independently of + // the build type. + if (otherCcCompilationContext.getCppModuleMap() != null) { + directModuleMaps.add(otherCcCompilationContext.getCppModuleMap().getArtifact()); + } + + defines.addAll(otherCcCompilationContext.getDefines()); + return this; + } + + /** + * Merges the {@code CcCompilationContext}s of some targets into this one by adding the contents + * of all of their attributes. Targets that do not implement {@link CcCompilationContext} are + * ignored. + */ + public Builder mergeDependentCcCompilationContexts(Iterable targets) { + for (CcCompilationContext target : targets) { + mergeDependentCcCompilationContext(target); + } + return this; + } + + /** + * Adds multiple compilation prerequisites. + * + *

There are two kinds of "compilation prerequisites": declared header files and pregrepped + * headers. + */ + public Builder addCompilationPrerequisites(Iterable prerequisites) { + // LIPO collector must not add compilation prerequisites in order to avoid + // the creation of a middleman action. + for (Artifact prerequisite : prerequisites) { + String basename = prerequisite.getFilename(); + Preconditions.checkArgument(!Link.OBJECT_FILETYPES.matches(basename)); + Preconditions.checkArgument(!Link.ARCHIVE_LIBRARY_FILETYPES.matches(basename)); + Preconditions.checkArgument(!Link.SHARED_LIBRARY_FILETYPES.matches(basename)); + } + Iterables.addAll(compilationPrerequisites, prerequisites); + return this; + } + + /** + * Add a single include directory to be added with "-I". It can be either + * relative to the exec root (see + * {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or + * absolute. Before it is stored, the include directory is normalized. + */ + public Builder addIncludeDir(PathFragment includeDir) { + includeDirs.add(includeDir); + return this; + } + + /** + * Add multiple include directories to be added with "-I". These can be + * either relative to the exec root (see {@link + * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. The + * entries are normalized before they are stored. + */ + public Builder addIncludeDirs(Iterable includeDirs) { + for (PathFragment includeDir : includeDirs) { + addIncludeDir(includeDir); + } + return this; + } + + /** + * Add a single include directory to be added with "-iquote". It can be + * either relative to the exec root (see {@link + * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. Before it + * is stored, the include directory is normalized. + */ + public Builder addQuoteIncludeDir(PathFragment quoteIncludeDir) { + quoteIncludeDirs.add(quoteIncludeDir); + return this; + } + + /** + * Add a single include directory to be added with "-isystem". It can be + * either relative to the exec root (see {@link + * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. Before it + * is stored, the include directory is normalized. + */ + public Builder addSystemIncludeDir(PathFragment systemIncludeDir) { + systemIncludeDirs.add(systemIncludeDir); + return this; + } + + /** + * Add a single declared include dir, relative to a "-I" or "-iquote" + * directory". + */ + public Builder addDeclaredIncludeDir(PathFragment dir) { + declaredIncludeDirs.add(dir); + return this; + } + + /** + * Add a single declared include directory, relative to a "-I" or "-iquote" + * directory", from which inclusion will produce a warning. + */ + public Builder addDeclaredIncludeWarnDir(PathFragment dir) { + declaredIncludeWarnDirs.add(dir); + return this; + } + + /** + * Adds a header that has been declared in the {@code src} or {@code headers attribute}. The + * header will also be added to the compilation prerequisites. + * + *

Filters out fileset directory artifacts, which are not valid inputs. + */ + public Builder addDeclaredIncludeSrc(Artifact header) { + if (!header.isFileset()) { + declaredIncludeSrcs.add(header); + compilationPrerequisites.add(header); + } + return this; + } + + /** + * Adds multiple headers that have been declared in the {@code src} or {@code headers + * attribute}. The headers will also be added to the compilation prerequisites. + * + *

Filters out fileset directory artifacts, which are not valid inputs. + */ + public Builder addDeclaredIncludeSrcs(Collection declaredIncludeSrcs) { + for (Artifact source : declaredIncludeSrcs) { + addDeclaredIncludeSrc(source); + } + return this; + } + + public Builder addModularHdrs(Collection headers) { + this.moduleInfo.addHeaders(headers); + this.picModuleInfo.addHeaders(headers); + return this; + } + + public Builder addTextualHdrs(Collection headers) { + this.moduleInfo.addTextualHeaders(headers); + this.picModuleInfo.addTextualHeaders(headers); + return this; + } + + /** + * Add a map of generated source or header Artifact to an output Artifact after grepping the + * file for include statements. + */ + public Builder addPregreppedHeaders(List pregrepped) { + addCompilationPrerequisites( + pregrepped + .stream() + .map(pregreppedHeader -> pregreppedHeader.greppedHeader()) + .collect(Collectors.toList())); + this.pregreppedHdrs.addAll(pregrepped); + return this; + } + + /** Add a set of required non-code compilation input. */ + public Builder addNonCodeInputs(Iterable inputs) { + nonCodeInputs.addAll(inputs); + return this; + } + + /** + * Adds a single define. + */ + public Builder addDefine(String define) { + defines.add(define); + return this; + } + + /** + * Adds multiple defines. + */ + public Builder addDefines(Iterable defines) { + Iterables.addAll(this.defines, defines); + return this; + } + + /** Sets the C++ module map. */ + public Builder setCppModuleMap(CppModuleMap cppModuleMap) { + this.cppModuleMap = cppModuleMap; + return this; + } + + /** Sets the C++ module map used to verify that headers are modules compatible. */ + public Builder setVerificationModuleMap(CppModuleMap verificationModuleMap) { + this.verificationModuleMap = verificationModuleMap; + return this; + } + + /** + * Causes the module map to be passed as an action input to dependant compilations. + */ + public Builder setPropagateCppModuleMapAsActionInput(boolean propagateModuleMap) { + this.propagateModuleMapAsActionInput = propagateModuleMap; + return this; + } + + /** + * Sets the C++ header module in non-pic mode. + * + * @param headerModule The .pcm file generated for this library. + */ + public Builder setHeaderModule(Artifact headerModule) { + this.moduleInfo.setHeaderModule(headerModule); + return this; + } + + /** + * Sets the C++ header module in pic mode. + * @param picHeaderModule The .pic.pcm file generated for this library. + */ + public Builder setPicHeaderModule(Artifact picHeaderModule) { + this.picModuleInfo.setHeaderModule(picHeaderModule); + return this; + } + + /** Builds the {@link CcCompilationContext}. */ + public CcCompilationContext build() { + return build( + ruleContext == null ? null : ruleContext.getActionOwner(), + ruleContext == null ? null : ruleContext.getAnalysisEnvironment().getMiddlemanFactory()); + } + + @VisibleForTesting // productionVisibility = Visibility.PRIVATE + public CcCompilationContext build(ActionOwner owner, MiddlemanFactory middlemanFactory) { + Preconditions.checkState( + Objects.equals(moduleInfo.textualHeaders, picModuleInfo.textualHeaders), + "Module and PIC module's textual headers are expected to be identical"); + // We don't create middlemen in LIPO collector subtree, because some target CT + // will do that instead. + Artifact prerequisiteStampFile = (ruleContext != null + && ruleContext.getFragment(CppConfiguration.class).isLipoContextCollector()) + ? getMiddlemanArtifact(middlemanFactory) + : createMiddleman(owner, middlemanFactory); + + return new CcCompilationContext( + new CommandLineCcCompilationContext( + ImmutableList.copyOf(includeDirs), + ImmutableList.copyOf(quoteIncludeDirs), + ImmutableList.copyOf(systemIncludeDirs), + ImmutableList.copyOf(defines)), + prerequisiteStampFile == null + ? ImmutableSet.of() + : ImmutableSet.of(prerequisiteStampFile), + declaredIncludeDirs.build(), + declaredIncludeWarnDirs.build(), + declaredIncludeSrcs.build(), + pregreppedHdrs.build(), + nonCodeInputs.build(), + moduleInfo.build(), + picModuleInfo.build(), + directModuleMaps.build(), + cppModuleMap, + verificationModuleMap, + propagateModuleMapAsActionInput); + } + + /** + * Creates a middleman for the compilation prerequisites. + * + * @return the middleman or null if there are no prerequisites + */ + private Artifact createMiddleman(ActionOwner owner, + MiddlemanFactory middlemanFactory) { + if (compilationPrerequisites.isEmpty()) { + return null; + } + + // Compilation prerequisites gathered in the compilationPrerequisites + // must be generated prior to executing C++ compilation step that depends + // on them (since these prerequisites include all potential header files, etc + // that could be referenced during compilation). So there is a definite need + // to ensure scheduling edge dependency. However, those prerequisites should + // have no effect on the decision whether C++ compilation should happen in + // the first place - only CppCompileAction outputs (*.o and *.d files) and + // all files referenced by the *.d file should be used to make that decision. + // If this action was never executed, then *.d file would be missing, forcing + // compilation to occur. If *.d file is present and has not changed then the + // only reason that would force us to re-compile would be change in one of + // the files referenced by the *.d file, since no other files participated + // in the compilation. We also need to propagate errors through this + // dependency link. So we use an error propagating middleman. + // Such middleman will be ignored by the dependency checker yet will still + // represent an edge in the action dependency graph - forcing proper execution + // order and error propagation. + String name = + cppModuleMap != null ? cppModuleMap.getName() : ruleContext.getLabel().toString(); + return middlemanFactory.createErrorPropagatingMiddleman( + owner, name, purpose, + ImmutableList.copyOf(compilationPrerequisites), + ruleContext.getConfiguration().getMiddlemanDirectory( + ruleContext.getRule().getRepository())); + } + + /** + * Returns the same set of artifacts as createMiddleman() would, but without + * actually creating middlemen. + */ + private Artifact getMiddlemanArtifact(MiddlemanFactory middlemanFactory) { + if (compilationPrerequisites.isEmpty()) { + return null; + } + + return middlemanFactory.getErrorPropagatingMiddlemanArtifact( + ruleContext.getLabel().toString(), + purpose, + ruleContext.getConfiguration().getMiddlemanDirectory( + ruleContext.getRule().getRepository())); + } + } + + /** + * Gathers data about the direct and transitive .pcm files belonging to this context. Can be to + * either gather data on PIC or on no-PIC .pcm files. + */ + @Immutable + @AutoCodec + public static final class ModuleInfo { + /** + * The module built for this context. If null, then no module is being compiled for this + * context. + */ + private final Artifact headerModule; + + /** All header files that are compiled into this module. */ + private final ImmutableSet modularHeaders; + + /** All header files that are contained in this module. */ + private final ImmutableSet textualHeaders; + + /** + * All transitive modules that this context depends on, excluding headerModule. + */ + private final NestedSet transitiveModules; + + /** + * All information about mapping transitive headers to transitive modules. + */ + public final NestedSet transitiveModuleHeaders; + + public ModuleInfo( + Artifact headerModule, + ImmutableSet modularHeaders, + ImmutableSet textualHeaders, + NestedSet transitiveModules, + NestedSet transitiveModuleHeaders) { + this.headerModule = headerModule; + this.modularHeaders = modularHeaders; + this.textualHeaders = textualHeaders; + this.transitiveModules = transitiveModules; + this.transitiveModuleHeaders = transitiveModuleHeaders; + } + + public Collection getUsedModules(Set usedHeaders) { + List result = new ArrayList<>(); + for (TransitiveModuleHeaders transitiveModule : transitiveModuleHeaders) { + if (transitiveModule.module.equals(headerModule)) { + // Do not add the module of the current rule for both: + // 1. the module compile itself + // 2. compiles of other translation units of the same rule. + continue; + } + boolean providesUsedHeader = false; + for (Artifact header : transitiveModule.headers) { + if (usedHeaders.contains(header)) { + providesUsedHeader = true; + break; + } + } + if (providesUsedHeader) { + result.add(transitiveModule); + } + } + return result; + } + + /** + * Builder class for {@link ModuleInfo}. + */ + public static class Builder { + private Artifact headerModule = null; + private final Set modularHeaders = new LinkedHashSet<>(); + private final Set textualHeaders = new LinkedHashSet<>(); + private final NestedSetBuilder transitiveModules = NestedSetBuilder.stableOrder(); + private final NestedSetBuilder transitiveModuleHeaders = + NestedSetBuilder.stableOrder(); + + public Builder setHeaderModule(Artifact headerModule) { + this.headerModule = headerModule; + return this; + } + + public Builder addHeaders(Collection headers) { + this.modularHeaders.addAll(headers); + return this; + } + + public Builder addTextualHeaders(Collection headers) { + this.textualHeaders.addAll(headers); + return this; + } + + /** + * Merges a {@link ModuleInfo} into this one. In contrast to addTransitive, this doesn't add + * the dependent module to transitiveModules, but just merges the transitive sets. The main + * usage is to merge multiple {@link ModuleInfo} instances for Lipo. + */ + public Builder merge(ModuleInfo other) { + if (headerModule == null) { + headerModule = other.headerModule; + } + modularHeaders.addAll(other.modularHeaders); + textualHeaders.addAll(other.textualHeaders); + transitiveModules.addTransitive(other.transitiveModules); + transitiveModuleHeaders.addTransitive(other.transitiveModuleHeaders); + return this; + } + + /** + * Adds the {@link ModuleInfo} of a dependency and builds up the transitive data structures. + */ + public Builder addTransitive(ModuleInfo moduleInfo) { + if (moduleInfo.headerModule != null) { + transitiveModules.add(moduleInfo.headerModule); + } + transitiveModules.addTransitive(moduleInfo.transitiveModules); + transitiveModuleHeaders.addTransitive(moduleInfo.transitiveModuleHeaders); + return this; + } + + public ModuleInfo build() { + ImmutableSet modularHeaders = ImmutableSet.copyOf(this.modularHeaders); + NestedSet transitiveModules = this.transitiveModules.build(); + if (headerModule != null) { + transitiveModuleHeaders.add( + new TransitiveModuleHeaders(headerModule, modularHeaders, transitiveModules)); + } + return new ModuleInfo( + headerModule, + modularHeaders, + ImmutableSet.copyOf(this.textualHeaders), + transitiveModules, + transitiveModuleHeaders.build()); + } + } + } + + /** Collects data for a specific module in a special format that makes pruning easy. */ + @Immutable + @AutoCodec + public static final class TransitiveModuleHeaders { + /** + * The module that we are calculating information for. + */ + private final Artifact module; + + /** + * The headers compiled into this module. + */ + private final ImmutableSet headers; + + /** + * This nested set contains 'module' as well as all targets it transitively depends on. + * If any of the 'headers' is used, all of these modules a required for the compilation. + */ + private final NestedSet transitiveModules; + + public TransitiveModuleHeaders( + Artifact module, + ImmutableSet headers, + NestedSet transitiveModules) { + this.module = module; + this.headers = headers; + this.transitiveModules = transitiveModules; + } + + public Artifact getModule() { + return module; + } + + public Collection getTransitiveModules() { + return transitiveModules.toCollection(); + } + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java deleted file mode 100644 index 3603f20e4f..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java +++ /dev/null @@ -1,955 +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.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.ActionOwner; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.MiddlemanFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -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.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.cpp.CppHelper.PregreppedHeader; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; -import com.google.devtools.build.lib.vfs.PathFragment; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nullable; - -/** - * Immutable store of information needed for C++ compilation that is aggregated across dependencies. - */ -@Immutable -@AutoCodec -@SkylarkModule( - name = "cc_compilation_info", - documented = false, - category = SkylarkModuleCategory.PROVIDER, - doc = - "Immutable store of information needed for C++ compilation that is aggregated across " - + "dependencies." -) -// TODO(b/77669139): Rename to CcCompilationContext. -public final class CcCompilationContextInfo { - /** An empty {@code CcCompilationContextInfo}. */ - public static final CcCompilationContextInfo EMPTY = new Builder(null).build(); - - private final CommandLineCcCompilationContextInfo commandLineCcCompilationContextInfo; - - private final NestedSet declaredIncludeDirs; - private final NestedSet declaredIncludeWarnDirs; - private final NestedSet declaredIncludeSrcs; - - /** - * Module maps from direct dependencies. - */ - private final NestedSet directModuleMaps; - - /** Non-code mandatory compilation inputs. */ - private final NestedSet nonCodeInputs; - - private final NestedSet pregreppedHdrs; - - private final ModuleInfo moduleInfo; - private final ModuleInfo picModuleInfo; - - private final CppModuleMap cppModuleMap; - private final CppModuleMap verificationModuleMap; - - private final boolean propagateModuleMapAsActionInput; - - // Derived from depsContexts. - private final ImmutableSet compilationPrerequisites; - - @AutoCodec.Instantiator - @VisibleForSerialization - CcCompilationContextInfo( - CommandLineCcCompilationContextInfo commandLineCcCompilationContextInfo, - ImmutableSet compilationPrerequisites, - NestedSet declaredIncludeDirs, - NestedSet declaredIncludeWarnDirs, - NestedSet declaredIncludeSrcs, - NestedSet pregreppedHdrs, - NestedSet nonCodeInputs, - ModuleInfo moduleInfo, - ModuleInfo picModuleInfo, - NestedSet directModuleMaps, - CppModuleMap cppModuleMap, - @Nullable CppModuleMap verificationModuleMap, - boolean propagateModuleMapAsActionInput) { - Preconditions.checkNotNull(commandLineCcCompilationContextInfo); - this.commandLineCcCompilationContextInfo = commandLineCcCompilationContextInfo; - this.declaredIncludeDirs = declaredIncludeDirs; - this.declaredIncludeWarnDirs = declaredIncludeWarnDirs; - this.declaredIncludeSrcs = declaredIncludeSrcs; - this.directModuleMaps = directModuleMaps; - this.pregreppedHdrs = pregreppedHdrs; - this.moduleInfo = moduleInfo; - this.picModuleInfo = picModuleInfo; - this.cppModuleMap = cppModuleMap; - this.nonCodeInputs = nonCodeInputs; - this.verificationModuleMap = verificationModuleMap; - this.compilationPrerequisites = compilationPrerequisites; - this.propagateModuleMapAsActionInput = propagateModuleMapAsActionInput; - } - - /** - * Returns the transitive compilation prerequisites consolidated into middlemen prerequisites, or - * an empty set if there are no prerequisites. - * - *

Transitive compilation prerequisites are the prerequisites that will be needed by all - * reverse dependencies; note that these do specifically not include any compilation prerequisites - * that are only needed by the rule itself (for example, compiled source files from the {@code - * srcs} attribute). - * - *

To reduce the number of edges in the action graph, we express the dependency on compilation - * prerequisites as a transitive dependency via a middleman. After they have been accumulated - * (using {@link Builder#addCompilationPrerequisites(Iterable)}, {@link - * Builder#mergeDependentCcCompilationContextInfo(CcCompilationContextInfo)}, and {@link - * Builder#mergeDependentCcCompilationContextInfos(Iterable)}, they are consolidated into a single - * middleman Artifact when {@link Builder#build()} is called. - * - *

The returned set can be empty if there are no prerequisites. Usually it contains a single - * middleman, but if LIPO is used there can be two. - */ - public ImmutableSet getTransitiveCompilationPrerequisites() { - return compilationPrerequisites; - } - - /** - * Returns the immutable list of include directories to be added with "-I" - * (possibly empty but never null). This includes the include dirs from the - * transitive deps closure of the target. This list does not contain - * duplicates. All fragments are either absolute or relative to the exec root - * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). - */ - public ImmutableList getIncludeDirs() { - return commandLineCcCompilationContextInfo.includeDirs; - } - - /** - * Returns the immutable list of include directories to be added with - * "-iquote" (possibly empty but never null). This includes the include dirs - * from the transitive deps closure of the target. This list does not contain - * duplicates. All fragments are either absolute or relative to the exec root - * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). - */ - public ImmutableList getQuoteIncludeDirs() { - return commandLineCcCompilationContextInfo.quoteIncludeDirs; - } - - /** - * Returns the immutable list of include directories to be added with - * "-isystem" (possibly empty but never null). This includes the include dirs - * from the transitive deps closure of the target. This list does not contain - * duplicates. All fragments are either absolute or relative to the exec root - * (see {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}). - */ - public ImmutableList getSystemIncludeDirs() { - return commandLineCcCompilationContextInfo.systemIncludeDirs; - } - - /** - * Returns the immutable set of declared include directories, relative to a "-I" or "-iquote" - * directory" (possibly empty but never null). - */ - public NestedSet getDeclaredIncludeDirs() { - return declaredIncludeDirs; - } - - /** - * Returns the immutable set of include directories, relative to a "-I" or "-iquote" directory", - * from which inclusion will produce a warning (possibly empty but never null). - */ - public NestedSet getDeclaredIncludeWarnDirs() { - return declaredIncludeWarnDirs; - } - - /** - * Returns the immutable set of headers that have been declared in the {@code srcs} or {@code - * hdrs} attribute (possibly empty but never null). - */ - public NestedSet getDeclaredIncludeSrcs() { - return declaredIncludeSrcs; - } - - /** Returns headers given as textual_hdrs in this target. */ - public ImmutableSet getTextualHdrs() { - return moduleInfo.textualHeaders; - } - - /** - * Returns the immutable pairs of (header file, pregrepped header file). The value artifacts - * (pregrepped header file) are generated by {@link ExtractInclusionAction}. - */ - NestedSet getPregreppedHeaders() { - return pregreppedHdrs; - } - - public NestedSet getTransitiveModules(boolean usePic) { - return usePic ? picModuleInfo.transitiveModules : moduleInfo.transitiveModules; - } - - public Collection getUsedModules( - boolean usePic, Set usedHeaders) { - return usePic - ? picModuleInfo.getUsedModules(usedHeaders) - : moduleInfo.getUsedModules(usedHeaders); - } - - /** - * Returns the immutable set of additional transitive inputs needed for - * compilation, like C++ module map artifacts. - */ - public NestedSet getAdditionalInputs() { - NestedSetBuilder builder = NestedSetBuilder.stableOrder(); - builder.addTransitive(directModuleMaps); - builder.addTransitive(nonCodeInputs); - if (cppModuleMap != null && propagateModuleMapAsActionInput) { - builder.add(cppModuleMap.getArtifact()); - } - return builder.build(); - } - - /** - * @return modules maps from direct dependencies. - */ - public NestedSet getDirectModuleMaps() { - return directModuleMaps; - } - - /** - * @return all declared headers of the current module if the current target - * is compiled as a module. - */ - protected Set getHeaderModuleSrcs() { - return new ImmutableSet.Builder() - .addAll(moduleInfo.modularHeaders) - .addAll(moduleInfo.textualHeaders) - .build(); - } - - /** - * Returns the set of defines needed to compile this target (possibly empty - * but never null). This includes definitions from the transitive deps closure - * for the target. The order of the returned collection is deterministic. - */ - public ImmutableList getDefines() { - return commandLineCcCompilationContextInfo.defines; - } - - /** - * Returns a {@code CcCompilationContextInfo} that is based on a given {@code - * CcCompilationContextInfo} but returns empty sets for {@link #getDeclaredIncludeDirs()} and - * {@link #getDeclaredIncludeWarnDirs()}. - */ - public static CcCompilationContextInfo disallowUndeclaredHeaders( - CcCompilationContextInfo ccCompilationContextInfo) { - return new CcCompilationContextInfo( - ccCompilationContextInfo.commandLineCcCompilationContextInfo, - ccCompilationContextInfo.compilationPrerequisites, - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - ccCompilationContextInfo.declaredIncludeSrcs, - ccCompilationContextInfo.pregreppedHdrs, - ccCompilationContextInfo.nonCodeInputs, - ccCompilationContextInfo.moduleInfo, - ccCompilationContextInfo.picModuleInfo, - ccCompilationContextInfo.directModuleMaps, - ccCompilationContextInfo.cppModuleMap, - ccCompilationContextInfo.verificationModuleMap, - ccCompilationContextInfo.propagateModuleMapAsActionInput); - } - - /** - * Returns the context for a LIPO compile action. This uses the include dirs and defines of the - * library, but the declared inclusion dirs/srcs from both the library and the owner binary. - * - *

TODO(bazel-team): this might make every LIPO target have an unnecessary large set of - * inclusion dirs/srcs. The correct behavior would be to merge only the contexts of actual - * referred targets (as listed in .imports file). - * - *

Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, {@link - * #getDeclaredIncludeWarnDirs()}, and {@link #getDeclaredIncludeSrcs()}) needs to use the union - * of the contexts of the involved source files. - * - *

For include and define command line flags ({@link #getIncludeDirs()} {@link - * #getQuoteIncludeDirs()}, {@link #getSystemIncludeDirs()}, and {@link #getDefines()}) LIPO - * compilations use the same values as non-LIPO compilation. - * - *

Include scanning is not handled by this method. See {@code - * IncludeScannable#getAuxiliaryScannables()} instead. - * - * @param ownerCcCompilationContextInfo the {@code CcCompilationContextInfo} of the owner binary - * @param libCcCompilationContextInfo the {@code CcCompilationContextInfo} of the library - */ - public static CcCompilationContextInfo mergeForLipo( - CcCompilationContextInfo ownerCcCompilationContextInfo, - CcCompilationContextInfo libCcCompilationContextInfo) { - ImmutableSet.Builder prerequisites = ImmutableSet.builder(); - prerequisites.addAll(ownerCcCompilationContextInfo.compilationPrerequisites); - prerequisites.addAll(libCcCompilationContextInfo.compilationPrerequisites); - ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); - moduleInfo.merge(ownerCcCompilationContextInfo.moduleInfo); - moduleInfo.merge(libCcCompilationContextInfo.moduleInfo); - ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); - picModuleInfo.merge(ownerCcCompilationContextInfo.picModuleInfo); - picModuleInfo.merge(libCcCompilationContextInfo.picModuleInfo); - return new CcCompilationContextInfo( - libCcCompilationContextInfo.commandLineCcCompilationContextInfo, - prerequisites.build(), - mergeSets( - ownerCcCompilationContextInfo.declaredIncludeDirs, - libCcCompilationContextInfo.declaredIncludeDirs), - mergeSets( - ownerCcCompilationContextInfo.declaredIncludeWarnDirs, - libCcCompilationContextInfo.declaredIncludeWarnDirs), - mergeSets( - ownerCcCompilationContextInfo.declaredIncludeSrcs, - libCcCompilationContextInfo.declaredIncludeSrcs), - mergeSets( - ownerCcCompilationContextInfo.pregreppedHdrs, - libCcCompilationContextInfo.pregreppedHdrs), - mergeSets( - ownerCcCompilationContextInfo.nonCodeInputs, libCcCompilationContextInfo.nonCodeInputs), - moduleInfo.build(), - picModuleInfo.build(), - mergeSets( - ownerCcCompilationContextInfo.directModuleMaps, - libCcCompilationContextInfo.directModuleMaps), - libCcCompilationContextInfo.cppModuleMap, - libCcCompilationContextInfo.verificationModuleMap, - libCcCompilationContextInfo.propagateModuleMapAsActionInput); - } - - /** - * Return a nested set containing all elements from {@code s1} and {@code s2}. - */ - private static NestedSet mergeSets(NestedSet s1, NestedSet s2) { - NestedSetBuilder builder = NestedSetBuilder.stableOrder(); - builder.addTransitive(s1); - builder.addTransitive(s2); - return builder.build(); - } - - /** @return the C++ module map of the owner. */ - public CppModuleMap getCppModuleMap() { - return cppModuleMap; - } - - /** @return the C++ module map of the owner. */ - public CppModuleMap getVerificationModuleMap() { - return verificationModuleMap; - } - - /** - * The parts of the {@code CcCompilationContextInfo} that influence the command line of - * compilation actions. - */ - @Immutable - @AutoCodec - @VisibleForSerialization - static class CommandLineCcCompilationContextInfo { - private final ImmutableList includeDirs; - private final ImmutableList quoteIncludeDirs; - private final ImmutableList systemIncludeDirs; - private final ImmutableList defines; - - CommandLineCcCompilationContextInfo( - ImmutableList includeDirs, - ImmutableList quoteIncludeDirs, - ImmutableList systemIncludeDirs, - ImmutableList defines) { - this.includeDirs = includeDirs; - this.quoteIncludeDirs = quoteIncludeDirs; - this.systemIncludeDirs = systemIncludeDirs; - this.defines = defines; - } - } - - /** Builder class for {@link CcCompilationContextInfo}. */ - public static class Builder { - private String purpose; - private final Set compilationPrerequisites = new LinkedHashSet<>(); - private final Set includeDirs = new LinkedHashSet<>(); - private final Set quoteIncludeDirs = new LinkedHashSet<>(); - private final Set systemIncludeDirs = new LinkedHashSet<>(); - private final NestedSetBuilder declaredIncludeDirs = - NestedSetBuilder.stableOrder(); - private final NestedSetBuilder declaredIncludeWarnDirs = - NestedSetBuilder.stableOrder(); - private final NestedSetBuilder declaredIncludeSrcs = - NestedSetBuilder.stableOrder(); - private final NestedSetBuilder pregreppedHdrs = - NestedSetBuilder.stableOrder(); - private final NestedSetBuilder nonCodeInputs = NestedSetBuilder.stableOrder(); - private final ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); - private final ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); - private final NestedSetBuilder directModuleMaps = NestedSetBuilder.stableOrder(); - private final Set defines = new LinkedHashSet<>(); - private CppModuleMap cppModuleMap; - private CppModuleMap verificationModuleMap; - private boolean propagateModuleMapAsActionInput = true; - - /** The rule that owns the context */ - private final RuleContext ruleContext; - - /** Creates a new builder for a {@link CcCompilationContextInfo} instance. */ - public Builder(RuleContext ruleContext) { - this.ruleContext = ruleContext; - } - - /** - * Overrides the purpose of this context. This is useful if a Target needs more than one - * CcCompilationContextInfo. (The purpose is used to construct the name of the prerequisites - * middleman for the context, and all artifacts for a given Target must have distinct names.) - * - * @param purpose must be a string which is suitable for use as a filename. A single rule may - * have many middlemen with distinct purposes. - * @see MiddlemanFactory#createErrorPropagatingMiddleman - */ - public Builder setPurpose(String purpose) { - this.purpose = purpose; - return this; - } - - public String getPurpose() { - return purpose; - } - - /** - * Merges the {@link CcCompilationContextInfo} of a dependency into this one by adding the - * contents of all of its attributes. - */ - public Builder mergeDependentCcCompilationContextInfo( - CcCompilationContextInfo otherCcCompilationContextInfo) { - Preconditions.checkNotNull(otherCcCompilationContextInfo); - compilationPrerequisites.addAll( - otherCcCompilationContextInfo.getTransitiveCompilationPrerequisites()); - includeDirs.addAll(otherCcCompilationContextInfo.getIncludeDirs()); - quoteIncludeDirs.addAll(otherCcCompilationContextInfo.getQuoteIncludeDirs()); - systemIncludeDirs.addAll(otherCcCompilationContextInfo.getSystemIncludeDirs()); - declaredIncludeDirs.addTransitive(otherCcCompilationContextInfo.getDeclaredIncludeDirs()); - declaredIncludeWarnDirs.addTransitive( - otherCcCompilationContextInfo.getDeclaredIncludeWarnDirs()); - declaredIncludeSrcs.addTransitive(otherCcCompilationContextInfo.getDeclaredIncludeSrcs()); - pregreppedHdrs.addTransitive(otherCcCompilationContextInfo.getPregreppedHeaders()); - moduleInfo.addTransitive(otherCcCompilationContextInfo.moduleInfo); - picModuleInfo.addTransitive(otherCcCompilationContextInfo.picModuleInfo); - nonCodeInputs.addTransitive(otherCcCompilationContextInfo.nonCodeInputs); - - // All module maps of direct dependencies are inputs to the current compile independently of - // the build type. - if (otherCcCompilationContextInfo.getCppModuleMap() != null) { - directModuleMaps.add(otherCcCompilationContextInfo.getCppModuleMap().getArtifact()); - } - - defines.addAll(otherCcCompilationContextInfo.getDefines()); - return this; - } - - /** - * Merges the {@code CcCompilationContextInfo}s of some targets into this one by adding the - * contents of all of their attributes. Targets that do not implement {@link - * CcCompilationContextInfo} are ignored. - */ - public Builder mergeDependentCcCompilationContextInfos( - Iterable targets) { - for (CcCompilationContextInfo target : targets) { - mergeDependentCcCompilationContextInfo(target); - } - return this; - } - - /** - * Adds multiple compilation prerequisites. - * - *

There are two kinds of "compilation prerequisites": declared header files and pregrepped - * headers. - */ - public Builder addCompilationPrerequisites(Iterable prerequisites) { - // LIPO collector must not add compilation prerequisites in order to avoid - // the creation of a middleman action. - for (Artifact prerequisite : prerequisites) { - String basename = prerequisite.getFilename(); - Preconditions.checkArgument(!Link.OBJECT_FILETYPES.matches(basename)); - Preconditions.checkArgument(!Link.ARCHIVE_LIBRARY_FILETYPES.matches(basename)); - Preconditions.checkArgument(!Link.SHARED_LIBRARY_FILETYPES.matches(basename)); - } - Iterables.addAll(compilationPrerequisites, prerequisites); - return this; - } - - /** - * Add a single include directory to be added with "-I". It can be either - * relative to the exec root (see - * {@link com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or - * absolute. Before it is stored, the include directory is normalized. - */ - public Builder addIncludeDir(PathFragment includeDir) { - includeDirs.add(includeDir); - return this; - } - - /** - * Add multiple include directories to be added with "-I". These can be - * either relative to the exec root (see {@link - * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. The - * entries are normalized before they are stored. - */ - public Builder addIncludeDirs(Iterable includeDirs) { - for (PathFragment includeDir : includeDirs) { - addIncludeDir(includeDir); - } - return this; - } - - /** - * Add a single include directory to be added with "-iquote". It can be - * either relative to the exec root (see {@link - * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. Before it - * is stored, the include directory is normalized. - */ - public Builder addQuoteIncludeDir(PathFragment quoteIncludeDir) { - quoteIncludeDirs.add(quoteIncludeDir); - return this; - } - - /** - * Add a single include directory to be added with "-isystem". It can be - * either relative to the exec root (see {@link - * com.google.devtools.build.lib.analysis.BlazeDirectories#getExecRoot}) or absolute. Before it - * is stored, the include directory is normalized. - */ - public Builder addSystemIncludeDir(PathFragment systemIncludeDir) { - systemIncludeDirs.add(systemIncludeDir); - return this; - } - - /** - * Add a single declared include dir, relative to a "-I" or "-iquote" - * directory". - */ - public Builder addDeclaredIncludeDir(PathFragment dir) { - declaredIncludeDirs.add(dir); - return this; - } - - /** - * Add a single declared include directory, relative to a "-I" or "-iquote" - * directory", from which inclusion will produce a warning. - */ - public Builder addDeclaredIncludeWarnDir(PathFragment dir) { - declaredIncludeWarnDirs.add(dir); - return this; - } - - /** - * Adds a header that has been declared in the {@code src} or {@code headers attribute}. The - * header will also be added to the compilation prerequisites. - * - *

Filters out fileset directory artifacts, which are not valid inputs. - */ - public Builder addDeclaredIncludeSrc(Artifact header) { - if (!header.isFileset()) { - declaredIncludeSrcs.add(header); - compilationPrerequisites.add(header); - } - return this; - } - - /** - * Adds multiple headers that have been declared in the {@code src} or {@code headers - * attribute}. The headers will also be added to the compilation prerequisites. - * - *

Filters out fileset directory artifacts, which are not valid inputs. - */ - public Builder addDeclaredIncludeSrcs(Collection declaredIncludeSrcs) { - for (Artifact source : declaredIncludeSrcs) { - addDeclaredIncludeSrc(source); - } - return this; - } - - public Builder addModularHdrs(Collection headers) { - this.moduleInfo.addHeaders(headers); - this.picModuleInfo.addHeaders(headers); - return this; - } - - public Builder addTextualHdrs(Collection headers) { - this.moduleInfo.addTextualHeaders(headers); - this.picModuleInfo.addTextualHeaders(headers); - return this; - } - - /** - * Add a map of generated source or header Artifact to an output Artifact after grepping the - * file for include statements. - */ - public Builder addPregreppedHeaders(List pregrepped) { - addCompilationPrerequisites( - pregrepped - .stream() - .map(pregreppedHeader -> pregreppedHeader.greppedHeader()) - .collect(Collectors.toList())); - this.pregreppedHdrs.addAll(pregrepped); - return this; - } - - /** Add a set of required non-code compilation input. */ - public Builder addNonCodeInputs(Iterable inputs) { - nonCodeInputs.addAll(inputs); - return this; - } - - /** - * Adds a single define. - */ - public Builder addDefine(String define) { - defines.add(define); - return this; - } - - /** - * Adds multiple defines. - */ - public Builder addDefines(Iterable defines) { - Iterables.addAll(this.defines, defines); - return this; - } - - /** Sets the C++ module map. */ - public Builder setCppModuleMap(CppModuleMap cppModuleMap) { - this.cppModuleMap = cppModuleMap; - return this; - } - - /** Sets the C++ module map used to verify that headers are modules compatible. */ - public Builder setVerificationModuleMap(CppModuleMap verificationModuleMap) { - this.verificationModuleMap = verificationModuleMap; - return this; - } - - /** - * Causes the module map to be passed as an action input to dependant compilations. - */ - public Builder setPropagateCppModuleMapAsActionInput(boolean propagateModuleMap) { - this.propagateModuleMapAsActionInput = propagateModuleMap; - return this; - } - - /** - * Sets the C++ header module in non-pic mode. - * - * @param headerModule The .pcm file generated for this library. - */ - public Builder setHeaderModule(Artifact headerModule) { - this.moduleInfo.setHeaderModule(headerModule); - return this; - } - - /** - * Sets the C++ header module in pic mode. - * @param picHeaderModule The .pic.pcm file generated for this library. - */ - public Builder setPicHeaderModule(Artifact picHeaderModule) { - this.picModuleInfo.setHeaderModule(picHeaderModule); - return this; - } - - /** Builds the {@link CcCompilationContextInfo}. */ - public CcCompilationContextInfo build() { - return build( - ruleContext == null ? null : ruleContext.getActionOwner(), - ruleContext == null ? null : ruleContext.getAnalysisEnvironment().getMiddlemanFactory()); - } - - @VisibleForTesting // productionVisibility = Visibility.PRIVATE - public CcCompilationContextInfo build(ActionOwner owner, MiddlemanFactory middlemanFactory) { - Preconditions.checkState( - Objects.equals(moduleInfo.textualHeaders, picModuleInfo.textualHeaders), - "Module and PIC module's textual headers are expected to be identical"); - // We don't create middlemen in LIPO collector subtree, because some target CT - // will do that instead. - Artifact prerequisiteStampFile = (ruleContext != null - && ruleContext.getFragment(CppConfiguration.class).isLipoContextCollector()) - ? getMiddlemanArtifact(middlemanFactory) - : createMiddleman(owner, middlemanFactory); - - return new CcCompilationContextInfo( - new CommandLineCcCompilationContextInfo( - ImmutableList.copyOf(includeDirs), - ImmutableList.copyOf(quoteIncludeDirs), - ImmutableList.copyOf(systemIncludeDirs), - ImmutableList.copyOf(defines)), - prerequisiteStampFile == null - ? ImmutableSet.of() - : ImmutableSet.of(prerequisiteStampFile), - declaredIncludeDirs.build(), - declaredIncludeWarnDirs.build(), - declaredIncludeSrcs.build(), - pregreppedHdrs.build(), - nonCodeInputs.build(), - moduleInfo.build(), - picModuleInfo.build(), - directModuleMaps.build(), - cppModuleMap, - verificationModuleMap, - propagateModuleMapAsActionInput); - } - - /** - * Creates a middleman for the compilation prerequisites. - * - * @return the middleman or null if there are no prerequisites - */ - private Artifact createMiddleman(ActionOwner owner, - MiddlemanFactory middlemanFactory) { - if (compilationPrerequisites.isEmpty()) { - return null; - } - - // Compilation prerequisites gathered in the compilationPrerequisites - // must be generated prior to executing C++ compilation step that depends - // on them (since these prerequisites include all potential header files, etc - // that could be referenced during compilation). So there is a definite need - // to ensure scheduling edge dependency. However, those prerequisites should - // have no effect on the decision whether C++ compilation should happen in - // the first place - only CppCompileAction outputs (*.o and *.d files) and - // all files referenced by the *.d file should be used to make that decision. - // If this action was never executed, then *.d file would be missing, forcing - // compilation to occur. If *.d file is present and has not changed then the - // only reason that would force us to re-compile would be change in one of - // the files referenced by the *.d file, since no other files participated - // in the compilation. We also need to propagate errors through this - // dependency link. So we use an error propagating middleman. - // Such middleman will be ignored by the dependency checker yet will still - // represent an edge in the action dependency graph - forcing proper execution - // order and error propagation. - String name = - cppModuleMap != null ? cppModuleMap.getName() : ruleContext.getLabel().toString(); - return middlemanFactory.createErrorPropagatingMiddleman( - owner, name, purpose, - ImmutableList.copyOf(compilationPrerequisites), - ruleContext.getConfiguration().getMiddlemanDirectory( - ruleContext.getRule().getRepository())); - } - - /** - * Returns the same set of artifacts as createMiddleman() would, but without - * actually creating middlemen. - */ - private Artifact getMiddlemanArtifact(MiddlemanFactory middlemanFactory) { - if (compilationPrerequisites.isEmpty()) { - return null; - } - - return middlemanFactory.getErrorPropagatingMiddlemanArtifact( - ruleContext.getLabel().toString(), - purpose, - ruleContext.getConfiguration().getMiddlemanDirectory( - ruleContext.getRule().getRepository())); - } - } - - /** - * Gathers data about the direct and transitive .pcm files belonging to this context. Can be to - * either gather data on PIC or on no-PIC .pcm files. - */ - @Immutable - @AutoCodec - public static final class ModuleInfo { - /** - * The module built for this context. If null, then no module is being compiled for this - * context. - */ - private final Artifact headerModule; - - /** All header files that are compiled into this module. */ - private final ImmutableSet modularHeaders; - - /** All header files that are contained in this module. */ - private final ImmutableSet textualHeaders; - - /** - * All transitive modules that this context depends on, excluding headerModule. - */ - private final NestedSet transitiveModules; - - /** - * All information about mapping transitive headers to transitive modules. - */ - public final NestedSet transitiveModuleHeaders; - - public ModuleInfo( - Artifact headerModule, - ImmutableSet modularHeaders, - ImmutableSet textualHeaders, - NestedSet transitiveModules, - NestedSet transitiveModuleHeaders) { - this.headerModule = headerModule; - this.modularHeaders = modularHeaders; - this.textualHeaders = textualHeaders; - this.transitiveModules = transitiveModules; - this.transitiveModuleHeaders = transitiveModuleHeaders; - } - - public Collection getUsedModules(Set usedHeaders) { - List result = new ArrayList<>(); - for (TransitiveModuleHeaders transitiveModule : transitiveModuleHeaders) { - if (transitiveModule.module.equals(headerModule)) { - // Do not add the module of the current rule for both: - // 1. the module compile itself - // 2. compiles of other translation units of the same rule. - continue; - } - boolean providesUsedHeader = false; - for (Artifact header : transitiveModule.headers) { - if (usedHeaders.contains(header)) { - providesUsedHeader = true; - break; - } - } - if (providesUsedHeader) { - result.add(transitiveModule); - } - } - return result; - } - - /** - * Builder class for {@link ModuleInfo}. - */ - public static class Builder { - private Artifact headerModule = null; - private final Set modularHeaders = new LinkedHashSet<>(); - private final Set textualHeaders = new LinkedHashSet<>(); - private final NestedSetBuilder transitiveModules = NestedSetBuilder.stableOrder(); - private final NestedSetBuilder transitiveModuleHeaders = - NestedSetBuilder.stableOrder(); - - public Builder setHeaderModule(Artifact headerModule) { - this.headerModule = headerModule; - return this; - } - - public Builder addHeaders(Collection headers) { - this.modularHeaders.addAll(headers); - return this; - } - - public Builder addTextualHeaders(Collection headers) { - this.textualHeaders.addAll(headers); - return this; - } - - /** - * Merges a {@link ModuleInfo} into this one. In contrast to addTransitive, this doesn't add - * the dependent module to transitiveModules, but just merges the transitive sets. The main - * usage is to merge multiple {@link ModuleInfo} instances for Lipo. - */ - public Builder merge(ModuleInfo other) { - if (headerModule == null) { - headerModule = other.headerModule; - } - modularHeaders.addAll(other.modularHeaders); - textualHeaders.addAll(other.textualHeaders); - transitiveModules.addTransitive(other.transitiveModules); - transitiveModuleHeaders.addTransitive(other.transitiveModuleHeaders); - return this; - } - - /** - * Adds the {@link ModuleInfo} of a dependency and builds up the transitive data structures. - */ - public Builder addTransitive(ModuleInfo moduleInfo) { - if (moduleInfo.headerModule != null) { - transitiveModules.add(moduleInfo.headerModule); - } - transitiveModules.addTransitive(moduleInfo.transitiveModules); - transitiveModuleHeaders.addTransitive(moduleInfo.transitiveModuleHeaders); - return this; - } - - public ModuleInfo build() { - ImmutableSet modularHeaders = ImmutableSet.copyOf(this.modularHeaders); - NestedSet transitiveModules = this.transitiveModules.build(); - if (headerModule != null) { - transitiveModuleHeaders.add( - new TransitiveModuleHeaders(headerModule, modularHeaders, transitiveModules)); - } - return new ModuleInfo( - headerModule, - modularHeaders, - ImmutableSet.copyOf(this.textualHeaders), - transitiveModules, - transitiveModuleHeaders.build()); - } - } - } - - /** Collects data for a specific module in a special format that makes pruning easy. */ - @Immutable - @AutoCodec - public static final class TransitiveModuleHeaders { - /** - * The module that we are calculating information for. - */ - private final Artifact module; - - /** - * The headers compiled into this module. - */ - private final ImmutableSet headers; - - /** - * This nested set contains 'module' as well as all targets it transitively depends on. - * If any of the 'headers' is used, all of these modules a required for the compilation. - */ - private final NestedSet transitiveModules; - - public TransitiveModuleHeaders( - Artifact module, - ImmutableSet headers, - NestedSet transitiveModules) { - this.module = module; - this.headers = headers; - this.transitiveModules = transitiveModules; - } - - public Artifact getModule() { - return module; - } - - public Collection getTransitiveModules() { - return transitiveModules.toCollection(); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index 11afab6332..0ce68ce615 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -129,16 +129,16 @@ public final class CcCompilationHelper { private static final Function CPP_DEPS_TO_MODULES = dep -> { CcCompilationInfo ccCompilationInfo = dep.get(CcCompilationInfo.PROVIDER); - CcCompilationContextInfo ccCompilationContextInfo = null; + CcCompilationContext ccCompilationContext = null; if (ccCompilationInfo != null) { - ccCompilationContextInfo = ccCompilationInfo.getCcCompilationContextInfo(); + ccCompilationContext = ccCompilationInfo.getCcCompilationContext(); } - return ccCompilationContextInfo == null ? null : ccCompilationContextInfo.getCppModuleMap(); + return ccCompilationContext == null ? null : ccCompilationContext.getCppModuleMap(); }; /** * Contains the providers as well as the {@code CcCompilationOutputs} and the {@code - * CcCompilationContextInfo}. + * CcCompilationContext}. */ @SkylarkModule( name = "compilation_info", @@ -146,7 +146,7 @@ public final class CcCompilationHelper { category = SkylarkModuleCategory.BUILTIN, doc = "Helper class containing CC compilation providers." ) - // TODO(plf): Rename so that it's not confused with CcCompilationContextInfo and also consider + // TODO(plf): Rename so that it's not confused with CcCompilationContext and also consider // merging // this class with {@code CcCompilationOutputs}. public static final class CompilationInfo { @@ -191,9 +191,9 @@ public final class CcCompilationHelper { return (CcCompilationInfo) providers.getProvider(CcCompilationInfo.PROVIDER.getKey()); } - public CcCompilationContextInfo getCcCompilationContextInfo() { + public CcCompilationContext getCcCompilationContext() { return ((CcCompilationInfo) providers.getProvider(CcCompilationInfo.PROVIDER.getKey())) - .getCcCompilationContextInfo(); + .getCcCompilationContext(); } } @@ -218,7 +218,7 @@ public final class CcCompilationHelper { private CoptsFilter coptsFilter = CoptsFilter.alwaysPasses(); private final Set defines = new LinkedHashSet<>(); private final List deps = new ArrayList<>(); - private final List depCcCompilationContextInfos = new ArrayList<>(); + private final List depCcCompilationContexts = new ArrayList<>(); private final List looseIncludeDirs = new ArrayList<>(); private final List systemIncludeDirs = new ArrayList<>(); private final List includeDirs = new ArrayList<>(); @@ -243,7 +243,7 @@ public final class CcCompilationHelper { private boolean generatePicAction; // TODO(plf): Pull out of class. - private CcCompilationContextInfo ccCompilationContextInfo; + private CcCompilationContext ccCompilationContext; /** * Creates a CcCompilationHelper. @@ -559,9 +559,8 @@ public final class CcCompilationHelper { return this; } - public CcCompilationHelper addDepCcCompilationContextInfo( - CcCompilationContextInfo ccCompilationContextInfo) { - this.depCcCompilationContextInfos.add(Preconditions.checkNotNull(ccCompilationContextInfo)); + public CcCompilationHelper addDepCcCompilationContext(CcCompilationContext ccCompilationContext) { + this.depCcCompilationContexts.add(Preconditions.checkNotNull(ccCompilationContext)); return this; } @@ -711,11 +710,11 @@ public final class CcCompilationHelper { } } - ccCompilationContextInfo = initializeCcCompilationContextInfo(); + ccCompilationContext = initializeCcCompilationContext(); boolean compileHeaderModules = featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES); Preconditions.checkState( - !compileHeaderModules || ccCompilationContextInfo.getCppModuleMap() != null, + !compileHeaderModules || ccCompilationContext.getCppModuleMap() != null, "All cc rules must support module maps."); // Create compile actions (both PIC and no-PIC). @@ -747,7 +746,7 @@ public final class CcCompilationHelper { dwoArtifacts.getDwoArtifacts(), dwoArtifacts.getPicDwoArtifacts()), collectTransitiveLipoInfo(ccOutputs)); CcCompilationInfo.Builder ccCompilationInfoBuilder = CcCompilationInfo.Builder.create(); - ccCompilationInfoBuilder.setCcCompilationContextInfo(ccCompilationContextInfo); + ccCompilationInfoBuilder.setCcCompilationContext(ccCompilationContext); providers.put(ccCompilationInfoBuilder.build()); Map> outputGroups = new TreeMap<>(); @@ -761,7 +760,7 @@ public final class CcCompilationHelper { ccOutputs.getFilesToCompile(isLipoCollector, processHeadersInDependencies, usePic)); outputGroups.put( OutputGroupInfo.COMPILATION_PREREQUISITES, - CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContextInfo)); + CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContext)); } return new CompilationInfo(providers.build(), outputGroups, ccOutputs); @@ -902,13 +901,13 @@ public final class CcCompilationHelper { } /** - * Create {@code CcCompilationContextInfo} for cc compile action from generated inputs. + * Create {@code CcCompilationContext} for cc compile action from generated inputs. * - *

TODO(plf): Try to pull out CcCompilationContextInfo building out of this class. + *

TODO(plf): Try to pull out CcCompilationContext building out of this class. */ - public CcCompilationContextInfo initializeCcCompilationContextInfo() { - CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = - new CcCompilationContextInfo.Builder(ruleContext); + public CcCompilationContext initializeCcCompilationContext() { + CcCompilationContext.Builder ccCompilationContextBuilder = + new CcCompilationContext.Builder(ruleContext); // Setup the include path; local include directories come before those inherited from deps or // from the toolchain; in case of aliasing (same include file found on different entries), @@ -920,63 +919,62 @@ public final class CcCompilationHelper { // we might pick up stale generated files. PathFragment repositoryPath = ruleContext.getLabel().getPackageIdentifier().getRepository().getPathUnderExecRoot(); - ccCompilationContextInfoBuilder.addQuoteIncludeDir(repositoryPath); - ccCompilationContextInfoBuilder.addQuoteIncludeDir( + ccCompilationContextBuilder.addQuoteIncludeDir(repositoryPath); + ccCompilationContextBuilder.addQuoteIncludeDir( ruleContext.getConfiguration().getGenfilesFragment().getRelative(repositoryPath)); for (PathFragment systemIncludeDir : systemIncludeDirs) { - ccCompilationContextInfoBuilder.addSystemIncludeDir(systemIncludeDir); + ccCompilationContextBuilder.addSystemIncludeDir(systemIncludeDir); } for (PathFragment includeDir : includeDirs) { - ccCompilationContextInfoBuilder.addIncludeDir(includeDir); + ccCompilationContextBuilder.addIncludeDir(includeDir); } PublicHeaders publicHeaders = computePublicHeaders(); if (publicHeaders.getVirtualIncludePath() != null) { - ccCompilationContextInfoBuilder.addIncludeDir(publicHeaders.getVirtualIncludePath()); + ccCompilationContextBuilder.addIncludeDir(publicHeaders.getVirtualIncludePath()); } if (useDeps) { - ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( - CcCompilationInfo.getCcCompilationContextInfos(deps)); - ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( - depCcCompilationContextInfos); + ccCompilationContextBuilder.mergeDependentCcCompilationContexts( + CcCompilationInfo.getCcCompilationContexts(deps)); + ccCompilationContextBuilder.mergeDependentCcCompilationContexts(depCcCompilationContexts); } - CppHelper.mergeToolchainDependentCcCompilationContextInfo( - ruleContext, ccToolchain, ccCompilationContextInfoBuilder); + CppHelper.mergeToolchainDependentCcCompilationContext( + ruleContext, ccToolchain, ccCompilationContextBuilder); // But defines come after those inherited from deps. - ccCompilationContextInfoBuilder.addDefines(defines); + ccCompilationContextBuilder.addDefines(defines); // There are no ordering constraints for declared include dirs/srcs, or the pregrepped headers. - ccCompilationContextInfoBuilder.addDeclaredIncludeSrcs(publicHeaders.getHeaders()); - ccCompilationContextInfoBuilder.addDeclaredIncludeSrcs(publicTextualHeaders); - ccCompilationContextInfoBuilder.addDeclaredIncludeSrcs(privateHeaders); - ccCompilationContextInfoBuilder.addDeclaredIncludeSrcs(additionalInputs); - ccCompilationContextInfoBuilder.addNonCodeInputs(additionalInputs); - ccCompilationContextInfoBuilder.addModularHdrs(publicHeaders.getHeaders()); - ccCompilationContextInfoBuilder.addModularHdrs(privateHeaders); - ccCompilationContextInfoBuilder.addTextualHdrs(publicTextualHeaders); - ccCompilationContextInfoBuilder.addPregreppedHeaders( + ccCompilationContextBuilder.addDeclaredIncludeSrcs(publicHeaders.getHeaders()); + ccCompilationContextBuilder.addDeclaredIncludeSrcs(publicTextualHeaders); + ccCompilationContextBuilder.addDeclaredIncludeSrcs(privateHeaders); + ccCompilationContextBuilder.addDeclaredIncludeSrcs(additionalInputs); + ccCompilationContextBuilder.addNonCodeInputs(additionalInputs); + ccCompilationContextBuilder.addModularHdrs(publicHeaders.getHeaders()); + ccCompilationContextBuilder.addModularHdrs(privateHeaders); + ccCompilationContextBuilder.addTextualHdrs(publicTextualHeaders); + ccCompilationContextBuilder.addPregreppedHeaders( CppHelper.createExtractInclusions(ruleContext, semantics, publicHeaders.getHeaders())); - ccCompilationContextInfoBuilder.addPregreppedHeaders( + ccCompilationContextBuilder.addPregreppedHeaders( CppHelper.createExtractInclusions(ruleContext, semantics, publicTextualHeaders)); - ccCompilationContextInfoBuilder.addPregreppedHeaders( + ccCompilationContextBuilder.addPregreppedHeaders( CppHelper.createExtractInclusions(ruleContext, semantics, privateHeaders)); // Add this package's dir to declaredIncludeDirs, & this rule's headers to declaredIncludeSrcs // Note: no include dir for STRICT mode. if (headersCheckingMode == HeadersCheckingMode.WARN) { - ccCompilationContextInfoBuilder.addDeclaredIncludeWarnDir( + ccCompilationContextBuilder.addDeclaredIncludeWarnDir( ruleContext.getLabel().getPackageFragment()); for (PathFragment looseIncludeDir : looseIncludeDirs) { - ccCompilationContextInfoBuilder.addDeclaredIncludeWarnDir(looseIncludeDir); + ccCompilationContextBuilder.addDeclaredIncludeWarnDir(looseIncludeDir); } } else if (headersCheckingMode == HeadersCheckingMode.LOOSE) { - ccCompilationContextInfoBuilder.addDeclaredIncludeDir( + ccCompilationContextBuilder.addDeclaredIncludeDir( ruleContext.getLabel().getPackageFragment()); for (PathFragment looseIncludeDir : looseIncludeDirs) { - ccCompilationContextInfoBuilder.addDeclaredIncludeDir(looseIncludeDir); + ccCompilationContextBuilder.addDeclaredIncludeDir(looseIncludeDir); } } @@ -985,9 +983,9 @@ public final class CcCompilationHelper { cppModuleMap = CppHelper.createDefaultCppModuleMap(ruleContext, /*suffix=*/ ""); } - ccCompilationContextInfoBuilder.setPropagateCppModuleMapAsActionInput( + ccCompilationContextBuilder.setPropagateCppModuleMapAsActionInput( propagateModuleMapToCompileAction); - ccCompilationContextInfoBuilder.setCppModuleMap(cppModuleMap); + ccCompilationContextBuilder.setCppModuleMap(cppModuleMap); // There are different modes for module compilation: // 1. We create the module map and compile the module so that libraries depending on us can // use the resulting module artifacts in their compilation (compiled is true). @@ -1009,12 +1007,11 @@ public final class CcCompilationHelper { createModuleMapAction(cppModuleMap, publicHeaders, dependentModuleMaps, compiled)); } if (getGeneratesPicHeaderModule()) { - ccCompilationContextInfoBuilder.setPicHeaderModule( + ccCompilationContextBuilder.setPicHeaderModule( getPicHeaderModule(cppModuleMap.getArtifact())); } if (getGeneratesNoPicHeaderModule()) { - ccCompilationContextInfoBuilder.setHeaderModule( - getHeaderModule(cppModuleMap.getArtifact())); + ccCompilationContextBuilder.setHeaderModule(getHeaderModule(cppModuleMap.getArtifact())); } if (!compiled && featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS) @@ -1028,13 +1025,13 @@ public final class CcCompilationHelper { ruleContext.registerAction( createModuleMapAction( verificationMap, publicHeaders, dependentModuleMaps, /*compiledModule=*/ true)); - ccCompilationContextInfoBuilder.setVerificationModuleMap(verificationMap); + ccCompilationContextBuilder.setVerificationModuleMap(verificationMap); } } - ccCompilationContextInfoBuilder.setPurpose(purpose); + ccCompilationContextBuilder.setPurpose(purpose); - semantics.setupCcCompilationContextInfo(ruleContext, ccCompilationContextInfoBuilder); - return ccCompilationContextInfoBuilder.build(); + semantics.setupCcCompilationContext(ruleContext, ccCompilationContextBuilder); + return ccCompilationContextBuilder.build(); } /** @@ -1064,9 +1061,9 @@ public final class CcCompilationHelper { } /** - * Sets the purpose for the {@code CcCompilationContextInfo}. + * Sets the purpose for the {@code CcCompilationContext}. * - * @see CcCompilationContextInfo.Builder#setPurpose + * @see CcCompilationContext.Builder#setPurpose * @param purpose must be a string which is suitable for use as a filename. A single rule may have * many middlemen with distinct purposes. */ @@ -1116,12 +1113,12 @@ public final class CcCompilationHelper { CcCompilationInfo stl = ruleContext.getPrerequisite(":stl", Mode.TARGET, CcCompilationInfo.PROVIDER); if (stl != null) { - result.add(stl.getCcCompilationContextInfo().getCppModuleMap()); + result.add(stl.getCcCompilationContext().getCppModuleMap()); } } if (ccToolchain != null) { - result.add(ccToolchain.getCcCompilationContextInfo().getCppModuleMap()); + result.add(ccToolchain.getCcCompilationContext().getCppModuleMap()); } for (CppModuleMap additionalCppModuleMap : additionalCppModuleMaps) { result.add(additionalCppModuleMap); @@ -1284,14 +1281,14 @@ public final class CcCompilationHelper { */ private CcCompilationOutputs createCcCompileActions() throws RuleErrorException { CcCompilationOutputs.Builder result = new CcCompilationOutputs.Builder(); - Preconditions.checkNotNull(ccCompilationContextInfo); + Preconditions.checkNotNull(ccCompilationContext); AnalysisEnvironment env = ruleContext.getAnalysisEnvironment(); if (shouldProvideHeaderModules()) { Label moduleMapLabel = - Label.parseAbsoluteUnchecked(ccCompilationContextInfo.getCppModuleMap().getName()); + Label.parseAbsoluteUnchecked(ccCompilationContext.getCppModuleMap().getName()); Collection modules = - createModuleAction(result, ccCompilationContextInfo.getCppModuleMap()); + createModuleAction(result, ccCompilationContext.getCppModuleMap()); if (featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULE_CODEGEN)) { for (Artifact module : modules) { // TODO(djasper): Investigate whether we need to use a label separate from that of the @@ -1299,9 +1296,9 @@ public final class CcCompilationHelper { createModuleCodegenAction(result, moduleMapLabel, module); } } - } else if (ccCompilationContextInfo.getVerificationModuleMap() != null) { + } else if (ccCompilationContext.getVerificationModuleMap() != null) { Collection modules = - createModuleAction(result, ccCompilationContextInfo.getVerificationModuleMap()); + createModuleAction(result, ccCompilationContext.getVerificationModuleMap()); for (Artifact module : modules) { result.addHeaderTokenFile(module); } @@ -1356,7 +1353,7 @@ public final class CcCompilationHelper { source.getType() == CppSource.Type.CLIF_INPUT_PROTO ? ArtifactCategory.CLIF_OUTPUT_PROTO : ArtifactCategory.OBJECT_FILE, - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* addObject= */ true, isCodeCoverageEnabled(), // The source action does not generate dwo when it has bitcode @@ -1433,7 +1430,7 @@ public final class CcCompilationHelper { usePic, /* ccRelativeName= */ null, /* autoFdoImportPath= */ null, - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -1535,11 +1532,11 @@ public final class CcCompilationHelper { dotdFileExecPath, ImmutableList.copyOf(variablesExtensions), allAdditionalBuildVariables.build(), - ccCompilationContextInfo.getDirectModuleMaps(), - ccCompilationContextInfo.getIncludeDirs(), - ccCompilationContextInfo.getQuoteIncludeDirs(), - ccCompilationContextInfo.getSystemIncludeDirs(), - ccCompilationContextInfo.getDefines()); + ccCompilationContext.getDirectModuleMaps(), + ccCompilationContext.getIncludeDirs(), + ccCompilationContext.getQuoteIncludeDirs(), + ccCompilationContext.getSystemIncludeDirs(), + ccCompilationContext.getDefines()); } private static String toPathString(Artifact a) { @@ -1559,13 +1556,13 @@ public final class CcCompilationHelper { /** * Creates a basic cpp compile action builder for source file. Configures options, crosstool - * inputs, output and dotd file names, {@code CcCompilationContextInfo} and copts. + * inputs, output and dotd file names, {@code CcCompilationContext} and copts. */ private CppCompileActionBuilder createCompileActionBuilder(Artifact source) { CppCompileActionBuilder builder = new CppCompileActionBuilder(ruleContext, ccToolchain, configuration); builder.setSourceFile(source); - builder.setCcCompilationContextInfo(ccCompilationContextInfo); + builder.setCcCompilationContext(ccCompilationContext); builder.setCoptsFilter(coptsFilter); return builder; } @@ -1618,7 +1615,7 @@ public final class CcCompilationHelper { /* usePic= */ pic, ccRelativeName, module.getExecPath(), - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), gcnoFile, dwoFile, /* ltoIndexingFile= */ null, @@ -1669,7 +1666,7 @@ public final class CcCompilationHelper { generatePicAction, /* ccRelativeName= */ null, /* autoFdoImportPath= */ null, - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -1730,14 +1727,14 @@ public final class CcCompilationHelper { ImmutableList.Builder directOutputs = new ImmutableList.Builder<>(); PathFragment ccRelativeName = sourceArtifact.getRootRelativePath(); if (CppHelper.isLipoOptimization(cppConfiguration, ccToolchain)) { - // TODO(bazel-team): we shouldn't be needing this, merging ccCompilationContextInfo with the + // TODO(bazel-team): we shouldn't be needing this, merging ccCompilationContext with the // binary // is a superset of necessary information. LipoContextProvider lipoProvider = Preconditions.checkNotNull(CppHelper.getLipoContextProvider(ruleContext), outputName); - builder.setCcCompilationContextInfo( - CcCompilationContextInfo.mergeForLipo( - lipoProvider.getLipoCcCompilationContextInfo(), ccCompilationContextInfo)); + builder.setCcCompilationContext( + CcCompilationContext.mergeForLipo( + lipoProvider.getLipoCcCompilationContext(), ccCompilationContext)); } Preconditions.checkState(generatePicAction || generateNoPicAction); if (fake) { @@ -1786,7 +1783,7 @@ public final class CcCompilationHelper { /* usePic= */ true, ccRelativeName, sourceArtifact.getExecPath(), - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), gcnoFile, dwoFile, ltoIndexingFile, @@ -1961,7 +1958,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, execPath, - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -2002,7 +1999,7 @@ public final class CcCompilationHelper { for (TransitiveInfoCollection dep : ruleContext.getPrerequisites("deps", Mode.TARGET)) { CcCompilationInfo ccCompilationInfo = dep.get(CcCompilationInfo.PROVIDER); if (ccCompilationInfo != null - && ccCompilationInfo.getCcCompilationContextInfo() != null + && ccCompilationInfo.getCcCompilationContext() != null && InstrumentedFilesCollector.shouldIncludeLocalSources(configuration, dep)) { return true; } @@ -2071,7 +2068,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, source.getExecPath(), - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -2093,7 +2090,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, source.getExecPath(), - ccCompilationContextInfo.getCppModuleMap(), + ccCompilationContext.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java index cba5d39184..6879ee5341 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java @@ -41,57 +41,56 @@ public final class CcCompilationInfo extends NativeInfo { public static final NativeProvider PROVIDER = new NativeProvider(CcCompilationInfo.class, "CcCompilationInfo") {}; - private final CcCompilationContextInfo ccCompilationContextInfo; + private final CcCompilationContext ccCompilationContext; @AutoCodec.Instantiator @VisibleForSerialization - CcCompilationInfo(CcCompilationContextInfo ccCompilationContextInfo) { + CcCompilationInfo(CcCompilationContext ccCompilationContext) { super(PROVIDER); - this.ccCompilationContextInfo = ccCompilationContextInfo; + this.ccCompilationContext = ccCompilationContext; } @SkylarkCallable( - name = "cc_compilation_context_info", + name = "cc_compilation_context", structField = true, allowReturnNones = true, doc = "Returns compilation information for this C++ target." ) - public CcCompilationContextInfo getCcCompilationContextInfo() { - return ccCompilationContextInfo; + public CcCompilationContext getCcCompilationContext() { + return ccCompilationContext; } /** A Builder for {@link CcCompilationInfo}. */ public static class Builder { - CcCompilationContextInfo ccCompilationContextInfo; + CcCompilationContext ccCompilationContext; public static CcCompilationInfo.Builder create() { return new CcCompilationInfo.Builder(); } - public

Builder setCcCompilationContextInfo( - CcCompilationContextInfo ccCompilationContextInfo) { - Preconditions.checkState(this.ccCompilationContextInfo == null); - this.ccCompilationContextInfo = ccCompilationContextInfo; + public

Builder setCcCompilationContext( + CcCompilationContext ccCompilationContext) { + Preconditions.checkState(this.ccCompilationContext == null); + this.ccCompilationContext = ccCompilationContext; return this; } public CcCompilationInfo build() { - return new CcCompilationInfo(ccCompilationContextInfo); + return new CcCompilationInfo(ccCompilationContext); } } - public static ImmutableList getCcCompilationContextInfos( + public static ImmutableList getCcCompilationContexts( Iterable deps) { - ImmutableList.Builder ccCompilationContextInfosBuilder = + ImmutableList.Builder ccCompilationContextsBuilder = ImmutableList.builder(); for (CcCompilationInfo ccCompilationInfo : AnalysisUtils.getProviders(deps, CcCompilationInfo.PROVIDER)) { - CcCompilationContextInfo ccCompilationContextInfo = - ccCompilationInfo.getCcCompilationContextInfo(); - if (ccCompilationContextInfo != null) { - ccCompilationContextInfosBuilder.add(ccCompilationContextInfo); + CcCompilationContext ccCompilationContext = ccCompilationInfo.getCcCompilationContext(); + if (ccCompilationContext != null) { + ccCompilationContextsBuilder.add(ccCompilationContext); } } - return ccCompilationContextInfosBuilder.build(); + return ccCompilationContextsBuilder.build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java index b0537a2a66..373d2d5747 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java @@ -170,8 +170,7 @@ public abstract class CcImport implements RuleConfiguredTargetFactory { LinkingInfo linkingInfo = linkingHelper.link( - compilationInfo.getCcCompilationOutputs(), - compilationInfo.getCcCompilationContextInfo()); + compilationInfo.getCcCompilationOutputs(), compilationInfo.getCcCompilationContext()); return new RuleConfiguredTargetBuilder(ruleContext) .addProviders(compilationInfo.getProviders()) 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 3399f0845a..cd883d1d35 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 @@ -290,8 +290,7 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { CompilationInfo compilationInfo = compilationHelper.compile(); LinkingInfo linkingInfo = linkingHelper.link( - compilationInfo.getCcCompilationOutputs(), - compilationInfo.getCcCompilationContextInfo()); + compilationInfo.getCcCompilationOutputs(), compilationInfo.getCcCompilationContext()); /* * We always generate a static library, even if there aren't any source files. 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 3941926f45..4ad7a1b030 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 @@ -330,10 +330,10 @@ public final class CcLinkParams { /** Adds a collection of linkstamps. */ public Builder addLinkstamps( - NestedSet linkstamps, CcCompilationContextInfo ccCompilationContextInfo) { + NestedSet linkstamps, CcCompilationContext ccCompilationContext) { for (Artifact linkstamp : linkstamps) { linkstampsBuilder.add( - new Linkstamp(linkstamp, ccCompilationContextInfo.getDeclaredIncludeSrcs())); + new Linkstamp(linkstamp, ccCompilationContext.getDeclaredIncludeSrcs())); } return this; } 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 5683e08200..e9ee36a498 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 @@ -438,14 +438,13 @@ public final class CcLinkingHelper { * * @throws RuleErrorException */ - // TODO(b/73997894): Try to remove CcCompilationContextInfo. Right now headers are passed as non + // TODO(b/73997894): Try to remove CcCompilationContext. Right now headers are passed as non // code // inputs to the linker. - public LinkingInfo link( - CcCompilationOutputs ccOutputs, CcCompilationContextInfo ccCompilationContextInfo) + public LinkingInfo link(CcCompilationOutputs ccOutputs, CcCompilationContext ccCompilationContext) throws RuleErrorException, InterruptedException { Preconditions.checkNotNull(ccOutputs); - Preconditions.checkNotNull(ccCompilationContextInfo); + Preconditions.checkNotNull(ccCompilationContext); if (checkDepsGenerateCpp) { for (LanguageDependentFragment dep : @@ -551,11 +550,11 @@ public final class CcLinkingHelper { if (emitCcSpecificLinkParamsProvider) { providers.add( new CcSpecificLinkParamsProvider( - createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); + createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } else { ccLinkingInfoBuilder.setCcLinkParamsInfo( new CcLinkParamsInfo( - createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); + createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } providers.put(ccLinkingInfoBuilder.build()); return new LinkingInfo( @@ -637,13 +636,13 @@ public final class CcLinkingHelper { private CcLinkParamsStore createCcLinkParamsStore( final CcLinkingOutputs ccLinkingOutputs, - final CcCompilationContextInfo ccCompilationContextInfo, + final CcCompilationContext ccCompilationContext, final boolean forcePic) { return new CcLinkParamsStore() { @Override protected void collect( CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { - builder.addLinkstamps(linkstamps.build(), ccCompilationContextInfo); + builder.addLinkstamps(linkstamps.build(), ccCompilationContext); builder.addTransitiveTargets( deps, CcLinkParamsInfo.TO_LINK_PARAMS, CcSpecificLinkParamsProvider.TO_LINK_PARAMS); if (!neverlink) { 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 3d4fc9bcc5..88c959de22 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 @@ -50,9 +50,9 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { + " src or headers attribute" + "(possibly empty but never None).") public NestedSet getTransitiveHeaders() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - return ccCompilationContextInfo.getDeclaredIncludeSrcs(); + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + return ccCompilationContext.getDeclaredIncludeSrcs(); } @SkylarkCallable( @@ -102,11 +102,11 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { "Returns the list of defines used to compile this target " + "(possibly empty but never None).") public ImmutableList getDefines() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - return ccCompilationContextInfo == null + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + return ccCompilationContext == null ? ImmutableList.of() - : ccCompilationContextInfo.getDefines(); + : ccCompilationContext.getDefines(); } @SkylarkCallable( @@ -116,13 +116,13 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { "Returns the list of system include directories used to compile this target " + "(possibly empty but never None).") public ImmutableList getSystemIncludeDirs() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - if (ccCompilationContextInfo == null) { + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + if (ccCompilationContext == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationContextInfo.getSystemIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getSystemIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -135,13 +135,13 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { "Returns the list of include directories used to compile this target " + "(possibly empty but never None).") public ImmutableList getIncludeDirs() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - if (ccCompilationContextInfo == null) { + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + if (ccCompilationContext == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationContextInfo.getIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -154,13 +154,13 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { "Returns the list of quote include directories used to compile this target " + "(possibly empty but never None).") public ImmutableList getQuoteIncludeDirs() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - if (ccCompilationContextInfo == null) { + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + if (ccCompilationContext == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationContextInfo.getQuoteIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getQuoteIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -173,20 +173,20 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { "Returns the list of flags used to compile this target " + "(possibly empty but never None).") public ImmutableList getCcFlags() { - CcCompilationContextInfo ccCompilationContextInfo = - getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); + CcCompilationContext ccCompilationContext = + getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); ImmutableList.Builder options = ImmutableList.builder(); - for (String define : ccCompilationContextInfo.getDefines()) { + for (String define : ccCompilationContext.getDefines()) { options.add("-D" + define); } - for (PathFragment path : ccCompilationContextInfo.getSystemIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getSystemIncludeDirs()) { options.add("-isystem " + path.getSafePathString()); } - for (PathFragment path : ccCompilationContextInfo.getIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getIncludeDirs()) { options.add("-I " + path.getSafePathString()); } - for (PathFragment path : ccCompilationContextInfo.getQuoteIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getQuoteIncludeDirs()) { options.add("-iquote " + path.getSafePathString()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java index 77d4606f2a..7e92423e94 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java @@ -480,14 +480,13 @@ public class CcToolchain implements RuleConfiguredTargetFactory { Preconditions.checkState( (dynamicRuntimeLinkMiddleman == null) == dynamicRuntimeLinkSymlinks.isEmpty()); - CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = - new CcCompilationContextInfo.Builder(ruleContext); + CcCompilationContext.Builder ccCompilationContextBuilder = + new CcCompilationContext.Builder(ruleContext); CppModuleMap moduleMap = createCrosstoolModuleMap(ruleContext); if (moduleMap != null) { - ccCompilationContextInfoBuilder.setCppModuleMap(moduleMap); + ccCompilationContextBuilder.setCppModuleMap(moduleMap); } - final CcCompilationContextInfo ccCompilationContextInfo = - ccCompilationContextInfoBuilder.build(); + final CcCompilationContext ccCompilationContext = ccCompilationContextBuilder.build(); boolean supportsParamFiles = ruleContext.attributes().get("supports_param_files", BOOLEAN); boolean supportsHeaderParsing = ruleContext.attributes().get("supports_header_parsing", BOOLEAN); @@ -557,7 +556,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { dynamicRuntimeLinkSymlinks, dynamicRuntimeLinkMiddleman, runtimeSolibDir, - ccCompilationContextInfo, + ccCompilationContext, supportsParamFiles, supportsHeaderParsing, getBuildVariables(ruleContext, toolchainInfo.getDefaultSysroot()), diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java index 913fe2cf17..66650d016d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java @@ -75,7 +75,7 @@ public final class CcToolchainProvider extends ToolchainInfo { /* dynamicRuntimeLinkInputs= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), /* dynamicRuntimeLinkMiddleman= */ null, /* dynamicRuntimeSolibDir= */ PathFragment.EMPTY_FRAGMENT, - CcCompilationContextInfo.EMPTY, + CcCompilationContext.EMPTY, /* supportsParamFiles= */ false, /* supportsHeaderParsing= */ false, Variables.EMPTY, @@ -109,7 +109,7 @@ public final class CcToolchainProvider extends ToolchainInfo { private final NestedSet dynamicRuntimeLinkInputs; @Nullable private final Artifact dynamicRuntimeLinkMiddleman; private final PathFragment dynamicRuntimeSolibDir; - private final CcCompilationContextInfo ccCompilationContextInfo; + private final CcCompilationContext ccCompilationContext; private final boolean supportsParamFiles; private final boolean supportsHeaderParsing; private final Variables buildVariables; @@ -147,7 +147,7 @@ public final class CcToolchainProvider extends ToolchainInfo { NestedSet dynamicRuntimeLinkInputs, @Nullable Artifact dynamicRuntimeLinkMiddleman, PathFragment dynamicRuntimeSolibDir, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, boolean supportsParamFiles, boolean supportsHeaderParsing, Variables buildVariables, @@ -181,7 +181,7 @@ public final class CcToolchainProvider extends ToolchainInfo { this.dynamicRuntimeLinkInputs = Preconditions.checkNotNull(dynamicRuntimeLinkInputs); this.dynamicRuntimeLinkMiddleman = dynamicRuntimeLinkMiddleman; this.dynamicRuntimeSolibDir = Preconditions.checkNotNull(dynamicRuntimeSolibDir); - this.ccCompilationContextInfo = Preconditions.checkNotNull(ccCompilationContextInfo); + this.ccCompilationContext = Preconditions.checkNotNull(ccCompilationContext); this.supportsParamFiles = supportsParamFiles; this.supportsHeaderParsing = supportsHeaderParsing; this.buildVariables = buildVariables; @@ -434,9 +434,9 @@ public final class CcToolchainProvider extends ToolchainInfo { return dynamicRuntimeSolibDir; } - /** Returns the {@code CcCompilationContextInfo} for the toolchain. */ - public CcCompilationContextInfo getCcCompilationContextInfo() { - return ccCompilationContextInfo; + /** Returns the {@code CcCompilationContext} for the toolchain. */ + public CcCompilationContext getCcCompilationContext() { + return ccCompilationContext; } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java index f9c2f662af..166805d066 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java @@ -56,19 +56,19 @@ public enum CompileBuildVariables { /** * Variable for the collection of include paths. * - * @see CcCompilationContextInfo#getIncludeDirs(). + * @see CcCompilationContext#getIncludeDirs(). */ INCLUDE_PATHS("include_paths"), /** * Variable for the collection of quote include paths. * - * @see CcCompilationContextInfo#getIncludeDirs(). + * @see CcCompilationContext#getIncludeDirs(). */ QUOTE_INCLUDE_PATHS("quote_include_paths"), /** * Variable for the collection of system include paths. * - * @see CcCompilationContextInfo#getIncludeDirs(). + * @see CcCompilationContext#getIncludeDirs(). */ SYSTEM_INCLUDE_PATHS("system_include_paths"), /** Variable for the module map file name. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index 8b43ac1dae..9ff24cf011 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -182,7 +182,7 @@ public class CppCompileAction extends AbstractAction protected final boolean needsIncludeValidation; private final IncludeProcessing includeProcessing; - private final CcCompilationContextInfo ccCompilationContextInfo; + private final CcCompilationContext ccCompilationContext; private final Iterable lipoScannables; private final ImmutableList builtinIncludeFiles; // A list of files to include scan that are not source files, pcm files, lipo scannables, or @@ -246,7 +246,7 @@ public class CppCompileAction extends AbstractAction * @param dwoFile the .dwo output file where debug information is stored for Fission builds (null * if Fission mode is disabled) * @param optionalSourceFile an additional optional source file (null if unneeded) - * @param ccCompilationContextInfo the {@code CcCompilationContextInfo} + * @param ccCompilationContext the {@code CcCompilationContext} * @param coptsFilter regular expression to remove options from {@code copts} * @param lipoScannables List of artifacts to include-scan when this action is a lipo action * @param additionalIncludeScanningRoots list of additional artifacts to include-scan @@ -278,7 +278,7 @@ public class CppCompileAction extends AbstractAction @Nullable Artifact ltoIndexingFile, Artifact optionalSourceFile, ImmutableMap localShellEnvironment, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, CoptsFilter coptsFilter, Iterable lipoScannables, ImmutableList additionalIncludeScanningRoots, @@ -315,7 +315,7 @@ public class CppCompileAction extends AbstractAction usePic, useHeaderModules, isStrictSystemIncludes, - ccCompilationContextInfo, + ccCompilationContext, lipoScannables, builtinIncludeFiles, ImmutableList.copyOf(additionalIncludeScanningRoots), @@ -357,7 +357,7 @@ public class CppCompileAction extends AbstractAction boolean usePic, boolean useHeaderModules, boolean isStrictSystemIncludes, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, Iterable lipoScannables, ImmutableList builtinIncludeFiles, ImmutableList additionalIncludeScanningRoots, @@ -389,7 +389,7 @@ public class CppCompileAction extends AbstractAction this.usePic = usePic; this.useHeaderModules = useHeaderModules; this.isStrictSystemIncludes = isStrictSystemIncludes; - this.ccCompilationContextInfo = ccCompilationContextInfo; + this.ccCompilationContext = ccCompilationContext; this.lipoScannables = lipoScannables; this.builtinIncludeFiles = builtinIncludeFiles; this.additionalIncludeScanningRoots = additionalIncludeScanningRoots; @@ -501,9 +501,8 @@ public class CppCompileAction extends AbstractAction // Here, we cannot really know what the top-level modules are, so we just mark all // transitive modules as "top level". topLevelModules = - Sets.newLinkedHashSet( - ccCompilationContextInfo.getTransitiveModules(usePic).toCollection()); - result.addTransitive(ccCompilationContextInfo.getTransitiveModules(usePic)); + Sets.newLinkedHashSet(ccCompilationContext.getTransitiveModules(usePic).toCollection()); + result.addTransitive(ccCompilationContext.getTransitiveModules(usePic)); } result.addTransitive(prunableInputs); return result.build(); @@ -526,8 +525,8 @@ public class CppCompileAction extends AbstractAction } else { usedModules = Sets.newLinkedHashSet(); topLevelModules = null; - for (CcCompilationContextInfo.TransitiveModuleHeaders usedModule : - ccCompilationContextInfo.getUsedModules(usePic, initialResultSet)) { + for (CcCompilationContext.TransitiveModuleHeaders usedModule : + ccCompilationContext.getUsedModules(usePic, initialResultSet)) { usedModules.add(usedModule.getModule()); } initialResultSet.addAll(usedModules); @@ -619,12 +618,12 @@ public class CppCompileAction extends AbstractAction public Map getLegalGeneratedScannerFileMap() { Map legalOuts = new HashMap<>(); - for (Artifact a : ccCompilationContextInfo.getDeclaredIncludeSrcs()) { + for (Artifact a : ccCompilationContext.getDeclaredIncludeSrcs()) { if (!a.isSourceArtifact()) { legalOuts.put(a, null); } } - for (PregreppedHeader pregreppedSrcs : ccCompilationContextInfo.getPregreppedHeaders()) { + for (PregreppedHeader pregreppedSrcs : ccCompilationContext.getPregreppedHeaders()) { Artifact hdr = pregreppedSrcs.originalHeader(); Preconditions.checkState(!hdr.isSourceArtifact(), hdr); legalOuts.put(hdr, pregreppedSrcs.greppedHeader()); @@ -647,19 +646,19 @@ public class CppCompileAction extends AbstractAction } @VisibleForTesting - public CcCompilationContextInfo getCcCompilationContextInfo() { - return ccCompilationContextInfo; + public CcCompilationContext getCcCompilationContext() { + return ccCompilationContext; } @Override public List getQuoteIncludeDirs() { - return ccCompilationContextInfo.getQuoteIncludeDirs(); + return ccCompilationContext.getQuoteIncludeDirs(); } @Override public List getIncludeDirs() { ImmutableList.Builder result = ImmutableList.builder(); - result.addAll(ccCompilationContextInfo.getIncludeDirs()); + result.addAll(ccCompilationContext.getIncludeDirs()); for (String opt : compileCommandLine.getCopts()) { if (opt.startsWith("-I") && opt.length() > 2) { // We insist on the combined form "-Idir". @@ -676,7 +675,7 @@ public class CppCompileAction extends AbstractAction // system_includes attribute in cc_toolchain); note that that would disallow users from // specifying system include paths via the copts attribute. // Currently, this works together with the include_paths features because getCommandLine() will - // get the system include paths from the {@code CcCompilationContextInfo} instead. + // get the system include paths from the {@code CcCompilationContext} instead. ImmutableList.Builder result = ImmutableList.builder(); List compilerOptions = getCompilerOptions(); for (int i = 0; i < compilerOptions.size(); i++) { @@ -711,7 +710,7 @@ public class CppCompileAction extends AbstractAction @Override public Artifact getMainIncludeScannerSource() { return getSourceFile().isFileType(CppFileTypes.CPP_MODULE_MAP) - ? Iterables.getFirst(ccCompilationContextInfo.getHeaderModuleSrcs(), null) + ? Iterables.getFirst(ccCompilationContext.getHeaderModuleSrcs(), null) : getSourceFile(); } @@ -723,7 +722,7 @@ public class CppCompileAction extends AbstractAction // module map, and we need to include-scan all headers that are referenced in the module map. // We need to do include scanning as long as we want to support building code bases that are // not fully strict layering clean. - builder.addAll(ccCompilationContextInfo.getHeaderModuleSrcs()); + builder.addAll(ccCompilationContext.getHeaderModuleSrcs()); } else { builder.add(getSourceFile()); builder.addAll(additionalIncludeScanningRoots); @@ -742,7 +741,7 @@ public class CppCompileAction extends AbstractAction */ @VisibleForTesting public ImmutableCollection getDefines() { - return ccCompilationContextInfo.getDefines(); + return ccCompilationContext.getDefines(); } @Override @@ -784,7 +783,7 @@ public class CppCompileAction extends AbstractAction } else { info.addSourcesAndHeaders(getSourceFile().getExecPathString()); info.addAllSourcesAndHeaders( - Artifact.toExecPaths(ccCompilationContextInfo.getDeclaredIncludeSrcs())); + Artifact.toExecPaths(ccCompilationContext.getDeclaredIncludeSrcs())); } for (Map.Entry envVariable : getEnvironment().entrySet()) { info.addVariable( @@ -858,14 +857,14 @@ public class CppCompileAction extends AbstractAction // Copy the sets to hash sets for fast contains checking. // Avoid immutable sets here to limit memory churn. Set declaredIncludeDirs = - Sets.newHashSet(ccCompilationContextInfo.getDeclaredIncludeDirs()); + Sets.newHashSet(ccCompilationContext.getDeclaredIncludeDirs()); Set warnIncludeDirs = - Sets.newHashSet(ccCompilationContextInfo.getDeclaredIncludeWarnDirs()); + Sets.newHashSet(ccCompilationContext.getDeclaredIncludeWarnDirs()); Set declaredIncludeSrcs = Sets.newHashSet(getDeclaredIncludeSrcs()); Set transitiveModules = - Sets.newHashSet(ccCompilationContextInfo.getTransitiveModules(usePic)); + Sets.newHashSet(ccCompilationContext.getTransitiveModules(usePic)); for (Artifact input : inputsForValidation) { - if (ccCompilationContextInfo.getTransitiveCompilationPrerequisites().contains(input) + if (ccCompilationContext.getTransitiveCompilationPrerequisites().contains(input) || transitiveModules.contains(input) || allowedIncludes.contains(input)) { continue; // ignore our fixed source in mandatoryInput: we just want includes @@ -896,21 +895,20 @@ public class CppCompileAction extends AbstractAction System.err.println("INFO: Include(s) were OK for '" + getSourceFile() + "', declared srcs:"); } - for (Artifact a : ccCompilationContextInfo.getDeclaredIncludeSrcs()) { + for (Artifact a : ccCompilationContext.getDeclaredIncludeSrcs()) { System.err.println(" '" + a.toDetailString() + "'"); } System.err.println(" or under declared dirs:"); - for (PathFragment f : - Sets.newTreeSet(ccCompilationContextInfo.getDeclaredIncludeDirs())) { + for (PathFragment f : Sets.newTreeSet(ccCompilationContext.getDeclaredIncludeDirs())) { System.err.println(" '" + f + "'"); } System.err.println(" or under declared warn dirs:"); for (PathFragment f : - Sets.newTreeSet(ccCompilationContextInfo.getDeclaredIncludeWarnDirs())) { + Sets.newTreeSet(ccCompilationContext.getDeclaredIncludeWarnDirs())) { System.err.println(" '" + f + "'"); } System.err.println(" with prefixes:"); - for (PathFragment dirpath : ccCompilationContextInfo.getQuoteIncludeDirs()) { + for (PathFragment dirpath : ccCompilationContext.getQuoteIncludeDirs()) { System.err.println(" '" + dirpath + "'"); } } @@ -929,7 +927,7 @@ public class CppCompileAction extends AbstractAction Iterable getValidationIgnoredDirs() { List cxxSystemIncludeDirs = getBuiltInIncludeDirectories(); - return Iterables.concat(cxxSystemIncludeDirs, ccCompilationContextInfo.getSystemIncludeDirs()); + return Iterables.concat(cxxSystemIncludeDirs, ccCompilationContext.getSystemIncludeDirs()); } /** @@ -1043,8 +1041,8 @@ public class CppCompileAction extends AbstractAction addNonSources(result, mandatoryInputs); addNonSources(result, prunableInputs); addNonSources(result, getDeclaredIncludeSrcs()); - addNonSources(result, ccCompilationContextInfo.getTransitiveCompilationPrerequisites()); - addNonSources(result, ccCompilationContextInfo.getTransitiveModules(usePic)); + addNonSources(result, ccCompilationContext.getTransitiveCompilationPrerequisites()); + addNonSources(result, ccCompilationContext.getTransitiveModules(usePic)); Artifact artifact = getSourceFile(); if (!artifact.isSourceArtifact()) { result.add(artifact); @@ -1070,7 +1068,7 @@ public class CppCompileAction extends AbstractAction * listed in {@code declaredIncludeSrcs}). */ public NestedSet getDeclaredIncludeDirs() { - return ccCompilationContextInfo.getDeclaredIncludeDirs(); + return ccCompilationContext.getDeclaredIncludeDirs(); } /** @@ -1078,7 +1076,7 @@ public class CppCompileAction extends AbstractAction * not specifically listed in {@code declaredIncludeSrcs}). */ public NestedSet getDeclaredIncludeWarnDirs() { - return ccCompilationContextInfo.getDeclaredIncludeWarnDirs(); + return ccCompilationContext.getDeclaredIncludeWarnDirs(); } /** Return explicitly listed header files. */ @@ -1086,13 +1084,13 @@ public class CppCompileAction extends AbstractAction public NestedSet getDeclaredIncludeSrcs() { if (lipoScannables != null && lipoScannables.iterator().hasNext()) { NestedSetBuilder srcs = NestedSetBuilder.stableOrder(); - srcs.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); + srcs.addTransitive(ccCompilationContext.getDeclaredIncludeSrcs()); for (IncludeScannable lipoScannable : lipoScannables) { srcs.addTransitive(lipoScannable.getDeclaredIncludeSrcs()); } return srcs.build(); } - return ccCompilationContextInfo.getDeclaredIncludeSrcs(); + return ccCompilationContext.getDeclaredIncludeSrcs(); } /** @@ -1127,10 +1125,9 @@ public class CppCompileAction extends AbstractAction * that affect whether validateIncludes() will report an error or warning * have changed, otherwise we might miss some errors. */ - fp.addPaths(ccCompilationContextInfo.getDeclaredIncludeDirs()); - fp.addPaths(ccCompilationContextInfo.getDeclaredIncludeWarnDirs()); - actionKeyContext.addNestedSetToFingerprint( - fp, ccCompilationContextInfo.getDeclaredIncludeSrcs()); + fp.addPaths(ccCompilationContext.getDeclaredIncludeDirs()); + fp.addPaths(ccCompilationContext.getDeclaredIncludeWarnDirs()); + actionKeyContext.addNestedSetToFingerprint(fp, ccCompilationContext.getDeclaredIncludeSrcs()); fp.addInt(0); // mark the boundary between input types actionKeyContext.addNestedSetToFingerprint(fp, getMandatoryInputs()); fp.addInt(0); @@ -1370,7 +1367,7 @@ public class CppCompileAction extends AbstractAction legend = " Argument: "; } - for (PathFragment path : ccCompilationContextInfo.getDeclaredIncludeDirs()) { + for (PathFragment path : ccCompilationContext.getDeclaredIncludeDirs()) { message.append(" Declared include directory: "); message.append(ShellEscaper.escapeString(path.getPathString())); message.append('\n'); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 5d456784e4..da8bcdb627 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -64,7 +64,7 @@ public class CppCompileActionBuilder { private PathFragment tempOutputFile; private DotdFile dotdFile; private Artifact gcnoFile; - private CcCompilationContextInfo ccCompilationContextInfo = CcCompilationContextInfo.EMPTY; + private CcCompilationContext ccCompilationContext = CcCompilationContext.EMPTY; private final List pluginOpts = new ArrayList<>(); private CoptsFilter coptsFilter = CoptsFilter.alwaysPasses(); private ImmutableList extraSystemIncludePrefixes = ImmutableList.of(); @@ -148,7 +148,7 @@ public class CppCompileActionBuilder { this.tempOutputFile = other.tempOutputFile; this.dotdFile = other.dotdFile; this.gcnoFile = other.gcnoFile; - this.ccCompilationContextInfo = other.ccCompilationContextInfo; + this.ccCompilationContext = other.ccCompilationContext; this.pluginOpts.addAll(other.pluginOpts); this.coptsFilter = other.coptsFilter; this.extraSystemIncludePrefixes = ImmutableList.copyOf(other.extraSystemIncludePrefixes); @@ -201,8 +201,8 @@ public class CppCompileActionBuilder { return sourceFile; } - public CcCompilationContextInfo getCcCompilationContextInfo() { - return ccCompilationContextInfo; + public CcCompilationContext getCcCompilationContext() { + return ccCompilationContext; } public NestedSet getMandatoryInputs() { @@ -337,7 +337,7 @@ public class CppCompileActionBuilder { NestedSet allInputs = buildAllInputs(realMandatoryInputs); NestedSetBuilder prunableInputBuilder = NestedSetBuilder.stableOrder(); - prunableInputBuilder.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); + prunableInputBuilder.addTransitive(ccCompilationContext.getDeclaredIncludeSrcs()); prunableInputBuilder.addTransitive(cppSemantics.getAdditionalPrunableIncludes()); Iterable lipoScannables = getLipoScannables(realMandatoryInputs); @@ -380,7 +380,7 @@ public class CppCompileActionBuilder { tempOutputFile, dotdFile, localShellEnvironment, - ccCompilationContextInfo, + ccCompilationContext, coptsFilter, getLipoScannables(realMandatoryInputs), cppSemantics, @@ -411,7 +411,7 @@ public class CppCompileActionBuilder { ltoIndexingFile, optionalSourceFile, localShellEnvironment, - ccCompilationContextInfo, + ccCompilationContext, coptsFilter, getLipoScannables(realMandatoryInputs), additionalIncludeScanningRoots.build(), @@ -445,13 +445,11 @@ public class CppCompileActionBuilder { NestedSetBuilder realMandatoryInputsBuilder = NestedSetBuilder.compileOrder(); realMandatoryInputsBuilder.addTransitive(mandatoryInputsBuilder.build()); realMandatoryInputsBuilder.addAll(getBuiltinIncludeFiles()); - realMandatoryInputsBuilder.addAll( - ccCompilationContextInfo.getTransitiveCompilationPrerequisites()); + realMandatoryInputsBuilder.addAll(ccCompilationContext.getTransitiveCompilationPrerequisites()); if (useHeaderModules() && !shouldPruneModules()) { - realMandatoryInputsBuilder.addTransitive( - ccCompilationContextInfo.getTransitiveModules(usePic)); + realMandatoryInputsBuilder.addTransitive(ccCompilationContext.getTransitiveModules(usePic)); } - realMandatoryInputsBuilder.addTransitive(ccCompilationContextInfo.getAdditionalInputs()); + realMandatoryInputsBuilder.addTransitive(ccCompilationContext.getAdditionalInputs()); realMandatoryInputsBuilder.add(Preconditions.checkNotNull(sourceFile)); if (grepIncludes != null) { realMandatoryInputsBuilder.add(grepIncludes); @@ -663,9 +661,9 @@ public class CppCompileActionBuilder { return this; } - public CppCompileActionBuilder setCcCompilationContextInfo( - CcCompilationContextInfo ccCompilationContextInfo) { - this.ccCompilationContextInfo = ccCompilationContextInfo; + public CppCompileActionBuilder setCcCompilationContext( + CcCompilationContext ccCompilationContext) { + this.ccCompilationContext = ccCompilationContext; return this; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index ec59a60663..6f262410c2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -200,7 +200,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { /** * If true, the ConfiguredTarget is only used to get the necessary cross-referenced {@code - * CcCompilationContextInfo}s, but registering build actions is disabled. + * CcCompilationContext}s, but registering build actions is disabled. */ private final boolean lipoContextCollector; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index b26425b3ba..eed09427a1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -112,28 +112,27 @@ public class CppHelper { * Merges the STL and toolchain contexts into context builder. The STL is automatically determined * using the ":stl" attribute. */ - public static void mergeToolchainDependentCcCompilationContextInfo( + public static void mergeToolchainDependentCcCompilationContext( RuleContext ruleContext, CcToolchainProvider toolchain, - CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder) { + CcCompilationContext.Builder ccCompilationContextBuilder) { if (ruleContext.getRule().getAttributeDefinition(":stl") != null) { TransitiveInfoCollection stl = ruleContext.getPrerequisite(":stl", Mode.TARGET); if (stl != null) { CcCompilationInfo ccCompilationInfo = stl.get(CcCompilationInfo.PROVIDER); - CcCompilationContextInfo ccCompilationContextInfo = - ccCompilationInfo != null ? ccCompilationInfo.getCcCompilationContextInfo() : null; - if (ccCompilationContextInfo == null) { + CcCompilationContext ccCompilationContext = + ccCompilationInfo != null ? ccCompilationInfo.getCcCompilationContext() : null; + if (ccCompilationContext == null) { ruleContext.ruleError( "Unable to merge the STL '" + stl.getLabel() + "' and toolchain contexts"); return; } - ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfo( - ccCompilationContextInfo); + ccCompilationContextBuilder.mergeDependentCcCompilationContext(ccCompilationContext); } } if (toolchain != null) { - ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfo( - toolchain.getCcCompilationContextInfo()); + ccCompilationContextBuilder.mergeDependentCcCompilationContext( + toolchain.getCcCompilationContext()); } } @@ -652,7 +651,7 @@ public class CppHelper { /** * Emits a warning on the rule if there are identical linkstamp artifacts with different {@code - * CcCompilationContextInfo}s. + * CcCompilationContext}s. */ public static void checkLinkstampsUnique(RuleErrorConsumer listener, CcLinkParams linkParams) { Map> result = new LinkedHashMap<>(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSemantics.java index fe939422d1..93048e9654 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSemantics.java @@ -30,13 +30,13 @@ public interface CppSemantics { void finalizeCompileActionBuilder(RuleContext ruleContext, CppCompileActionBuilder actionBuilder); /** - * Called before {@link CcCompilationContextInfo}s are finalized. + * Called before {@link CcCompilationContext}s are finalized. * *

Gives the semantics implementation the opportunity to change what the C++ rule propagates to * dependent rules. */ - void setupCcCompilationContextInfo( - RuleContext ruleContext, CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder); + void setupCcCompilationContext( + RuleContext ruleContext, CcCompilationContext.Builder ccCompilationContextBuilder); /** * Returns the set of includes which are not mandatory and may be pruned by include processing. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java index f7b2a2e581..e4f36efd4d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java @@ -74,7 +74,7 @@ public class FakeCppCompileAction extends CppCompileAction { PathFragment tempOutputFile, DotdFile dotdFile, ImmutableMap localShellEnvironment, - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, CoptsFilter nocopts, Iterable lipoScannables, CppSemantics cppSemantics, @@ -110,7 +110,7 @@ public class FakeCppCompileAction extends CppCompileAction { // cc_fake_binary and for the negative compilation tests that depend on // the cc_fake_binary, and the runfiles must be determined at analysis // time, so they can't depend on the contents of the ".d" file.) - CcCompilationContextInfo.disallowUndeclaredHeaders(ccCompilationContextInfo), + CcCompilationContext.disallowUndeclaredHeaders(ccCompilationContext), nocopts, lipoScannables, /* additionalIncludeScanningRoots=*/ ImmutableList.of(), diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java index ea6dddc02b..0a1223f98a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java @@ -116,12 +116,12 @@ import java.util.zip.ZipFile; * .gcda files are added, too. * * - *

If we do LIPO, the actual {@code CcCompilationContextInfo} for LIPO compilation actions is - * pieced together from the {@code CcCompilationContextInfo} in LipoContextProvider and that of the - * rule being compiled. (see {@link CcCompilationContextInfo#mergeForLipo}) This is so that the - * include files for the extra LIPO sources are found and is, strictly speaking, incorrect, since it - * also changes the declared include directories of the main source file, which in theory can result - * in the compilation passing even though it should fail with undeclared inclusion errors. + *

If we do LIPO, the actual {@code CcCompilationContext} for LIPO compilation actions is pieced + * together from the {@code CcCompilationContext} in LipoContextProvider and that of the rule being + * compiled. (see {@link CcCompilationContext#mergeForLipo}) This is so that the include files for + * the extra LIPO sources are found and is, strictly speaking, incorrect, since it also changes the + * declared include directories of the main source file, which in theory can result in the + * compilation passing even though it should fail with undeclared inclusion errors. * *

During the actual execution of the C++ compile action, the extra sources also need to be * include scanned, which is the reason why they are {@link IncludeScannable} objects and not simple diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LipoContextProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LipoContextProvider.java index 6f9f5fc697..90d6117cb0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LipoContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LipoContextProvider.java @@ -33,24 +33,24 @@ import java.util.Map; @Immutable @AutoCodec public final class LipoContextProvider implements TransitiveInfoProvider { - private final CcCompilationContextInfo ccCompilationContextInfo; + private final CcCompilationContext ccCompilationContext; private final ImmutableMap includeScannables; private final ImmutableMap sourceArtifactMap; @AutoCodec.Instantiator public LipoContextProvider( - CcCompilationContextInfo ccCompilationContextInfo, + CcCompilationContext ccCompilationContext, Map includeScannables, Map sourceArtifactMap) { - this.ccCompilationContextInfo = ccCompilationContextInfo; + this.ccCompilationContext = ccCompilationContext; this.includeScannables = ImmutableMap.copyOf(includeScannables); this.sourceArtifactMap = ImmutableMap.copyOf(sourceArtifactMap); } - /** Returns merged {@code CcCompilationContextInfo} for the whole LIPO subtree. */ - public CcCompilationContextInfo getLipoCcCompilationContextInfo() { - return ccCompilationContextInfo; + /** Returns merged {@code CcCompilationContext} for the whole LIPO subtree. */ + public CcCompilationContext getLipoCcCompilationContext() { + return ccCompilationContext; } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java index 850cc9d19a..6404293882 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java @@ -197,7 +197,7 @@ public abstract class CcProtoAspect extends NativeAspectClass implements Configu initializeLinkingHelper(featureConfiguration) .link( compilationInfo.getCcCompilationOutputs(), - compilationInfo.getCcCompilationContextInfo()); + compilationInfo.getCcCompilationContext()); ccLibraryProviders = new TransitiveInfoProviderMapBuilder() diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index 7b36226405..3d938743a1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -91,7 +91,7 @@ import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.apple.XcodeConfig; import com.google.devtools.build.lib.rules.apple.XcodeConfigProvider; import com.google.devtools.build.lib.rules.cpp.CcCommon; -import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs; @@ -446,22 +446,22 @@ public class CompilationSupport { resultLink.addLinkActionInput(linkActionInput); } - CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = - new CcCompilationContextInfo.Builder(ruleContext); - ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( + CcCompilationContext.Builder ccCompilationContextBuilder = + new CcCompilationContext.Builder(ruleContext); + ccCompilationContextBuilder.mergeDependentCcCompilationContexts( Arrays.asList( - objcArcCompilationInfo.getCcCompilationContextInfo(), - nonObjcArcCompilationInfo.getCcCompilationContextInfo())); - ccCompilationContextInfoBuilder.setPurpose( + objcArcCompilationInfo.getCcCompilationContext(), + nonObjcArcCompilationInfo.getCcCompilationContext())); + ccCompilationContextBuilder.setPurpose( String.format("%s_merged_arc_non_arc_objc", semantics.getPurpose())); - semantics.setupCcCompilationContextInfo(ruleContext, ccCompilationContextInfoBuilder); + semantics.setupCcCompilationContext(ruleContext, ccCompilationContextBuilder); CcCompilationOutputs.Builder compilationOutputsBuilder = new CcCompilationOutputs.Builder(); compilationOutputsBuilder.merge(objcArcCompilationInfo.getCcCompilationOutputs()); compilationOutputsBuilder.merge(nonObjcArcCompilationInfo.getCcCompilationOutputs()); LinkingInfo linkingInfo = - resultLink.link(compilationOutputsBuilder.build(), ccCompilationContextInfoBuilder.build()); + resultLink.link(compilationOutputsBuilder.build(), ccCompilationContextBuilder.build()); Map> mergedOutputGroups = CcCommon.mergeOutputGroups( 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 f53d612f97..f5a441ebd4 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 @@ -67,7 +67,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTa import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.rules.apple.AppleToolchain; -import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +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; @@ -171,7 +171,7 @@ public final class ObjcCommon { private DsymOutputType dsymOutputType; private Optional linkedBinary = Optional.absent(); private Optional linkmapFile = Optional.absent(); - private Iterable depCcHeaderProviders = ImmutableList.of(); + private Iterable depCcHeaderProviders = ImmutableList.of(); private Iterable depCcLinkProviders = ImmutableList.of(); /** @@ -270,23 +270,22 @@ public final class ObjcCommon { addAnyProviders(cppDeps, depCT, CcCompilationInfo.PROVIDER); if (isCcLibrary(dep)) { cppDepLinkParams.add(depCT.get(CcLinkingInfo.PROVIDER).getCcLinkParamsInfo()); - CcCompilationContextInfo ccCompilationContextInfo = - depCT.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - addDefines(ccCompilationContextInfo.getDefines()); + CcCompilationContext ccCompilationContext = + depCT.get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + addDefines(ccCompilationContext.getDefines()); } } - ImmutableList.Builder ccCompilationContextInfoBuilder = + ImmutableList.Builder ccCompilationContextBuilder = ImmutableList.builder(); for (CcCompilationInfo ccCompilationInfo : cppDeps.build()) { - CcCompilationContextInfo ccCompilationContextInfo = - ccCompilationInfo.getCcCompilationContextInfo(); - if (ccCompilationContextInfo != null) { - ccCompilationContextInfoBuilder.add(ccCompilationContextInfo); + CcCompilationContext ccCompilationContext = ccCompilationInfo.getCcCompilationContext(); + if (ccCompilationContext != null) { + ccCompilationContextBuilder.add(ccCompilationContext); } } addDepObjcProviders(propagatedObjcDeps.build()); this.depCcHeaderProviders = - Iterables.concat(this.depCcHeaderProviders, ccCompilationContextInfoBuilder.build()); + Iterables.concat(this.depCcHeaderProviders, ccCompilationContextBuilder.build()); this.depCcLinkProviders = Iterables.concat(this.depCcLinkProviders, cppDepLinkParams.build()); return this; } @@ -454,11 +453,11 @@ public final class ObjcCommon { objcProvider.addTransitiveAndPropagate(ObjcProvider.MERGE_ZIP, provider); } - for (CcCompilationContextInfo headerProvider : depCcHeaderProviders) { + for (CcCompilationContext headerProvider : depCcHeaderProviders) { objcProvider.addAll(HEADER, filterFileset(headerProvider.getDeclaredIncludeSrcs())); objcProvider.addAll(INCLUDE, headerProvider.getIncludeDirs()); // TODO(bazel-team): This pulls in stl via - // CppHelper.mergeToolchainDependentCcCompilationContextInfo but + // CppHelper.mergeToolchainDependentCcCompilationContext but // probably shouldn't. objcProvider.addAll(INCLUDE_SYSTEM, headerProvider.getSystemIncludeDirs()); objcProvider.addAll(DEFINE, headerProvider.getDefines()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java index dca862897a..d0180622c1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java @@ -24,7 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder; import com.google.devtools.build.lib.rules.cpp.CppConfiguration; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode; @@ -121,13 +121,13 @@ public class ObjcCppSemantics implements CppSemantics { } @Override - public void setupCcCompilationContextInfo( - RuleContext ruleContext, CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder) { + public void setupCcCompilationContext( + RuleContext ruleContext, CcCompilationContext.Builder ccCompilationContextBuilder) { // The genfiles root of each child configuration must be added to the compile action so that // generated headers can be resolved. for (PathFragment iquotePath : ObjcCommon.userHeaderSearchPaths(objcProvider, ruleContext.getConfiguration())) { - ccCompilationContextInfoBuilder.addQuoteIncludeDir(iquotePath); + ccCompilationContextBuilder.addQuoteIncludeDir(iquotePath); } } @@ -168,12 +168,12 @@ public class ObjcCppSemantics implements CppSemantics { } /** - * Gets the purpose for the {@code CcCompilationContextInfo}. + * Gets the purpose for the {@code CcCompilationContext}. * - * @see CcCompilationContextInfo.Builder#setPurpose + * @see CcCompilationContext.Builder#setPurpose */ public String getPurpose() { - // ProtoSupport creates multiple {@code CcCompilationContextInfo}s for a single rule, + // ProtoSupport creates multiple {@code CcCompilationContext}s for a single rule, // potentially // multiple archives per build configuration. This covers that worst case. return "ObjcCppSemantics_build_arch_" 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 0c55c45c10..979ae10212 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 @@ -24,7 +24,7 @@ import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTa import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; 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.CcCompilationContextInfo; +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.CcLinkingInfo; @@ -94,8 +94,8 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder() .addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build(); - CcCompilationContextInfo ccCompilationContextInfo = - new CcCompilationContextInfo.Builder(ruleContext) + CcCompilationContext ccCompilationContext = + new CcCompilationContext.Builder(ruleContext) .addDeclaredIncludeSrcs( CompilationAttributes.Builder.fromRuleContext(ruleContext) .build() @@ -106,7 +106,7 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { .build(); CcCompilationInfo.Builder ccCompilationInfoBuilder = CcCompilationInfo.Builder.create(); - ccCompilationInfoBuilder.setCcCompilationContextInfo(ccCompilationContextInfo); + ccCompilationInfoBuilder.setCcCompilationContext(ccCompilationContext); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); ccLinkingInfoBuilder.setCcLinkParamsInfo( diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java index 10cc6500d0..46507cc745 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java @@ -312,7 +312,7 @@ public final class PrintActionCommand implements BlazeCommand { *

However, since there is a scheduling dependency on the header files, we can use the system * to implement said scheduling dependency to figure them out. Thus, we go a-fishing in the action * graph reaching through error propagating middlemen: one of these exists for each {@code - * CcCompilationContextInfo} in the transitive closure of the rule. + * CcCompilationContext} in the transitive closure of the rule. */ private static void expandRecursiveHelper( ActionGraph actionGraph, diff --git a/src/test/java/com/google/devtools/build/lib/rules/AliasTest.java b/src/test/java/com/google/devtools/build/lib/rules/AliasTest.java index cc9f49aaaa..5d95e66e8d 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/AliasTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/AliasTest.java @@ -41,7 +41,7 @@ public class AliasTest extends BuildViewTestCase { "alias(name='b', actual='a')"); ConfiguredTarget b = getConfiguredTarget("//a:b"); - assertThat(b.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo()).isNotNull(); + assertThat(b.get(CcCompilationInfo.PROVIDER).getCcCompilationContext()).isNotNull(); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index 656a64a76b..d2be295616 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -253,10 +253,7 @@ public class CcCommonTest extends BuildViewTestCase { " srcs = ['defines.cc'],", " defines = ['FOO', 'BAR'])"); assertThat( - isolatedDefines - .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo() - .getDefines()) + isolatedDefines.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getDefines()) .containsExactly("FOO", "BAR") .inOrder(); } @@ -424,10 +421,7 @@ public class CcCommonTest extends BuildViewTestCase { ConfiguredTarget foo = getConfiguredTarget("//bang:bang"); String includesRoot = "bang/bang_includes"; - assertThat( - foo.get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo() - .getSystemIncludeDirs()) + assertThat(foo.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getSystemIncludeDirs()) .containsAllOf( PathFragment.create(includesRoot), targetConfig.getGenfilesFragment().getRelative(includesRoot)); @@ -457,16 +451,13 @@ public class CcCommonTest extends BuildViewTestCase { .addAll( noIncludes .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo() + .getCcCompilationContext() .getSystemIncludeDirs()) .add(PathFragment.create(includesRoot)) .add(targetConfig.getGenfilesFragment().getRelative(includesRoot)) .add(targetConfig.getBinFragment().getRelative(includesRoot)) .build(); - assertThat( - foo.get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo() - .getSystemIncludeDirs()) + assertThat(foo.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getSystemIncludeDirs()) .containsExactlyElementsIn(expected); } @@ -875,12 +866,11 @@ public class CcCommonTest extends BuildViewTestCase { "cc_library(name='a', hdrs=['v1/b/c.h'], strip_include_prefix='v1', include_prefix='lib')"); ConfiguredTarget lib = getConfiguredTarget("//third_party/a"); - CcCompilationContextInfo ccCompilationContextInfo = - lib.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - assertThat( - ActionsTestUtil.prettyArtifactNames(ccCompilationContextInfo.getDeclaredIncludeSrcs())) + CcCompilationContext ccCompilationContext = + lib.get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + assertThat(ActionsTestUtil.prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs())) .containsExactly("third_party/a/_virtual_includes/a/lib/b/c.h"); - assertThat(ccCompilationContextInfo.getIncludeDirs()) + assertThat(ccCompilationContext.getIncludeDirs()) .containsExactly( getTargetConfiguration() .getBinFragment() @@ -916,14 +906,14 @@ public class CcCommonTest extends BuildViewTestCase { "cc_library(name='relative', hdrs=['v1/b.h'], strip_include_prefix='v1')", "cc_library(name='absolute', hdrs=['v1/b.h'], strip_include_prefix='/third_party')"); - CcCompilationContextInfo relative = + CcCompilationContext relative = getConfiguredTarget("//third_party/a:relative") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo(); - CcCompilationContextInfo absolute = + .getCcCompilationContext(); + CcCompilationContext absolute = getConfiguredTarget("//third_party/a:absolute") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo(); + .getCcCompilationContext(); assertThat(ActionsTestUtil.prettyArtifactNames(relative.getDeclaredIncludeSrcs())) .containsExactly("third_party/a/_virtual_includes/relative/b.h"); @@ -950,12 +940,11 @@ public class CcCommonTest extends BuildViewTestCase { "licenses(['notice'])", "cc_library(name='a', hdrs=['a.h'], include_prefix='third_party')"); - CcCompilationContextInfo ccCompilationContextInfo = + CcCompilationContext ccCompilationContext = getConfiguredTarget("//third_party:a") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo(); - assertThat( - ActionsTestUtil.prettyArtifactNames(ccCompilationContextInfo.getDeclaredIncludeSrcs())) + .getCcCompilationContext(); + assertThat(ActionsTestUtil.prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs())) .doesNotContain("third_party/_virtual_includes/a/third_party/a.h"); } 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 1926d1fee7..1e096b4ff7 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 @@ -314,7 +314,7 @@ public class CcImportConfiguredTargetTest extends BuildViewTestCase { "foo", "cc_import(name = 'foo', static_library = 'libfoo.a', hdrs = ['foo.h'])") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo() + .getCcCompilationContext() .getDeclaredIncludeSrcs(); assertThat(artifactsToStrings(headers)).containsExactly("src a/foo.h"); } 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 5ab844b922..d860ba6d03 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 @@ -91,14 +91,13 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { private CppModuleMapAction getCppModuleMapAction(String label) throws Exception { ConfiguredTarget target = getConfiguredTarget(label); CppModuleMap cppModuleMap = - target.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo().getCppModuleMap(); + target.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getCppModuleMap(); return (CppModuleMapAction) getGeneratingAction(cppModuleMap.getArtifact()); } private void assertNoCppModuleMapAction(String label) throws Exception { ConfiguredTarget target = getConfiguredTarget(label); - assertThat( - target.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo().getCppModuleMap()) + assertThat(target.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getCppModuleMap()) .isNull(); } @@ -107,7 +106,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { ConfiguredTarget l = scratchConfiguredTarget("a", "l", "cc_library(name='l', srcs=['l.cc'], defines=['V=$(FOO)'], toolchains=[':v'])", "make_variable_tester(name='v', variables={'FOO': 'BAR'})"); - assertThat(l.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo().getDefines()) + assertThat(l.get(CcCompilationInfo.PROVIDER).getCcCompilationContext().getDefines()) .contains("V=BAR"); } @@ -572,7 +571,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { CppCompileAction aObjectAction = (CppCompileAction) getGeneratingAction(aObjectArtifact); assertThat(aObjectAction.getIncludeScannerSources()).containsExactly( getSourceArtifact("module/a.cc")); - assertThat(aObjectAction.getCcCompilationContextInfo().getTransitiveModules(true)) + assertThat(aObjectAction.getCcCompilationContext().getTransitiveModules(true)) .contains(getBinArtifact("_objs/b/module/b.pic.pcm", "//module:b")); assertThat(aObjectAction.getInputs()).contains( getGenfilesArtifactWithNoOwner("module/b.cppmap")); @@ -770,9 +769,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { getConfiguredTarget("//module:j"); Artifact jObjectArtifact = getBinArtifact("_objs/j/module/j.pic.o", "//module:j"); CppCompileAction jObjectAction = (CppCompileAction) getGeneratingAction(jObjectArtifact); - assertThat( - getHeaderModules( - jObjectAction.getCcCompilationContextInfo().getTransitiveModules(true))) + assertThat(getHeaderModules(jObjectAction.getCcCompilationContext().getTransitiveModules(true))) .containsExactly( getBinArtifact("_objs/b/module/b.pic.pcm", "//module:b"), getBinArtifact("_objs/g/module/g.pic.pcm", "//module:g")); @@ -780,9 +777,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { getSourceArtifact("module/j.cc")); assertThat(jObjectAction.getMainIncludeScannerSource()).isEqualTo( getSourceArtifact("module/j.cc")); - assertThat( - getHeaderModules( - jObjectAction.getCcCompilationContextInfo().getTransitiveModules(true))) + assertThat(getHeaderModules(jObjectAction.getCcCompilationContext().getTransitiveModules(true))) .containsExactly( getBinArtifact("_objs/b/module/b.pic.pcm", "//module:b"), getBinArtifact("_objs/g/module/g.pic.pcm", "//module:g")); @@ -812,9 +807,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .containsExactly( getGenfilesArtifact("b.cppmap", "//module:b"), getGenfilesArtifact("c.cppmap", "//nomodule:e")); - assertThat( - getHeaderModules( - cObjectAction.getCcCompilationContextInfo().getTransitiveModules(true))) + assertThat(getHeaderModules(cObjectAction.getCcCompilationContext().getTransitiveModules(true))) .containsExactly(getBinArtifact("_objs/b/module/b.pic.pcm", "//module:b")); getConfiguredTarget("//nomodule:d"); @@ -824,9 +817,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .containsExactly( getGenfilesArtifact("c.cppmap", "//nomodule:c"), getGenfilesArtifact("d.cppmap", "//nomodule:d")); - assertThat( - getHeaderModules( - dObjectAction.getCcCompilationContextInfo().getTransitiveModules(true))) + assertThat(getHeaderModules(dObjectAction.getCcCompilationContext().getTransitiveModules(true))) .containsExactly(getBinArtifact("_objs/b/module/b.pic.pcm", "//module:b")); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java index fa367f0ab9..d039539178 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java @@ -57,7 +57,7 @@ public class CcToolchainProviderTest { /* dynamicRuntimeLinkInputs= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), /* dynamicRuntimeLinkMiddleman= */ null, /* dynamicRuntimeSolibDir= */ PathFragment.EMPTY_FRAGMENT, - CcCompilationContextInfo.EMPTY, + CcCompilationContext.EMPTY, /* supportsParamFiles= */ false, /* supportsHeaderParsing= */ false, Variables.EMPTY, @@ -94,7 +94,7 @@ public class CcToolchainProviderTest { /* dynamicRuntimeLinkInputs= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), /* dynamicRuntimeLinkMiddleman= */ null, /* dynamicRuntimeSolibDir= */ PathFragment.EMPTY_FRAGMENT, - CcCompilationContextInfo.EMPTY, + CcCompilationContext.EMPTY, /* supportsParamFiles= */ false, /* supportsHeaderParsing= */ false, Variables.EMPTY, diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/MockCppSemantics.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/MockCppSemantics.java index f1ab983aee..699275f721 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/MockCppSemantics.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/MockCppSemantics.java @@ -38,8 +38,8 @@ public final class MockCppSemantics implements CppSemantics { RuleContext ruleContext, CppCompileActionBuilder actionBuilder) {} @Override - public void setupCcCompilationContextInfo( - RuleContext ruleContext, CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder) {} + public void setupCcCompilationContext( + RuleContext ruleContext, CcCompilationContext.Builder ccCompilationContextBuilder) {} @Override public NestedSet getAdditionalPrunableIncludes() { diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java index e2309ba184..d7bf3eaf99 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java @@ -24,7 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContext; import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo; import com.google.devtools.build.lib.vfs.FileSystemUtils; import org.junit.Before; @@ -108,27 +108,27 @@ public class CcProtoLibraryTest extends BuildViewTestCase { "proto_library(name = 'alias_proto', deps = [':foo_proto'])", "proto_library(name = 'foo_proto', srcs = ['foo.proto'])"); - CcCompilationContextInfo ccCompilationContextInfo = + CcCompilationContext ccCompilationContext = getConfiguredTarget("//x:foo_cc_proto") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo(); - assertThat(prettyArtifactNames(ccCompilationContextInfo.getDeclaredIncludeSrcs())) + .getCcCompilationContext(); + assertThat(prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs())) .containsExactly("x/foo.pb.h"); } @Test - public void ccCompilationContextInfo() throws Exception { + public void ccCompilationContext() throws Exception { scratch.file( "x/BUILD", "cc_proto_library(name = 'foo_cc_proto', deps = ['foo_proto'])", "proto_library(name = 'foo_proto', srcs = ['foo.proto'], deps = [':bar_proto'])", "proto_library(name = 'bar_proto', srcs = ['bar.proto'])"); - CcCompilationContextInfo ccCompilationContextInfo = + CcCompilationContext ccCompilationContext = getConfiguredTarget("//x:foo_cc_proto") .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContextInfo(); - assertThat(prettyArtifactNames(ccCompilationContextInfo.getDeclaredIncludeSrcs())) + .getCcCompilationContext(); + assertThat(prettyArtifactNames(ccCompilationContext.getDeclaredIncludeSrcs())) .containsExactly("x/foo.pb.h", "x/bar.pb.h"); } @@ -178,9 +178,9 @@ public class CcProtoLibraryTest extends BuildViewTestCase { getTargetConfiguration().getGenfilesFragment().toString())); Artifact headerFile = getGenfilesArtifactWithNoOwner("external/bla/foo/bar.pb.h"); - CcCompilationContextInfo ccCompilationContextInfo = - target.get(CcCompilationInfo.PROVIDER).getCcCompilationContextInfo(); - assertThat(ccCompilationContextInfo.getDeclaredIncludeSrcs()).containsExactly(headerFile); + CcCompilationContext ccCompilationContext = + target.get(CcCompilationInfo.PROVIDER).getCcCompilationContext(); + assertThat(ccCompilationContext.getDeclaredIncludeSrcs()).containsExactly(headerFile); } @Test -- cgit v1.2.3