Skip to content

Commit 0dce082

Browse files
Add feature to produce indexstore files for CC builds
1 parent 4b194d2 commit 0dce082

File tree

14 files changed

+204
-5
lines changed

14 files changed

+204
-5
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/ArtifactCategory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum ArtifactCategory {
2525
DYNAMIC_LIBRARY("lib", ".so", ".dylib", ".dll", ".wasm"),
2626
EXECUTABLE("", "", ".exe", ".wasm"),
2727
INTERFACE_LIBRARY("lib", ".ifso", ".tbd", ".if.lib", ".lib"),
28+
INDEXSTORE_FILE("", ".indexstore"),
2829
PIC_FILE("", ".pic"),
2930
INCLUDED_FILE_LIST("", ".d"),
3031
SERIALIZED_DIAGNOSTICS_FILE("", ".dia"),

src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,8 @@ private Artifact createCompileActionTemplate(
14681468
SpecialArtifact outputFiles =
14691469
CppHelper.getCompileOutputTreeArtifact(
14701470
actionConstructionContext, label, sourceArtifact, outputName, usePic);
1471-
// Dotd and dia file outputs are specified in the execution phase.
1472-
builder.setOutputs(outputFiles, /* dotdFile= */ null, /* diagnosticsFile= */ null);
1471+
// Dotd, dia and indexstore file outputs are specified in the execution phase.
1472+
builder.setOutputs(outputFiles, /* dotdFile= */ null, /* diagnosticsFile= */ null, /* indexstoreFiles */ null);
14731473
builder.setVariables(
14741474
setupCompileBuildVariables(
14751475
builder,
@@ -1497,12 +1497,19 @@ private Artifact createCompileActionTemplate(
14971497
CppHelper.getDiagnosticsOutputTreeArtifact(
14981498
actionConstructionContext, label, sourceArtifact, outputName, usePic);
14991499
}
1500+
SpecialArtifact indexstoreTreeArtifact = null;
1501+
if (builder.indexstoreFilesEnabled()) {
1502+
indexstoreTreeArtifact =
1503+
CppHelper.getIndexstoreOutputTreeArtifact(
1504+
actionConstructionContext, label, sourceArtifact, outputName);
1505+
}
15001506
CppCompileActionTemplate actionTemplate =
15011507
new CppCompileActionTemplate(
15021508
sourceArtifact,
15031509
outputFiles,
15041510
dotdTreeArtifact,
15051511
diagnosticsTreeArtifact,
1512+
indexstoreTreeArtifact,
15061513
builder,
15071514
ccToolchain,
15081515
outputCategories,
@@ -1574,6 +1581,10 @@ private CcToolchainVariables setupCompileBuildVariables(
15741581
if (builder.getDiagnosticsFile() != null) {
15751582
diagnosticsFileExecPath = builder.getDiagnosticsFile().getExecPathString();
15761583
}
1584+
String indexstoreFilesExecPath = null;
1585+
if (builder.getIndexstoreFiles() != null) {
1586+
indexstoreFilesExecPath = builder.getIndexstoreFiles().getExecPathString();
1587+
}
15771588
if (needsFdoBuildVariables && fdoContext.hasArtifacts(cppConfiguration)) {
15781589
// This modifies the passed-in builder, which is a surprising side-effect, and makes it unsafe
15791590
// to call this method multiple times for the same builder.
@@ -1650,6 +1661,7 @@ private CcToolchainVariables setupCompileBuildVariables(
16501661
getCopts(builder.getSourceFile(), sourceLabel),
16511662
dotdFileExecPath,
16521663
diagnosticsFileExecPath,
1664+
indexstoreFilesExecPath,
16531665
usePic,
16541666
ccCompilationContext.getExternalIncludeDirs(),
16551667
additionalBuildVariables);

src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public CcToolchainVariables getCompileBuildVariables(
360360
/* fdoStamp= */ null,
361361
/* dotdFileExecPath= */ null,
362362
/* diagnosticsFileExecPath= */ null,
363+
/* indexstoreFilesExecPath= */ null,
363364
variablesExtensions,
364365
/* additionalBuildVariables= */ ImmutableMap.of(),
365366
/* directModuleMaps= */ ImmutableList.of(),

src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public enum CompileBuildVariables {
4646
DEPENDENCY_FILE("dependency_file"),
4747
/** Variable for the serialized diagnostics file path */
4848
SERIALIZED_DIAGNOSTICS_FILE("serialized_diagnostics_file"),
49+
/** Variable for the indexstore file paths */
50+
INDEXSTORE_FILES("indexstore_files"),
4951
/** Variable for the module file name. */
5052
MODULE_NAME("module_name"),
5153
/**
@@ -154,6 +156,7 @@ public static CcToolchainVariables setupVariablesOrReportRuleError(
154156
String fdoStamp,
155157
String dotdFileExecPath,
156158
String diagnosticsFileExecPath,
159+
String indexstoreFilesExecPath,
157160
ImmutableList<VariablesExtension> variablesExtensions,
158161
ImmutableMap<String, String> additionalBuildVariables,
159162
Iterable<Artifact> directModuleMaps,
@@ -188,6 +191,7 @@ public static CcToolchainVariables setupVariablesOrReportRuleError(
188191
fdoStamp,
189192
dotdFileExecPath,
190193
diagnosticsFileExecPath,
194+
indexstoreFilesExecPath,
191195
variablesExtensions,
192196
additionalBuildVariables,
193197
directModuleMaps,
@@ -224,6 +228,7 @@ public static CcToolchainVariables setupVariablesOrThrowEvalException(
224228
String fdoStamp,
225229
String dotdFileExecPath,
226230
String diagnosticsFileExecPath,
231+
String indexstoreFilesExecPath,
227232
ImmutableList<VariablesExtension> variablesExtensions,
228233
ImmutableMap<String, String> additionalBuildVariables,
229234
Iterable<Artifact> directModuleMaps,
@@ -258,6 +263,7 @@ public static CcToolchainVariables setupVariablesOrThrowEvalException(
258263
fdoStamp,
259264
dotdFileExecPath,
260265
diagnosticsFileExecPath,
266+
indexstoreFilesExecPath,
261267
variablesExtensions,
262268
additionalBuildVariables,
263269
directModuleMaps,
@@ -288,6 +294,7 @@ private static CcToolchainVariables setupVariables(
288294
String fdoStamp,
289295
String dotdFileExecPath,
290296
String diagnosticsFileExecPath,
297+
String indexstoreFilesExecPath,
291298
ImmutableList<VariablesExtension> variablesExtensions,
292299
ImmutableMap<String, String> additionalBuildVariables,
293300
Iterable<Artifact> directModuleMaps,
@@ -327,6 +334,7 @@ private static CcToolchainVariables setupVariables(
327334
userCompileFlags,
328335
dotdFileExecPath,
329336
diagnosticsFileExecPath,
337+
indexstoreFilesExecPath,
330338
usePic,
331339
ImmutableList.of(),
332340
ImmutableMap.of());
@@ -347,6 +355,7 @@ public static void setupSpecificVariables(
347355
Iterable<String> userCompileFlags,
348356
String dotdFileExecPath,
349357
String diagnosticsFileExecPath,
358+
String indexstoreFilesExecPath,
350359
boolean usePic,
351360
ImmutableList<PathFragment> externalIncludeDirs,
352361
Map<String, String> additionalBuildVariables) {
@@ -372,6 +381,12 @@ public static void setupSpecificVariables(
372381
SERIALIZED_DIAGNOSTICS_FILE.getVariableName(), diagnosticsFileExecPath);
373382
}
374383

384+
// Set indexstore_files to enable <object>.indexstore files generation.
385+
if (indexstoreFilesExecPath != null) {
386+
buildVariables.addStringVariable(
387+
INDEXSTORE_FILES.getVariableName(), indexstoreFilesExecPath);
388+
}
389+
375390
if (gcnoFile != null) {
376391
buildVariables.addStringVariable(GCOV_GCNO_FILE.getVariableName(), gcnoFile);
377392
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable
224224
* @param outputFile the object file that is written as result of the compilation
225225
* @param dotdFile the .d file that is generated as a side-effect of compilation
226226
* @param diagnosticsFile the .dia file that is generated as a side-effect of compilation
227+
* @param indexstoreFiles the .indexstore files that are generated as a side-effect of compilation
227228
* @param gcnoFile the coverage notes that are written in coverage mode, can be null
228229
* @param dwoFile the .dwo output file where debug information is stored for Fission builds (null
229230
* if Fission mode is disabled)
@@ -253,6 +254,7 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable
253254
Artifact outputFile,
254255
@Nullable Artifact dotdFile,
255256
@Nullable Artifact diagnosticsFile,
257+
@Nullable Artifact indexstoreFiles,
256258
@Nullable Artifact gcnoFile,
257259
@Nullable Artifact dwoFile,
258260
@Nullable Artifact ltoIndexingFile,
@@ -276,6 +278,7 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable
276278
outputFile,
277279
dotdFile,
278280
diagnosticsFile,
281+
indexstoreFiles,
279282
gcnoFile,
280283
dwoFile,
281284
ltoIndexingFile,
@@ -305,6 +308,7 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable
305308
actionName,
306309
dotdFile,
307310
diagnosticsFile,
311+
indexstoreFiles,
308312
featureConfiguration,
309313
variables);
310314
this.executionInfo = executionInfo;
@@ -331,6 +335,7 @@ private static ImmutableSet<Artifact> collectOutputs(
331335
@Nullable Artifact outputFile,
332336
@Nullable Artifact dotdFile,
333337
@Nullable Artifact diagnosticsFile,
338+
@Nullable Artifact indexstoreFiles,
334339
@Nullable Artifact gcnoFile,
335340
@Nullable Artifact dwoFile,
336341
@Nullable Artifact ltoIndexingFile,
@@ -350,6 +355,9 @@ private static ImmutableSet<Artifact> collectOutputs(
350355
if (diagnosticsFile != null) {
351356
outputs.add(diagnosticsFile);
352357
}
358+
if (indexstoreFiles != null) {
359+
outputs.add(indexstoreFiles);
360+
}
353361
if (dwoFile != null) {
354362
outputs.add(dwoFile);
355363
}
@@ -365,6 +373,7 @@ static CompileCommandLine buildCommandLine(
365373
String actionName,
366374
Artifact dotdFile,
367375
Artifact diagnosticsFile,
376+
Artifact indexstoreFiles,
368377
FeatureConfiguration featureConfiguration,
369378
CcToolchainVariables variables) {
370379
return CompileCommandLine.builder(sourceFile, coptsFilter, actionName, dotdFile)

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class CppCompileActionBuilder {
6060
private Artifact ltoIndexingFile;
6161
private Artifact dotdFile;
6262
private Artifact diagnosticsFile;
63+
private Artifact indexstoreFiles;
6364
private Artifact gcnoFile;
6465
private CcCompilationContext ccCompilationContext = CcCompilationContext.EMPTY;
6566
private final List<String> pluginOpts = new ArrayList<>();
@@ -320,6 +321,7 @@ public CppCompileAction buildAndVerify() throws UnconfiguredActionConfigExceptio
320321
outputFile,
321322
dotdFile,
322323
diagnosticsFile,
324+
indexstoreFiles,
323325
gcnoFile,
324326
dwoFile,
325327
ltoIndexingFile,
@@ -493,12 +495,17 @@ public boolean serializedDiagnosticsFilesEnabled() {
493495
return featureConfiguration.isEnabled(CppRuleClasses.SERIALIZED_DIAGNOSTICS_FILE);
494496
}
495497

498+
public boolean indexstoreFilesEnabled() {
499+
return featureConfiguration.isEnabled(CppRuleClasses.INDEXSTORE_FILES);
500+
}
501+
496502
@CanIgnoreReturnValue
497503
public CppCompileActionBuilder setOutputs(
498-
Artifact outputFile, Artifact dotdFile, Artifact diagnosticsFile) {
504+
Artifact outputFile, Artifact dotdFile, Artifact diagnosticsFile, Artifact indexstoreFiles) {
499505
this.outputFile = outputFile;
500506
this.dotdFile = dotdFile;
501507
this.diagnosticsFile = diagnosticsFile;
508+
this.indexstoreFiles = indexstoreFiles;
502509
return this;
503510
}
504511

@@ -533,6 +540,15 @@ public CppCompileActionBuilder setOutputs(
533540
} else {
534541
diagnosticsFile = null;
535542
}
543+
if (indexstoreFilesEnabled()) {
544+
String indexstoreFilesName =
545+
CppHelper.getIndexstoreFilesName(ccToolchain, outputCategory, outputName);
546+
indexstoreFiles =
547+
CppHelper.getCompileOutputArtifact(
548+
actionConstructionContext, label, indexstoreFilesName, configuration);
549+
} else {
550+
indexstoreFiles = null;
551+
}
536552
return this;
537553
}
538554

@@ -564,6 +580,10 @@ public Artifact getDiagnosticsFile() {
564580
return this.diagnosticsFile;
565581
}
566582

583+
public Artifact getIndexstoreFiles() {
584+
return this.indexstoreFiles;
585+
}
586+
567587
@CanIgnoreReturnValue
568588
public CppCompileActionBuilder setGcnoFile(Artifact gcnoFile) {
569589
this.gcnoFile = gcnoFile;

src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionTemplate.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class CppCompileActionTemplate extends ActionKeyCacher
4848
private final SpecialArtifact outputTreeArtifact;
4949
private final SpecialArtifact dotdTreeArtifact;
5050
private final SpecialArtifact diagnosticsTreeArtifact;
51+
private final SpecialArtifact indexstoreTreeArtifact;
5152
private final CcToolchainProvider toolchain;
5253
private final ImmutableList<ArtifactCategory> categories;
5354
private final ActionOwner actionOwner;
@@ -61,6 +62,7 @@ public final class CppCompileActionTemplate extends ActionKeyCacher
6162
* @param outputTreeArtifact the TreeArtifact that contains compilation outputs.
6263
* @param dotdTreeArtifact the TreeArtifact that contains dotd files.
6364
* @param diagnosticsTreeArtifact the TreeArtifact that contains serialized diagnostics files.
65+
* @param indexstoreTreeArtifact the TreeArtifact that contains indexstore files.
6466
* @param cppCompileActionBuilder An almost completely configured {@link CppCompileActionBuilder}
6567
* without the input and output files set. It is used as a template to instantiate expanded
6668
* {CppCompileAction}s.
@@ -74,6 +76,7 @@ public final class CppCompileActionTemplate extends ActionKeyCacher
7476
SpecialArtifact outputTreeArtifact,
7577
SpecialArtifact dotdTreeArtifact,
7678
SpecialArtifact diagnosticsTreeArtifact,
79+
SpecialArtifact indexstoreTreeArtifact,
7780
CppCompileActionBuilder cppCompileActionBuilder,
7881
CcToolchainProvider toolchain,
7982
ImmutableList<ArtifactCategory> categories,
@@ -83,6 +86,7 @@ public final class CppCompileActionTemplate extends ActionKeyCacher
8386
this.outputTreeArtifact = outputTreeArtifact;
8487
this.dotdTreeArtifact = dotdTreeArtifact;
8588
this.diagnosticsTreeArtifact = diagnosticsTreeArtifact;
89+
this.indexstoreTreeArtifact = indexstoreTreeArtifact;
8690
this.toolchain = toolchain;
8791
this.categories = categories;
8892
this.actionOwner = checkNotNull(actionOwner, outputTreeArtifact);
@@ -146,12 +150,19 @@ public ImmutableList<CppCompileAction> generateActionsForInputArtifacts(
146150
TreeFileArtifact.createTemplateExpansionOutput(
147151
diagnosticsTreeArtifact, outputName + ".dia", artifactOwner);
148152
}
153+
TreeFileArtifact indexstoreFilesArtifact = null;
154+
if (indexstoreTreeArtifact != null) {
155+
indexstoreFilesArtifact =
156+
TreeFileArtifact.createTemplateExpansionOutput(
157+
indexstoreTreeArtifact, outputName + ".indexstore", artifactOwner);
158+
}
149159
expandedActions.add(
150160
createAction(
151161
inputTreeFileArtifact,
152162
outputTreeFileArtifact,
153163
dotdFileArtifact,
154164
diagnosticsFileArtifact,
165+
indexstoreFilesArtifact,
155166
privateHeaders));
156167
}
157168

@@ -171,6 +182,7 @@ protected void computeKey(
171182
CppActionNames.CPP_COMPILE,
172183
dotdTreeArtifact,
173184
diagnosticsTreeArtifact,
185+
indexstoreTreeArtifact,
174186
cppCompileActionBuilder.getFeatureConfiguration(),
175187
cppCompileActionBuilder.getVariables());
176188
CppCompileAction.computeKey(
@@ -202,13 +214,14 @@ private CppCompileAction createAction(
202214
TreeFileArtifact outputTreeFileArtifact,
203215
@Nullable Artifact dotdFileArtifact,
204216
@Nullable Artifact diagnosticsFileArtifact,
217+
@Nullable Artifact indexstoreFilesArtifact,
205218
NestedSet<Artifact> privateHeaders)
206219
throws ActionExecutionException {
207220
CppCompileActionBuilder builder =
208221
new CppCompileActionBuilder(cppCompileActionBuilder)
209222
.setAdditionalPrunableHeaders(privateHeaders)
210223
.setSourceFile(sourceTreeFileArtifact)
211-
.setOutputs(outputTreeFileArtifact, dotdFileArtifact, diagnosticsFileArtifact);
224+
.setOutputs(outputTreeFileArtifact, dotdFileArtifact, diagnosticsFileArtifact, indexstoreFilesArtifact);
212225

213226
CcToolchainVariables.Builder buildVariables =
214227
CcToolchainVariables.builder(cppCompileActionBuilder.getVariables());
@@ -228,6 +241,11 @@ private CppCompileAction createAction(
228241
CompileBuildVariables.SERIALIZED_DIAGNOSTICS_FILE.getVariableName(),
229242
diagnosticsFileArtifact.getExecPathString());
230243
}
244+
if (indexstoreFilesArtifact != null) {
245+
buildVariables.overrideStringVariable(
246+
CompileBuildVariables.INDEXSTORE_FILES.getVariableName(),
247+
indexstoreFilesArtifact.getExecPathString());
248+
}
231249

232250
builder.setVariables(buildVariables.build());
233251

0 commit comments

Comments
 (0)