Skip to content

Commit c58fd49

Browse files
committed
[Parseable Output] Generate valid output for files of unknown types
When we encounter an input or output with an unknown extension 'TY_INVALID', still produce valid JSON specifying the type as "unknown" instead of either crashing or producing malformed JSON. Resolves rdar://94348593
1 parent c068363 commit c58fd49

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/Basic/ParseableOutput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ template <> struct ScalarEnumerationTraits<file_types::ID> {
4242
std::string typeName = file_types::getTypeName(ty).str();
4343
out.enumCase(value, typeName.c_str(), ty);
4444
});
45+
out.enumCase(value, "unknown", file_types::ID::TY_INVALID);
4546
}
4647
};
4748

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ static swift::file_types::ID computeFileTypeForPath(const StringRef Path) {
601601
// then iterate over all preceeding possible extension variants.
602602
while (llvm::sys::path::has_extension(PathStem)) {
603603
auto NextExtension = llvm::sys::path::extension(PathStem);
604+
PathStem = llvm::sys::path::stem(PathStem);
604605
Extension = NextExtension.str() + Extension;
605606
FileType = file_types::lookupTypeForExtension(Extension);
606607
if (FileType != swift::file_types::ID::TY_INVALID)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-swift-frontend -primary-file %s %S/Inputs/filelist-other.swift -o %t.out -module-name parseable_output -empty-abi-descriptor -emit-abi-descriptor-path %t.abi.weird_file_extension -emit-module -emit-module-path %t.swiftmodule -frontend-parseable-output 2>&1 | %FileCheck %s
2+
3+
// CHECK: {{[1-9][0-9]*}}
4+
// CHECK-NEXT: {
5+
// CHECK-NEXT: "kind": "began",
6+
// CHECK-NEXT: "name": "compile",
7+
// CHECK: "inputs": [
8+
// CHECK-NEXT: "{{.*[\\/]}}parseable_output_unknown_file_type.swift"
9+
// CHECK: "outputs": [
10+
// CHECK-NEXT: {
11+
// CHECK-NEXT: "type": "image",
12+
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output_unknown_file_type.swift.tmp.out"
13+
// CHECK-NEXT: },
14+
// CHECK-NEXT: {
15+
// CHECK-NEXT: "type": "swiftmodule",
16+
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output_unknown_file_type.swift.tmp.swiftmodule"
17+
// CHECK-NEXT: },
18+
// CHECK-NEXT: {
19+
// CHECK-NEXT: "type": "unknown",
20+
// CHECK-NEXT: "path": "{{.*[\\/]}}parseable_output_unknown_file_type.swift.tmp.abi.weird_file_extension"
21+
// CHECK-NEXT: }
22+
// CHECK-NEXT: ],
23+
// CHECK-NEXT: "pid": [[PID:[0-9]*]]
24+
// CHECK-NEXT: "process": {
25+
// CHECK-NEXT: "real_pid": [[PID]]
26+
// CHECK-NEXT: }
27+
// CHECK-NEXT: }
28+
29+
// CHECK-NEXT: {{[1-9][0-9]*}}
30+
// CHECK-NEXT: {
31+
// CHECK-NEXT: "kind": "finished",
32+
// CHECK-NEXT: "name": "compile",
33+
// CHECK-NEXT: "pid": [[PID]],
34+
// CHECK-NEXT: "process": {
35+
// CHECK-NEXT: "real_pid": [[PID]]
36+
// CHECK-NEXT: },
37+
// CHECK-NEXT: "exit-status": 0
38+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)