Only compile a single source file once for a given cc_* rule.
RELNOTES: None.
@@ -201,7 +201,7 @@ public final class CcCompilationHelper {
private final List<Artifact> additionalIncludeScanningRoots = new ArrayList<>();
private final List<PathFragment> additionalExportedHeaders = new ArrayList<>();
private final List<CppModuleMap> additionalCppModuleMaps = new ArrayList<>();
- private final Set<CppSource> compilationUnitSources = new LinkedHashSet<>();
+ private final LinkedHashMap<Artifact, CppSource> compilationUnitSources = new LinkedHashMap<>();
private final List<Artifact> objectFiles = new ArrayList<>();
private final List<Artifact> picObjectFiles = new ArrayList<>();
private ImmutableList<String> copts = ImmutableList.of();
@@ -408,8 +408,10 @@ public final class CcCompilationHelper {
Preconditions.checkState(isHeader || isTextualInclude);
if (ccToolchain.shouldProcessHeaders(featureConfiguration) && !isTextualInclude) {
- compilationUnitSources.add(CppSource.create(privateHeader, label, CppSource.Type.HEADER));
+ compilationUnitSources.put(
+ privateHeader, CppSource.create(privateHeader, label, CppSource.Type.HEADER));
}
+
this.privateHeaders.add(privateHeader);
return this;
}
@@ -464,7 +466,8 @@ public final class CcCompilationHelper {
if (isTextualInclude || !isHeader || !ccToolchain.shouldProcessHeaders(featureConfiguration)) {
return;
}
- compilationUnitSources.add(CppSource.create(header, label, CppSource.Type.HEADER));
+
+ compilationUnitSources.put(header, CppSource.create(header, label, CppSource.Type.HEADER));
}
/** Adds a header to {@code publicHeaders}, but not to this target's module map. */
@@ -497,7 +500,7 @@ public final class CcCompilationHelper {
} else {
type = CppSource.Type.SOURCE;
}
- compilationUnitSources.add(CppSource.create(source, label, type));
+ compilationUnitSources.put(source, CppSource.create(source, label, type));
}
/**
@@ -507,7 +510,7 @@ public final class CcCompilationHelper {
* compilation.
*/
public ImmutableSet<CppSource> getCompilationUnitSources() {
- return ImmutableSet.copyOf(this.compilationUnitSources);
+ return ImmutableSet.copyOf(this.compilationUnitSources.values());
}
/**
@@ -1232,7 +1235,7 @@ public final class CcCompilationHelper {
* for all artifacts.
*/
private ImmutableMap<Artifact, String> calculateOutputNameMapByType(
- Set<CppSource> sources, String prefixDir) {
+ Map<Artifact, CppSource> sources, String prefixDir) {
ImmutableMap.Builder<Artifact, String> builder = ImmutableMap.builder();
builder.putAll(
calculateOutputNameMap(
@@ -1248,9 +1251,11 @@ public final class CcCompilationHelper {
}
private NestedSet<Artifact> getSourceArtifactsByType(
- Set<CppSource> sources, CppSource.Type type) {
+ Map<Artifact, CppSource> sources, CppSource.Type type) {
NestedSetBuilder<Artifact> result = NestedSetBuilder.stableOrder();
- result.addAll(sources
+ result.addAll(
+ sources
+ .values()
.stream()
.filter(source -> source.getType().equals(type))
.map(CppSource::getSource)
@@ -1299,7 +1304,7 @@ public final class CcCompilationHelper {
outputNameMap = calculateOutputNameMapByType(compilationUnitSources, outputNamePrefixDir);
}
- for (CppSource source : compilationUnitSources) {
+ for (CppSource source : compilationUnitSources.values()) {
Artifact sourceArtifact = source.getSource();
Label sourceLabel = source.getLabel();
CppCompileActionBuilder builder = initializeCompileAction(sourceArtifact);
