Переглянути джерело

cmScanDepFormat: P1689R4: Make work-directory optional

Ben Boeckel 4 роки тому
батько
коміт
3e5b609547
2 змінених файлів з 11 додано та 4 видалено
  1. 1 0
      Help/dev/experimental.rst
  2. 10 4
      Source/cmScanDepFormat.cxx

+ 1 - 0
Help/dev/experimental.rst

@@ -45,6 +45,7 @@ by the `P1689r3`_ paper, with the following updates:
   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``.
+* The ``work-directory`` field is optional.
 
 Compiler writers may try out their scanning functionality using
 the `cxx-modules-sandbox`_ test project, modified to set variables

+ 10 - 4
Source/cmScanDepFormat.cxx

@@ -5,6 +5,9 @@
 
 #include <cctype>
 #include <cstdio>
+#include <utility>
+
+#include <cm/optional>
 
 #include <cm3p/json/reader.h>
 #include <cm3p/json/value.h>
@@ -69,8 +72,9 @@ static Json::Value EncodeFilename(std::string const& path)
       return false;                                                           \
     }                                                                         \
                                                                               \
-    if (!work_directory.empty() && !cmSystemTools::FileIsFullPath(res)) {     \
-      res = cmStrCat(work_directory, '/', res);                               \
+    if (work_directory && !work_directory->empty() &&                         \
+        !cmSystemTools::FileIsFullPath(res)) {                                \
+      res = cmStrCat(*work_directory, '/', res);                              \
     }                                                                         \
   } while (0)
 
@@ -106,10 +110,12 @@ bool cmScanDepFormat_P1689_Parse(std::string const& arg_pp,
     }
 
     for (auto const& rule : rules) {
-      std::string work_directory;
+      cm::optional<std::string> work_directory;
       Json::Value const& workdir = rule["work-directory"];
       if (workdir.isString()) {
-        PARSE_BLOB(workdir, work_directory);
+        std::string wd;
+        PARSE_BLOB(workdir, wd);
+        work_directory = std::move(wd);
       } else if (!workdir.isNull()) {
         cmSystemTools::Error(cmStrCat("-E cmake_ninja_dyndep failed to parse ",
                                       arg_pp,