1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 20:46:37 +08:00

cmScanDepFormat: P1689R4: Make work-directory optional

This commit is contained in:
Ben Boeckel
2021-06-08 11:27:39 -04:00
committed by Brad King
parent aab9a5fc3e
commit 3e5b609547
2 changed files with 11 additions and 4 deletions

View File

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

View File

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