From 3f6c57b3a2c86444ce4be119f51578ab7198071e Mon Sep 17 00:00:00 2001 From: plf Date: Tue, 3 Apr 2018 08:40:03 -0700 Subject: C++: Rename CcCompilationInfo to CcCompilationContextInfo. This is done so that the name CcCompilationInfo can be used for the C++ provider that will wrap all providers for compilation, similar to JavaInfo in Java. RELNOTES:none PiperOrigin-RevId: 191445120 --- .../lib/bazel/rules/cpp/BazelCppSemantics.java | 5 +- .../devtools/build/lib/rules/cpp/CcBinary.java | 27 +- .../devtools/build/lib/rules/cpp/CcCommon.java | 18 +- .../lib/rules/cpp/CcCompilationContextInfo.java | 952 +++++++++++++++++++++ .../build/lib/rules/cpp/CcCompilationHelper.java | 174 ++-- .../build/lib/rules/cpp/CcCompilationInfo.java | 938 -------------------- .../devtools/build/lib/rules/cpp/CcImport.java | 3 +- .../devtools/build/lib/rules/cpp/CcLibrary.java | 3 +- .../devtools/build/lib/rules/cpp/CcLinkParams.java | 5 +- .../build/lib/rules/cpp/CcLinkingHelper.java | 16 +- .../build/lib/rules/cpp/CcSkylarkApiProvider.java | 44 +- .../devtools/build/lib/rules/cpp/CcToolchain.java | 10 +- .../build/lib/rules/cpp/CcToolchainProvider.java | 14 +- .../build/lib/rules/cpp/CompileBuildVariables.java | 21 +- .../build/lib/rules/cpp/CppCompileAction.java | 85 +- .../lib/rules/cpp/CppCompileActionBuilder.java | 27 +- .../build/lib/rules/cpp/CppConfiguration.java | 3 +- .../devtools/build/lib/rules/cpp/CppHelper.java | 17 +- .../lib/rules/cpp/CppLinkstampCompileHelper.java | 6 +- .../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 +- .../devtools/build/lib/rules/java/JavaCommon.java | 13 +- .../build/lib/rules/objc/CompilationSupport.java | 17 +- .../devtools/build/lib/rules/objc/ObjcCommon.java | 15 +- .../build/lib/rules/objc/ObjcCppSemantics.java | 16 +- .../devtools/build/lib/rules/objc/ObjcLibrary.java | 8 +- .../lib/runtime/commands/PrintActionCommand.java | 2 +- 30 files changed, 1267 insertions(+), 1208 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java (limited to 'src/main/java/com/google/devtools/build') 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 23ea2a39ed..7cbb0dda83 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.CcCompilationInfo.Builder; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo.Builder; 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,7 +50,8 @@ public class BazelCppSemantics implements AspectLegalCppSemantics { } @Override - public void setupCcCompilationInfo(RuleContext ruleContext, Builder ccCompilationInfoBuilder) {} + public void setupCcCompilationContextInfo( + RuleContext ruleContext, Builder ccCompilationContextInfoBuilder) {} @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 2059b96c84..b06003c89a 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 @@ -98,7 +98,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CcToolchainProvider toolchain, CcLinkingOutputs linkingOutputs, CcLinkingOutputs ccLibraryLinkingOutputs, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, LinkStaticness linkStaticness, NestedSet filesToBuild, Iterable fakeLinkerInputs, @@ -152,12 +152,12 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { sourcesBuilder.add(cppSource.getSource()); } builder.addSymlinksToArtifacts(sourcesBuilder.build()); - builder.addSymlinksToArtifacts(ccCompilationInfo.getDeclaredIncludeSrcs()); + builder.addSymlinksToArtifacts(ccCompilationContextInfo.getDeclaredIncludeSrcs()); // Add additional files that are referenced from the compile command, like module maps // or header modules. - builder.addSymlinksToArtifacts(ccCompilationInfo.getAdditionalInputs()); + builder.addSymlinksToArtifacts(ccCompilationContextInfo.getAdditionalInputs()); builder.addSymlinksToArtifacts( - ccCompilationInfo.getTransitiveModules(usePic(context, toolchain))); + ccCompilationContextInfo.getTransitiveModules(usePic(context, toolchain))); } return builder.build(); } @@ -234,7 +234,8 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .setFake(fake) .addPrecompiledFiles(precompiledFiles); CompilationInfo compilationInfo = compilationHelper.compile(); - CcCompilationInfo ccCompilationInfo = compilationInfo.getCcCompilationInfo(); + CcCompilationContextInfo ccCompilationContextInfo = + compilationInfo.getCcCompilationContextInfo(); CcCompilationOutputs ccCompilationOutputs = compilationInfo.getCcCompilationOutputs(); // We currently only want link the dynamic library generated for test code separately. @@ -269,7 +270,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .enableInterfaceSharedObjects(); linkingHelper.setStaticLinkType(LinkTargetType.STATIC_LIBRARY); ccLinkingOutputs = - linkingHelper.link(ccCompilationOutputs, ccCompilationInfo).getCcLinkingOutputs(); + linkingHelper.link(ccCompilationOutputs, ccCompilationContextInfo).getCcLinkingOutputs(); } CcLinkParams linkParams = @@ -288,7 +289,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { precompiledFiles, ccCompilationOutputs, ccLinkingOutputs, - ccCompilationInfo.getTransitiveCompilationPrerequisites(), + ccCompilationContextInfo.getTransitiveCompilationPrerequisites(), fake, binary, linkParams, @@ -468,7 +469,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { ccToolchain, linkingOutputs, ccLinkingOutputs, - ccCompilationInfo, + ccCompilationContextInfo, linkStaticness, filesToBuild, fakeLinkerInputs, @@ -494,7 +495,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { ruleBuilder, filesToBuild, ccCompilationOutputs, - ccCompilationInfo, + ccCompilationContextInfo, linkingOutputs, dwoArtifacts, transitiveLipoInfo, @@ -543,7 +544,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .addProvider( LipoContextProvider.class, new LipoContextProvider( - ccCompilationInfo, + ccCompilationContextInfo, ImmutableMap.copyOf(scannableMap), ImmutableMap.copyOf(sourceFileMap))) .addProvider(CppLinkAction.Context.class, linkContext) @@ -873,7 +874,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { RuleConfiguredTargetBuilder builder, NestedSet filesToBuild, CcCompilationOutputs ccCompilationOutputs, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, CcLinkingOutputs linkingOutputs, DwoArtifactsCollector dwoArtifacts, TransitiveLipoInfoProvider transitiveLipoInfo, @@ -893,7 +894,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CppHelper.usePicForDynamicLibraries(ruleContext, toolchain)); builder .setFilesToBuild(filesToBuild) - .addNativeDeclaredProvider(ccCompilationInfo) + .addNativeDeclaredProvider(ccCompilationContextInfo) .addProvider(TransitiveLipoInfoProvider.class, transitiveLipoInfo) .addProvider( CcExecutionDynamicLibrariesProvider.class, @@ -919,7 +920,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, headerTokens) .addOutputGroup( OutputGroupInfo.COMPILATION_PREREQUISITES, - CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationInfo)); + CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContextInfo)); 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 8ddd0a1e5f..dbca6e6571 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 @@ -597,10 +597,12 @@ public final class CcCommon { /** Collects compilation prerequisite artifacts. */ static NestedSet collectCompilationPrerequisites( - RuleContext ruleContext, CcCompilationInfo ccCompilationInfo) { - // TODO(bazel-team): Use ccCompilationInfo.getCompilationPrerequisites() instead; note that this + RuleContext ruleContext, CcCompilationContextInfo ccCompilationContextInfo) { + // TODO(bazel-team): Use ccCompilationContextInfo.getCompilationPrerequisites() instead; note + // that this // will - // need cleaning up the prerequisites, as the {@code CcCompilationInfo} currently collects them + // need cleaning up the prerequisites, as the {@code CcCompilationContextInfo} currently + // collects them // transitively (to get transitive headers), but source files are not transitive compilation // prerequisites. NestedSetBuilder prerequisites = NestedSetBuilder.stableOrder(); @@ -612,10 +614,10 @@ public final class CcCommon { provider.getFilesToBuild(), SourceCategory.CC_AND_OBJC.getSourceTypes())); } } - prerequisites.addTransitive(ccCompilationInfo.getDeclaredIncludeSrcs()); - prerequisites.addTransitive(ccCompilationInfo.getAdditionalInputs()); - prerequisites.addTransitive(ccCompilationInfo.getTransitiveModules(true)); - prerequisites.addTransitive(ccCompilationInfo.getTransitiveModules(false)); + prerequisites.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); + prerequisites.addTransitive(ccCompilationContextInfo.getAdditionalInputs()); + prerequisites.addTransitive(ccCompilationContextInfo.getTransitiveModules(true)); + prerequisites.addTransitive(ccCompilationContextInfo.getTransitiveModules(false)); return prerequisites.build(); } @@ -711,7 +713,7 @@ public final class CcCommon { unsupportedFeaturesBuilder.add(CppRuleClasses.PARSE_HEADERS); unsupportedFeaturesBuilder.add(CppRuleClasses.PREPROCESS_HEADERS); } - if (toolchain.getCcCompilationInfo().getCppModuleMap() == null) { + if (toolchain.getCcCompilationContextInfo().getCppModuleMap() == null) { unsupportedFeaturesBuilder.add(CppRuleClasses.MODULE_MAPS); } ImmutableSet allUnsupportedFeatures = unsupportedFeaturesBuilder.build(); 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 new file mode 100644 index 0000000000..c7b64d7c05 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationContextInfo.java @@ -0,0 +1,952 @@ +// 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.packages.NativeInfo; +import com.google.devtools.build.lib.packages.NativeProvider; +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.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." +) +public final class CcCompilationContextInfo extends NativeInfo { + public static final NativeProvider PROVIDER = + new NativeProvider( + CcCompilationContextInfo.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) { + super(PROVIDER); + 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 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) { + // 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 102b42427c..a097a81790 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 @@ -128,13 +128,14 @@ public final class CcCompilationHelper { /** Function for extracting module maps from CppCompilationDependencies. */ private static final Function CPP_DEPS_TO_MODULES = dep -> { - CcCompilationInfo ccCompilationInfo = dep.get(CcCompilationInfo.PROVIDER); - return ccCompilationInfo == null ? null : ccCompilationInfo.getCppModuleMap(); + CcCompilationContextInfo ccCompilationContextInfo = + dep.get(CcCompilationContextInfo.PROVIDER); + return ccCompilationContextInfo == null ? null : ccCompilationContextInfo.getCppModuleMap(); }; /** * Contains the providers as well as the {@code CcCompilationOutputs} and the {@code - * CcCompilationInfo}. + * CcCompilationContextInfo}. */ @SkylarkModule( name = "compilation_info", @@ -142,23 +143,24 @@ public final class CcCompilationHelper { category = SkylarkModuleCategory.BUILTIN, doc = "Helper class containing CC compilation providers." ) - // TODO(plf): Rename so that it's not confused with CcCompilationInfo and also consider merging + // TODO(plf): Rename so that it's not confused with CcCompilationContextInfo and also consider + // merging // this class with {@code CcCompilationOutputs}. public static final class CompilationInfo { private final TransitiveInfoProviderMap providers; private final Map> outputGroups; private final CcCompilationOutputs compilationOutputs; - private final CcCompilationInfo ccCompilationInfo; + private final CcCompilationContextInfo ccCompilationContextInfo; private CompilationInfo( TransitiveInfoProviderMap providers, Map> outputGroups, CcCompilationOutputs compilationOutputs, - CcCompilationInfo ccCompilationInfo) { + CcCompilationContextInfo ccCompilationContextInfo) { this.providers = providers; this.outputGroups = outputGroups; this.compilationOutputs = compilationOutputs; - this.ccCompilationInfo = ccCompilationInfo; + this.ccCompilationContextInfo = ccCompilationContextInfo; } public TransitiveInfoProviderMap getProviders() { @@ -175,8 +177,8 @@ public final class CcCompilationHelper { } @SkylarkCallable(name = "cc_compilation_info", documented = false) - public CcCompilationInfo getCcCompilationInfo() { - return ccCompilationInfo; + public CcCompilationContextInfo getCcCompilationContextInfo() { + return ccCompilationContextInfo; } } @@ -201,7 +203,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 depCcCompilationInfos = new ArrayList<>(); + private final List depCcCompilationContextInfos = new ArrayList<>(); private final List looseIncludeDirs = new ArrayList<>(); private final List systemIncludeDirs = new ArrayList<>(); private final List includeDirs = new ArrayList<>(); @@ -227,7 +229,7 @@ public final class CcCompilationHelper { private boolean generatePicAction; // TODO(plf): Pull out of class. - private CcCompilationInfo ccCompilationInfo; + private CcCompilationContextInfo ccCompilationContextInfo; /** * Creates a CcCompilationHelper. @@ -542,8 +544,9 @@ public final class CcCompilationHelper { return this; } - public CcCompilationHelper addDepCcCompilationInfo(CcCompilationInfo ccCompilationInfo) { - this.depCcCompilationInfos.add(Preconditions.checkNotNull(ccCompilationInfo)); + public CcCompilationHelper addDepCcCompilationContextInfo( + CcCompilationContextInfo ccCompilationContextInfo) { + this.depCcCompilationContextInfos.add(Preconditions.checkNotNull(ccCompilationContextInfo)); return this; } @@ -693,11 +696,11 @@ public final class CcCompilationHelper { } } - ccCompilationInfo = initializeCcCompilationInfo(); + ccCompilationContextInfo = initializeCcCompilationContextInfo(); boolean compileHeaderModules = featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES); Preconditions.checkState( - !compileHeaderModules || ccCompilationInfo.getCppModuleMap() != null, + !compileHeaderModules || ccCompilationContextInfo.getCppModuleMap() != null, "All cc rules must support module maps."); // Create compile actions (both PIC and no-PIC). @@ -728,7 +731,7 @@ public final class CcCompilationHelper { new CppDebugFileProvider( dwoArtifacts.getDwoArtifacts(), dwoArtifacts.getPicDwoArtifacts()), collectTransitiveLipoInfo(ccOutputs)); - providers.put(ccCompilationInfo); + providers.put(ccCompilationContextInfo); Map> outputGroups = new TreeMap<>(); outputGroups.put(OutputGroupInfo.TEMP_FILES, getTemps(ccOutputs)); @@ -741,10 +744,11 @@ public final class CcCompilationHelper { ccOutputs.getFilesToCompile(isLipoCollector, processHeadersInDependencies, usePic)); outputGroups.put( OutputGroupInfo.COMPILATION_PREREQUISITES, - CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationInfo)); + CcCommon.collectCompilationPrerequisites(ruleContext, ccCompilationContextInfo)); } - return new CompilationInfo(providers.build(), outputGroups, ccOutputs, ccCompilationInfo); + return new CompilationInfo( + providers.build(), outputGroups, ccOutputs, ccCompilationContextInfo); } @Immutable @@ -882,12 +886,13 @@ public final class CcCompilationHelper { } /** - * Create {@code CcCompilationInfo} for cc compile action from generated inputs. + * Create {@code CcCompilationContextInfo} for cc compile action from generated inputs. * - *

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

TODO(plf): Try to pull out CcCompilationContextInfo building out of this class. */ - public CcCompilationInfo initializeCcCompilationInfo() { - CcCompilationInfo.Builder ccCompilationInfoBuilder = new CcCompilationInfo.Builder(ruleContext); + public CcCompilationContextInfo initializeCcCompilationContextInfo() { + CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = + new CcCompilationContextInfo.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), @@ -899,61 +904,63 @@ public final class CcCompilationHelper { // we might pick up stale generated files. PathFragment repositoryPath = ruleContext.getLabel().getPackageIdentifier().getRepository().getPathUnderExecRoot(); - ccCompilationInfoBuilder.addQuoteIncludeDir(repositoryPath); - ccCompilationInfoBuilder.addQuoteIncludeDir( + ccCompilationContextInfoBuilder.addQuoteIncludeDir(repositoryPath); + ccCompilationContextInfoBuilder.addQuoteIncludeDir( ruleContext.getConfiguration().getGenfilesFragment().getRelative(repositoryPath)); for (PathFragment systemIncludeDir : systemIncludeDirs) { - ccCompilationInfoBuilder.addSystemIncludeDir(systemIncludeDir); + ccCompilationContextInfoBuilder.addSystemIncludeDir(systemIncludeDir); } for (PathFragment includeDir : includeDirs) { - ccCompilationInfoBuilder.addIncludeDir(includeDir); + ccCompilationContextInfoBuilder.addIncludeDir(includeDir); } PublicHeaders publicHeaders = computePublicHeaders(); if (publicHeaders.getVirtualIncludePath() != null) { - ccCompilationInfoBuilder.addIncludeDir(publicHeaders.getVirtualIncludePath()); + ccCompilationContextInfoBuilder.addIncludeDir(publicHeaders.getVirtualIncludePath()); } if (useDeps) { - ccCompilationInfoBuilder.mergeDependentCcCompilationInfos( - AnalysisUtils.getProviders(deps, CcCompilationInfo.PROVIDER)); - ccCompilationInfoBuilder.mergeDependentCcCompilationInfos(depCcCompilationInfos); + ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( + AnalysisUtils.getProviders(deps, CcCompilationContextInfo.PROVIDER)); + ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( + depCcCompilationContextInfos); } - CppHelper.mergeToolchainDependentCcCompilationInfo( - ruleContext, ccToolchain, ccCompilationInfoBuilder); + CppHelper.mergeToolchainDependentCcCompilationContextInfo( + ruleContext, ccToolchain, ccCompilationContextInfoBuilder); // But defines come after those inherited from deps. - ccCompilationInfoBuilder.addDefines(defines); + ccCompilationContextInfoBuilder.addDefines(defines); // There are no ordering constraints for declared include dirs/srcs, or the pregrepped headers. - ccCompilationInfoBuilder.addDeclaredIncludeSrcs(publicHeaders.getHeaders()); - ccCompilationInfoBuilder.addDeclaredIncludeSrcs(publicTextualHeaders); - ccCompilationInfoBuilder.addDeclaredIncludeSrcs(privateHeaders); - ccCompilationInfoBuilder.addDeclaredIncludeSrcs(additionalInputs); - ccCompilationInfoBuilder.addNonCodeInputs(additionalInputs); - ccCompilationInfoBuilder.addModularHdrs(publicHeaders.getHeaders()); - ccCompilationInfoBuilder.addModularHdrs(privateHeaders); - ccCompilationInfoBuilder.addTextualHdrs(publicTextualHeaders); - ccCompilationInfoBuilder.addPregreppedHeaders( + 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( CppHelper.createExtractInclusions(ruleContext, semantics, publicHeaders.getHeaders())); - ccCompilationInfoBuilder.addPregreppedHeaders( + ccCompilationContextInfoBuilder.addPregreppedHeaders( CppHelper.createExtractInclusions(ruleContext, semantics, publicTextualHeaders)); - ccCompilationInfoBuilder.addPregreppedHeaders( + ccCompilationContextInfoBuilder.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) { - ccCompilationInfoBuilder.addDeclaredIncludeWarnDir( + ccCompilationContextInfoBuilder.addDeclaredIncludeWarnDir( ruleContext.getLabel().getPackageFragment()); for (PathFragment looseIncludeDir : looseIncludeDirs) { - ccCompilationInfoBuilder.addDeclaredIncludeWarnDir(looseIncludeDir); + ccCompilationContextInfoBuilder.addDeclaredIncludeWarnDir(looseIncludeDir); } } else if (headersCheckingMode == HeadersCheckingMode.LOOSE) { - ccCompilationInfoBuilder.addDeclaredIncludeDir(ruleContext.getLabel().getPackageFragment()); + ccCompilationContextInfoBuilder.addDeclaredIncludeDir( + ruleContext.getLabel().getPackageFragment()); for (PathFragment looseIncludeDir : looseIncludeDirs) { - ccCompilationInfoBuilder.addDeclaredIncludeDir(looseIncludeDir); + ccCompilationContextInfoBuilder.addDeclaredIncludeDir(looseIncludeDir); } } @@ -962,9 +969,9 @@ public final class CcCompilationHelper { cppModuleMap = CppHelper.createDefaultCppModuleMap(ruleContext, /*suffix=*/ ""); } - ccCompilationInfoBuilder.setPropagateCppModuleMapAsActionInput( + ccCompilationContextInfoBuilder.setPropagateCppModuleMapAsActionInput( propagateModuleMapToCompileAction); - ccCompilationInfoBuilder.setCppModuleMap(cppModuleMap); + ccCompilationContextInfoBuilder.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). @@ -986,10 +993,12 @@ public final class CcCompilationHelper { createModuleMapAction(cppModuleMap, publicHeaders, dependentModuleMaps, compiled)); } if (getGeneratesPicHeaderModule()) { - ccCompilationInfoBuilder.setPicHeaderModule(getPicHeaderModule(cppModuleMap.getArtifact())); + ccCompilationContextInfoBuilder.setPicHeaderModule( + getPicHeaderModule(cppModuleMap.getArtifact())); } if (getGeneratesNoPicHeaderModule()) { - ccCompilationInfoBuilder.setHeaderModule(getHeaderModule(cppModuleMap.getArtifact())); + ccCompilationContextInfoBuilder.setHeaderModule( + getHeaderModule(cppModuleMap.getArtifact())); } if (!compiled && featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS) @@ -1003,13 +1012,13 @@ public final class CcCompilationHelper { ruleContext.registerAction( createModuleMapAction( verificationMap, publicHeaders, dependentModuleMaps, /*compiledModule=*/ true)); - ccCompilationInfoBuilder.setVerificationModuleMap(verificationMap); + ccCompilationContextInfoBuilder.setVerificationModuleMap(verificationMap); } } - ccCompilationInfoBuilder.setPurpose(purpose); + ccCompilationContextInfoBuilder.setPurpose(purpose); - semantics.setupCcCompilationInfo(ruleContext, ccCompilationInfoBuilder); - return ccCompilationInfoBuilder.build(); + semantics.setupCcCompilationContextInfo(ruleContext, ccCompilationContextInfoBuilder); + return ccCompilationContextInfoBuilder.build(); } /** @@ -1039,9 +1048,9 @@ public final class CcCompilationHelper { } /** - * Sets the purpose for the {@code CcCompilationInfo}. + * Sets the purpose for the {@code CcCompilationContextInfo}. * - * @see CcCompilationInfo.Builder#setPurpose + * @see CcCompilationContextInfo.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. */ @@ -1088,15 +1097,15 @@ public final class CcCompilationHelper { List result = deps.stream().map(CPP_DEPS_TO_MODULES).collect(toCollection(ArrayList::new)); if (ruleContext.getRule().getAttributeDefinition(":stl") != null) { - CcCompilationInfo stl = - ruleContext.getPrerequisite(":stl", Mode.TARGET, CcCompilationInfo.PROVIDER); + CcCompilationContextInfo stl = + ruleContext.getPrerequisite(":stl", Mode.TARGET, CcCompilationContextInfo.PROVIDER); if (stl != null) { result.add(stl.getCppModuleMap()); } } if (ccToolchain != null) { - result.add(ccToolchain.getCcCompilationInfo().getCppModuleMap()); + result.add(ccToolchain.getCcCompilationContextInfo().getCppModuleMap()); } for (CppModuleMap additionalCppModuleMap : additionalCppModuleMaps) { result.add(additionalCppModuleMap); @@ -1227,14 +1236,14 @@ public final class CcCompilationHelper { */ private CcCompilationOutputs createCcCompileActions() throws RuleErrorException { CcCompilationOutputs.Builder result = new CcCompilationOutputs.Builder(); - Preconditions.checkNotNull(ccCompilationInfo); + Preconditions.checkNotNull(ccCompilationContextInfo); AnalysisEnvironment env = ruleContext.getAnalysisEnvironment(); if (shouldProvideHeaderModules()) { Label moduleMapLabel = - Label.parseAbsoluteUnchecked(ccCompilationInfo.getCppModuleMap().getName()); + Label.parseAbsoluteUnchecked(ccCompilationContextInfo.getCppModuleMap().getName()); Collection modules = - createModuleAction(result, ccCompilationInfo.getCppModuleMap()); + createModuleAction(result, ccCompilationContextInfo.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 @@ -1242,9 +1251,9 @@ public final class CcCompilationHelper { createModuleCodegenAction(result, moduleMapLabel, module); } } - } else if (ccCompilationInfo.getVerificationModuleMap() != null) { + } else if (ccCompilationContextInfo.getVerificationModuleMap() != null) { Collection modules = - createModuleAction(result, ccCompilationInfo.getVerificationModuleMap()); + createModuleAction(result, ccCompilationContextInfo.getVerificationModuleMap()); for (Artifact module : modules) { result.addHeaderTokenFile(module); } @@ -1304,7 +1313,7 @@ public final class CcCompilationHelper { source.getType() == CppSource.Type.CLIF_INPUT_PROTO ? ArtifactCategory.CLIF_OUTPUT_PROTO : ArtifactCategory.OBJECT_FILE, - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), /* addObject= */ true, isCodeCoverageEnabled(), // The source action does not generate dwo when it has bitcode @@ -1383,7 +1392,7 @@ public final class CcCompilationHelper { usePic, /* ccRelativeName= */ null, /* autoFdoImportPath= */ null, - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -1476,7 +1485,7 @@ public final class CcCompilationHelper { gcnoFile, dwoFile, ltoIndexingFile, - ccCompilationInfo, + ccCompilationContextInfo, ImmutableList.of(), userCompileFlags.build(), cppModuleMap, @@ -1502,13 +1511,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 CcCompilationInfo} and copts. + * inputs, output and dotd file names, {@code CcCompilationContextInfo} and copts. */ private CppCompileActionBuilder createCompileActionBuilder(Artifact source) { CppCompileActionBuilder builder = new CppCompileActionBuilder(ruleContext, ccToolchain, configuration); builder.setSourceFile(source); - builder.setCcCompilationInfo(ccCompilationInfo); + builder.setCcCompilationContextInfo(ccCompilationContextInfo); builder.setCoptsFilter(coptsFilter); return builder; } @@ -1563,7 +1572,7 @@ public final class CcCompilationHelper { /* usePic= */ pic, ccRelativeName, module.getExecPath(), - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), gcnoFile, dwoFile, /* ltoIndexingFile= */ null, @@ -1614,7 +1623,7 @@ public final class CcCompilationHelper { generatePicAction, /* ccRelativeName= */ null, /* autoFdoImportPath= */ null, - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -1675,13 +1684,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 ccCompilationInfo with the binary + // TODO(bazel-team): we shouldn't be needing this, merging ccCompilationContextInfo with the + // binary // is a superset of necessary information. LipoContextProvider lipoProvider = Preconditions.checkNotNull(CppHelper.getLipoContextProvider(ruleContext), outputName); - builder.setCcCompilationInfo( - CcCompilationInfo.mergeForLipo( - lipoProvider.getLipoCcCompilationInfo(), ccCompilationInfo)); + builder.setCcCompilationContextInfo( + CcCompilationContextInfo.mergeForLipo( + lipoProvider.getLipoCcCompilationContextInfo(), ccCompilationContextInfo)); } Preconditions.checkState(generatePicAction || generateNoPicAction); if (fake) { @@ -1730,7 +1740,7 @@ public final class CcCompilationHelper { /* usePic= */ true, ccRelativeName, sourceArtifact.getExecPath(), - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), gcnoFile, dwoFile, ltoIndexingFile, @@ -1905,7 +1915,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, execPath, - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -1944,7 +1954,7 @@ public final class CcCompilationHelper { // implementation (with caching results of this method) to avoid O(N^2) slowdown. if (ruleContext.getRule().isAttrDefined("deps", BuildType.LABEL_LIST)) { for (TransitiveInfoCollection dep : ruleContext.getPrerequisites("deps", Mode.TARGET)) { - if (dep.get(CcCompilationInfo.PROVIDER) != null + if (dep.get(CcCompilationContextInfo.PROVIDER) != null && InstrumentedFilesCollector.shouldIncludeLocalSources(configuration, dep)) { return true; } @@ -2013,7 +2023,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, source.getExecPath(), - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.getCppModuleMap(), /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, @@ -2035,7 +2045,7 @@ public final class CcCompilationHelper { usePic, ccRelativeName, source.getExecPath(), - ccCompilationInfo.getCppModuleMap(), + ccCompilationContextInfo.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 deleted file mode 100644 index b020862723..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationInfo.java +++ /dev/null @@ -1,938 +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.packages.NativeInfo; -import com.google.devtools.build.lib.packages.NativeProvider; -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.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." -) -public final class CcCompilationInfo extends NativeInfo { - public static final NativeProvider PROVIDER = - new NativeProvider(CcCompilationInfo.class, "CcCompilationInfo") {}; - - /** An empty {@code CcCompilationInfo}. */ - public static final CcCompilationInfo EMPTY = new Builder(null).build(); - - private final CommandLineCcCompilationInfo commandLineCcCompilationInfo; - - 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 - CcCompilationInfo( - CommandLineCcCompilationInfo commandLineCcCompilationInfo, - 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) { - super(PROVIDER); - Preconditions.checkNotNull(commandLineCcCompilationInfo); - this.commandLineCcCompilationInfo = commandLineCcCompilationInfo; - 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#mergeDependentCcCompilationInfo(CcCompilationInfo)}, and {@link - * Builder#mergeDependentCcCompilationInfos(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 commandLineCcCompilationInfo.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 commandLineCcCompilationInfo.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 commandLineCcCompilationInfo.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 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 commandLineCcCompilationInfo.defines; - } - - /** - * Returns a {@code CcCompilationInfo} that is based on a given {@code CcCompilationInfo} but - * returns empty sets for {@link #getDeclaredIncludeDirs()} and {@link - * #getDeclaredIncludeWarnDirs()}. - */ - public static CcCompilationInfo disallowUndeclaredHeaders(CcCompilationInfo ccCompilationInfo) { - return new CcCompilationInfo( - ccCompilationInfo.commandLineCcCompilationInfo, - ccCompilationInfo.compilationPrerequisites, - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - ccCompilationInfo.declaredIncludeSrcs, - ccCompilationInfo.pregreppedHdrs, - ccCompilationInfo.nonCodeInputs, - ccCompilationInfo.moduleInfo, - ccCompilationInfo.picModuleInfo, - ccCompilationInfo.directModuleMaps, - ccCompilationInfo.cppModuleMap, - ccCompilationInfo.verificationModuleMap, - ccCompilationInfo.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 ownerCcCompilationInfo the {@code CcCompilationInfo} of the owner binary - * @param libCcCompilationInfo the {@code CcCompilationInfo} of the library - */ - public static CcCompilationInfo mergeForLipo( - CcCompilationInfo ownerCcCompilationInfo, CcCompilationInfo libCcCompilationInfo) { - ImmutableSet.Builder prerequisites = ImmutableSet.builder(); - prerequisites.addAll(ownerCcCompilationInfo.compilationPrerequisites); - prerequisites.addAll(libCcCompilationInfo.compilationPrerequisites); - ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); - moduleInfo.merge(ownerCcCompilationInfo.moduleInfo); - moduleInfo.merge(libCcCompilationInfo.moduleInfo); - ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); - picModuleInfo.merge(ownerCcCompilationInfo.picModuleInfo); - picModuleInfo.merge(libCcCompilationInfo.picModuleInfo); - return new CcCompilationInfo( - libCcCompilationInfo.commandLineCcCompilationInfo, - prerequisites.build(), - mergeSets( - ownerCcCompilationInfo.declaredIncludeDirs, libCcCompilationInfo.declaredIncludeDirs), - mergeSets( - ownerCcCompilationInfo.declaredIncludeWarnDirs, - libCcCompilationInfo.declaredIncludeWarnDirs), - mergeSets( - ownerCcCompilationInfo.declaredIncludeSrcs, libCcCompilationInfo.declaredIncludeSrcs), - mergeSets(ownerCcCompilationInfo.pregreppedHdrs, libCcCompilationInfo.pregreppedHdrs), - mergeSets(ownerCcCompilationInfo.nonCodeInputs, libCcCompilationInfo.nonCodeInputs), - moduleInfo.build(), - picModuleInfo.build(), - mergeSets(ownerCcCompilationInfo.directModuleMaps, libCcCompilationInfo.directModuleMaps), - libCcCompilationInfo.cppModuleMap, - libCcCompilationInfo.verificationModuleMap, - libCcCompilationInfo.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 CcCompilationInfo} that influence the command line of compilation - * actions. - */ - @Immutable - @AutoCodec - @VisibleForSerialization - static class CommandLineCcCompilationInfo { - private final ImmutableList includeDirs; - private final ImmutableList quoteIncludeDirs; - private final ImmutableList systemIncludeDirs; - private final ImmutableList defines; - - CommandLineCcCompilationInfo( - ImmutableList includeDirs, - ImmutableList quoteIncludeDirs, - ImmutableList systemIncludeDirs, - ImmutableList defines) { - this.includeDirs = includeDirs; - this.quoteIncludeDirs = quoteIncludeDirs; - this.systemIncludeDirs = systemIncludeDirs; - this.defines = defines; - } - } - - /** Builder class for {@link CcCompilationInfo}. */ - 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 CcCompilationInfo} instance. */ - public Builder(RuleContext ruleContext) { - this.ruleContext = ruleContext; - } - - /** - * Overrides the purpose of this context. This is useful if a Target needs more than one - * CcCompilationInfo. (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 context of a dependency into this one by adding the contents of all of its - * attributes. - */ - public Builder mergeDependentCcCompilationInfo(CcCompilationInfo otherCcCompilationInfo) { - Preconditions.checkNotNull(otherCcCompilationInfo); - compilationPrerequisites.addAll( - otherCcCompilationInfo.getTransitiveCompilationPrerequisites()); - includeDirs.addAll(otherCcCompilationInfo.getIncludeDirs()); - quoteIncludeDirs.addAll(otherCcCompilationInfo.getQuoteIncludeDirs()); - systemIncludeDirs.addAll(otherCcCompilationInfo.getSystemIncludeDirs()); - declaredIncludeDirs.addTransitive(otherCcCompilationInfo.getDeclaredIncludeDirs()); - declaredIncludeWarnDirs.addTransitive(otherCcCompilationInfo.getDeclaredIncludeWarnDirs()); - declaredIncludeSrcs.addTransitive(otherCcCompilationInfo.getDeclaredIncludeSrcs()); - pregreppedHdrs.addTransitive(otherCcCompilationInfo.getPregreppedHeaders()); - moduleInfo.addTransitive(otherCcCompilationInfo.moduleInfo); - picModuleInfo.addTransitive(otherCcCompilationInfo.picModuleInfo); - nonCodeInputs.addTransitive(otherCcCompilationInfo.nonCodeInputs); - - // All module maps of direct dependencies are inputs to the current compile independently of - // the build type. - if (otherCcCompilationInfo.getCppModuleMap() != null) { - directModuleMaps.add(otherCcCompilationInfo.getCppModuleMap().getArtifact()); - } - - defines.addAll(otherCcCompilationInfo.getDefines()); - return this; - } - - /** - * Merges the {@code CcCompilationInfo}s of some targets into this one by adding the contents of - * all of their attributes. Targets that do not implement {@link CcCompilationInfo} are ignored. - */ - public Builder mergeDependentCcCompilationInfos(Iterable targets) { - for (CcCompilationInfo target : targets) { - mergeDependentCcCompilationInfo(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 CcCompilationInfo}. */ - public CcCompilationInfo build() { - return build( - ruleContext == null ? null : ruleContext.getActionOwner(), - ruleContext == null ? null : ruleContext.getAnalysisEnvironment().getMiddlemanFactory()); - } - - @VisibleForTesting // productionVisibility = Visibility.PRIVATE - public CcCompilationInfo build(ActionOwner owner, MiddlemanFactory middlemanFactory) { - // 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 CcCompilationInfo( - new CommandLineCcCompilationInfo( - 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/CcImport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcImport.java index 3a100a777e..3df13788ce 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,7 +170,8 @@ public abstract class CcImport implements RuleConfiguredTargetFactory { LinkingInfo linkingInfo = linkingHelper.link( - compilationInfo.getCcCompilationOutputs(), compilationInfo.getCcCompilationInfo()); + compilationInfo.getCcCompilationOutputs(), + compilationInfo.getCcCompilationContextInfo()); 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 80f3950d4a..8d0406545d 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 @@ -284,7 +284,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { CompilationInfo compilationInfo = compilationHelper.compile(); LinkingInfo linkingInfo = linkingHelper.link( - compilationInfo.getCcCompilationOutputs(), compilationInfo.getCcCompilationInfo()); + compilationInfo.getCcCompilationOutputs(), + compilationInfo.getCcCompilationContextInfo()); /* * 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 a842b86be9..df9613d460 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 @@ -327,9 +327,10 @@ public final class CcLinkParams { /** Adds a collection of linkstamps. */ public Builder addLinkstamps( - NestedSet linkstamps, CcCompilationInfo ccCompilationInfo) { + NestedSet linkstamps, CcCompilationContextInfo ccCompilationContextInfo) { for (Artifact linkstamp : linkstamps) { - linkstampsBuilder.add(new Linkstamp(linkstamp, ccCompilationInfo.getDeclaredIncludeSrcs())); + linkstampsBuilder.add( + new Linkstamp(linkstamp, ccCompilationContextInfo.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 2606f9056c..a764e8752e 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,12 +438,14 @@ public final class CcLinkingHelper { * * @throws RuleErrorException */ - // TODO(b/73997894): Try to remove CcCompilationInfo. Right now headers are passed as non code + // TODO(b/73997894): Try to remove CcCompilationContextInfo. Right now headers are passed as non + // code // inputs to the linker. - public LinkingInfo link(CcCompilationOutputs ccOutputs, CcCompilationInfo ccCompilationInfo) + public LinkingInfo link( + CcCompilationOutputs ccOutputs, CcCompilationContextInfo ccCompilationContextInfo) throws RuleErrorException, InterruptedException { Preconditions.checkNotNull(ccOutputs); - Preconditions.checkNotNull(ccCompilationInfo); + Preconditions.checkNotNull(ccCompilationContextInfo); if (checkDepsGenerateCpp) { for (LanguageDependentFragment dep : @@ -548,11 +550,11 @@ public final class CcLinkingHelper { if (emitCcSpecificLinkParamsProvider) { providers.add( new CcSpecificLinkParamsProvider( - createCcLinkParamsStore(ccLinkingOutputs, ccCompilationInfo, forcePic))); + createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); } else { providers.put( new CcLinkParamsInfo( - createCcLinkParamsStore(ccLinkingOutputs, ccCompilationInfo, forcePic))); + createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContextInfo, forcePic))); } return new LinkingInfo( providers.build(), outputGroups, ccLinkingOutputs, originalLinkingOutputs); @@ -633,13 +635,13 @@ public final class CcLinkingHelper { private CcLinkParamsStore createCcLinkParamsStore( final CcLinkingOutputs ccLinkingOutputs, - final CcCompilationInfo ccCompilationInfo, + final CcCompilationContextInfo ccCompilationContextInfo, final boolean forcePic) { return new CcLinkParamsStore() { @Override protected void collect( CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { - builder.addLinkstamps(linkstamps.build(), ccCompilationInfo); + builder.addLinkstamps(linkstamps.build(), ccCompilationContextInfo); 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 95a5a9436a..61c89dd801 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,8 +50,9 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider { + " src or headers attribute" + "(possibly empty but never None).") public NestedSet getTransitiveHeaders() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); - return ccCompilationInfo.getDeclaredIncludeSrcs(); + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); + return ccCompilationContextInfo.getDeclaredIncludeSrcs(); } @SkylarkCallable( @@ -97,8 +98,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() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); - return ccCompilationInfo == null ? ImmutableList.of() : ccCompilationInfo.getDefines(); + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); + return ccCompilationContextInfo == null + ? ImmutableList.of() + : ccCompilationContextInfo.getDefines(); } @SkylarkCallable( @@ -108,12 +112,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() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); - if (ccCompilationInfo == null) { + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); + if (ccCompilationContextInfo == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationInfo.getSystemIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.getSystemIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -126,12 +131,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() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); - if (ccCompilationInfo == null) { + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); + if (ccCompilationContextInfo == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationInfo.getIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.getIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -144,12 +150,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() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); - if (ccCompilationInfo == null) { + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); + if (ccCompilationContextInfo == null) { return ImmutableList.of(); } ImmutableList.Builder builder = ImmutableList.builder(); - for (PathFragment path : ccCompilationInfo.getQuoteIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.getQuoteIncludeDirs()) { builder.add(path.getSafePathString()); } return builder.build(); @@ -162,19 +169,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() { - CcCompilationInfo ccCompilationInfo = getInfo().get(CcCompilationInfo.PROVIDER); + CcCompilationContextInfo ccCompilationContextInfo = + getInfo().get(CcCompilationContextInfo.PROVIDER); ImmutableList.Builder options = ImmutableList.builder(); - for (String define : ccCompilationInfo.getDefines()) { + for (String define : ccCompilationContextInfo.getDefines()) { options.add("-D" + define); } - for (PathFragment path : ccCompilationInfo.getSystemIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.getSystemIncludeDirs()) { options.add("-isystem " + path.getSafePathString()); } - for (PathFragment path : ccCompilationInfo.getIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.getIncludeDirs()) { options.add("-I " + path.getSafePathString()); } - for (PathFragment path : ccCompilationInfo.getQuoteIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.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 c99bf1d24a..650f7c75c5 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 @@ -471,12 +471,14 @@ public class CcToolchain implements RuleConfiguredTargetFactory { Preconditions.checkState( (dynamicRuntimeLinkMiddleman == null) == dynamicRuntimeLinkSymlinks.isEmpty()); - CcCompilationInfo.Builder ccCompilationInfoBuilder = new CcCompilationInfo.Builder(ruleContext); + CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = + new CcCompilationContextInfo.Builder(ruleContext); CppModuleMap moduleMap = createCrosstoolModuleMap(ruleContext); if (moduleMap != null) { - ccCompilationInfoBuilder.setCppModuleMap(moduleMap); + ccCompilationContextInfoBuilder.setCppModuleMap(moduleMap); } - final CcCompilationInfo ccCompilationInfo = ccCompilationInfoBuilder.build(); + final CcCompilationContextInfo ccCompilationContextInfo = + ccCompilationContextInfoBuilder.build(); boolean supportsParamFiles = ruleContext.attributes().get("supports_param_files", BOOLEAN); boolean supportsHeaderParsing = ruleContext.attributes().get("supports_header_parsing", BOOLEAN); @@ -545,7 +547,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { dynamicRuntimeLinkSymlinks, dynamicRuntimeLinkMiddleman, runtimeSolibDir, - ccCompilationInfo, + ccCompilationContextInfo, 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 5347f5175b..d7625aae83 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 @@ -74,7 +74,7 @@ public final class CcToolchainProvider extends ToolchainInfo { /* dynamicRuntimeLinkInputs= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), /* dynamicRuntimeLinkMiddleman= */ null, /* dynamicRuntimeSolibDir= */ PathFragment.EMPTY_FRAGMENT, - CcCompilationInfo.EMPTY, + CcCompilationContextInfo.EMPTY, /* supportsParamFiles= */ false, /* supportsHeaderParsing= */ false, Variables.EMPTY, @@ -105,7 +105,7 @@ public final class CcToolchainProvider extends ToolchainInfo { private final NestedSet dynamicRuntimeLinkInputs; @Nullable private final Artifact dynamicRuntimeLinkMiddleman; private final PathFragment dynamicRuntimeSolibDir; - private final CcCompilationInfo ccCompilationInfo; + private final CcCompilationContextInfo ccCompilationContextInfo; private final boolean supportsParamFiles; private final boolean supportsHeaderParsing; private final Variables buildVariables; @@ -138,7 +138,7 @@ public final class CcToolchainProvider extends ToolchainInfo { NestedSet dynamicRuntimeLinkInputs, @Nullable Artifact dynamicRuntimeLinkMiddleman, PathFragment dynamicRuntimeSolibDir, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, boolean supportsParamFiles, boolean supportsHeaderParsing, Variables buildVariables, @@ -169,7 +169,7 @@ public final class CcToolchainProvider extends ToolchainInfo { this.dynamicRuntimeLinkInputs = Preconditions.checkNotNull(dynamicRuntimeLinkInputs); this.dynamicRuntimeLinkMiddleman = dynamicRuntimeLinkMiddleman; this.dynamicRuntimeSolibDir = Preconditions.checkNotNull(dynamicRuntimeSolibDir); - this.ccCompilationInfo = Preconditions.checkNotNull(ccCompilationInfo); + this.ccCompilationContextInfo = Preconditions.checkNotNull(ccCompilationContextInfo); this.supportsParamFiles = supportsParamFiles; this.supportsHeaderParsing = supportsHeaderParsing; this.buildVariables = buildVariables; @@ -375,9 +375,9 @@ public final class CcToolchainProvider extends ToolchainInfo { return dynamicRuntimeSolibDir; } - /** Returns the {@code CcCompilationInfo} for the toolchain. */ - public CcCompilationInfo getCcCompilationInfo() { - return ccCompilationInfo; + /** Returns the {@code CcCompilationContextInfo} for the toolchain. */ + public CcCompilationContextInfo getCcCompilationContextInfo() { + return ccCompilationContextInfo; } /** 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 453d61f37a..155b070dcc 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 @@ -54,19 +54,19 @@ public enum CompileBuildVariables { /** * Variable for the collection of include paths. * - * @see CcCompilationInfo#getIncludeDirs(). + * @see CcCompilationContextInfo#getIncludeDirs(). */ INCLUDE_PATHS("include_paths"), /** * Variable for the collection of quote include paths. * - * @see CcCompilationInfo#getIncludeDirs(). + * @see CcCompilationContextInfo#getIncludeDirs(). */ QUOTE_INCLUDE_PATHS("quote_include_paths"), /** * Variable for the collection of system include paths. * - * @see CcCompilationInfo#getIncludeDirs(). + * @see CcCompilationContextInfo#getIncludeDirs(). */ SYSTEM_INCLUDE_PATHS("system_include_paths"), /** Variable for the module map file name. */ @@ -111,7 +111,7 @@ public enum CompileBuildVariables { Artifact gcnoFile, Artifact dwoFile, Artifact ltoIndexingFile, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, ImmutableList includes, ImmutableList userCompileFlags, CppModuleMap cppModuleMap, @@ -174,7 +174,7 @@ public enum CompileBuildVariables { buildVariables.addStringVariable( MODULE_MAP_FILE.getVariableName(), cppModuleMap.getArtifact().getExecPathString()); StringSequenceBuilder sequence = new StringSequenceBuilder(); - for (Artifact artifact : ccCompilationInfo.getDirectModuleMaps()) { + for (Artifact artifact : ccCompilationContextInfo.getDirectModuleMaps()) { sequence.addValue(artifact.getExecPathString()); } buildVariables.addCustomBuiltVariable(DEPENDENT_MODULE_MAP_FILES.getVariableName(), sequence); @@ -185,13 +185,14 @@ public enum CompileBuildVariables { } if (featureConfiguration.isEnabled(CppRuleClasses.INCLUDE_PATHS)) { buildVariables.addStringSequenceVariable( - INCLUDE_PATHS.getVariableName(), getSafePathStrings(ccCompilationInfo.getIncludeDirs())); + INCLUDE_PATHS.getVariableName(), + getSafePathStrings(ccCompilationContextInfo.getIncludeDirs())); buildVariables.addStringSequenceVariable( QUOTE_INCLUDE_PATHS.getVariableName(), - getSafePathStrings(ccCompilationInfo.getQuoteIncludeDirs())); + getSafePathStrings(ccCompilationContextInfo.getQuoteIncludeDirs())); buildVariables.addStringSequenceVariable( SYSTEM_INCLUDE_PATHS.getVariableName(), - getSafePathStrings(ccCompilationInfo.getSystemIncludeDirs())); + getSafePathStrings(ccCompilationContextInfo.getSystemIncludeDirs())); } if (!includes.isEmpty()) { @@ -204,11 +205,11 @@ public enum CompileBuildVariables { // Stamp FDO builds with FDO subtype string defines = ImmutableList.builder() - .addAll(ccCompilationInfo.getDefines()) + .addAll(ccCompilationContextInfo.getDefines()) .add(CppConfiguration.FDO_STAMP_MACRO + "=\"" + fdoStamp + "\"") .build(); } else { - defines = ccCompilationInfo.getDefines(); + defines = ccCompilationContextInfo.getDefines(); } buildVariables.addStringSequenceVariable(PREPROCESSOR_DEFINES.getVariableName(), defines); 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 9d42abea81..3533ce071d 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 @@ -185,7 +185,7 @@ public class CppCompileAction extends AbstractAction protected final boolean needsIncludeValidation; private final IncludeProcessing includeProcessing; - private final CcCompilationInfo ccCompilationInfo; + private final CcCompilationContextInfo ccCompilationContextInfo; 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 @@ -250,7 +250,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 ccCompilationInfo the {@code CcCompilationInfo} + * @param ccCompilationContextInfo the {@code CcCompilationContextInfo} * @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 @@ -283,7 +283,7 @@ public class CppCompileAction extends AbstractAction @Nullable Artifact ltoIndexingFile, Artifact optionalSourceFile, ImmutableMap localShellEnvironment, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, CoptsFilter coptsFilter, Iterable lipoScannables, ImmutableList additionalIncludeScanningRoots, @@ -320,7 +320,7 @@ public class CppCompileAction extends AbstractAction usePic, useHeaderModules, isStrictSystemIncludes, - ccCompilationInfo, + ccCompilationContextInfo, lipoScannables, builtinIncludeFiles, ImmutableList.copyOf(additionalIncludeScanningRoots), @@ -364,7 +364,7 @@ public class CppCompileAction extends AbstractAction boolean usePic, boolean useHeaderModules, boolean isStrictSystemIncludes, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, Iterable lipoScannables, ImmutableList builtinIncludeFiles, ImmutableList additionalIncludeScanningRoots, @@ -396,7 +396,7 @@ public class CppCompileAction extends AbstractAction this.usePic = usePic; this.useHeaderModules = useHeaderModules; this.isStrictSystemIncludes = isStrictSystemIncludes; - this.ccCompilationInfo = ccCompilationInfo; + this.ccCompilationContextInfo = ccCompilationContextInfo; this.lipoScannables = lipoScannables; this.builtinIncludeFiles = builtinIncludeFiles; this.additionalIncludeScanningRoots = additionalIncludeScanningRoots; @@ -509,8 +509,9 @@ 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(ccCompilationInfo.getTransitiveModules(usePic).toCollection()); - result.addTransitive(ccCompilationInfo.getTransitiveModules(usePic)); + Sets.newLinkedHashSet( + ccCompilationContextInfo.getTransitiveModules(usePic).toCollection()); + result.addTransitive(ccCompilationContextInfo.getTransitiveModules(usePic)); } result.addTransitive(prunableInputs); return result.build(); @@ -537,8 +538,8 @@ public class CppCompileAction extends AbstractAction } else { usedModules = Sets.newLinkedHashSet(); topLevelModules = null; - for (CcCompilationInfo.TransitiveModuleHeaders usedModule : - ccCompilationInfo.getUsedModules(usePic, initialResultSet)) { + for (CcCompilationContextInfo.TransitiveModuleHeaders usedModule : + ccCompilationContextInfo.getUsedModules(usePic, initialResultSet)) { usedModules.add(usedModule.getModule()); } initialResultSet.addAll(usedModules); @@ -630,12 +631,12 @@ public class CppCompileAction extends AbstractAction public Map getLegalGeneratedScannerFileMap() { Map legalOuts = new HashMap<>(); - for (Artifact a : ccCompilationInfo.getDeclaredIncludeSrcs()) { + for (Artifact a : ccCompilationContextInfo.getDeclaredIncludeSrcs()) { if (!a.isSourceArtifact()) { legalOuts.put(a, null); } } - for (PregreppedHeader pregreppedSrcs : ccCompilationInfo.getPregreppedHeaders()) { + for (PregreppedHeader pregreppedSrcs : ccCompilationContextInfo.getPregreppedHeaders()) { Artifact hdr = pregreppedSrcs.originalHeader(); Preconditions.checkState(!hdr.isSourceArtifact(), hdr); legalOuts.put(hdr, pregreppedSrcs.greppedHeader()); @@ -658,19 +659,19 @@ public class CppCompileAction extends AbstractAction } @VisibleForTesting - public CcCompilationInfo getCcCompilationInfo() { - return ccCompilationInfo; + public CcCompilationContextInfo getCcCompilationContextInfo() { + return ccCompilationContextInfo; } @Override public List getQuoteIncludeDirs() { - return ccCompilationInfo.getQuoteIncludeDirs(); + return ccCompilationContextInfo.getQuoteIncludeDirs(); } @Override public List getIncludeDirs() { ImmutableList.Builder result = ImmutableList.builder(); - result.addAll(ccCompilationInfo.getIncludeDirs()); + result.addAll(ccCompilationContextInfo.getIncludeDirs()); for (String opt : compileCommandLine.getCopts()) { if (opt.startsWith("-I") && opt.length() > 2) { // We insist on the combined form "-Idir". @@ -687,7 +688,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 CcCompilationInfo} instead. + // get the system include paths from the {@code CcCompilationContextInfo} instead. ImmutableList.Builder result = ImmutableList.builder(); List compilerOptions = getCompilerOptions(); for (int i = 0; i < compilerOptions.size(); i++) { @@ -722,7 +723,7 @@ public class CppCompileAction extends AbstractAction @Override public Artifact getMainIncludeScannerSource() { return getSourceFile().isFileType(CppFileTypes.CPP_MODULE_MAP) - ? Iterables.getFirst(ccCompilationInfo.getHeaderModuleSrcs(), null) + ? Iterables.getFirst(ccCompilationContextInfo.getHeaderModuleSrcs(), null) : getSourceFile(); } @@ -734,7 +735,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(ccCompilationInfo.getHeaderModuleSrcs()); + builder.addAll(ccCompilationContextInfo.getHeaderModuleSrcs()); } else { builder.add(getSourceFile()); builder.addAll(additionalIncludeScanningRoots); @@ -753,7 +754,7 @@ public class CppCompileAction extends AbstractAction */ @VisibleForTesting public ImmutableCollection getDefines() { - return ccCompilationInfo.getDefines(); + return ccCompilationContextInfo.getDefines(); } @Override @@ -795,7 +796,7 @@ public class CppCompileAction extends AbstractAction } else { info.addSourcesAndHeaders(getSourceFile().getExecPathString()); info.addAllSourcesAndHeaders( - Artifact.toExecPaths(ccCompilationInfo.getDeclaredIncludeSrcs())); + Artifact.toExecPaths(ccCompilationContextInfo.getDeclaredIncludeSrcs())); } for (Entry envVariable : getEnvironment().entrySet()) { info.addVariable( @@ -872,14 +873,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(ccCompilationInfo.getDeclaredIncludeDirs()); + Sets.newHashSet(ccCompilationContextInfo.getDeclaredIncludeDirs()); Set warnIncludeDirs = - Sets.newHashSet(ccCompilationInfo.getDeclaredIncludeWarnDirs()); + Sets.newHashSet(ccCompilationContextInfo.getDeclaredIncludeWarnDirs()); Set declaredIncludeSrcs = Sets.newHashSet(getDeclaredIncludeSrcs()); Set transitiveModules = - Sets.newHashSet(ccCompilationInfo.getTransitiveModules(usePic)); + Sets.newHashSet(ccCompilationContextInfo.getTransitiveModules(usePic)); for (Artifact input : inputsForValidation) { - if (ccCompilationInfo.getTransitiveCompilationPrerequisites().contains(input) + if (ccCompilationContextInfo.getTransitiveCompilationPrerequisites().contains(input) || transitiveModules.contains(input) || allowedIncludes.contains(input)) { continue; // ignore our fixed source in mandatoryInput: we just want includes @@ -909,19 +910,21 @@ public class CppCompileAction extends AbstractAction System.err.println("INFO: Include(s) were OK for '" + getSourceFile() + "', declared srcs:"); } - for (Artifact a : ccCompilationInfo.getDeclaredIncludeSrcs()) { + for (Artifact a : ccCompilationContextInfo.getDeclaredIncludeSrcs()) { System.err.println(" '" + a.toDetailString() + "'"); } System.err.println(" or under declared dirs:"); - for (PathFragment f : Sets.newTreeSet(ccCompilationInfo.getDeclaredIncludeDirs())) { + for (PathFragment f : + Sets.newTreeSet(ccCompilationContextInfo.getDeclaredIncludeDirs())) { System.err.println(" '" + f + "'"); } System.err.println(" or under declared warn dirs:"); - for (PathFragment f : Sets.newTreeSet(ccCompilationInfo.getDeclaredIncludeWarnDirs())) { + for (PathFragment f : + Sets.newTreeSet(ccCompilationContextInfo.getDeclaredIncludeWarnDirs())) { System.err.println(" '" + f + "'"); } System.err.println(" with prefixes:"); - for (PathFragment dirpath : ccCompilationInfo.getQuoteIncludeDirs()) { + for (PathFragment dirpath : ccCompilationContextInfo.getQuoteIncludeDirs()) { System.err.println(" '" + dirpath + "'"); } } @@ -940,7 +943,7 @@ public class CppCompileAction extends AbstractAction Iterable getValidationIgnoredDirs() { List cxxSystemIncludeDirs = getBuiltInIncludeDirectories(); - return Iterables.concat(cxxSystemIncludeDirs, ccCompilationInfo.getSystemIncludeDirs()); + return Iterables.concat(cxxSystemIncludeDirs, ccCompilationContextInfo.getSystemIncludeDirs()); } /** @@ -1056,8 +1059,9 @@ public class CppCompileAction extends AbstractAction addToMap(allowedDerivedInputMap, mandatoryInputs); addToMap(allowedDerivedInputMap, prunableInputs); addToMap(allowedDerivedInputMap, getDeclaredIncludeSrcs()); - addToMap(allowedDerivedInputMap, ccCompilationInfo.getTransitiveCompilationPrerequisites()); - addToMap(allowedDerivedInputMap, ccCompilationInfo.getTransitiveModules(usePic)); + addToMap( + allowedDerivedInputMap, ccCompilationContextInfo.getTransitiveCompilationPrerequisites()); + addToMap(allowedDerivedInputMap, ccCompilationContextInfo.getTransitiveModules(usePic)); Artifact artifact = getSourceFile(); if (!artifact.isSourceArtifact()) { allowedDerivedInputMap.put(artifact.getExecPath(), artifact); @@ -1083,7 +1087,7 @@ public class CppCompileAction extends AbstractAction * listed in {@code declaredIncludeSrcs}). */ public NestedSet getDeclaredIncludeDirs() { - return ccCompilationInfo.getDeclaredIncludeDirs(); + return ccCompilationContextInfo.getDeclaredIncludeDirs(); } /** @@ -1091,7 +1095,7 @@ public class CppCompileAction extends AbstractAction * not specifically listed in {@code declaredIncludeSrcs}). */ public NestedSet getDeclaredIncludeWarnDirs() { - return ccCompilationInfo.getDeclaredIncludeWarnDirs(); + return ccCompilationContextInfo.getDeclaredIncludeWarnDirs(); } /** Return explicitly listed header files. */ @@ -1099,13 +1103,13 @@ public class CppCompileAction extends AbstractAction public NestedSet getDeclaredIncludeSrcs() { if (lipoScannables != null && lipoScannables.iterator().hasNext()) { NestedSetBuilder srcs = NestedSetBuilder.stableOrder(); - srcs.addTransitive(ccCompilationInfo.getDeclaredIncludeSrcs()); + srcs.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); for (IncludeScannable lipoScannable : lipoScannables) { srcs.addTransitive(lipoScannable.getDeclaredIncludeSrcs()); } return srcs.build(); } - return ccCompilationInfo.getDeclaredIncludeSrcs(); + return ccCompilationContextInfo.getDeclaredIncludeSrcs(); } /** @@ -1140,9 +1144,10 @@ 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(ccCompilationInfo.getDeclaredIncludeDirs()); - fp.addPaths(ccCompilationInfo.getDeclaredIncludeWarnDirs()); - actionKeyContext.addNestedSetToFingerprint(fp, ccCompilationInfo.getDeclaredIncludeSrcs()); + fp.addPaths(ccCompilationContextInfo.getDeclaredIncludeDirs()); + fp.addPaths(ccCompilationContextInfo.getDeclaredIncludeWarnDirs()); + actionKeyContext.addNestedSetToFingerprint( + fp, ccCompilationContextInfo.getDeclaredIncludeSrcs()); fp.addInt(0); // mark the boundary between input types actionKeyContext.addNestedSetToFingerprint(fp, getMandatoryInputs()); fp.addInt(0); @@ -1375,7 +1380,7 @@ public class CppCompileAction extends AbstractAction legend = " Argument: "; } - for (PathFragment path : ccCompilationInfo.getDeclaredIncludeDirs()) { + for (PathFragment path : ccCompilationContextInfo.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 6a5271520a..43c54bc2bf 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 @@ -63,7 +63,7 @@ public class CppCompileActionBuilder { private PathFragment tempOutputFile; private DotdFile dotdFile; private Artifact gcnoFile; - private CcCompilationInfo ccCompilationInfo = CcCompilationInfo.EMPTY; + private CcCompilationContextInfo ccCompilationContextInfo = CcCompilationContextInfo.EMPTY; private final List pluginOpts = new ArrayList<>(); private CoptsFilter coptsFilter = CoptsFilter.alwaysPasses(); private ImmutableList extraSystemIncludePrefixes = ImmutableList.of(); @@ -147,7 +147,7 @@ public class CppCompileActionBuilder { this.tempOutputFile = other.tempOutputFile; this.dotdFile = other.dotdFile; this.gcnoFile = other.gcnoFile; - this.ccCompilationInfo = other.ccCompilationInfo; + this.ccCompilationContextInfo = other.ccCompilationContextInfo; this.pluginOpts.addAll(other.pluginOpts); this.coptsFilter = other.coptsFilter; this.extraSystemIncludePrefixes = ImmutableList.copyOf(other.extraSystemIncludePrefixes); @@ -200,8 +200,8 @@ public class CppCompileActionBuilder { return sourceFile; } - public CcCompilationInfo getCcCompilationInfo() { - return ccCompilationInfo; + public CcCompilationContextInfo getCcCompilationContextInfo() { + return ccCompilationContextInfo; } public NestedSet getMandatoryInputs() { @@ -336,7 +336,7 @@ public class CppCompileActionBuilder { NestedSet allInputs = buildAllInputs(realMandatoryInputs); NestedSetBuilder prunableInputBuilder = NestedSetBuilder.stableOrder(); - prunableInputBuilder.addTransitive(ccCompilationInfo.getDeclaredIncludeSrcs()); + prunableInputBuilder.addTransitive(ccCompilationContextInfo.getDeclaredIncludeSrcs()); prunableInputBuilder.addTransitive(cppSemantics.getAdditionalPrunableIncludes()); Iterable lipoScannables = getLipoScannables(realMandatoryInputs); @@ -380,7 +380,7 @@ public class CppCompileActionBuilder { tempOutputFile, dotdFile, localShellEnvironment, - ccCompilationInfo, + ccCompilationContextInfo, coptsFilter, getLipoScannables(realMandatoryInputs), cppSemantics, @@ -412,7 +412,7 @@ public class CppCompileActionBuilder { ltoIndexingFile, optionalSourceFile, localShellEnvironment, - ccCompilationInfo, + ccCompilationContextInfo, coptsFilter, getLipoScannables(realMandatoryInputs), additionalIncludeScanningRoots.build(), @@ -446,11 +446,13 @@ public class CppCompileActionBuilder { NestedSetBuilder realMandatoryInputsBuilder = NestedSetBuilder.compileOrder(); realMandatoryInputsBuilder.addTransitive(mandatoryInputsBuilder.build()); realMandatoryInputsBuilder.addAll(getBuiltinIncludeFiles()); - realMandatoryInputsBuilder.addAll(ccCompilationInfo.getTransitiveCompilationPrerequisites()); + realMandatoryInputsBuilder.addAll( + ccCompilationContextInfo.getTransitiveCompilationPrerequisites()); if (useHeaderModules() && !shouldPruneModules()) { - realMandatoryInputsBuilder.addTransitive(ccCompilationInfo.getTransitiveModules(usePic)); + realMandatoryInputsBuilder.addTransitive( + ccCompilationContextInfo.getTransitiveModules(usePic)); } - realMandatoryInputsBuilder.addTransitive(ccCompilationInfo.getAdditionalInputs()); + realMandatoryInputsBuilder.addTransitive(ccCompilationContextInfo.getAdditionalInputs()); realMandatoryInputsBuilder.add(Preconditions.checkNotNull(sourceFile)); if (grepIncludes != null) { realMandatoryInputsBuilder.add(grepIncludes); @@ -658,8 +660,9 @@ public class CppCompileActionBuilder { return this; } - public CppCompileActionBuilder setCcCompilationInfo(CcCompilationInfo ccCompilationInfo) { - this.ccCompilationInfo = ccCompilationInfo; + public CppCompileActionBuilder setCcCompilationContextInfo( + CcCompilationContextInfo ccCompilationContextInfo) { + this.ccCompilationContextInfo = ccCompilationContextInfo; 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 a8e609824e..2f9f067dbc 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 @@ -199,10 +199,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment { private final boolean shouldProvideMakeVariables; private final boolean dropFullyStaticLinkingMode; - /** * If true, the ConfiguredTarget is only used to get the necessary cross-referenced {@code - * CcCompilationInfo}s, but registering build actions is disabled. + * CcCompilationContextInfo}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 c79c3da3e6..c95219225c 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 @@ -57,7 +57,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.packages.RuleErrorConsumer; -import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo.Builder; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo.Builder; import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Linkstamp; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Tool; @@ -113,22 +113,25 @@ public class CppHelper { * Merges the STL and toolchain contexts into context builder. The STL is automatically determined * using the ":stl" attribute. */ - public static void mergeToolchainDependentCcCompilationInfo( - RuleContext ruleContext, CcToolchainProvider toolchain, Builder ccCompilationInfoBuilder) { + public static void mergeToolchainDependentCcCompilationContextInfo( + RuleContext ruleContext, + CcToolchainProvider toolchain, + Builder ccCompilationContextInfoBuilder) { if (ruleContext.getRule().getAttributeDefinition(":stl") != null) { TransitiveInfoCollection stl = ruleContext.getPrerequisite(":stl", Mode.TARGET); if (stl != null) { - CcCompilationInfo provider = stl.get(CcCompilationInfo.PROVIDER); + CcCompilationContextInfo provider = stl.get(CcCompilationContextInfo.PROVIDER); if (provider == null) { ruleContext.ruleError("Unable to merge the STL '" + stl.getLabel() + "' and toolchain contexts"); return; } - ccCompilationInfoBuilder.mergeDependentCcCompilationInfo(provider); + ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfo(provider); } } if (toolchain != null) { - ccCompilationInfoBuilder.mergeDependentCcCompilationInfo(toolchain.getCcCompilationInfo()); + ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfo( + toolchain.getCcCompilationContextInfo()); } } @@ -697,7 +700,7 @@ public class CppHelper { /** * Emits a warning on the rule if there are identical linkstamp artifacts with different {@code - * CcCompilationInfo}s. + * CcCompilationContextInfo}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/CppLinkstampCompileHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java index b3e8b56a92..f059510d91 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java @@ -143,8 +143,8 @@ public class CppLinkstampCompileHelper { // TODO(b/34761650): Remove all this hardcoding by separating a full blown compile action. Preconditions.checkArgument( featureConfiguration.actionIsConfigured(CppCompileAction.LINKSTAMP_COMPILE)); - CcCompilationInfo ccCompilationInfo = - new CcCompilationInfo.Builder(ruleContext) + CcCompilationContextInfo ccCompilationContextInfo = + new CcCompilationContextInfo.Builder(ruleContext) .addIncludeDir(PathFragment.create(".")) .addDefines( computeAllLinkstampDefines( @@ -165,7 +165,7 @@ public class CppLinkstampCompileHelper { /* gcnoFile= */ null, /* dwoFile= */ null, /* ltoIndexingFile= */ null, - ccCompilationInfo, + ccCompilationContextInfo, buildInfoHeaderArtifacts .stream() .map(Artifact::getExecPathString) 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 4dce64b0fe..fe939422d1 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 CcCompilationInfo}s are finalized. + * Called before {@link CcCompilationContextInfo}s are finalized. * *

Gives the semantics implementation the opportunity to change what the C++ rule propagates to * dependent rules. */ - void setupCcCompilationInfo( - RuleContext ruleContext, CcCompilationInfo.Builder ccCompilationInfoBuilder); + void setupCcCompilationContextInfo( + RuleContext ruleContext, CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder); /** * 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 a3aa127b07..0a35544599 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 @@ -75,7 +75,7 @@ public class FakeCppCompileAction extends CppCompileAction { PathFragment tempOutputFile, DotdFile dotdFile, ImmutableMap localShellEnvironment, - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, CoptsFilter nocopts, Iterable lipoScannables, CppSemantics cppSemantics, @@ -112,7 +112,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.) - CcCompilationInfo.disallowUndeclaredHeaders(ccCompilationInfo), + CcCompilationContextInfo.disallowUndeclaredHeaders(ccCompilationContextInfo), nocopts, lipoScannables, 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 e86514e199..7f19208e98 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 CcCompilationInfo} for LIPO compilation actions is pieced - * together from the {@code CcCompilationInfo} in LipoContextProvider and that of the rule being - * compiled. (see {@link CcCompilationInfo#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 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. * *

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 bf3771718e..6f9f5fc697 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 CcCompilationInfo ccCompilationInfo; + private final CcCompilationContextInfo ccCompilationContextInfo; private final ImmutableMap includeScannables; private final ImmutableMap sourceArtifactMap; @AutoCodec.Instantiator public LipoContextProvider( - CcCompilationInfo ccCompilationInfo, + CcCompilationContextInfo ccCompilationContextInfo, Map includeScannables, Map sourceArtifactMap) { - this.ccCompilationInfo = ccCompilationInfo; + this.ccCompilationContextInfo = ccCompilationContextInfo; this.includeScannables = ImmutableMap.copyOf(includeScannables); this.sourceArtifactMap = ImmutableMap.copyOf(sourceArtifactMap); } - /** Returns merged {@code CcCompilationInfo} for the whole LIPO subtree. */ - public CcCompilationInfo getLipoCcCompilationInfo() { - return ccCompilationInfo; + /** Returns merged {@code CcCompilationContextInfo} for the whole LIPO subtree. */ + public CcCompilationContextInfo getLipoCcCompilationContextInfo() { + return ccCompilationContextInfo; } /** 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 acb8bd7aeb..3d5adfc97d 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 @@ -194,7 +194,7 @@ public abstract class CcProtoAspect extends NativeAspectClass implements Configu initializeLinkingHelper(featureConfiguration) .link( compilationInfo.getCcCompilationOutputs(), - compilationInfo.getCcCompilationInfo()); + compilationInfo.getCcCompilationContextInfo()); ccLibraryProviders = new TransitiveInfoProviderMapBuilder() diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index 3b34318e64..49832a9d4d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -49,7 +49,7 @@ import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; -import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; import com.google.devtools.build.lib.rules.cpp.LinkerInput; import com.google.devtools.build.lib.rules.java.JavaCompilationArgs.ClasspathType; import com.google.devtools.build.lib.syntax.Type; @@ -410,12 +410,13 @@ public class JavaCommon { } /** Collects transitive C++ dependencies. */ - protected CcCompilationInfo collectTransitiveCppDeps() { - CcCompilationInfo.Builder builder = new CcCompilationInfo.Builder(ruleContext); + protected CcCompilationContextInfo collectTransitiveCppDeps() { + CcCompilationContextInfo.Builder builder = new CcCompilationContextInfo.Builder(ruleContext); for (TransitiveInfoCollection dep : targetsTreatedAsDeps(ClasspathType.BOTH)) { - CcCompilationInfo ccCompilationInfo = dep.get(CcCompilationInfo.PROVIDER); - if (ccCompilationInfo != null) { - builder.mergeDependentCcCompilationInfo(ccCompilationInfo); + CcCompilationContextInfo ccCompilationContextInfo = + dep.get(CcCompilationContextInfo.PROVIDER); + if (ccCompilationContextInfo != null) { + builder.mergeDependentCcCompilationContextInfo(ccCompilationContextInfo); } } return builder.build(); 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 6de440a748..def979fdb3 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 @@ -89,9 +89,9 @@ 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.CcCompilationHelper; import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo; -import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo; import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs; import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper; import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo; @@ -446,21 +446,22 @@ public class CompilationSupport { resultLink.addLinkActionInput(linkActionInput); } - CcCompilationInfo.Builder ccCompilationInfoBuilder = new CcCompilationInfo.Builder(ruleContext); - ccCompilationInfoBuilder.mergeDependentCcCompilationInfos( + CcCompilationContextInfo.Builder ccCompilationContextInfoBuilder = + new CcCompilationContextInfo.Builder(ruleContext); + ccCompilationContextInfoBuilder.mergeDependentCcCompilationContextInfos( Arrays.asList( - objcArcCompilationInfo.getCcCompilationInfo(), - nonObjcArcCompilationInfo.getCcCompilationInfo())); - ccCompilationInfoBuilder.setPurpose( + objcArcCompilationInfo.getCcCompilationContextInfo(), + nonObjcArcCompilationInfo.getCcCompilationContextInfo())); + ccCompilationContextInfoBuilder.setPurpose( String.format("%s_merged_arc_non_arc_objc", semantics.getPurpose())); - semantics.setupCcCompilationInfo(ruleContext, ccCompilationInfoBuilder); + semantics.setupCcCompilationContextInfo(ruleContext, ccCompilationContextInfoBuilder); CcCompilationOutputs.Builder compilationOutputsBuilder = new CcCompilationOutputs.Builder(); compilationOutputsBuilder.merge(objcArcCompilationInfo.getCcCompilationOutputs()); compilationOutputsBuilder.merge(nonObjcArcCompilationInfo.getCcCompilationOutputs()); LinkingInfo linkingInfo = - resultLink.link(compilationOutputsBuilder.build(), ccCompilationInfoBuilder.build()); + resultLink.link(compilationOutputsBuilder.build(), ccCompilationContextInfoBuilder.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 1b1a89d527..d4a26a234d 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.CcCompilationInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParams; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; import com.google.devtools.build.lib.rules.cpp.CppFileTypes; @@ -167,7 +167,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(); /** @@ -256,17 +256,18 @@ public final class ObjcCommon { Builder addDeps(List deps) { ImmutableList.Builder propagatedObjcDeps = ImmutableList.builder(); - ImmutableList.Builder cppDeps = ImmutableList.builder(); + ImmutableList.Builder cppDeps = + ImmutableList.builder(); ImmutableList.Builder cppDepLinkParams = ImmutableList.builder(); for (ConfiguredTargetAndData dep : deps) { ConfiguredTarget depCT = dep.getConfiguredTarget(); addAnyProviders(propagatedObjcDeps, depCT, ObjcProvider.SKYLARK_CONSTRUCTOR); - addAnyProviders(cppDeps, depCT, CcCompilationInfo.PROVIDER); + addAnyProviders(cppDeps, depCT, CcCompilationContextInfo.PROVIDER); if (isCcLibrary(dep)) { cppDepLinkParams.add(depCT.get(CcLinkParamsInfo.PROVIDER)); - addDefines(depCT.get(CcCompilationInfo.PROVIDER).getDefines()); + addDefines(depCT.get(CcCompilationContextInfo.PROVIDER).getDefines()); } } addDepObjcProviders(propagatedObjcDeps.build()); @@ -422,11 +423,11 @@ public final class ObjcCommon { objcProvider.addTransitiveAndPropagate(ObjcProvider.MERGE_ZIP, provider); } - for (CcCompilationInfo headerProvider : depCcHeaderProviders) { + for (CcCompilationContextInfo headerProvider : depCcHeaderProviders) { objcProvider.addAll(HEADER, filterFileset(headerProvider.getDeclaredIncludeSrcs())); objcProvider.addAll(INCLUDE, headerProvider.getIncludeDirs()); // TODO(bazel-team): This pulls in stl via - // CppHelper.mergeToolchainDependentCcCompilationInfo but + // CppHelper.mergeToolchainDependentCcCompilationContextInfo 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 53836f4348..9e496fa3ce 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,8 +24,8 @@ 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.CcCompilationInfo; -import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo.Builder; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo.Builder; 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; @@ -122,12 +122,13 @@ public class ObjcCppSemantics implements CppSemantics { } @Override - public void setupCcCompilationInfo(RuleContext ruleContext, Builder ccCompilationInfoBuilder) { + public void setupCcCompilationContextInfo( + RuleContext ruleContext, Builder ccCompilationContextInfoBuilder) { // 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())) { - ccCompilationInfoBuilder.addQuoteIncludeDir(iquotePath); + ccCompilationContextInfoBuilder.addQuoteIncludeDir(iquotePath); } } @@ -168,12 +169,13 @@ public class ObjcCppSemantics implements CppSemantics { } /** - * Gets the purpose for the {@code CcCompilationInfo}. + * Gets the purpose for the {@code CcCompilationContextInfo}. * - * @see CcCompilationInfo.Builder#setPurpose + * @see CcCompilationContextInfo.Builder#setPurpose */ public String getPurpose() { - // ProtoSupport creates multiple {@code CcCompilationInfo}s for a single rule, potentially + // ProtoSupport creates multiple {@code CcCompilationContextInfo}s for a single rule, + // potentially // multiple archives per build configuration. This covers that worst case. return "ObjcCppSemantics_build_arch_" + buildConfiguration.getMnemonic() 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 323de180cd..ec1be25f8b 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.CcCompilationInfo; +import com.google.devtools.build.lib.rules.cpp.CcCompilationContextInfo; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsInfo; import com.google.devtools.build.lib.rules.objc.ObjcCommon.ResourceAttributes; import com.google.devtools.build.lib.syntax.Type; @@ -92,8 +92,8 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder() .addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)).build(); - CcCompilationInfo ccCompilationInfo = - new CcCompilationInfo.Builder(ruleContext) + CcCompilationContextInfo ccCompilationContextInfo = + new CcCompilationContextInfo.Builder(ruleContext) .addDeclaredIncludeSrcs( CompilationAttributes.Builder.fromRuleContext(ruleContext) .build() @@ -103,7 +103,7 @@ public class ObjcLibrary implements RuleConfiguredTargetFactory { return ObjcRuleClasses.ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addNativeDeclaredProvider(common.getObjcProvider()) - .addNativeDeclaredProvider(ccCompilationInfo) + .addNativeDeclaredProvider(ccCompilationContextInfo) .addProvider(J2ObjcEntryClassProvider.class, j2ObjcEntryClassProvider) .addProvider(J2ObjcMappingFileProvider.class, j2ObjcMappingFileProvider) .addProvider( 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 9b61941914..10cc6500d0 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 - * CcCompilationInfo} in the transitive closure of the rule. + * CcCompilationContextInfo} in the transitive closure of the rule. */ private static void expandRecursiveHelper( ActionGraph actionGraph, -- cgit v1.2.3