Просмотр исходного кода

cmScanDepFormat: P1689R4: Factor out primary-output field

Ben Boeckel 4 лет назад
Родитель
Сommit
aab9a5fc3e
3 измененных файлов с 18 добавлено и 9 удалено
  1. 1 0
      Help/dev/experimental.rst
  2. 16 9
      Source/cmScanDepFormat.cxx
  3. 1 0
      Source/cmScanDepFormat.h

+ 1 - 0
Help/dev/experimental.rst

@@ -44,6 +44,7 @@ by the `P1689r3`_ paper, with the following updates:
 * Omit the ``outputs``, ``inputs``, and ``depends`` fields from
   each entry in the ``rules`` array.  They are unused.
 * Flatten ``future-compile`` members directly into each rule.
+* Factor a ``primary-output`` field out of the now-flattened ``outputs``.
 
 Compiler writers may try out their scanning functionality using
 the `cxx-modules-sandbox`_ test project, modified to set variables

+ 16 - 9
Source/cmScanDepFormat.cxx

@@ -117,17 +117,20 @@ bool cmScanDepFormat_P1689_Parse(std::string const& arg_pp,
         return false;
       }
 
+      if (rule.isMember("primary-output")) {
+        Json::Value const& primary_output = rule["primary-output"];
+        PARSE_FILENAME(primary_output, info->PrimaryOutput);
+      }
+
       if (rule.isMember("outputs")) {
         Json::Value const& outputs = rule["outputs"];
         if (outputs.isArray()) {
-          if (outputs.empty()) {
-            cmSystemTools::Error(
-              cmStrCat("-E cmake_ninja_dyndep failed to parse ", arg_pp,
-                       ": expected at least one 1 output"));
-            return false;
-          }
+          for (auto const& output : outputs) {
+            std::string extra_output;
+            PARSE_FILENAME(output, extra_output);
 
-          PARSE_FILENAME(outputs[0], info->PrimaryOutput);
+            info->ExtraOutputs.emplace_back(extra_output);
+          }
         }
       }
 
@@ -202,8 +205,12 @@ bool cmScanDepFormat_P1689_Write(std::string const& path,
 
   Json::Value rule(Json::objectValue);
 
-  Json::Value& outputs = rule["outputs"] = Json::arrayValue;
-  outputs.append(info.PrimaryOutput);
+  rule["primary-output"] = EncodeFilename(info.PrimaryOutput);
+
+  Json::Value& rule_outputs = rule["outputs"] = Json::arrayValue;
+  for (auto const& output : info.ExtraOutputs) {
+    rule_outputs.append(EncodeFilename(output));
+  }
 
   Json::Value& provides = rule["provides"] = Json::arrayValue;
   for (auto const& provide : info.Provides) {

+ 1 - 0
Source/cmScanDepFormat.h

@@ -14,6 +14,7 @@ struct cmSourceReqInfo
 struct cmScanDepInfo
 {
   std::string PrimaryOutput;
+  std::vector<std::string> ExtraOutputs;
 
   // Set of provided and required modules.
   std::vector<cmSourceReqInfo> Provides;