[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
This commit is contained in:
Artem Chikin
2022-06-03 11:27:36 -07:00
parent 07ffddebae
commit 19c5c201dc
3 changed files with 40 additions and 0 deletions

View File

@@ -601,6 +601,7 @@ static swift::file_types::ID computeFileTypeForPath(const StringRef Path) {
// then iterate over all preceeding possible extension variants.
while (llvm::sys::path::has_extension(PathStem)) {
auto NextExtension = llvm::sys::path::extension(PathStem);
PathStem = llvm::sys::path::stem(PathStem);
Extension = NextExtension.str() + Extension;
FileType = file_types::lookupTypeForExtension(Extension);
if (FileType != swift::file_types::ID::TY_INVALID)