@@ -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,
@@ -2421,60 +2427,74 @@ static bool hasExistingAdditionalOutput(CommandOutput &output,
2421
2427
return false ;
2422
2428
}
2423
2429
2424
- static void addAuxiliaryOutput (
2430
+ static llvm::SmallString< 128 > computeAuxiliaryOutputPath (
2425
2431
Compilation &C, CommandOutput &output, file_types::ID outputType,
2426
2432
const TypeToPathMap *outputMap, StringRef workingDirectory,
2427
2433
StringRef outputPath = StringRef(),
2428
2434
llvm::opt::OptSpecifier requireArg = llvm::opt::OptSpecifier()) {
2429
2435
2430
2436
if (hasExistingAdditionalOutput (output, outputType, outputPath))
2431
- return ;
2437
+ return {} ;
2432
2438
2433
- StringRef outputMapPath;
2434
2439
if (outputMap) {
2435
2440
auto iter = outputMap->find (outputType);
2436
- if (iter != outputMap->end ())
2437
- outputMapPath = iter->second ;
2441
+ if (iter != outputMap->end ()) {
2442
+ StringRef outputMapPath = iter->second ;
2443
+ // Prefer a path from the OutputMap.
2444
+ if (!outputMapPath.empty ())
2445
+ return outputMapPath;
2446
+ }
2438
2447
}
2448
+ if (!outputPath.empty ())
2449
+ return outputPath;
2439
2450
2440
- if (!outputMapPath.empty ()) {
2441
- // Prefer a path from the OutputMap.
2442
- output.setAdditionalOutputForType (outputType, outputMapPath);
2443
- } else if (!outputPath.empty ()) {
2444
- output.setAdditionalOutputForType (outputType, outputPath);
2445
- } else if (requireArg.isValid () && !C.getArgs ().getLastArg (requireArg)) {
2451
+ if (requireArg.isValid () && !C.getArgs ().getLastArg (requireArg)) {
2446
2452
// This auxiliary output only exists if requireArg is passed, but it
2447
2453
// wasn't this time.
2448
- return ;
2449
- } else {
2450
- // Put the auxiliary output file next to "the" primary output file.
2451
- //
2452
- // FIXME: when we're in WMO and have multiple primary outputs, we derive the
2453
- // additional filename here from the _first_ primary output name, which
2454
- // means that in the derived OFM (in Job.cpp) the additional output will
2455
- // have a possibly-surprising name. But that's only half the problem: it
2456
- // also get associated with the first primary _input_, even when there are
2457
- // multiple primary inputs; really it should be associated with the build as
2458
- // a whole -- derived OFM input "" -- but that's a more general thing to
2459
- // fix.
2460
- llvm::SmallString<128 > path;
2461
- if (output.getPrimaryOutputType () != file_types::TY_Nothing)
2462
- path = output.getPrimaryOutputFilenames ()[0 ];
2463
- else if (!output.getBaseInput (0 ).empty ())
2464
- path = llvm::sys::path::filename (output.getBaseInput (0 ));
2465
- else {
2466
- formFilenameFromBaseAndExt (C.getOutputInfo ().ModuleName , /* newExt=*/ " " ,
2467
- workingDirectory, path);
2468
- }
2469
- assert (!path.empty ());
2470
-
2471
- bool isTempFile = C.isTemporaryFile (path);
2472
- llvm::sys::path::replace_extension (
2473
- path, file_types::getExtension (outputType));
2474
- output.setAdditionalOutputForType (outputType, path);
2475
- if (isTempFile)
2476
- C.addTemporaryFile (path);
2454
+ return {};
2477
2455
}
2456
+
2457
+ // Put the auxiliary output file next to "the" primary output file.
2458
+ //
2459
+ // FIXME: when we're in WMO and have multiple primary outputs, we derive the
2460
+ // additional filename here from the _first_ primary output name, which
2461
+ // means that in the derived OFM (in Job.cpp) the additional output will
2462
+ // have a possibly-surprising name. But that's only half the problem: it
2463
+ // also get associated with the first primary _input_, even when there are
2464
+ // multiple primary inputs; really it should be associated with the build as
2465
+ // a whole -- derived OFM input "" -- but that's a more general thing to
2466
+ // fix.
2467
+ llvm::SmallString<128 > path;
2468
+ if (output.getPrimaryOutputType () != file_types::TY_Nothing)
2469
+ path = output.getPrimaryOutputFilenames ()[0 ];
2470
+ else if (!output.getBaseInput (0 ).empty ())
2471
+ path = llvm::sys::path::filename (output.getBaseInput (0 ));
2472
+ else {
2473
+ formFilenameFromBaseAndExt (C.getOutputInfo ().ModuleName , /* newExt=*/ " " ,
2474
+ workingDirectory, path);
2475
+ }
2476
+ assert (!path.empty ());
2477
+
2478
+ const bool isTempFile = C.isTemporaryFile (path);
2479
+ llvm::sys::path::replace_extension (path,
2480
+ file_types::getExtension (outputType));
2481
+ if (isTempFile)
2482
+ C.addTemporaryFile (path);
2483
+ return path;
2484
+ }
2485
+
2486
+ static void addAuxiliaryOutput (
2487
+ Compilation &C, CommandOutput &output, file_types::ID outputType,
2488
+ const TypeToPathMap *outputMap, StringRef workingDirectory,
2489
+ StringRef outputPath = StringRef(),
2490
+ llvm::opt::OptSpecifier requireArg = llvm::opt::OptSpecifier()) {
2491
+
2492
+ const auto path =
2493
+ computeAuxiliaryOutputPath (C, output, outputType, outputMap,
2494
+ workingDirectory, outputPath, requireArg);
2495
+ if (path.empty ())
2496
+ return ;
2497
+ output.setAdditionalOutputForType (outputType, path);
2478
2498
}
2479
2499
2480
2500
static void addDiagFileOutputForPersistentPCHAction (
@@ -3053,8 +3073,12 @@ void Driver::chooseDependenciesOutputPaths(Compilation &C,
3053
3073
llvm::SmallString<128 > &Buf,
3054
3074
CommandOutput *Output) const {
3055
3075
if (C.getArgs ().hasArg (options::OPT_emit_dependencies)) {
3056
- addAuxiliaryOutput (C, *Output, file_types::TY_Dependencies, OutputMap,
3057
- workingDirectory);
3076
+ auto depPath = computeAuxiliaryOutputPath (
3077
+ C, *Output, file_types::TY_Dependencies, OutputMap, workingDirectory);
3078
+ C.addDependencyPathOrCreateDummy (depPath, [&] {
3079
+ addAuxiliaryOutput (C, *Output, file_types::TY_Dependencies, OutputMap,
3080
+ workingDirectory);
3081
+ });
3058
3082
}
3059
3083
if (C.getIncrementalBuildEnabled ()) {
3060
3084
file_types::forEachIncrementalOutputType ([&](file_types::ID type) {
0 commit comments