Skip to content

Commit 38a6559

Browse files
author
David Ungar
committed
Take path arg for comparo
1 parent d4e265d commit 38a6559

File tree

6 files changed

+73
-23
lines changed

6 files changed

+73
-23
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ WARNING(incremental_requires_build_record_entry,none,
107107
"ignoring -incremental; output file map has no master dependencies "
108108
"entry (\"%0\" under \"\")", (StringRef))
109109

110+
WARNING(unable_to_open_incremental_comparison_log,none,
111+
"unable to open incremental comparison log file '%0'", (StringRef))
112+
110113
ERROR(error_os_minimum_deployment,none,
111114
"Swift requires a minimum deployment target of %0", (StringRef))
112115
ERROR(error_sdk_too_old,none,

include/swift/Driver/Compilation.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "swift/Basic/ArrayRefView.h"
2121
#include "swift/Basic/LLVM.h"
22+
#include "swift/Basic/NullablePtr.h"
2223
#include "swift/Basic/OutputFileMap.h"
2324
#include "swift/Basic/Statistic.h"
2425
#include "swift/Driver/Driver.h"
@@ -230,14 +231,21 @@ class Compilation {
230231
/// How many .swift input files?
231232
unsigned countSwiftInputs() const;
232233

233-
/// Print out a short message comparing dependencies w/ source-ranges
234+
/// Print out a short message comparing dependencies w/ source-ranges, or
235+
/// output it to the path below
234236
const bool CompareIncrementalSchemes;
235237

238+
/// If not empty, the path to use to log the comparision.
239+
const StringRef CompareIncrementalSchemesPath;
240+
236241
template <typename DepJobsT, typename RangeJobsT>
237242
void updateJobsForComparison(const DepJobsT &depJobs,
238243
const RangeJobsT &rangeJobs);
239244
void setFallingBackForComparison();
240-
void printComparision() const;
245+
void outputComparison() const;
246+
247+
private:
248+
void outputComparison(llvm::raw_ostream &) const;
241249

242250
private:
243251
llvm::SmallPtrSet<const Job *, 16> DependencyCompileJobs;
@@ -280,7 +288,8 @@ class Compilation {
280288
bool EmitExperimentalDependencyDotFileAfterEveryImport = false,
281289
bool ExperimentalDependenciesIncludeIntrafileOnes = false,
282290
bool EnableSourceRangeDependencies = false,
283-
bool CompareIncrementalSchemes = false);
291+
bool CompareIncrementalSchemes = false,
292+
StringRef CompareIncrementalSchemesPath = "");
284293
// clang-format on
285294
~Compilation();
286295

include/swift/Option/Options.td

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,19 @@ HelpText<"Try using source range information">;
145145

146146

147147
def driver_compare_incremental_schemes :
148-
Flag<["-"], "driver-compare-incremental-schemes">, Flags<[]>,
148+
Flag<["-"], "driver-compare-incremental-schemes">, Flags<[DoesNotAffectIncrementalBuild]>,
149149
HelpText<"Print a simple message comparing dependencies with source ranges (w/ fallback)">;
150150

151+
def driver_compare_incremental_schemes_path :
152+
Separate<["-"], "driver-compare-incremental-schemes-path">, Flags<[ArgumentIsPath,DoesNotAffectIncrementalBuild]>,
153+
HelpText<"Path to use for machine-readable comparision">,
154+
MetaVarName<"<path>">;
155+
156+
def driver_compare_incremental_schemes_path_EQ :
157+
Joined<["-"], "driver-compare-incremental-schemes-path=">, Flags<[]>,
158+
Alias<driver_compare_incremental_schemes_path>;
159+
160+
151161
def driver_verify_experimental_dependency_graph_after_every_import :
152162
Flag<["-"], "driver-verify-experimental-dependency-graph-after-every-import">,
153163
InternalDebugOpt,

lib/Driver/Compilation.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ Compilation::Compilation(DiagnosticEngine &Diags,
126126
bool EmitExperimentalDependencyDotFileAfterEveryImport,
127127
bool ExperimentalDependenciesIncludeIntrafileOnes,
128128
bool EnableSourceRangeDependencies,
129-
bool CompareIncrementalSchemes)
129+
bool CompareIncrementalSchemes,
130+
StringRef CompareIncrementalSchemesPath)
130131
: Diags(Diags), TheToolChain(TC),
131132
TheOutputInfo(OI),
132133
Level(Level),
@@ -156,7 +157,8 @@ Compilation::Compilation(DiagnosticEngine &Diags,
156157
ExperimentalDependenciesIncludeIntrafileOnes(
157158
ExperimentalDependenciesIncludeIntrafileOnes),
158159
EnableSourceRangeDependencies(EnableSourceRangeDependencies),
159-
CompareIncrementalSchemes(CompareIncrementalSchemes) {
160+
CompareIncrementalSchemes(CompareIncrementalSchemes),
161+
CompareIncrementalSchemesPath(CompareIncrementalSchemesPath) {
160162
};
161163
// clang-format on
162164

@@ -1906,7 +1908,7 @@ int Compilation::performJobs(std::unique_ptr<TaskQueue> &&TQ) {
19061908
bool abnormalExit;
19071909
int result = performJobsImpl(abnormalExit, std::move(TQ));
19081910

1909-
printComparision();
1911+
outputComparison();
19101912

19111913
if (!SaveTemps) {
19121914
for (const auto &pathPair : TempFilePaths) {
@@ -1954,21 +1956,42 @@ void Compilation::setFallingBackForComparison() {
19541956
SourceRangeCompileJobs = None;
19551957
}
19561958

1957-
void Compilation::printComparision() const {
1959+
void Compilation::outputComparison() const {
19581960
if (!CompareIncrementalSchemes)
19591961
return;
1962+
1963+
if (CompareIncrementalSchemesPath.empty()) {
1964+
outputComparison(llvm::outs());
1965+
return;
1966+
}
1967+
1968+
std::error_code EC;
1969+
using namespace llvm::sys::fs;
1970+
llvm::raw_fd_ostream OS(CompareIncrementalSchemesPath, EC, CD_OpenAlways,
1971+
FA_Write, OF_Append | OF_Text);
1972+
1973+
if (EC) {
1974+
getDiags().diagnose(SourceLoc(),
1975+
diag::unable_to_open_incremental_comparison_log,
1976+
CompareIncrementalSchemesPath);
1977+
return;
1978+
}
1979+
outputComparison(OS);
1980+
}
1981+
1982+
void Compilation::outputComparison(llvm::raw_ostream &out) const {
19601983
if (!getIncrementalBuildEnabled())
1961-
llvm::outs() << "*** Comparing incremental strategies is moot: incremental "
1962-
"compilation disabled ***\n";
1984+
out << "*** Comparing incremental strategies is moot: incremental "
1985+
"compilation disabled ***\n";
19631986
else if (SourceRangeCompileJobs)
1964-
llvm::outs() << "*** Comparing deps: " << DependencyCompileJobs.size()
1965-
<< ", ranges: " << SourceRangeCompileJobs->size()
1966-
<< ", total: " << countSwiftInputs() << " ***\n";
1987+
out << "*** Comparing deps: " << DependencyCompileJobs.size()
1988+
<< ", ranges: " << SourceRangeCompileJobs->size()
1989+
<< ", total: " << countSwiftInputs() << " ***\n";
19671990
else
1968-
llvm::outs() << "*** Comparing incremental strategies is moot: would fall "
1969-
"back and run "
1970-
<< DependencyCompileJobs.size()
1971-
<< ", total: " << countSwiftInputs() << " ***\n";
1991+
out << "*** Comparing incremental strategies is moot: would fall "
1992+
"back and run "
1993+
<< DependencyCompileJobs.size() << ", total: " << countSwiftInputs()
1994+
<< " ***\n";
19721995
}
19731996

19741997
unsigned Compilation::countSwiftInputs() const {

lib/Driver/Driver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,10 @@ Driver::buildCompilation(const ToolChain &TC,
857857
const bool EnableSourceRangeDependencies =
858858
ArgList->hasArg(options::OPT_enable_source_range_dependencies);
859859
const bool CompareIncrementalSchemes =
860-
ArgList->hasArg(options::OPT_driver_compare_incremental_schemes);
860+
ArgList->hasArg(options::OPT_driver_compare_incremental_schemes) ||
861+
ArgList->hasArg(options::OPT_driver_compare_incremental_schemes_path);
862+
const StringRef CompareIncrementalSchemesPath = ArgList->getLastArgValue(
863+
options::OPT_driver_compare_incremental_schemes_path);
861864

862865
Optional<OutputFileMap> OFM = buildOutputFileMap(
863866
*TranslatedArgList, workingDirectory,
@@ -982,7 +985,8 @@ Driver::buildCompilation(const ToolChain &TC,
982985
EmitExperimentalDependencyDotFileAfterEveryImport,
983986
ExperimentalDependenciesIncludeIntrafileOnes,
984987
EnableSourceRangeDependencies,
985-
CompareIncrementalSchemes);
988+
CompareIncrementalSchemes,
989+
CompareIncrementalSchemesPath);
986990
// clang-format on
987991
}
988992

test/Driver/Dependencies/range-lifecycle.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
// Now, do it again with range dependencies enabled:
7070
// =============================================================================
7171

72-
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output2
72+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes-path=./comparo -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output2
7373

7474
// RUN: %FileCheck -check-prefix=CHECK-HAS-NO-BATCHES %s < %t/output2
7575

76-
// RUN: %FileCheck -check-prefix=CHECK-COMPARE-DISABLED %s < %t/output2
76+
// RUN: %FileCheck -check-prefix=CHECK-COMPARE-DISABLED %s < %t/comparo
7777

7878
// RUN: %FileCheck -check-prefix=CHECK-TURN-ON-RANGES %s < %t/output2
7979

@@ -131,11 +131,12 @@
131131
// =============================================================================
132132

133133

134-
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output3
134+
// RUN: cd %t && %swiftc_driver -driver-compare-incremental-schemes-path ./comparo -enable-source-range-dependencies -output-file-map %t/output.json -incremental -enable-batch-mode ./main.swift ./fileA.swift ./fileB.swift -module-name main -j2 -driver-show-job-lifecycle -driver-show-incremental >& %t/output3
135135

136136
// RUN: %FileCheck -check-prefix=CHECK-HAS-NO-BATCHES %s < %t/output3
137137

138-
// RUN: %FileCheck -check-prefix=CHECK-COMPARE-0-0-3 %s < %t/output3
138+
// RUN: %FileCheck -check-prefix=CHECK-COMPARE-DISABLED %s < %t/comparo
139+
// RUN: %FileCheck -check-prefix=CHECK-COMPARE-0-0-3 %s < %t/comparo
139140
// CHECK-COMPARE-0-0-3: *** Comparing deps: 0, ranges: 0, total: 3 ***
140141

141142
// RUN: %FileCheck -check-prefix=CHECK-INCREMENTAL-ENABLED %s < %t/output3

0 commit comments

Comments
 (0)