aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java274
1 files changed, 134 insertions, 140 deletions
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 6f574abe67..f768eda0f5 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
@@ -88,9 +88,12 @@ import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType;
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.CcCompilationHelper;
+import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs;
-import com.google.devtools.build.lib.rules.cpp.CcLibraryHelper;
-import com.google.devtools.build.lib.rules.cpp.CcLibraryHelper.Info;
+import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper;
+import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchain;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.CollidingProvidesException;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
@@ -301,7 +304,7 @@ public class CompilationSupport {
}
}
- private Info.CompilationInfo compile(
+ private CompilationInfo compile(
ObjcProvider objcProvider,
VariablesExtension extension,
ExtraCompileArgs extraCompileArgs,
@@ -318,12 +321,12 @@ public class CompilationSupport {
ObjcCppSemantics semantics,
String purpose)
throws RuleErrorException, InterruptedException {
- CcLibraryHelper result =
- new CcLibraryHelper(
+ CcCompilationHelper result =
+ new CcCompilationHelper(
ruleContext,
semantics,
getFeatureConfiguration(ruleContext, ccToolchain, buildConfiguration, objcProvider),
- CcLibraryHelper.SourceCategory.CC_AND_OBJC,
+ CcCompilationHelper.SourceCategory.CC_AND_OBJC,
ccToolchain,
fdoSupport,
buildConfiguration)
@@ -398,7 +401,7 @@ public class CompilationSupport {
String purpose = String.format("%s_objc_arc", semantics.getPurpose());
extensionBuilder.setArcEnabled(true);
- Info.CompilationInfo objcArcCompilationInfo =
+ CompilationInfo objcArcCompilationInfo =
compile(
objcProvider,
extensionBuilder.build(),
@@ -417,7 +420,7 @@ public class CompilationSupport {
purpose = String.format("%s_non_objc_arc", semantics.getPurpose());
extensionBuilder.setArcEnabled(false);
- Info.CompilationInfo nonObjcArcCompilationInfo =
+ CompilationInfo nonObjcArcCompilationInfo =
compile(
objcProvider,
extensionBuilder.build(),
@@ -434,23 +437,18 @@ public class CompilationSupport {
semantics,
purpose);
- CcLibraryHelper resultLink =
- new CcLibraryHelper(
+ CcLinkingHelper resultLink =
+ new CcLinkingHelper(
ruleContext,
semantics,
getFeatureConfiguration(ruleContext, ccToolchain, buildConfiguration, objcProvider),
- CcLibraryHelper.SourceCategory.CC_AND_OBJC,
ccToolchain,
fdoSupport,
buildConfiguration)
- .addPrecompiledFiles(precompiledFiles)
.addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET))
- // Not all our dependencies need to export cpp information.
- // For example, objc_proto_library can depend on a proto_library rule that does not
- // generate C++ protos.
- .setCheckDepsGenerateCpp(false)
.setLinkedArtifactNameSuffix(intermediateArtifacts.archiveFileNameSuffix())
.setNeverLink(true)
+ .setCheckDepsGenerateCpp(false)
.addVariableExtension(extensionBuilder.build());
if (linkType != null) {
@@ -475,15 +473,15 @@ public class CompilationSupport {
compilationOutputsBuilder.merge(objcArcCompilationInfo.getCcCompilationOutputs());
compilationOutputsBuilder.merge(nonObjcArcCompilationInfo.getCcCompilationOutputs());
- Info.LinkingInfo linkingInfo =
- resultLink.link(
- compilationOutputsBuilder.build(), compilationContextBuilder.build());
+ LinkingInfo linkingInfo =
+ resultLink.link(compilationOutputsBuilder.build(), compilationContextBuilder.build());
Map<String, NestedSet<Artifact>> mergedOutputGroups =
- Info.mergeOutputGroups(
- objcArcCompilationInfo.getOutputGroups(),
- nonObjcArcCompilationInfo.getOutputGroups(),
- linkingInfo.getOutputGroups());
+ CcCommon.mergeOutputGroups(
+ ImmutableList.of(
+ objcArcCompilationInfo.getOutputGroups(),
+ nonObjcArcCompilationInfo.getOutputGroups(),
+ linkingInfo.getOutputGroups()));
return new Pair<>(compilationOutputsBuilder.build(), ImmutableMap.copyOf(mergedOutputGroups));
}
@@ -572,36 +570,6 @@ public class CompilationSupport {
}
}
- private void registerHeaderScanningActions(
- CcCompilationOutputs ccCompilationOutputs,
- ObjcProvider objcProvider,
- CompilationArtifacts compilationArtifacts) {
- // PIC is not used for Obj-C builds, if that changes this method will need to change
- if (!isHeaderThinningEnabled() || ccCompilationOutputs.getObjectFiles(false).isEmpty()) {
- return;
- }
-
- ImmutableList.Builder<ObjcHeaderThinningInfo> headerThinningInfos = ImmutableList.builder();
- AnalysisEnvironment analysisEnvironment = ruleContext.getAnalysisEnvironment();
- for (Artifact objectFile : ccCompilationOutputs.getObjectFiles(false)) {
- ActionAnalysisMetadata generatingAction =
- analysisEnvironment.getLocalGeneratingAction(objectFile);
- if (generatingAction instanceof CppCompileAction) {
- CppCompileAction action = (CppCompileAction) generatingAction;
- Artifact sourceFile = action.getSourceFile();
- if (!sourceFile.isTreeArtifact()
- && SOURCES_FOR_HEADER_THINNING.matches(sourceFile.getFilename())) {
- headerThinningInfos.add(
- new ObjcHeaderThinningInfo(
- sourceFile,
- intermediateArtifacts.headersListFile(sourceFile),
- action.getCompilerOptions()));
- }
- }
- }
- registerHeaderScanningActions(headerThinningInfos.build(), objcProvider, compilationArtifacts);
- }
-
/**
* Iterable wrapper providing strong type safety for arguments to binary linking.
*/
@@ -890,72 +858,6 @@ public class CompilationSupport {
}
/**
- * Registers all actions necessary to compile this rule's sources and archive them.
- *
- * @param compilationArtifacts collection of artifacts required for the compilation
- * @param objcProvider provides all compiling and linking information to register these actions
- * @param toolchain the toolchain to be used in determining command lines
- * @return this compilation support
- * @throws RuleErrorException for invalid crosstool files
- */
- CompilationSupport registerCompileAndArchiveActions(
- CompilationArtifacts compilationArtifacts,
- ObjcProvider objcProvider,
- CcToolchainProvider toolchain)
- throws RuleErrorException, InterruptedException {
- return registerCompileAndArchiveActions(
- compilationArtifacts,
- objcProvider,
- ExtraCompileArgs.NONE,
- ImmutableList.<PathFragment>of(),
- toolchain,
- maybeGetFdoSupport());
- }
-
- /**
- * Registers all actions necessary to compile this rule's sources and archive them.
- *
- * @param common common information about this rule and its dependencies
- * @return this compilation support
- * @throws RuleErrorException for invalid crosstool files
- */
- CompilationSupport registerCompileAndArchiveActions(ObjcCommon common)
- throws RuleErrorException, InterruptedException {
- return registerCompileAndArchiveActions(
- common, ExtraCompileArgs.NONE, ImmutableList.<PathFragment>of());
- }
-
- /**
- * Registers all actions necessary to compile this rule's sources and archive them.
- *
- * @param common common information about this rule and its dependencies
- * @param priorityHeaders priority headers to be included before the dependency headers
- * @return this compilation support
- * @throws RuleErrorException for invalid crosstool files
- */
- CompilationSupport registerCompileAndArchiveActions(
- ObjcCommon common, Iterable<PathFragment> priorityHeaders)
- throws RuleErrorException, InterruptedException {
- return registerCompileAndArchiveActions(common, ExtraCompileArgs.NONE, priorityHeaders);
- }
-
- /**
- * Registers an action to create an archive artifact by fully (statically) linking all transitive
- * dependencies of this rule.
- *
- * @param objcProvider provides all compiling and linking information to create this artifact
- * @param outputArchive the output artifact for this action
- */
- public CompilationSupport registerFullyLinkAction(
- ObjcProvider objcProvider, Artifact outputArchive) throws InterruptedException {
- return registerFullyLinkAction(
- objcProvider,
- outputArchive,
- toolchain,
- maybeGetFdoSupport());
- }
-
- /**
* Returns a provider that collects this target's instrumented sources as well as those of its
* dependencies.
*
@@ -984,27 +886,6 @@ public class CompilationSupport {
}
/**
- * Registers an action that will generate a clang module map for this target, using the hdrs
- * attribute of this rule.
- */
- CompilationSupport registerGenerateModuleMapAction(CompilationArtifacts compilationArtifacts) {
- // TODO(bazel-team): Include textual headers in the module map when Xcode 6 support is
- // dropped.
- // TODO(b/32225593): Include private headers in the module map.
- Iterable<Artifact> publicHeaders = attributes.hdrs();
- publicHeaders = Iterables.concat(publicHeaders, compilationArtifacts.getAdditionalHdrs());
- CppModuleMap moduleMap = intermediateArtifacts.moduleMap();
- registerGenerateModuleMapAction(moduleMap, publicHeaders);
-
- Optional<Artifact> umbrellaHeader = moduleMap.getUmbrellaHeader();
- if (umbrellaHeader.isPresent()) {
- registerGenerateUmbrellaHeaderAction(umbrellaHeader.get(), publicHeaders);
- }
-
- return this;
- }
-
- /**
* Validates compilation-related attributes on this rule.
*
* @return this compilation support
@@ -1049,6 +930,56 @@ public class CompilationSupport {
*
* @param compilationArtifacts collection of artifacts required for the compilation
* @param objcProvider provides all compiling and linking information to register these actions
+ * @param toolchain the toolchain to be used in determining command lines
+ * @return this compilation support
+ * @throws RuleErrorException for invalid crosstool files
+ */
+ CompilationSupport registerCompileAndArchiveActions(
+ CompilationArtifacts compilationArtifacts,
+ ObjcProvider objcProvider,
+ CcToolchainProvider toolchain)
+ throws RuleErrorException, InterruptedException {
+ return registerCompileAndArchiveActions(
+ compilationArtifacts,
+ objcProvider,
+ ExtraCompileArgs.NONE,
+ ImmutableList.<PathFragment>of(),
+ toolchain,
+ maybeGetFdoSupport());
+ }
+
+ /**
+ * Registers all actions necessary to compile this rule's sources and archive them.
+ *
+ * @param common common information about this rule and its dependencies
+ * @return this compilation support
+ * @throws RuleErrorException for invalid crosstool files
+ */
+ CompilationSupport registerCompileAndArchiveActions(ObjcCommon common)
+ throws RuleErrorException, InterruptedException {
+ return registerCompileAndArchiveActions(
+ common, ExtraCompileArgs.NONE, ImmutableList.<PathFragment>of());
+ }
+
+ /**
+ * Registers all actions necessary to compile this rule's sources and archive them.
+ *
+ * @param common common information about this rule and its dependencies
+ * @param priorityHeaders priority headers to be included before the dependency headers
+ * @return this compilation support
+ * @throws RuleErrorException for invalid crosstool files
+ */
+ CompilationSupport registerCompileAndArchiveActions(
+ ObjcCommon common, Iterable<PathFragment> priorityHeaders)
+ throws RuleErrorException, InterruptedException {
+ return registerCompileAndArchiveActions(common, ExtraCompileArgs.NONE, priorityHeaders);
+ }
+
+ /**
+ * Registers all actions necessary to compile this rule's sources and archive them.
+ *
+ * @param compilationArtifacts collection of artifacts required for the compilation
+ * @param objcProvider provides all compiling and linking information to register these actions
* @param extraCompileArgs args to be added to compile actions
* @param priorityHeaders priority headers to be included before the dependency headers
* @param ccToolchain the cpp toolchain provider, may be null
@@ -1381,6 +1312,18 @@ public class CompilationSupport {
*
* @param objcProvider provides all compiling and linking information to create this artifact
* @param outputArchive the output artifact for this action
+ */
+ public CompilationSupport registerFullyLinkAction(
+ ObjcProvider objcProvider, Artifact outputArchive) throws InterruptedException {
+ return registerFullyLinkAction(objcProvider, outputArchive, toolchain, maybeGetFdoSupport());
+ }
+
+ /**
+ * Registers an action to create an archive artifact by fully (statically) linking all transitive
+ * dependencies of this rule.
+ *
+ * @param objcProvider provides all compiling and linking information to create this artifact
+ * @param outputArchive the output artifact for this action
* @param ccToolchain the cpp toolchain provider, may be null
* @param fdoSupport the cpp FDO support provider, may be null
* @return this {@link CompilationSupport} instance
@@ -1745,6 +1688,27 @@ public class CompilationSupport {
}
/**
+ * Registers an action that will generate a clang module map for this target, using the hdrs
+ * attribute of this rule.
+ */
+ CompilationSupport registerGenerateModuleMapAction(CompilationArtifacts compilationArtifacts) {
+ // TODO(bazel-team): Include textual headers in the module map when Xcode 6 support is
+ // dropped.
+ // TODO(b/32225593): Include private headers in the module map.
+ Iterable<Artifact> publicHeaders = attributes.hdrs();
+ publicHeaders = Iterables.concat(publicHeaders, compilationArtifacts.getAdditionalHdrs());
+ CppModuleMap moduleMap = intermediateArtifacts.moduleMap();
+ registerGenerateModuleMapAction(moduleMap, publicHeaders);
+
+ Optional<Artifact> umbrellaHeader = moduleMap.getUmbrellaHeader();
+ if (umbrellaHeader.isPresent()) {
+ registerGenerateUmbrellaHeaderAction(umbrellaHeader.get(), publicHeaders);
+ }
+
+ return this;
+ }
+
+ /**
* Registers an action that will generate a clang module map.
* @param moduleMap the module map to generate
* @param publicHeaders the headers that should be directly accessible by dependers
@@ -1840,6 +1804,36 @@ public class CompilationSupport {
.getProvider(FilesToRunProvider.class);
}
+ private void registerHeaderScanningActions(
+ CcCompilationOutputs ccCompilationOutputs,
+ ObjcProvider objcProvider,
+ CompilationArtifacts compilationArtifacts) {
+ // PIC is not used for Obj-C builds, if that changes this method will need to change
+ if (!isHeaderThinningEnabled() || ccCompilationOutputs.getObjectFiles(false).isEmpty()) {
+ return;
+ }
+
+ ImmutableList.Builder<ObjcHeaderThinningInfo> headerThinningInfos = ImmutableList.builder();
+ AnalysisEnvironment analysisEnvironment = ruleContext.getAnalysisEnvironment();
+ for (Artifact objectFile : ccCompilationOutputs.getObjectFiles(false)) {
+ ActionAnalysisMetadata generatingAction =
+ analysisEnvironment.getLocalGeneratingAction(objectFile);
+ if (generatingAction instanceof CppCompileAction) {
+ CppCompileAction action = (CppCompileAction) generatingAction;
+ Artifact sourceFile = action.getSourceFile();
+ if (!sourceFile.isTreeArtifact()
+ && SOURCES_FOR_HEADER_THINNING.matches(sourceFile.getFilename())) {
+ headerThinningInfos.add(
+ new ObjcHeaderThinningInfo(
+ sourceFile,
+ intermediateArtifacts.headersListFile(sourceFile),
+ action.getCompilerOptions()));
+ }
+ }
+ }
+ registerHeaderScanningActions(headerThinningInfos.build(), objcProvider, compilationArtifacts);
+ }
+
/**
* Creates and registers ObjcHeaderScanning {@link SpawnAction}. Groups all the actions by their
* compilation command line arguments and creates a ObjcHeaderScanning action for each unique one.