From 3a7153440282148233c7dff33538fd3b46a3175d Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 12 May 2021 10:05:50 -0400 Subject: Ninja: Restore support for Fortran in a symlinked build tree Since commit f3eed2c49d (cmGlobalNinjaGenerator: use P1689 dependency file format for Fortran, 2019-03-12, v3.20.0-rc1~454^2), Fortran stopped working in a build tree whose path contains a symlink. The reason is that the P1689r3 format's `work-directory` field gets populated with the realpath (via `getcwd`) of the build tree instead of the logical path to the build tree used for generating relative paths in `build.ninja`. This causes the `Fortran.dd` file to get absolute (real)paths to `.o` files, and Ninja does not match them with the relative `.o` file paths in `build.ninja`. Fix this by dropping use of the `work-directory` field. This restores our prior approach of generating paths in the dyndep file using the same forms of paths received from the buildsystem generator. The P1689r3 paper's format may need to be revised to account for this. Fixes: #21683 --- Source/cmScanDepFormat.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/cmScanDepFormat.cxx b/Source/cmScanDepFormat.cxx index e046069..f988fe4 100644 --- a/Source/cmScanDepFormat.cxx +++ b/Source/cmScanDepFormat.cxx @@ -69,7 +69,7 @@ static Json::Value EncodeFilename(std::string const& path) return false; \ } \ \ - if (!cmSystemTools::FileIsFullPath(res)) { \ + if (!work_directory.empty() && !cmSystemTools::FileIsFullPath(res)) { \ res = cmStrCat(work_directory, '/', res); \ } \ } while (0) @@ -105,15 +105,16 @@ bool cmScanDepFormat_P1689_Parse(std::string const& arg_pp, cmSourceInfo* info) } for (auto const& rule : rules) { + std::string work_directory; Json::Value const& workdir = rule["work-directory"]; - if (!workdir.isString()) { + if (workdir.isString()) { + PARSE_BLOB(workdir, work_directory); + } else if (!workdir.isNull()) { cmSystemTools::Error(cmStrCat("-E cmake_ninja_dyndep failed to parse ", arg_pp, ": work-directory is not a string")); return false; } - std::string work_directory; - PARSE_BLOB(workdir, work_directory); Json::Value const& depends = rule["depends"]; if (depends.isArray()) { @@ -203,8 +204,6 @@ bool cmScanDepFormat_P1689_Write(std::string const& path, Json::Value& rules = ddi["rules"] = Json::arrayValue; Json::Value rule(Json::objectValue); - rule["work-directory"] = - EncodeFilename(cmSystemTools::GetCurrentWorkingDirectory()); Json::Value& inputs = rule["inputs"] = Json::arrayValue; inputs.append(EncodeFilename(input)); -- cgit v0.12