@@ -18,7 +18,23 @@ std::string to_string_any(const T& value) {
1818 return oss.str ();
1919}
2020
21- nlohmann::json build_configuration () {
21+ // Look up the existing implementation version for a config name from a
22+ // previously generated JSON. Returns "A" if not found.
23+ std::string existing_version (const nlohmann::json& existing,
24+ const std::string& name) {
25+ if (existing.contains (" supportedConfigurations" )) {
26+ const auto & sc = existing[" supportedConfigurations" ];
27+ if (sc.contains (name) && sc[name].is_array () && !sc[name].empty ()) {
28+ const auto & first = sc[name][0 ];
29+ if (first.contains (" implementation" )) {
30+ return first[" implementation" ].get <std::string>();
31+ }
32+ }
33+ }
34+ return " A" ;
35+ }
36+
37+ nlohmann::json build_configuration (const nlohmann::json& existing) {
2238 nlohmann::json j;
2339 j[" version" ] = " 2" ;
2440
@@ -33,7 +49,7 @@ nlohmann::json build_configuration() {
3349 do { \
3450 auto obj = nlohmann::json::object (); \
3551 obj[" default" ] = to_string_any (DEFAULT_VALUE); \
36- obj[" implementation" ] = " A " ; \
52+ obj[" implementation" ] = existing_version (existing, QUOTED (NAME)); \
3753 { \
3854 std::string type_str = QUOTED (TYPE); \
3955 std::transform (type_str.begin (), type_str.end (), type_str.begin (), \
@@ -70,7 +86,17 @@ int main(int argc, char** argv) {
7086
7187 const fs::path output_file = result[" output-file" ].as <std::string>();
7288
73- const auto j = build_configuration ();
89+ // Read existing file to preserve implementation versions.
90+ nlohmann::json existing;
91+ {
92+ std::ifstream in (output_file);
93+ if (in) {
94+ existing = nlohmann::json::parse (in, nullptr , false );
95+ if (existing.is_discarded ()) existing = nlohmann::json::object ();
96+ }
97+ }
98+
99+ const auto j = build_configuration (existing);
74100 std::ofstream file (output_file, std::ios::binary);
75101 if (!file) {
76102 std::cerr << " Unable to write configuration file" ;
0 commit comments