From 3e5b609547750f0498b6ca924fb70379457653da Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 8 Jun 2021 11:27:39 -0400 Subject: cmScanDepFormat: P1689R4: Make work-directory optional --- Help/dev/experimental.rst | 1 + Source/cmScanDepFormat.cxx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index 517ffe4..9cf33eb 100644 --- a/Help/dev/experimental.rst +++ b/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 diff --git a/Source/cmScanDepFormat.cxx b/Source/cmScanDepFormat.cxx index d75a750..a40a552 100644 --- a/Source/cmScanDepFormat.cxx +++ b/Source/cmScanDepFormat.cxx @@ -5,6 +5,9 @@ #include #include +#include + +#include #include #include @@ -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 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, -- cgit v0.12