@@ -951,6 +951,11 @@ Driver::buildCompilation(const ToolChain &TC,
951
951
ArgList->hasArg (options::OPT_driver_time_compilation);
952
952
std::unique_ptr<UnifiedStatsReporter> StatsReporter =
953
953
createStatsReporter (ArgList.get (), Inputs, OI, DefaultTargetTriple);
954
+
955
+ const bool OnlyOneDependencyFile =
956
+ ArgList->hasFlag (options::OPT_enable_only_one_dependency_file,
957
+ options::OPT_disable_only_one_dependency_file, false );
958
+
954
959
// relies on the new dependency graph
955
960
const bool EnableFineGrainedDependencies =
956
961
ArgList->hasArg (options::OPT_enable_fine_grained_dependencies);
@@ -984,6 +989,7 @@ Driver::buildCompilation(const ToolChain &TC,
984
989
SaveTemps,
985
990
ShowDriverTimeCompilation,
986
991
std::move (StatsReporter),
992
+ OnlyOneDependencyFile,
987
993
EnableFineGrainedDependencies,
988
994
VerifyFineGrainedDependencyGraphAfterEveryImport,
989
995
EmitFineGrainedDependencyDotFileAfterEveryImport,
@@ -2425,60 +2431,74 @@ static bool hasExistingAdditionalOutput(CommandOutput &output,
2425
2431
return false ;
2426
2432
}
2427
2433
2428
- static void addAuxiliaryOutput (
2434
+ static llvm::SmallString< 128 > computeAuxiliaryOutputPath (
2429
2435
Compilation &C, CommandOutput &output, file_types::ID outputType,
2430
2436
const TypeToPathMap *outputMap, StringRef workingDirectory,
2431
2437
StringRef outputPath = StringRef(),
2432
2438
llvm::opt::OptSpecifier requireArg = llvm::opt::OptSpecifier()) {
2433
2439
2434
2440
if (hasExistingAdditionalOutput (output, outputType, outputPath))
2435
- return ;
2441
+ return {} ;
2436
2442
2437
- StringRef outputMapPath;
2438
2443
if (outputMap) {
2439
2444
auto iter = outputMap->find (outputType);
2440
- if (iter != outputMap->end ())
2441
- outputMapPath = iter->second ;
2445
+ if (iter != outputMap->end ()) {
2446
+ StringRef outputMapPath = iter->second ;
2447
+ // Prefer a path from the OutputMap.
2448
+ if (!outputMapPath.empty ())
2449
+ return outputMapPath;
2450
+ }
2442
2451
}
2452
+ if (!outputPath.empty ())
2453
+ return outputPath;
2443
2454
2444
- if (!outputMapPath.empty ()) {
2445
- // Prefer a path from the OutputMap.
2446
- output.setAdditionalOutputForType (outputType, outputMapPath);
2447
- } else if (!outputPath.empty ()) {
2448
- output.setAdditionalOutputForType (outputType, outputPath);
2449
- } else if (requireArg.isValid () && !C.getArgs ().getLastArg (requireArg)) {
2455
+ if (requireArg.isValid () && !C.getArgs ().getLastArg (requireArg)) {
2450
2456
// This auxiliary output only exists if requireArg is passed, but it
2451
2457
// wasn't this time.
2452
- return ;
2453
- } else {
2454
- // Put the auxiliary output file next to "the" primary output file.
2455
- //
2456
- // FIXME: when we're in WMO and have multiple primary outputs, we derive the
2457
- // additional filename here from the _first_ primary output name, which
2458
- // means that in the derived OFM (in Job.cpp) the additional output will
2459
- // have a possibly-surprising name. But that's only half the problem: it
2460
- // also get associated with the first primary _input_, even when there are
2461
- // multiple primary inputs; really it should be associated with the build as
2462
- // a whole -- derived OFM input "" -- but that's a more general thing to
2463
- // fix.
2464
- llvm::SmallString<128 > path;
2465
- if (output.getPrimaryOutputType () != file_types::TY_Nothing)
2466
- path = output.getPrimaryOutputFilenames ()[0 ];
2467
- else if (!output.getBaseInput (0 ).empty ())
2468
- path = llvm::sys::path::filename (output.getBaseInput (0 ));
2469
- else {
2470
- formFilenameFromBaseAndExt (C.getOutputInfo ().ModuleName , /* newExt=*/ " " ,
2471
- workingDirectory, path);
2472
- }
2473
- assert (!path.empty ());
2474
-
2475
- bool isTempFile = C.isTemporaryFile (path);
2476
- llvm::sys::path::replace_extension (
2477
- path, file_types::getExtension (outputType));
2478
- output.setAdditionalOutputForType (outputType, path);
2479
- if (isTempFile)
2480
- C.addTemporaryFile (path);
2458
+ return {};
2481
2459
}
2460
+
2461
+ // Put the auxiliary output file next to "the" primary output file.
2462
+ //
2463
+ // FIXME: when we're in WMO and have multiple primary outputs, we derive the
2464
+ // additional filename here from the _first_ primary output name, which
2465
+ // means that in the derived OFM (in Job.cpp) the additional output will
2466
+ // have a possibly-surprising name. But that's only half the problem: it
2467
+ // also get associated with the first primary _input_, even when there are
2468
+ // multiple primary inputs; really it should be associated with the build as
2469
+ // a whole -- derived OFM input "" -- but that's a more general thing to
2470
+ // fix.
2471
+ llvm::SmallString<128 > path;
2472
+ if (output.getPrimaryOutputType () != file_types::TY_Nothing)
2473
+ path = output.getPrimaryOutputFilenames ()[0 ];
2474
+ else if (!output.getBaseInput (0 ).empty ())
2475
+ path = llvm::sys::path::filename (output.getBaseInput (0 ));
2476
+ else {
2477
+ formFilenameFromBaseAndExt (C.getOutputInfo ().ModuleName , /* newExt=*/ " " ,
2478
+ workingDirectory, path);
2479
+ }
2480
+ assert (!path.empty ());
2481
+
2482
+ const bool isTempFile = C.isTemporaryFile (path);
2483
+ llvm::sys::path::replace_extension (path,
2484
+ file_types::getExtension (outputType));
2485
+ if (isTempFile)
2486
+ C.addTemporaryFile (path);
2487
+ return path;
2488
+ }
2489
+
2490
+ static void addAuxiliaryOutput (
2491
+ Compilation &C, CommandOutput &output, file_types::ID outputType,
2492
+ const TypeToPathMap *outputMap, StringRef workingDirectory,
2493
+ StringRef outputPath = StringRef(),
2494
+ llvm::opt::OptSpecifier requireArg = llvm::opt::OptSpecifier()) {
2495
+
2496
+ const auto path =
2497
+ computeAuxiliaryOutputPath (C, output, outputType, outputMap,
2498
+ workingDirectory, outputPath, requireArg);
2499
+ if (path.empty ())
2500
+ return ;
2501
+ output.setAdditionalOutputForType (outputType, path);
2482
2502
}
2483
2503
2484
2504
static void addDiagFileOutputForPersistentPCHAction (
@@ -3057,8 +3077,12 @@ void Driver::chooseDependenciesOutputPaths(Compilation &C,
3057
3077
llvm::SmallString<128 > &Buf,
3058
3078
CommandOutput *Output) const {
3059
3079
if (C.getArgs ().hasArg (options::OPT_emit_dependencies)) {
3060
- addAuxiliaryOutput (C, *Output, file_types::TY_Dependencies, OutputMap,
3061
- workingDirectory);
3080
+ auto depPath = computeAuxiliaryOutputPath (
3081
+ C, *Output, file_types::TY_Dependencies, OutputMap, workingDirectory);
3082
+ C.addDependencyPathOrCreateDummy (depPath, [&] {
3083
+ addAuxiliaryOutput (C, *Output, file_types::TY_Dependencies, OutputMap,
3084
+ workingDirectory);
3085
+ });
3062
3086
}
3063
3087
if (C.getIncrementalBuildEnabled ()) {
3064
3088
file_types::forEachIncrementalOutputType ([&](file_types::ID type) {
0 commit comments