aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompilationContext.java72
1 files changed, 47 insertions, 25 deletions
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 5b9059001a..da8827d6ac 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
@@ -28,22 +28,30 @@ 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.util.Pair;
+import com.google.devtools.build.lib.rules.cpp.CppHelper.PregreppedHeader;
+import com.google.devtools.build.lib.skyframe.serialization.InjectingObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+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.vfs.FileSystemProvider;
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.Map;
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 store of information needed for C++ compilation that is aggregated across dependencies.
*/
@Immutable
+@AutoCodec(dependency = FileSystemProvider.class)
public final class CppCompilationContext implements TransitiveInfoProvider {
+ public static final InjectingObjectCodec<CppCompilationContext, FileSystemProvider> CODEC =
+ new CppCompilationContext_AutoCodec();
+
/** An empty compilation context. */
public static final CppCompilationContext EMPTY = new Builder(null).build();
@@ -61,8 +69,8 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
/** Non-code mandatory compilation inputs. */
private final NestedSet<Artifact> nonCodeInputs;
- private final NestedSet<Pair<Artifact, Artifact>> pregreppedHdrs;
-
+ private final NestedSet<PregreppedHeader> pregreppedHdrs;
+
private final ModuleInfo moduleInfo;
private final ModuleInfo picModuleInfo;
@@ -74,13 +82,15 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
// Derived from depsContexts.
private final ImmutableSet<Artifact> compilationPrerequisites;
- private CppCompilationContext(
+ @AutoCodec.Instantiator
+ @VisibleForSerialization
+ CppCompilationContext(
CommandLineContext commandLineContext,
ImmutableSet<Artifact> compilationPrerequisites,
NestedSet<PathFragment> declaredIncludeDirs,
NestedSet<PathFragment> declaredIncludeWarnDirs,
NestedSet<Artifact> declaredIncludeSrcs,
- NestedSet<Pair<Artifact, Artifact>> pregreppedHdrs,
+ NestedSet<PregreppedHeader> pregreppedHdrs,
NestedSet<Artifact> nonCodeInputs,
ModuleInfo moduleInfo,
ModuleInfo picModuleInfo,
@@ -202,10 +212,10 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
}
/**
- * Returns the immutable pairs of (header file, pregrepped header file). The value artifacts
+ * Returns the immutable pairs of (header file, pregrepped header file). The value artifacts
* (pregrepped header file) are generated by {@link ExtractInclusionAction}.
*/
- NestedSet<Pair<Artifact, Artifact>> getPregreppedHeaders() {
+ NestedSet<PregreppedHeader> getPregreppedHeaders() {
return pregreppedHdrs;
}
@@ -355,11 +365,15 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
}
/**
- * The parts of the compilation context that influence the command line of
- * compilation actions.
+ * The parts of the compilation context that influence the command line of compilation actions.
*/
@Immutable
- private static class CommandLineContext {
+ @AutoCodec
+ @VisibleForSerialization
+ static class CommandLineContext {
+ public static final ObjectCodec<CommandLineContext> CODEC =
+ new CppCompilationContext_CommandLineContext_AutoCodec();
+
private final ImmutableList<PathFragment> includeDirs;
private final ImmutableList<PathFragment> quoteIncludeDirs;
private final ImmutableList<PathFragment> systemIncludeDirs;
@@ -391,7 +405,7 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
NestedSetBuilder.stableOrder();
private final NestedSetBuilder<Artifact> declaredIncludeSrcs =
NestedSetBuilder.stableOrder();
- private final NestedSetBuilder<Pair<Artifact, Artifact>> pregreppedHdrs =
+ private final NestedSetBuilder<PregreppedHeader> pregreppedHdrs =
NestedSetBuilder.stableOrder();
private final NestedSetBuilder<Artifact> nonCodeInputs = NestedSetBuilder.stableOrder();
private final ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder();
@@ -595,14 +609,16 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
}
/**
- * Add a map of generated source or header Artifact to an output Artifact after grepping
- * the file for include statements.
+ * Add a map of generated source or header Artifact to an output Artifact after grepping the
+ * file for include statements.
*/
- public Builder addPregreppedHeaderMap(Map<Artifact, Artifact> pregrepped) {
- addCompilationPrerequisites(pregrepped.values());
- for (Map.Entry<Artifact, Artifact> entry : pregrepped.entrySet()) {
- this.pregreppedHdrs.add(Pair.of(entry.getKey(), entry.getValue()));
- }
+ public Builder addPregreppedHeaders(List<PregreppedHeader> pregrepped) {
+ addCompilationPrerequisites(
+ pregrepped
+ .stream()
+ .map(pregreppedHeader -> pregreppedHeader.greppedHeader())
+ .collect(Collectors.toList()));
+ this.pregreppedHdrs.addAll(pregrepped);
return this;
}
@@ -760,13 +776,17 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
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(dependency = FileSystemProvider.class)
public static final class ModuleInfo {
+ public static final InjectingObjectCodec<ModuleInfo, FileSystemProvider> CODEC =
+ new CppCompilationContext_ModuleInfo_AutoCodec();
+
/**
* The module built for this context. If null, then no module is being compiled for this
* context.
@@ -896,11 +916,13 @@ public final class CppCompilationContext implements TransitiveInfoProvider {
}
}
- /**
- * Collects data for a specific module in a special format that makes pruning easy.
- */
+ /** Collects data for a specific module in a special format that makes pruning easy. */
@Immutable
+ @AutoCodec(dependency = FileSystemProvider.class)
public static final class TransitiveModuleHeaders {
+ public static final InjectingObjectCodec<TransitiveModuleHeaders, FileSystemProvider> CODEC =
+ new CppCompilationContext_TransitiveModuleHeaders_AutoCodec();
+
/**
* The module that we are calculating information for.
*/