@VisibleForTesting // productionVisibility = Visibility.PRIVATE public CppCompilationContext 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 CppCompilationContext( new CommandLineContext( ImmutableList.copyOf(includeDirs), ImmutableList.copyOf(quoteIncludeDirs), ImmutableList.copyOf(systemIncludeDirs), ImmutableList.copyOf(defines)), prerequisiteStampFile == null ? ImmutableSet.<Artifact>of() : ImmutableSet.of(prerequisiteStampFile), declaredIncludeDirs.build(), declaredIncludeWarnDirs.build(), declaredIncludeSrcs.build(), pregreppedHdrs.build(), moduleInfo.build(), picModuleInfo.build(), transitiveModuleMaps.build(), directModuleMaps.build(), cppModuleMap, provideTransitiveModuleMaps, useHeaderModules); }
/** * Merges the context of a dependency into this one by adding the contents of all of its * attributes. */ public Builder mergeDependentContext(CppCompilationContext otherContext) { Preconditions.checkNotNull(otherContext); compilationPrerequisites.addAll(otherContext.getTransitiveCompilationPrerequisites()); includeDirs.addAll(otherContext.getIncludeDirs()); quoteIncludeDirs.addAll(otherContext.getQuoteIncludeDirs()); systemIncludeDirs.addAll(otherContext.getSystemIncludeDirs()); declaredIncludeDirs.addTransitive(otherContext.getDeclaredIncludeDirs()); declaredIncludeWarnDirs.addTransitive(otherContext.getDeclaredIncludeWarnDirs()); declaredIncludeSrcs.addTransitive(otherContext.getDeclaredIncludeSrcs()); pregreppedHdrs.addTransitive(otherContext.getPregreppedHeaders()); moduleInfo.addTransitive(otherContext.moduleInfo); picModuleInfo.addTransitive(otherContext.picModuleInfo); NestedSet<Artifact> othersTransitiveModuleMaps = otherContext.getTransitiveModuleMaps(); NestedSet<Artifact> othersDirectModuleMaps = otherContext.getDirectModuleMaps(); // Forward transitive information. // The other target's transitive module maps do not include its direct module maps, so we // add both. transitiveModuleMaps.addTransitive(othersTransitiveModuleMaps); transitiveModuleMaps.addTransitive(othersDirectModuleMaps); // All module maps of direct dependencies are inputs to the current compile independently of // the build type. if (otherContext.getCppModuleMap() != null) { directModuleMaps.add(otherContext.getCppModuleMap().getArtifact()); } defines.addAll(otherContext.getDefines()); 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. */ public Builder addDeclaredIncludeSrc(Artifact header) { declaredIncludeSrcs.add(header); compilationPrerequisites.add(header); moduleInfo.addHeader(header); picModuleInfo.addHeader(header); return this; }
/** * 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. * * <p>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). * * <p>Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, {@link * #getDeclaredIncludeWarnDirs()}, and {@link #getDeclaredIncludeSrcs()}) needs to use the union * of the contexts of the involved source files. * * <p>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. * * <p>Include scanning is not handled by this method. See {@code * IncludeScannable#getAuxiliaryScannables()} instead. * * @param ownerContext the compilation context of the owner binary * @param libContext the compilation context of the library */ public static CppCompilationContext mergeForLipo( CppCompilationContext ownerContext, CppCompilationContext libContext) { ImmutableSet.Builder<Artifact> prerequisites = ImmutableSet.builder(); prerequisites.addAll(ownerContext.compilationPrerequisites); prerequisites.addAll(libContext.compilationPrerequisites); ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); moduleInfo.merge(ownerContext.moduleInfo); moduleInfo.merge(libContext.moduleInfo); ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); picModuleInfo.merge(ownerContext.picModuleInfo); picModuleInfo.merge(libContext.picModuleInfo); return new CppCompilationContext( libContext.commandLineContext, prerequisites.build(), mergeSets(ownerContext.declaredIncludeDirs, libContext.declaredIncludeDirs), mergeSets(ownerContext.declaredIncludeWarnDirs, libContext.declaredIncludeWarnDirs), mergeSets(ownerContext.declaredIncludeSrcs, libContext.declaredIncludeSrcs), mergeSets(ownerContext.pregreppedHdrs, libContext.pregreppedHdrs), moduleInfo.build(), picModuleInfo.build(), mergeSets(ownerContext.transitiveModuleMaps, libContext.transitiveModuleMaps), mergeSets(ownerContext.directModuleMaps, libContext.directModuleMaps), libContext.cppModuleMap, libContext.provideTransitiveModuleMaps, libContext.useHeaderModules); }