@@ -42,7 +42,7 @@ static llvm::cl::OptionCategory Category("swift-serialize-diagnostics Options");
42
42
43
43
static llvm::cl::opt<std::string>
44
44
InputFilePath (" input-file-path" ,
45
- llvm::cl::desc (" Path to the YAML input file" ),
45
+ llvm::cl::desc (" Path to the YAML or `.strings` input file" ),
46
46
llvm::cl::cat(Category));
47
47
48
48
static llvm::cl::opt<std::string>
@@ -60,38 +60,50 @@ int main(int argc, char *argv[]) {
60
60
" Swift Serialize Diagnostics Tool\n " );
61
61
62
62
if (!llvm::sys::fs::exists (options::InputFilePath)) {
63
- llvm::errs () << " YAML file not found\n " ;
63
+ llvm::errs () << " diagnostics file not found\n " ;
64
64
return EXIT_FAILURE;
65
65
}
66
66
67
- YAMLLocalizationProducer yaml (options::InputFilePath);
68
-
69
67
auto localeCode = llvm::sys::path::filename (options::InputFilePath);
70
68
llvm::SmallString<128 > SerializedFilePath (options::OutputDirectory);
71
69
llvm::sys::path::append (SerializedFilePath, localeCode);
72
70
llvm::sys::path::replace_extension (SerializedFilePath, " .db" );
73
71
74
72
SerializedLocalizationWriter Serializer;
75
- yaml.forEachAvailable (
76
- [&Serializer](swift::DiagID id, llvm::StringRef translation) {
77
- Serializer.insert (id, translation);
78
- });
73
+
74
+ if (llvm::sys::path::extension (options::InputFilePath) == " .yaml" ) {
75
+ YAMLLocalizationProducer yaml (options::InputFilePath);
76
+
77
+ yaml.forEachAvailable (
78
+ [&Serializer](swift::DiagID id, llvm::StringRef translation) {
79
+ Serializer.insert (id, translation);
80
+ });
81
+
82
+ // Print out the diagnostics IDs that are available in YAML but not
83
+ // available in `.def`
84
+ if (!yaml.unknownIDs .empty ()) {
85
+ llvm::errs () << " These diagnostic IDs are no longer available: '" ;
86
+ llvm::interleave (
87
+ yaml.unknownIDs , [&](std::string id) { llvm::errs () << id; },
88
+ [&] { llvm::errs () << " , " ; });
89
+ llvm::errs () << " '\n " ;
90
+ }
91
+ } else {
92
+ assert (llvm::sys::path::extension (options::InputFilePath) == " .strings" );
93
+
94
+ StringsLocalizationProducer strings (options::InputFilePath);
95
+
96
+ strings.forEachAvailable (
97
+ [&Serializer](swift::DiagID id, llvm::StringRef translation) {
98
+ Serializer.insert (id, translation);
99
+ });
100
+ }
79
101
80
102
if (Serializer.emit (SerializedFilePath.str ())) {
81
103
llvm::errs () << " Cannot serialize diagnostic file "
82
104
<< options::InputFilePath << ' \n ' ;
83
105
return EXIT_FAILURE;
84
106
}
85
107
86
- // Print out the diagnostics IDs that are available in YAML but not available
87
- // in `.def`
88
- if (!yaml.unknownIDs .empty ()) {
89
- llvm::errs () << " These diagnostic IDs are no longer available: '" ;
90
- llvm::interleave (
91
- yaml.unknownIDs , [&](std::string id) { llvm::errs () << id; },
92
- [&] { llvm::errs () << " , " ; });
93
- llvm::errs () << " '\n " ;
94
- }
95
-
96
108
return EXIT_SUCCESS;
97
109
}
0 commit comments