aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Manuel Klimek <klimek@google.com>2015-08-10 13:24:08 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-08-11 07:51:22 +0000
commit310a1ebff45fb19d36edf0e09afda724de1158c8 (patch)
treed5be42829f1ba33d58844a3876730247f00e5429
parent42574a4d2ffd18947430186c5309df87e4c80c18 (diff)
Add a feature to control whether we provide transitive header modules to a
modules enabled build. -- MOS_MIGRATED_REVID=100272810
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java88
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java8
3 files changed, 65 insertions, 36 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 440c715b9a..790a9d7d97 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
@@ -801,8 +801,9 @@ public final class CcLibraryHelper {
if (model.getGeneratesNoPicHeaderModule()) {
contextBuilder.setHeaderModule(model.getHeaderModule(cppModuleMap.getArtifact()));
}
- if (featureConfiguration.isEnabled(CppRuleClasses.USE_HEADER_MODULES)) {
- contextBuilder.setUsingHeaderModules(true);
+ if (featureConfiguration.isEnabled(CppRuleClasses.USE_HEADER_MODULES)
+ && featureConfiguration.isEnabled(CppRuleClasses.TRANSITIVE_MODULE_MAPS)) {
+ contextBuilder.setProvideTransitiveModuleMaps(true);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java
index ead8123d89..7b1bb6419e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java
@@ -53,15 +53,19 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
private final Artifact headerModule;
private final Artifact picHeaderModule;
- // True if this context is for a compilation that uses header modules.
- private final boolean usingHeaderModules;
+ // True if this context is for a compilation that needs transitive module maps.
+ private final boolean provideTransitiveModuleMaps;
// Derived from depsContexts; no need to consider it for equals/hashCode.
private final ImmutableSet<Artifact> compilationPrerequisites;
- private CppCompilationContext(CommandLineContext commandLineContext,
- List<DepsContext> depsContexts, CppModuleMap cppModuleMap, Artifact headerModule,
- Artifact picHeaderModule, boolean usingHeaderModules) {
+ private CppCompilationContext(
+ CommandLineContext commandLineContext,
+ List<DepsContext> depsContexts,
+ CppModuleMap cppModuleMap,
+ Artifact headerModule,
+ Artifact picHeaderModule,
+ boolean provideTransitiveModuleMaps) {
Preconditions.checkNotNull(commandLineContext);
Preconditions.checkArgument(!depsContexts.isEmpty());
this.commandLineContext = commandLineContext;
@@ -69,7 +73,7 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
this.cppModuleMap = cppModuleMap;
this.headerModule = headerModule;
this.picHeaderModule = picHeaderModule;
- this.usingHeaderModules = usingHeaderModules;
+ this.provideTransitiveModuleMaps = provideTransitiveModuleMaps;
if (depsContexts.size() == 1) {
// Only LIPO targets have more than one DepsContexts. This codepath avoids creating
@@ -255,7 +259,7 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
builder.addTransitive(depsContext.topLevelHeaderModules);
builder.addTransitive(depsContext.impliedHeaderModules);
builder.addTransitive(depsContext.directModuleMaps);
- if (usingHeaderModules) {
+ if (provideTransitiveModuleMaps) {
builder.addTransitive(depsContext.transitiveModuleMaps);
}
}
@@ -358,13 +362,18 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
&& Objects.equals(picHeaderModule, other.picHeaderModule)
&& commandLineContext.equals(other.commandLineContext)
&& depsContexts.equals(other.depsContexts)
- && (usingHeaderModules == other.usingHeaderModules);
+ && (provideTransitiveModuleMaps == other.provideTransitiveModuleMaps);
}
@Override
public int hashCode() {
- return Objects.hash(headerModule, picHeaderModule, commandLineContext, depsContexts,
- cppModuleMap, usingHeaderModules);
+ return Objects.hash(
+ headerModule,
+ picHeaderModule,
+ commandLineContext,
+ depsContexts,
+ cppModuleMap,
+ provideTransitiveModuleMaps);
}
/**
@@ -387,9 +396,13 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
depsContext.transitiveModuleMaps,
depsContext.directModuleMaps));
}
- return new CppCompilationContext(context.commandLineContext, builder.build(),
- context.cppModuleMap, context.headerModule, context.picHeaderModule,
- context.usingHeaderModules);
+ return new CppCompilationContext(
+ context.commandLineContext,
+ builder.build(),
+ context.cppModuleMap,
+ context.headerModule,
+ context.picHeaderModule,
+ context.provideTransitiveModuleMaps);
}
/**
@@ -419,10 +432,13 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
*/
public static CppCompilationContext mergeForLipo(CppCompilationContext ownerContext,
CppCompilationContext libContext) {
- return new CppCompilationContext(libContext.commandLineContext,
+ return new CppCompilationContext(
+ libContext.commandLineContext,
ImmutableList.copyOf(Iterables.concat(ownerContext.depsContexts, libContext.depsContexts)),
- libContext.cppModuleMap, libContext.headerModule, libContext.picHeaderModule,
- /*usingHeaderModules=*/false);
+ libContext.cppModuleMap,
+ libContext.headerModule,
+ libContext.picHeaderModule,
+ /*providesTransitiveModuleMaps=*/ false);
}
/**
@@ -630,7 +646,7 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
private CppModuleMap cppModuleMap;
private Artifact headerModule;
private Artifact picHeaderModule;
- private boolean usingHeaderModules = false;
+ private boolean provideTransitiveModuleMaps = false;
/** The rule that owns the context */
private final RuleContext ruleContext;
@@ -874,10 +890,10 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
}
/**
- * Sets that the context will be used by a compilation that uses header modules.
+ * Sets that the context will be used by a compilation that needs transitive module maps.
*/
- public Builder setUsingHeaderModules(boolean usingHeaderModules) {
- this.usingHeaderModules = usingHeaderModules;
+ public Builder setProvideTransitiveModuleMaps(boolean provideTransitiveModuleMaps) {
+ this.provideTransitiveModuleMaps = provideTransitiveModuleMaps;
return this;
}
@@ -911,24 +927,28 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
: createMiddleman(owner, middlemanFactory);
return new CppCompilationContext(
- new CommandLineContext(ImmutableList.copyOf(includeDirs),
- ImmutableList.copyOf(quoteIncludeDirs), ImmutableList.copyOf(systemIncludeDirs),
+ new CommandLineContext(
+ ImmutableList.copyOf(includeDirs),
+ ImmutableList.copyOf(quoteIncludeDirs),
+ ImmutableList.copyOf(systemIncludeDirs),
ImmutableList.copyOf(defines)),
- ImmutableList.of(new DepsContext(prerequisiteStampFile,
- declaredIncludeDirs.build(),
- declaredIncludeWarnDirs.build(),
- declaredIncludeSrcs.build(),
- pregreppedHdrs.build(),
- headerModuleSrcs.build(),
- topLevelHeaderModules.build(),
- impliedHeaderModules,
- transitiveHeaderModuleSrcs.build(),
- transitiveModuleMaps.build(),
- directModuleMaps.build())),
+ ImmutableList.of(
+ new DepsContext(
+ prerequisiteStampFile,
+ declaredIncludeDirs.build(),
+ declaredIncludeWarnDirs.build(),
+ declaredIncludeSrcs.build(),
+ pregreppedHdrs.build(),
+ headerModuleSrcs.build(),
+ topLevelHeaderModules.build(),
+ impliedHeaderModules,
+ transitiveHeaderModuleSrcs.build(),
+ transitiveModuleMaps.build(),
+ directModuleMaps.build())),
cppModuleMap,
headerModule,
picHeaderModule,
- usingHeaderModules);
+ provideTransitiveModuleMaps);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
index ef2adfa186..ea32167f09 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
@@ -126,6 +126,14 @@ public class CppRuleClasses {
public static final String GENERATE_SUBMODULES = "generate_submodules";
/**
+ * A string constant for the transitive_module_maps feature.
+ *
+ * <p>This feature is used temporarily to switch between adding transitive module maps to a
+ * modules enabled build or only adding module maps from direct dependencies.
+ */
+ public static final String TRANSITIVE_MODULE_MAPS = "transitive_module_maps";
+
+ /**
* A string constant for switching on that a header module file includes information about
* all its dependencies, so we do not need to pass all transitive dependent header modules on
* the command line.