Skip to content

Commit 0c2f307

Browse files
authored
Merge pull request #58422 from artemcm/ParseableWMOOutput
2 parents ddbb38a + 9d2aecb commit 0c2f307

File tree

3 files changed

+92
-47
lines changed

3 files changed

+92
-47
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
590590

591591
static DetailedTaskDescription
592592
constructDetailedTaskDescription(const CompilerInvocation &Invocation,
593-
const InputFile &PrimaryInput,
593+
ArrayRef<InputFile> PrimaryInputs,
594594
ArrayRef<const char *> Args) {
595595
// Command line and arguments
596596
std::string Executable = Invocation.getFrontendOptions().MainExecutablePath;
@@ -604,24 +604,30 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
604604
CommandLine += std::string(" ") + A;
605605
}
606606

607-
// Primary Input only
608-
Inputs.push_back(CommandInput(PrimaryInput.getFileName()));
607+
// Primary Inputs
608+
for (const auto &input : PrimaryInputs) {
609+
Inputs.push_back(CommandInput(input.getFileName()));
610+
}
609611

610-
// Output for this Primary
611-
auto OutputFile = PrimaryInput.outputFilename();
612-
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
613-
llvm::sys::path::extension(OutputFile)),
614-
OutputFile));
612+
for (const auto &input : PrimaryInputs) {
613+
// Main outputs
614+
auto OutputFile = input.outputFilename();
615+
if (!OutputFile.empty()) {
616+
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
617+
llvm::sys::path::extension(OutputFile)),
618+
OutputFile));
619+
}
615620

616-
// Supplementary outputs
617-
const auto &primarySpecificFiles = PrimaryInput.getPrimarySpecificPaths();
618-
const auto &supplementaryOutputPaths =
619-
primarySpecificFiles.SupplementaryOutputs;
620-
supplementaryOutputPaths.forEachSetOutput([&](const std::string &output) {
621-
Outputs.push_back(OutputPair(
622-
file_types::lookupTypeForExtension(llvm::sys::path::extension(output)),
623-
output));
624-
});
621+
// Supplementary outputs
622+
const auto &primarySpecificFiles = input.getPrimarySpecificPaths();
623+
const auto &supplementaryOutputPaths =
624+
primarySpecificFiles.SupplementaryOutputs;
625+
supplementaryOutputPaths.forEachSetOutput([&](const std::string &output) {
626+
Outputs.push_back(OutputPair(file_types::lookupTypeForExtension(
627+
llvm::sys::path::extension(output)),
628+
output));
629+
});
630+
}
625631
return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
626632
Outputs};
627633
}
@@ -2125,15 +2131,26 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21252131
// making sure it cannot collide with a real PID (always positive). Non-batch
21262132
// compilation gets a real OS PID.
21272133
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
2128-
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2129-
unsigned idx) -> bool {
2130-
emitBeganMessage(
2131-
llvm::errs(),
2132-
mapFrontendInvocationToAction(Invocation),
2133-
constructDetailedTaskDescription(Invocation, Input, Args), Pid - idx,
2134-
ProcInfo);
2135-
return false;
2136-
});
2134+
2135+
if (IO.hasPrimaryInputs()) {
2136+
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2137+
unsigned idx) -> bool {
2138+
ArrayRef<InputFile> Inputs(Input);
2139+
emitBeganMessage(llvm::errs(),
2140+
mapFrontendInvocationToAction(Invocation),
2141+
constructDetailedTaskDescription(Invocation,
2142+
Inputs,
2143+
Args), Pid - idx,
2144+
ProcInfo);
2145+
return false;
2146+
});
2147+
} else {
2148+
// If no primary inputs are present, we are in WMO.
2149+
emitBeganMessage(llvm::errs(),
2150+
mapFrontendInvocationToAction(Invocation),
2151+
constructDetailedTaskDescription(Invocation, IO.getAllInputs(), Args),
2152+
OSPid, ProcInfo);
2153+
}
21372154
}
21382155

21392156
int ReturnValue = 0;
@@ -2164,23 +2181,41 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21642181
// making sure it cannot collide with a real PID (always positive). Non-batch
21652182
// compilation gets a real OS PID.
21662183
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
2167-
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2168-
unsigned idx) -> bool {
2169-
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
2170-
"Expected diagnostic collection for input.");
21712184

2172-
// Join all diagnostics produced for this file into a single output.
2173-
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
2185+
if (IO.hasPrimaryInputs()) {
2186+
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
2187+
unsigned idx) -> bool {
2188+
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
2189+
"Expected diagnostic collection for input.");
2190+
2191+
// Join all diagnostics produced for this file into a single output.
2192+
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
2193+
const char *const Delim = "";
2194+
std::ostringstream JoinedDiags;
2195+
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
2196+
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2197+
2198+
emitFinishedMessage(llvm::errs(),
2199+
mapFrontendInvocationToAction(Invocation),
2200+
JoinedDiags.str(), r, Pid - idx, ProcInfo);
2201+
return false;
2202+
});
2203+
} else {
2204+
// If no primary inputs are present, we are in WMO.
2205+
std::vector<std::string> AllDiagnostics;
2206+
for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
2207+
AllDiagnostics.insert(AllDiagnostics.end(),
2208+
FileDiagnostics.getValue().begin(),
2209+
FileDiagnostics.getValue().end());
2210+
}
21742211
const char *const Delim = "";
21752212
std::ostringstream JoinedDiags;
2176-
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
2213+
std::copy(AllDiagnostics.begin(), AllDiagnostics.end(),
21772214
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2178-
21792215
emitFinishedMessage(llvm::errs(),
21802216
mapFrontendInvocationToAction(Invocation),
2181-
JoinedDiags.str(), r, Pid - idx, ProcInfo);
2182-
return false;
2183-
});
2217+
JoinedDiags.str(), r, OSPid, ProcInfo);
2218+
}
21842219
}
21852220

21862221
return r;

test/Frontend/parseable_output.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
// RUN: %target-swift-frontend -primary-file %s -o %t.out -emit-module -emit-module-path %t.swiftmodule -frontend-parseable-output 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -primary-file %s %S/Inputs/filelist-other.swift -o %t.out -module-name parseable_output -emit-module -emit-module-path %t.swiftmodule -serialize-diagnostics -serialize-diagnostics-path %t.dia -frontend-parseable-output 2>&1 | %FileCheck %s
2+
// Check without primary files (WMO):
3+
// RUN: %target-swift-frontend %s %S/Inputs/filelist-other.swift -o %t.out -module-name parseable_output -emit-module -emit-module-path %t.swiftmodule -serialize-diagnostics -serialize-diagnostics-path %t.dia -frontend-parseable-output 2>&1 | %FileCheck %s
24

35
// CHECK: {{[1-9][0-9]*}}
46
// CHECK-NEXT: {
57
// CHECK-NEXT: "kind": "began",
68
// CHECK-NEXT: "name": "compile",
7-
// CHECK-NEXT: "command": "{{.*[\\/]}}swift-frontend{{(\.exe)?}}{{.*}}-primary-file {{.*[\\/]}}parseable_output.swift -o {{.*[\\/]}}parseable_output.swift.tmp.out -emit-module -emit-module-path {{.*[\\/]}}parseable_output.swift.tmp.swiftmodule -frontend-parseable-output",
9+
// CHECK-NEXT: "command": "{{.*[\\/]}}swift-frontend{{(\.exe)?}}{{.*}} {{.*[\\/]}}parseable_output.swift {{.*[\\/]}}filelist-other.swift -o {{.*[\\/]}}parseable_output.swift.tmp.out -module-name parseable_output -emit-module -emit-module-path {{.*[\\/]}}parseable_output.swift.tmp.swiftmodule -serialize-diagnostics -serialize-diagnostics-path {{.*[\\/]}}parseable_output.swift.tmp.dia -frontend-parseable-output",
810
// CHECK-NEXT: "command_executable": "{{.*[\\/]}}swift{{(-frontend|c)?(\.exe)?}}",
911
// CHECK-NEXT: "command_arguments": [
10-
// CHECK: "-primary-file",
11-
// CHECK-NEXT: "{{.*[\\/]}}parseable_output.swift",
12+
// CHECK: "{{.*[\\/]}}parseable_output.swift",
1213
// CHECK: "-o",
1314
// CHECK-NEXT: "{{.*[\\/]}}parseable_output.swift.tmp.out",
15+
// CHECK-NEXT: "-module-name",
16+
// CHECK-NEXT: "parseable_output",
1417
// CHECK-NEXT: "-emit-module",
1518
// CHECK-NEXT: "-emit-module-path",
1619
// CHECK-NEXT: "{{.*[\\/]}}parseable_output.swift.tmp.swiftmodule",
20+
// CHECK-NEXT: "-serialize-diagnostics",
21+
// CHECK-NEXT: "-serialize-diagnostics-path"
22+
// CHECK-NEXT: "{{.*[\\/]}}parseable_output.swift.tmp.dia",
1723
// CHECK-NEXT: "-frontend-parseable-output"
1824
// CHECK-NEXT: ],
1925
// CHECK-NEXT: "inputs": [
2026
// CHECK-NEXT: "{{.*[\\/]}}parseable_output.swift"
21-
// CHECK-NEXT: ],
22-
// CHECK-NEXT: "outputs": [
27+
// CHECK: "outputs": [
2328
// CHECK-NEXT: {
2429
// CHECK-NEXT: "type": "image",
2530
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output.swift.tmp.out"
2631
// CHECK-NEXT: },
2732
// CHECK-NEXT: {
2833
// CHECK-NEXT: "type": "swiftmodule",
2934
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output.swift.tmp.swiftmodule"
35+
// CHECK-NEXT: },
36+
// CHECK-NEXT: {
37+
// CHECK-NEXT: "type": "diagnostics",
38+
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output.swift.tmp.dia"
3039
// CHECK-NEXT: }
3140
// CHECK-NEXT: ],
3241
// CHECK-NEXT: "pid": [[PID:[0-9]*]]

test/Frontend/parseable_output_error.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: not %target-swift-frontend -primary-file %s -o %t.out -emit-module -emit-module-path %t.swiftmodule -frontend-parseable-output 2>&1 | %FileCheck %s
2+
// Check without primary files (WMO):
3+
// RUN: not %target-swift-frontend %s -o %t.out -emit-module -emit-module-path %t.swiftmodule -frontend-parseable-output 2>&1 | %FileCheck %s
24

35
func foo() {
46
return 11;
@@ -7,11 +9,10 @@ func foo() {
79
// CHECK-NEXT: {
810
// CHECK-NEXT: "kind": "began",
911
// CHECK-NEXT: "name": "compile",
10-
// CHECK-NEXT: "command": "{{.*[\\/]}}swift-frontend{{(\.exe)?}}{{.*}}-primary-file {{.*[\\/]}}parseable_output_error.swift -o {{.*[\\/]}}parseable_output_error.swift.tmp.out -emit-module -emit-module-path {{.*[\\/]}}parseable_output_error.swift.tmp.swiftmodule -frontend-parseable-output",
12+
// CHECK-NEXT: "command": "{{.*[\\/]}}swift-frontend{{(\.exe)?}}{{.*}} {{.*[\\/]}}parseable_output_error.swift -o {{.*[\\/]}}parseable_output_error.swift.tmp.out -emit-module -emit-module-path {{.*[\\/]}}parseable_output_error.swift.tmp.swiftmodule -frontend-parseable-output",
1113
// CHECK-NEXT: "command_executable": "{{.*[\\/]}}swift{{(-frontend|c)?(\.exe)?}}",
1214
// CHECK-NEXT: "command_arguments": [
13-
// CHECK: "-primary-file",
14-
// CHECK-NEXT: "{{.*[\\/]}}parseable_output_error.swift",
15+
// CHECK: "{{.*[\\/]}}parseable_output_error.swift",
1516
// CHECK-NEXT: "-o",
1617
// CHECK-NEXT: "{{.*[\\/]}}parseable_output_error.swift.tmp.out",
1718
// CHECK-NEXT: "-emit-module",
@@ -43,7 +44,7 @@ func foo() {
4344
// CHECK-NEXT: "kind": "finished",
4445
// CHECK-NEXT: "name": "compile",
4546
// CHECK-NEXT: "pid": [[PID]],
46-
// CHECK-NEXT: "output": "{{.*[\\/]}}parseable_output_error.swift:4:12: error: unexpected non-void return value in void function{{.*}}return 11;{{.*[\\/]}}parseable_output_error.swift:4:12: note: did you mean to add a return type?{{.*}}return 11;
47+
// CHECK-NEXT: "output": "{{.*[\\/]}}parseable_output_error.swift:6:12: error: unexpected non-void return value in void function{{.*}}return 11;{{.*[\\/]}}parseable_output_error.swift:6:12: note: did you mean to add a return type?{{.*}}return 11;
4748
// CHECK-NEXT: "process": {
4849
// CHECK-NEXT: "real_pid": [[PID]]
4950
// CHECK-NEXT: },

0 commit comments

Comments
 (0)