aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar plf <plf@google.com>2017-12-15 02:39:20 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-15 02:41:14 -0800
commitd6ac11dab81ec40e9adc717575904574c6c9dc48 (patch)
tree807cd75b2f1e8f13755075a74ec13f835def0e78 /src/main/java/com
parent6e3ddc72fd2cd39da95bbd2c7c4b1238d5ef6e41 (diff)
Remove source specific build variables from C++ API.
The only use case was for Objective-C rules so that different set of sources specified in the same rule could be compiled with either ARC or no ARC. To replace source specific build variables, we call into CcLibraryHelper twice for each set of sources. This has led to separating the building of compilation providers and outputs from those related to linking. In the case of Objective-C, the compilation outputs are merged and then passed to a single invocation of linking in CcLibraryHelper. In a later CL, the distinction between compilation and linking will be refined by separating them in different classes. RELNOTES:none PiperOrigin-RevId: 179167102
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java305
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java53
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java49
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java212
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java28
6 files changed, 462 insertions, 208 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index d22b1842fb..bdedfa8751 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -74,10 +74,10 @@ import javax.annotation.Nullable;
* Rules that generate source files and emulate cc_library on top of that should use this class
* instead of the lower-level APIs in CppHelper and CppModel.
*
- * <p>Rules that want to use this class are required to have implicit dependencies on the
- * toolchain, the STL, the lipo context, and so on. Optionally, they can also have copts,
- * and malloc attributes, but note that these require explicit calls to the corresponding setter
- * methods.
+ * <p>Rules that want to use this class are required to have implicit dependencies on the toolchain,
+ * the STL, the lipo context, and so on. Optionally, they can also have copts, and malloc
+ * attributes, but note that these require explicit calls to the corresponding setter methods.
+ * TODO(plf): Split this class in two, one for compilation and other for linking.
*/
public final class CcLibraryHelper {
/**
@@ -189,7 +189,7 @@ public final class CcLibraryHelper {
/**
* Contains the providers as well as the compilation and linking outputs, and the compilation
- * context.
+ * context. TODO(plf): Remove outer class Info.
*/
public static final class Info {
private final TransitiveInfoProviderMapBuilder providers;
@@ -199,20 +199,97 @@ public final class CcLibraryHelper {
private final CcLinkingOutputs linkingOutputsExcludingPrecompiledLibraries;
private final CppCompilationContext context;
- private Info(
- TransitiveInfoProviderMap providers,
- Map<String, NestedSet<Artifact>> outputGroups,
- CcCompilationOutputs compilationOutputs,
- CcLinkingOutputs linkingOutputs,
- CcLinkingOutputs linkingOutputsExcludingPrecompiledLibraries,
- CppCompilationContext context) {
- this.providers = new TransitiveInfoProviderMapBuilder().addAll(providers);
- this.outputGroups = ImmutableMap.copyOf(outputGroups);
- this.compilationOutputs = compilationOutputs;
- this.linkingOutputs = linkingOutputs;
+ /** Contains the providers as well as the compilation outputs, and the compilation context. */
+ public static final class CompilationInfo {
+ private final TransitiveInfoProviderMap providers;
+ private final Map<String, NestedSet<Artifact>> outputGroups;
+ private final CcCompilationOutputs compilationOutputs;
+ private final CppCompilationContext context;
+
+ private CompilationInfo(
+ TransitiveInfoProviderMap providers,
+ Map<String, NestedSet<Artifact>> outputGroups,
+ CcCompilationOutputs compilationOutputs,
+ CppCompilationContext context) {
+ this.providers = providers;
+ this.outputGroups = outputGroups;
+ this.compilationOutputs = compilationOutputs;
+ this.context = context;
+ }
+
+ public TransitiveInfoProviderMap getProviders() {
+ return providers;
+ }
+
+ public Map<String, NestedSet<Artifact>> getOutputGroups() {
+ return outputGroups;
+ }
+
+ public CcCompilationOutputs getCcCompilationOutputs() {
+ return compilationOutputs;
+ }
+
+ public CppCompilationContext getCppCompilationContext() {
+ return context;
+ }
+ }
+
+ /** Contains the providers as well as the linking outputs. */
+ public static final class LinkingInfo {
+ private final TransitiveInfoProviderMap providers;
+ private final Map<String, NestedSet<Artifact>> outputGroups;
+ private final CcLinkingOutputs linkingOutputs;
+ private final CcLinkingOutputs linkingOutputsExcludingPrecompiledLibraries;
+
+ private LinkingInfo(
+ TransitiveInfoProviderMap providers,
+ Map<String, NestedSet<Artifact>> outputGroups,
+ CcLinkingOutputs linkingOutputs,
+ CcLinkingOutputs linkingOutputsExcludingPrecompiledLibraries) {
+ this.providers = providers;
+ this.outputGroups = outputGroups;
+ this.linkingOutputs = linkingOutputs;
+ this.linkingOutputsExcludingPrecompiledLibraries =
+ linkingOutputsExcludingPrecompiledLibraries;
+ }
+
+ public TransitiveInfoProviderMap getProviders() {
+ return providers;
+ }
+
+ public Map<String, NestedSet<Artifact>> getOutputGroups() {
+ return outputGroups;
+ }
+
+ public CcLinkingOutputs getCcLinkingOutputs() {
+ return linkingOutputs;
+ }
+
+ /**
+ * Returns the linking outputs before adding the pre-compiled libraries. Avoid using this -
+ * pre-compiled and locally compiled libraries should be treated identically. This method only
+ * exists for backwards compatibility.
+ */
+ public CcLinkingOutputs getCcLinkingOutputsExcludingPrecompiledLibraries() {
+ return linkingOutputsExcludingPrecompiledLibraries;
+ }
+ }
+
+ public Info(CompilationInfo compilationInfo, LinkingInfo linkingInfo) {
+ this.providers =
+ new TransitiveInfoProviderMapBuilder()
+ .addAll(compilationInfo.getProviders())
+ .addAll(linkingInfo.getProviders());
+ this.outputGroups =
+ ImmutableMap.copyOf(
+ Iterables.concat(
+ compilationInfo.getOutputGroups().entrySet(),
+ linkingInfo.getOutputGroups().entrySet()));
+ this.compilationOutputs = compilationInfo.getCcCompilationOutputs();
+ this.linkingOutputs = linkingInfo.getCcLinkingOutputs();
this.linkingOutputsExcludingPrecompiledLibraries =
- linkingOutputsExcludingPrecompiledLibraries;
- this.context = context;
+ linkingInfo.getCcLinkingOutputsExcludingPrecompiledLibraries();
+ this.context = compilationInfo.getCppCompilationContext();
}
public TransitiveInfoProviderMap getProviders() {
@@ -265,6 +342,31 @@ public final class CcLibraryHelper {
public void addLinkingOutputsTo(NestedSetBuilder<Artifact> filesBuilder) {
addLinkingOutputsTo(filesBuilder, true);
}
+
+ /**
+ * Merges a list of output groups into one. The sets for each entry with a given key are merged.
+ */
+ public static Map<String, NestedSet<Artifact>> mergeOutputGroups(
+ List<Map<String, NestedSet<Artifact>>> outputGroupsList) {
+ Map<String, NestedSetBuilder<Artifact>> mergedOutputGroupsBuilder = new TreeMap<>();
+
+ for (Map<String, NestedSet<Artifact>> outputGroup : outputGroupsList) {
+ for (Map.Entry<String, NestedSet<Artifact>> entryOutputGroup : outputGroup.entrySet()) {
+ String key = entryOutputGroup.getKey();
+ mergedOutputGroupsBuilder.computeIfAbsent(
+ key, (String k) -> NestedSetBuilder.compileOrder());
+ mergedOutputGroupsBuilder.get(key).addTransitive(entryOutputGroup.getValue());
+ }
+ }
+
+ Map<String, NestedSet<Artifact>> mergedOutputGroups = new TreeMap<>();
+ for (Map.Entry<String, NestedSetBuilder<Artifact>> entryOutputGroupBuilder :
+ mergedOutputGroupsBuilder.entrySet()) {
+ mergedOutputGroups.put(
+ entryOutputGroupBuilder.getKey(), entryOutputGroupBuilder.getValue().build());
+ }
+ return mergedOutputGroups;
+ }
}
private final RuleContext ruleContext;
@@ -324,6 +426,7 @@ public final class CcLibraryHelper {
private String linkedArtifactNameSuffix = "";
private boolean useDeps = true;
private boolean generateModuleMap = true;
+ private String purpose = null;
/**
* Creates a CcLibraryHelper.
@@ -463,41 +566,27 @@ public final class CcLibraryHelper {
* will not be compiled, but also not made visible as includes to dependent rules. The given build
* variables will be added to those used for compiling this source.
*/
- public CcLibraryHelper addSources(
- Collection<Artifact> sources, Map<String, String> buildVariables) {
- Preconditions.checkNotNull(buildVariables);
+ public CcLibraryHelper addSources(Collection<Artifact> sources) {
for (Artifact source : sources) {
- addSource(source, ruleContext.getLabel(), buildVariables);
+ addSource(source, ruleContext.getLabel());
}
return this;
}
/**
* Add the corresponding files as source files. These may also be header files, in which case they
- * will not be compiled, but also not made visible as includes to dependent rules. The given
- * sources will be built without extra, source-specific build variables.
- */
- public CcLibraryHelper addSources(Collection<Artifact> sources) {
- addSources(sources, ImmutableMap.<String, String>of());
- return this;
- }
-
- /**
- * Add the corresponding files as source files. These may also be header files, in which case they
- * will not be compiled, but also not made visible as includes to dependent rules. The given
- * sources will be built without extra, source-specific build variables.
+ * will not be compiled, but also not made visible as includes to dependent rules.
*/
public CcLibraryHelper addSources(Iterable<Pair<Artifact, Label>> sources) {
for (Pair<Artifact, Label> source : sources) {
- addSource(source.first, source.second, ImmutableMap.<String, String>of());
+ addSource(source.first, source.second);
}
return this;
}
/**
* Add the corresponding files as source files. These may also be header files, in which case they
- * will not be compiled, but also not made visible as includes to dependent rules. The given
- * sources will be built without extra, source-specific build variables.
+ * will not be compiled, but also not made visible as includes to dependent rules.
*/
public CcLibraryHelper addSources(Artifact... sources) {
return addSources(Arrays.asList(sources));
@@ -522,8 +611,7 @@ public final class CcLibraryHelper {
if (isTextualInclude || !isHeader || !shouldProcessHeaders()) {
return;
}
- compilationUnitSources.add(
- CppSource.create(header, label, ImmutableMap.<String, String>of(), CppSource.Type.HEADER));
+ compilationUnitSources.add(CppSource.create(header, label, CppSource.Type.HEADER));
}
/** Adds a header to {@code publicHeaders}, but not to this target's module map. */
@@ -535,10 +623,9 @@ public final class CcLibraryHelper {
/**
* Adds a source to {@code compilationUnitSources} if it is a compiled file type (including
- * parsed/preprocessed header) and to {@code privateHeaders} if it is a header. The given build
- * variables will be added to those used for compiling this source.
+ * parsed/preprocessed header) and to {@code privateHeaders} if it is a header.
*/
- private void addSource(Artifact source, Label label, Map<String, String> buildVariables) {
+ private void addSource(Artifact source, Label label) {
Preconditions.checkNotNull(featureConfiguration);
boolean isHeader = CppFileTypes.CPP_HEADER.matches(source.getExecPath());
boolean isTextualInclude = CppFileTypes.CPP_TEXTUAL_INCLUDE.matches(source.getExecPath());
@@ -561,7 +648,7 @@ public final class CcLibraryHelper {
} else {
type = CppSource.Type.SOURCE;
}
- compilationUnitSources.add(CppSource.create(source, label, buildVariables, type));
+ compilationUnitSources.add(CppSource.create(source, label, type));
}
private boolean shouldProcessHeaders() {
@@ -945,11 +1032,25 @@ public final class CcLibraryHelper {
}
/**
- * Create the C++ compile and link actions, and the corresponding C++-related providers.
+ * Create the C++ compile and link actions, and the corresponding compilation related providers.
*
* @throws RuleErrorException
*/
public Info build() throws RuleErrorException, InterruptedException {
+ Info.CompilationInfo compilationInfo = compile();
+ Info.LinkingInfo linkingInfo =
+ link(
+ compilationInfo.getCcCompilationOutputs(), compilationInfo.getCppCompilationContext());
+
+ return new Info(compilationInfo, linkingInfo);
+ }
+
+ /**
+ * Create the C++ compile actions, and the corresponding compilation related providers.
+ *
+ * @throws RuleErrorException
+ */
+ public Info.CompilationInfo compile() throws RuleErrorException, InterruptedException {
if (checkDepsGenerateCpp) {
for (LanguageDependentFragment dep :
AnalysisUtils.getProviders(deps, LanguageDependentFragment.class)) {
@@ -980,6 +1081,65 @@ public final class CcLibraryHelper {
.build();
}
+ DwoArtifactsCollector dwoArtifacts =
+ DwoArtifactsCollector.transitiveCollector(
+ ccOutputs,
+ deps,
+ /*generateDwo=*/ false,
+ /*ltoBackendArtifactsUsePic=*/ false,
+ /*ltoBackendArtifacts=*/ ImmutableList.of());
+
+ // Be very careful when adding new providers here - it can potentially affect a lot of rules.
+ // We should consider merging most of these providers into a single provider.
+ TransitiveInfoProviderMapBuilder providers =
+ new TransitiveInfoProviderMapBuilder()
+ .add(
+ cppCompilationContext,
+ new CppDebugFileProvider(
+ dwoArtifacts.getDwoArtifacts(), dwoArtifacts.getPicDwoArtifacts()),
+ collectTransitiveLipoInfo(ccOutputs));
+
+ Map<String, NestedSet<Artifact>> outputGroups = new TreeMap<>();
+ outputGroups.put(OutputGroupInfo.TEMP_FILES, getTemps(ccOutputs));
+ CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
+ if (emitCompileProviders) {
+ boolean isLipoCollector = cppConfiguration.isLipoContextCollector();
+ boolean processHeadersInDependencies = cppConfiguration.processHeadersInDependencies();
+ boolean usePic = CppHelper.usePic(ruleContext, ccToolchain, false);
+ outputGroups.put(
+ OutputGroupInfo.FILES_TO_COMPILE,
+ ccOutputs.getFilesToCompile(isLipoCollector, processHeadersInDependencies, usePic));
+ outputGroups.put(
+ OutputGroupInfo.COMPILATION_PREREQUISITES,
+ CcCommon.collectCompilationPrerequisites(ruleContext, cppCompilationContext));
+ }
+
+ return new Info.CompilationInfo(
+ providers.build(), outputGroups, ccOutputs, cppCompilationContext);
+ }
+
+ /**
+ * Create the C++ link actions, and the corresponding linking related providers.
+ *
+ * @throws RuleErrorException
+ */
+ public Info.LinkingInfo link(
+ CcCompilationOutputs ccOutputs, CppCompilationContext cppCompilationContext)
+ throws RuleErrorException, InterruptedException {
+ Preconditions.checkNotNull(ccOutputs);
+ Preconditions.checkNotNull(cppCompilationContext);
+
+ if (checkDepsGenerateCpp) {
+ for (LanguageDependentFragment dep :
+ AnalysisUtils.getProviders(deps, LanguageDependentFragment.class)) {
+ LanguageDependentFragment.Checker.depSupportsLanguage(
+ ruleContext, dep, CppRuleClasses.LANGUAGE, "deps");
+ }
+ }
+
+ CppModel model = initializeCppModel();
+ model.setContext(cppCompilationContext);
+
// Create link actions (only if there are object files or if explicitly requested).
CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
if (emitLinkActions && (emitLinkActionsIfEmpty || !ccOutputs.isEmpty())) {
@@ -1046,13 +1206,6 @@ public final class CcLibraryHelper {
.build();
}
- DwoArtifactsCollector dwoArtifacts =
- DwoArtifactsCollector.transitiveCollector(
- ccOutputs,
- deps, /*generateDwo=*/
- false, /*ltoBackendArtifactsUsePic=*/
- false, /*ltoBackendArtifacts=*/
- ImmutableList.<LtoBackendArtifacts>of());
Runfiles cppStaticRunfiles = collectCppRunfiles(ccLinkingOutputs, true);
Runfiles cppSharedRunfiles = collectCppRunfiles(ccLinkingOutputs, false);
@@ -1060,31 +1213,14 @@ public final class CcLibraryHelper {
// We should consider merging most of these providers into a single provider.
TransitiveInfoProviderMapBuilder providers =
new TransitiveInfoProviderMapBuilder()
- .add(
- new CppRunfilesProvider(cppStaticRunfiles, cppSharedRunfiles),
- cppCompilationContext,
- new CppDebugFileProvider(
- dwoArtifacts.getDwoArtifacts(), dwoArtifacts.getPicDwoArtifacts()),
- collectTransitiveLipoInfo(ccOutputs));
+ .add(new CppRunfilesProvider(cppStaticRunfiles, cppSharedRunfiles));
+
Map<String, NestedSet<Artifact>> outputGroups = new TreeMap<>();
if (shouldAddLinkerOutputArtifacts(ruleContext, ccOutputs)) {
addLinkerOutputArtifacts(outputGroups, ccOutputs);
}
- outputGroups.put(OutputGroupInfo.TEMP_FILES, getTemps(ccOutputs));
- CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
- if (emitCompileProviders) {
- boolean isLipoCollector = cppConfiguration.isLipoContextCollector();
- boolean processHeadersInDependencies = cppConfiguration.processHeadersInDependencies();
- boolean usePic = CppHelper.usePic(ruleContext, ccToolchain, false);
- outputGroups.put(
- OutputGroupInfo.FILES_TO_COMPILE,
- ccOutputs.getFilesToCompile(isLipoCollector, processHeadersInDependencies, usePic));
- outputGroups.put(OutputGroupInfo.COMPILATION_PREREQUISITES,
- CcCommon.collectCompilationPrerequisites(ruleContext, cppCompilationContext));
- }
-
// TODO(bazel-team): Maybe we can infer these from other data at the places where they are
// used.
if (emitCcNativeLibrariesProvider) {
@@ -1094,6 +1230,7 @@ public final class CcLibraryHelper {
CcExecutionDynamicLibrariesProvider.class,
collectExecutionDynamicLibraryArtifacts(ccLinkingOutputs.getExecutionDynamicLibraries()));
+ CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
boolean forcePic = cppConfiguration.forcePic();
if (emitCcSpecificLinkParamsProvider) {
providers.add(
@@ -1104,13 +1241,8 @@ public final class CcLibraryHelper {
new CcLinkParamsInfo(
createCcLinkParamsStore(ccLinkingOutputs, cppCompilationContext, forcePic)));
}
- return new Info(
- providers.build(),
- outputGroups,
- ccOutputs,
- ccLinkingOutputs,
- originalLinkingOutputs,
- cppCompilationContext);
+ return new Info.LinkingInfo(
+ providers.build(), outputGroups, ccLinkingOutputs, originalLinkingOutputs);
}
/**
@@ -1328,7 +1460,11 @@ public final class CcLibraryHelper {
.getRelative(ruleContext.getUniqueDirectory("_virtual_includes")));
}
- /** Create context for cc compile action from generated inputs. */
+ /**
+ * Create context for cc compile action from generated inputs.
+ *
+ * TODO(plf): Try to pull out CppCompilationContext building out of this class.
+ */
private CppCompilationContext initializeCppCompilationContext(CppModel model) {
CppCompilationContext.Builder contextBuilder = new CppCompilationContext.Builder(ruleContext);
@@ -1446,6 +1582,7 @@ public final class CcLibraryHelper {
contextBuilder.setVerificationModuleMap(verificationMap);
}
}
+ contextBuilder.setPurpose(purpose);
semantics.setupCompilationContext(ruleContext, contextBuilder);
return contextBuilder.build();
@@ -1637,4 +1774,16 @@ public final class CcLibraryHelper {
generateModuleMap = false;
return this;
}
+
+ /**
+ * Sets the purpose for the context.
+ *
+ * @see CppCompilationContext.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.
+ */
+ public CcLibraryHelper setPurpose(@Nullable String purpose) {
+ this.purpose = purpose;
+ return this;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
index 2051817205..3610e2a8a4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
@@ -21,7 +21,6 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
@@ -54,7 +53,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -300,15 +298,13 @@ public final class CppModel {
}
/**
- * Adds a single source file to be compiled. The given build variables will be added to those used
- * to compile this source file. Note that this should only be called for primary compilation
- * units, including module files or headers to be parsed or preprocessed.
+ * Adds a single source file to be compiled. Note that this should only be called for primary
+ * compilation units, including module files or headers to be parsed or preprocessed.
*/
public CppModel addCompilationUnitSources(
- Iterable<Artifact> sourceFiles, Label sourceLabel, Map<String, String> buildVariables,
- CppSource.Type type) {
+ Iterable<Artifact> sourceFiles, Label sourceLabel, CppSource.Type type) {
for (Artifact sourceFile : sourceFiles) {
- this.sourceFiles.add(CppSource.create(sourceFile, sourceLabel, buildVariables, type));
+ this.sourceFiles.add(CppSource.create(sourceFile, sourceLabel, type));
}
return this;
}
@@ -524,8 +520,7 @@ public final class CppModel {
Artifact gcnoFile,
Artifact dwoFile,
Artifact ltoIndexingFile,
- CppModuleMap cppModuleMap,
- Map<String, String> sourceSpecificBuildVariables) {
+ CppModuleMap cppModuleMap) {
CcToolchainFeatures.Variables.Builder buildVariables =
new CcToolchainFeatures.Variables.Builder(ccToolchain.getBuildVariables());
@@ -650,8 +645,6 @@ public final class CppModel {
LTO_INDEXING_BITCODE_FILE_VARIABLE_NAME, ltoIndexingFile.getExecPathString());
}
- buildVariables.addAllStringVariables(sourceSpecificBuildVariables);
-
for (VariablesExtension extension : variablesExtensions) {
extension.addVariables(buildVariables);
}
@@ -744,8 +737,7 @@ public final class CppModel {
// info). In that case the LtoBackendAction will generate the dwo.
/* generateDwo= */ CppHelper.useFission(cppConfiguration, ccToolchain)
&& !bitcodeOutput,
- isGenerateDotdFile(sourceArtifact),
- source.getBuildVariables());
+ isGenerateDotdFile(sourceArtifact));
break;
}
} else {
@@ -801,8 +793,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
CppCompileAction compileAction = builder.buildOrThrowRuleError(ruleContext);
env.registerAction(compileAction);
@@ -856,8 +847,7 @@ public final class CppModel {
gcnoFile,
dwoFile,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
builder.setGcnoFile(gcnoFile);
builder.setDwoFile(dwoFile);
@@ -897,8 +887,7 @@ public final class CppModel {
/* addObject= */ false,
/* enableCoverage= */ false,
/* generateDwo= */ false,
- isGenerateDotdFile(moduleMapArtifact),
- ImmutableMap.of());
+ isGenerateDotdFile(moduleMapArtifact));
}
private void createClifMatchAction(
@@ -925,8 +914,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
CppCompileAction compileAction = builder.buildOrThrowRuleError(ruleContext);
env.registerAction(compileAction);
@@ -946,8 +934,7 @@ public final class CppModel {
boolean addObject,
boolean enableCoverage,
boolean generateDwo,
- boolean generateDotd,
- Map<String, String> sourceSpecificBuildVariables)
+ boolean generateDotd)
throws RuleErrorException {
ImmutableList.Builder<Artifact> directOutputs = new ImmutableList.Builder<>();
PathFragment ccRelativeName = sourceArtifact.getRootRelativePath();
@@ -1006,8 +993,7 @@ public final class CppModel {
gcnoFile,
dwoFile,
ltoIndexingFile,
- cppModuleMap,
- sourceSpecificBuildVariables);
+ cppModuleMap);
if (maySaveTemps) {
result.addTemps(
@@ -1074,8 +1060,7 @@ public final class CppModel {
gcnoFile,
noPicDwoFile,
ltoIndexingFile,
- cppModuleMap,
- sourceSpecificBuildVariables);
+ cppModuleMap);
if (maySaveTemps) {
result.addTemps(
@@ -1132,8 +1117,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- source.getBuildVariables());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
// Make sure this builder doesn't reference ruleContext outside of analysis phase.
CppCompileActionTemplate actionTemplate =
@@ -1190,8 +1174,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
CppCompileAction action = builder.buildOrThrowRuleError(ruleContext);
env.registerAction(action);
@@ -1581,8 +1564,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, dBuilder);
CppCompileAction dAction = dBuilder.buildOrThrowRuleError(ruleContext);
ruleContext.registerAction(dAction);
@@ -1599,8 +1581,7 @@ public final class CppModel {
/* gcnoFile= */ null,
/* dwoFile= */ null,
/* ltoIndexingFile= */ null,
- builder.getContext().getCppModuleMap(),
- /* sourceSpecificBuildVariables= */ ImmutableMap.of());
+ builder.getContext().getCppModuleMap());
semantics.finalizeCompileActionBuilder(ruleContext, sdBuilder);
CppCompileAction sdAction = sdBuilder.buildOrThrowRuleError(ruleContext);
ruleContext.registerAction(sdAction);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java
index 3546f42299..ac23cebc5d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java
@@ -17,13 +17,10 @@ package com.google.devtools.build.lib.rules.cpp;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.cmdline.Label;
-import java.util.Map;
-
/** A source file that is an input to a c++ compilation. */
public abstract class CppSource {
private final Artifact source;
private final Label label;
- private final Map<String, String> buildVariables;
/**
* Types of sources.
@@ -34,10 +31,9 @@ public abstract class CppSource {
CLIF_INPUT_PROTO,
}
- public CppSource(Artifact source, Label label, Map<String, String> buildVariables) {
+ public CppSource(Artifact source, Label label) {
this.source = source;
this.label = label;
- this.buildVariables = buildVariables;
}
/**
@@ -55,21 +51,14 @@ public abstract class CppSource {
}
/**
- * Returns build variables to be used specifically in the compilation of this source.
- */
- public Map<String, String> getBuildVariables() {
- return buildVariables;
- }
-
- /**
* Returns the type of this source.
*/
abstract Type getType();
private static class SourceCppSource extends CppSource {
- protected SourceCppSource(Artifact source, Label label, Map<String, String> buildVariables) {
- super(source, label, buildVariables);
+ protected SourceCppSource(Artifact source, Label label) {
+ super(source, label);
}
@Override
@@ -79,8 +68,8 @@ public abstract class CppSource {
}
private static class HeaderCppSource extends CppSource {
- protected HeaderCppSource(Artifact source, Label label, Map<String, String> buildVariables) {
- super(source, label, buildVariables);
+ protected HeaderCppSource(Artifact source, Label label) {
+ super(source, label);
}
@Override
@@ -90,8 +79,8 @@ public abstract class CppSource {
}
private static class ClifProtoCppSource extends CppSource {
- protected ClifProtoCppSource(Artifact source, Label label, Map<String, String> buildVariables) {
- super(source, label, buildVariables);
+ protected ClifProtoCppSource(Artifact source, Label label) {
+ super(source, label);
}
@Override
@@ -100,25 +89,21 @@ public abstract class CppSource {
}
}
-
-
/**
* Creates a {@code CppSource}.
- * @param source the actual source file
- * @param label the label from which this source arises in the build graph
- * @param buildVariables build variables that should be used specifically in the compilation
- * of this source
+ *
+ * @param source the actual source file
+ * @param label the label from which this source arises in the build graph
* @param type type of the source file.
*/
- static CppSource create(Artifact source, Label label, Map<String, String> buildVariables,
- Type type) {
+ static CppSource create(Artifact source, Label label, Type type) {
switch (type) {
- case SOURCE:
- return new SourceCppSource(source, label, buildVariables);
- case HEADER:
- return new HeaderCppSource(source, label, buildVariables);
- case CLIF_INPUT_PROTO:
- return new ClifProtoCppSource(source, label, buildVariables);
+ case SOURCE:
+ return new SourceCppSource(source, label);
+ case HEADER:
+ return new HeaderCppSource(source, label);
+ case CLIF_INPUT_PROTO:
+ return new ClifProtoCppSource(source, label);
default:
throw new IllegalStateException("Unhandled CppSource type: " + type);
}
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 bfca258170..c41c162a17 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
@@ -87,6 +87,7 @@ 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.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.CcToolchain;
@@ -94,6 +95,7 @@ import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.CollidingProv
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
+import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
@@ -117,6 +119,7 @@ import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
@@ -297,27 +300,21 @@ public class CompilationSupport {
}
}
- private CcLibraryHelper createCcLibraryHelper(
+ private Info.CompilationInfo compile(
ObjcProvider objcProvider,
- CompilationArtifacts compilationArtifacts,
VariablesExtension extension,
ExtraCompileArgs extraCompileArgs,
CcToolchainProvider ccToolchain,
FdoSupportProvider fdoSupport,
- Iterable<PathFragment> priorityHeaders) {
- PrecompiledFiles precompiledFiles = new PrecompiledFiles(ruleContext);
- Collection<Artifact> arcSources = ImmutableSortedSet.copyOf(compilationArtifacts.getSrcs());
- Collection<Artifact> nonArcSources =
- ImmutableSortedSet.copyOf(compilationArtifacts.getNonArcSrcs());
- Collection<Artifact> privateHdrs =
- ImmutableSortedSet.copyOf(compilationArtifacts.getPrivateHdrs());
- Collection<Artifact> publicHdrs =
- Stream.concat(
- Streams.stream(attributes.hdrs()),
- Streams.stream(compilationArtifacts.getAdditionalHdrs()))
- .collect(toImmutableSortedSet(naturalOrder()));
- Artifact pchHdr = getPchFile().orNull();
- ObjcCppSemantics semantics = createObjcCppSemantics(objcProvider, privateHdrs, pchHdr);
+ Iterable<PathFragment> priorityHeaders,
+ PrecompiledFiles precompiledFiles,
+ Collection<Artifact> sources,
+ Collection<Artifact> privateHdrs,
+ Collection<Artifact> publicHdrs,
+ Artifact pchHdr,
+ ObjcCppSemantics semantics,
+ String purpose)
+ throws RuleErrorException, InterruptedException {
CcLibraryHelper result =
new CcLibraryHelper(
ruleContext,
@@ -327,18 +324,12 @@ public class CompilationSupport {
ccToolchain,
fdoSupport,
buildConfiguration)
- .addSources(arcSources, ImmutableMap.of("objc_arc", ""))
- .addSources(nonArcSources, ImmutableMap.of("no_objc_arc", ""))
+ .addSources(sources)
.addSources(privateHdrs)
.addDefines(objcProvider.get(DEFINE))
.enableCompileProviders()
.addPublicHeaders(publicHdrs)
.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)
.setCopts(
ImmutableList.<String>builder()
.addAll(getCompileRuleCopts())
@@ -352,10 +343,9 @@ public class CompilationSupport {
.addIncludeDirs(objcProvider.get(INCLUDE))
.addSystemIncludeDirs(objcProvider.get(INCLUDE_SYSTEM))
.setCppModuleMap(intermediateArtifacts.moduleMap())
- .setLinkedArtifactNameSuffix(intermediateArtifacts.archiveFileNameSuffix())
.setPropagateModuleMapToCompileAction(false)
- .setNeverLink(true)
- .addVariableExtension(extension);
+ .addVariableExtension(extension)
+ .setPurpose(purpose);
if (pchHdr != null) {
result.addNonModuleMapHeader(pchHdr);
@@ -366,7 +356,126 @@ public class CompilationSupport {
if (getCustomModuleMap(ruleContext).isPresent()) {
result.doNotGenerateModuleMap();
}
- return result;
+
+ return result.compile();
+ }
+
+ private Pair<CcCompilationOutputs, ImmutableMap<String, NestedSet<Artifact>>>
+ ccCompileAndLink(
+ ObjcProvider objcProvider,
+ CompilationArtifacts compilationArtifacts,
+ ObjcVariablesExtension.Builder extensionBuilder,
+ ExtraCompileArgs extraCompileArgs,
+ CcToolchainProvider ccToolchain,
+ FdoSupportProvider fdoSupport,
+ Iterable<PathFragment> priorityHeaders,
+ LinkTargetType linkType,
+ Artifact linkActionInput)
+ throws RuleErrorException, InterruptedException {
+ PrecompiledFiles precompiledFiles = new PrecompiledFiles(ruleContext);
+ Collection<Artifact> arcSources = ImmutableSortedSet.copyOf(compilationArtifacts.getSrcs());
+ Collection<Artifact> nonArcSources =
+ ImmutableSortedSet.copyOf(compilationArtifacts.getNonArcSrcs());
+ Collection<Artifact> privateHdrs =
+ ImmutableSortedSet.copyOf(compilationArtifacts.getPrivateHdrs());
+ Collection<Artifact> publicHdrs =
+ Stream.concat(
+ Streams.stream(attributes.hdrs()),
+ Streams.stream(compilationArtifacts.getAdditionalHdrs()))
+ .collect(toImmutableSortedSet(naturalOrder()));
+ Artifact pchHdr = getPchFile().orNull();
+ ObjcCppSemantics semantics = createObjcCppSemantics(objcProvider, privateHdrs, pchHdr);
+
+ String purpose = String.format("%s_objc_arc", semantics.getPurpose());
+ extensionBuilder.setArcEnabled(true);
+ Info.CompilationInfo objcArcCompilationInfo =
+ compile(
+ objcProvider,
+ extensionBuilder.build(),
+ extraCompileArgs,
+ ccToolchain,
+ fdoSupport,
+ priorityHeaders,
+ precompiledFiles,
+ arcSources,
+ privateHdrs,
+ publicHdrs,
+ pchHdr,
+ semantics,
+ purpose);
+
+ purpose = String.format("%s_non_objc_arc", semantics.getPurpose());
+ extensionBuilder.setArcEnabled(false);
+ Info.CompilationInfo nonObjcArcCompilationInfo =
+ compile(
+ objcProvider,
+ extensionBuilder.build(),
+ extraCompileArgs,
+ ccToolchain,
+ fdoSupport,
+ priorityHeaders,
+ precompiledFiles,
+ nonArcSources,
+ privateHdrs,
+ publicHdrs,
+ pchHdr,
+ semantics,
+ purpose);
+
+ CcLibraryHelper resultLink =
+ new CcLibraryHelper(
+ 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)
+ .addVariableExtension(extensionBuilder.build());
+
+ if (linkType != null) {
+ resultLink.setLinkType(linkType);
+ }
+
+ if (linkActionInput != null) {
+ resultLink.addLinkActionInput(linkActionInput);
+ }
+
+ CppCompilationContext.Builder compilationContextBuilder =
+ new CppCompilationContext.Builder(ruleContext);
+ compilationContextBuilder.mergeDependentContexts(
+ Arrays.asList(
+ objcArcCompilationInfo.getCppCompilationContext(),
+ nonObjcArcCompilationInfo.getCppCompilationContext()));
+ compilationContextBuilder.setPurpose(
+ String.format("%s_merged_arc_non_arc_objc", semantics.getPurpose()));
+ semantics.setupCompilationContext(ruleContext, compilationContextBuilder);
+
+ CcCompilationOutputs.Builder compilationOutputsBuilder = new CcCompilationOutputs.Builder();
+ compilationOutputsBuilder.merge(objcArcCompilationInfo.getCcCompilationOutputs());
+ compilationOutputsBuilder.merge(nonObjcArcCompilationInfo.getCcCompilationOutputs());
+
+ Info.LinkingInfo linkingInfo =
+ resultLink.link(
+ compilationOutputsBuilder.build(), compilationContextBuilder.build());
+
+ List<Map<String, NestedSet<Artifact>>> outputGroupsList =
+ Arrays.asList(
+ objcArcCompilationInfo.getOutputGroups(),
+ nonObjcArcCompilationInfo.getOutputGroups(),
+ linkingInfo.getOutputGroups());
+
+ Map<String, NestedSet<Artifact>> mergedOutputGroups = Info.mergeOutputGroups(outputGroupsList);
+
+ return new Pair<>(compilationOutputsBuilder.build(), ImmutableMap.copyOf(mergedOutputGroups));
}
private ObjcCppSemantics createObjcCppSemantics(
@@ -453,16 +562,17 @@ public class CompilationSupport {
}
private void registerHeaderScanningActions(
- Info info, ObjcProvider objcProvider, CompilationArtifacts compilationArtifacts) {
+ 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()
- || info.getCcCompilationOutputs().getObjectFiles(false).isEmpty()) {
+ if (!isHeaderThinningEnabled() || ccCompilationOutputs.getObjectFiles(false).isEmpty()) {
return;
}
ImmutableList.Builder<ObjcHeaderThinningInfo> headerThinningInfos = ImmutableList.builder();
AnalysisEnvironment analysisEnvironment = ruleContext.getAnalysisEnvironment();
- for (Artifact objectFile : info.getCcCompilationOutputs().getObjectFiles(false)) {
+ for (Artifact objectFile : ccCompilationOutputs.getObjectFiles(false)) {
ActionAnalysisMetadata generatingAction =
analysisEnvironment.getLocalGeneratingAction(objectFile);
if (generatingAction instanceof CppCompileAction) {
@@ -947,7 +1057,8 @@ public class CompilationSupport {
.setCompilationArtifacts(compilationArtifacts)
.setIntermediateArtifacts(intermediateArtifacts)
.setConfiguration(buildConfiguration);
- CcLibraryHelper helper;
+
+ Pair<CcCompilationOutputs, ImmutableMap<String, NestedSet<Artifact>>> compilationInfo;
if (compilationArtifacts.getArchive().isPresent()) {
Artifact objList = intermediateArtifacts.archiveObjList();
@@ -957,33 +1068,34 @@ public class CompilationSupport {
extension.addVariableCategory(VariableCategory.ARCHIVE_VARIABLES);
- helper =
- createCcLibraryHelper(
- objcProvider,
- compilationArtifacts,
- extension.build(),
- extraCompileArgs,
- ccToolchain,
- fdoSupport,
- priorityHeaders)
- .setLinkType(LinkTargetType.OBJC_ARCHIVE)
- .addLinkActionInput(objList);
+ compilationInfo =
+ ccCompileAndLink(
+ objcProvider,
+ compilationArtifacts,
+ extension,
+ extraCompileArgs,
+ ccToolchain,
+ fdoSupport,
+ priorityHeaders,
+ LinkTargetType.OBJC_ARCHIVE,
+ objList);
} else {
- helper =
- createCcLibraryHelper(
+ compilationInfo =
+ ccCompileAndLink(
objcProvider,
compilationArtifacts,
- extension.build(),
+ extension,
extraCompileArgs,
ccToolchain,
fdoSupport,
- priorityHeaders);
+ priorityHeaders,
+ /* linkType */ null,
+ /* linkActionInput */ null);
}
- Info info = helper.build();
- outputGroupCollector.putAll(info.getOutputGroups());
+ outputGroupCollector.putAll(compilationInfo.getSecond());
- registerHeaderScanningActions(info, objcProvider, compilationArtifacts);
+ registerHeaderScanningActions(compilationInfo.getFirst(), objcProvider, compilationArtifacts);
return this;
}
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 267bb5caab..df959eb96e 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,6 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.rules.cpp.CppCompilationContext;
import com.google.devtools.build.lib.rules.cpp.CppCompilationContext.Builder;
import com.google.devtools.build.lib.rules.cpp.CppCompileActionBuilder;
import com.google.devtools.build.lib.rules.cpp.CppCompileActionContext;
@@ -130,14 +131,6 @@ public class ObjcCppSemantics implements CppSemantics {
ObjcCommon.userHeaderSearchPaths(objcProvider, ruleContext.getConfiguration())) {
contextBuilder.addQuoteIncludeDir(iquotePath);
}
-
- // ProtoSupport creates multiple compilation contexts for a single rule, potentially multiple
- // archives per build configuration. This covers that worst case.
- contextBuilder.setPurpose(
- "ObjcCppSemantics_build_arch_"
- + buildConfiguration.getMnemonic()
- + "_with_suffix_"
- + intermediateArtifacts.archiveFileNameSuffix());
}
@Override
@@ -175,4 +168,18 @@ public class ObjcCppSemantics implements CppSemantics {
public boolean needsIncludeValidation() {
return false;
}
+
+ /**
+ * Gets the purpose for the compilation context.
+ *
+ * @see CppCompilationContext.Builder#setPurpose
+ */
+ public String getPurpose() {
+ // ProtoSupport creates multiple compilation contexts for a single rule, potentially multiple
+ // archives per build configuration. This covers that worst case.
+ return "ObjcCppSemantics_build_arch_"
+ + buildConfiguration.getMnemonic()
+ + "_with_suffix_"
+ + intermediateArtifacts.archiveFileNameSuffix();
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
index 6698bfc910..6040007277 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
@@ -64,6 +64,10 @@ class ObjcVariablesExtension implements VariablesExtension {
static final String DSYM_PATH_VARIABLE_NAME = "dsym_path";
static final String DSYM_BUNDLE_ZIP_VARIABLE_NAME = "dsym_bundle_zip";
+ // ARC variables. Mutually exclusive.
+ static final String OBJC_ARC_VARIABLE_NAME = "objc_arc";
+ static final String NO_OBJC_ARC_VARIABLE_NAME = "no_objc_arc";
+
private final RuleContext ruleContext;
private final ObjcProvider objcProvider;
private final CompilationArtifacts compilationArtifacts;
@@ -78,6 +82,7 @@ class ObjcVariablesExtension implements VariablesExtension {
private final Artifact dsymBundleZip;
private final Artifact linkmap;
private final Artifact bitcodeSymbolMap;
+ private boolean arcEnabled = true;
private ObjcVariablesExtension(
RuleContext ruleContext,
@@ -93,7 +98,8 @@ class ObjcVariablesExtension implements VariablesExtension {
ImmutableSet<VariableCategory> activeVariableCategories,
Artifact dsymBundleZip,
Artifact linkmap,
- Artifact bitcodeSymbolMap) {
+ Artifact bitcodeSymbolMap,
+ boolean arcEnabled) {
this.ruleContext = ruleContext;
this.objcProvider = objcProvider;
this.compilationArtifacts = compilationArtifacts;
@@ -108,6 +114,7 @@ class ObjcVariablesExtension implements VariablesExtension {
this.dsymBundleZip = dsymBundleZip;
this.linkmap = linkmap;
this.bitcodeSymbolMap = bitcodeSymbolMap;
+ this.arcEnabled = arcEnabled;
}
/** Type of build variable that can optionally exported by this extension. */
@@ -117,7 +124,7 @@ class ObjcVariablesExtension implements VariablesExtension {
EXECUTABLE_LINKING_VARIABLES,
DSYM_VARIABLES,
LINKMAP_VARIABLES,
- BITCODE_VARIABLES;
+ BITCODE_VARIABLES
}
@Override
@@ -143,6 +150,11 @@ class ObjcVariablesExtension implements VariablesExtension {
if (activeVariableCategories.contains(VariableCategory.BITCODE_VARIABLES)) {
addBitcodeVariables(builder);
}
+ if (arcEnabled) {
+ builder.addStringVariable(OBJC_ARC_VARIABLE_NAME, "");
+ } else {
+ builder.addStringVariable(NO_OBJC_ARC_VARIABLE_NAME, "");
+ }
}
private void addPchVariables(CcToolchainFeatures.Variables.Builder builder) {
@@ -255,7 +267,8 @@ class ObjcVariablesExtension implements VariablesExtension {
private Artifact dsymBundleZip;
private Artifact linkmap;
private Artifact bitcodeSymbolMap;
-
+ private boolean arcEnabled = true;
+
private final ImmutableSet.Builder<VariableCategory> activeVariableCategoriesBuilder =
ImmutableSet.builder();
@@ -343,6 +356,12 @@ class ObjcVariablesExtension implements VariablesExtension {
return this;
}
+ /** Sets whether ARC is enabled. */
+ public Builder setArcEnabled(boolean enabled) {
+ this.arcEnabled = enabled;
+ return this;
+ }
+
public ObjcVariablesExtension build() {
ImmutableSet<VariableCategory> activeVariableCategories =
@@ -388,7 +407,8 @@ class ObjcVariablesExtension implements VariablesExtension {
activeVariableCategories,
dsymBundleZip,
linkmap,
- bitcodeSymbolMap);
+ bitcodeSymbolMap,
+ arcEnabled);
}
}
}