From 2b9890e9b940db59b4d1633fa5b8067f615ed0f4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Jun 2021 15:32:31 -0400 Subject: cmScanDepFormat: Avoid writing lookup-method with default value --- Source/cmScanDepFormat.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmScanDepFormat.cxx b/Source/cmScanDepFormat.cxx index 6620221..ae0e649 100644 --- a/Source/cmScanDepFormat.cxx +++ b/Source/cmScanDepFormat.cxx @@ -3,7 +3,6 @@ #include "cmScanDepFormat.h" -#include #include #include #include @@ -339,7 +338,7 @@ bool cmScanDepFormat_P1689_Write(std::string const& path, const char* lookup_method = nullptr; switch (require.Method) { case LookupMethod::ByName: - lookup_method = "by-name"; + // No explicit value needed for the default. break; case LookupMethod::IncludeAngle: lookup_method = "include-angle"; @@ -348,8 +347,9 @@ bool cmScanDepFormat_P1689_Write(std::string const& path, lookup_method = "include-quote"; break; } - assert(lookup_method); - require_obj["lookup-method"] = lookup_method; + if (lookup_method) { + require_obj["lookup-method"] = lookup_method; + } reqs.append(require_obj); } -- cgit v0.12 From 10b2e5346984d95c15d0cc38ddf5c5fad11a6a65 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Jun 2021 16:14:35 -0400 Subject: cmScanDepFormat: Remove Fortran-specific compiled-module-path logic Read and write the `compiled-module-path` field only when explicitly known. Move the assumption that the `compiled-module-path` can be derived from the logical module name from the scandep parser to the `cmake_ninja_dyndep` helper. --- Source/cmGlobalNinjaGenerator.cxx | 16 ++++++++++++---- Source/cmScanDepFormat.cxx | 11 ++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index cbe1bc8..5108a6f 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -2448,7 +2448,6 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( for (std::string const& provide : finfo.Provides) { cmSourceReqInfo src_info; src_info.LogicalName = provide; - src_info.CompiledModulePath = provide; info->ScanDep.Provides.emplace_back(src_info); } for (std::string const& require : finfo.Requires) { @@ -2458,7 +2457,6 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( } cmSourceReqInfo src_info; src_info.LogicalName = require; - src_info.CompiledModulePath = require; info->ScanDep.Requires.emplace_back(src_info); } for (std::string const& include : finfo.Includes) { @@ -2529,8 +2527,18 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( Json::Value tm = Json::objectValue; for (cmScanDepInfo const& object : objects) { for (auto const& p : object.Provides) { - std::string const mod = cmStrCat( - module_dir, cmSystemTools::GetFilenameName(p.CompiledModulePath)); + std::string mod; + if (!p.CompiledModulePath.empty()) { + // The scanner provided the path to the module file. + mod = p.CompiledModulePath; + if (!cmSystemTools::FileIsFullPath(mod)) { + // Treat relative to work directory (top of build tree). + mod = cmSystemTools::CollapseFullPath(mod, dir_top_bld); + } + } else { + // Assume the module file path matches the logical module name. + mod = cmStrCat(module_dir, p.LogicalName); + } mod_files[p.LogicalName] = mod; tm[p.LogicalName] = mod; } diff --git a/Source/cmScanDepFormat.cxx b/Source/cmScanDepFormat.cxx index ae0e649..6fcbce5 100644 --- a/Source/cmScanDepFormat.cxx +++ b/Source/cmScanDepFormat.cxx @@ -162,9 +162,6 @@ bool cmScanDepFormat_P1689_Parse(std::string const& arg_pp, provide["compiled-module-path"]; PARSE_FILENAME(compiled_module_path, provide_info.CompiledModulePath); - } else { - provide_info.CompiledModulePath = - cmStrCat(provide_info.LogicalName, ".mod"); } if (provide.isMember("unique-on-source-path")) { @@ -299,9 +296,7 @@ bool cmScanDepFormat_P1689_Write(std::string const& path, Json::Value provide_obj(Json::objectValue); auto const encoded = EncodeFilename(provide.LogicalName); provide_obj["logical-name"] = encoded; - if (provide.CompiledModulePath.empty()) { - provide_obj["compiled-module-path"] = encoded; - } else { + if (!provide.CompiledModulePath.empty()) { provide_obj["compiled-module-path"] = EncodeFilename(provide.CompiledModulePath); } @@ -321,9 +316,7 @@ bool cmScanDepFormat_P1689_Write(std::string const& path, Json::Value require_obj(Json::objectValue); auto const encoded = EncodeFilename(require.LogicalName); require_obj["logical-name"] = encoded; - if (require.CompiledModulePath.empty()) { - require_obj["compiled-module-path"] = encoded; - } else { + if (!require.CompiledModulePath.empty()) { require_obj["compiled-module-path"] = EncodeFilename(require.CompiledModulePath); } -- cgit v0.12 From a35d1212760707b195f6c462aadae8383ffcdeca Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Jun 2021 16:25:02 -0400 Subject: Ninja: Populate P1689R4 compiled-module-path field for Fortran When scanning Fortran dependencies, we know the file path at which a provided module file is written. Store it in the `compiled-module-path` field as specified by P1689R4. Our collator in `cmake_ninja_dyndep` no longer needs to assume that the module file path can be derived from the logical module name. In the future, the Fortran dependency scanning may be done by the compiler itself, in which case it will provide the value of `compiled-module-path`. --- Source/cmGlobalNinjaGenerator.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 5108a6f..963118f 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -2400,6 +2401,8 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( cm::optional info; cmFortranCompiler fc; std::vector includes; + std::string dir_top_bld; + std::string module_dir; { Json::Value tdio; Json::Value const& tdi = tdio; @@ -2414,6 +2417,11 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( } } + dir_top_bld = tdi["dir-top-bld"].asString(); + if (!dir_top_bld.empty() && !cmHasLiteralSuffix(dir_top_bld, "/")) { + dir_top_bld += '/'; + } + Json::Value const& tdi_include_dirs = tdi["include-dirs"]; if (tdi_include_dirs.isArray()) { for (auto const& tdi_include_dir : tdi_include_dirs) { @@ -2421,6 +2429,12 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( } } + Json::Value const& tdi_module_dir = tdi["module-dir"]; + module_dir = tdi_module_dir.asString(); + if (!module_dir.empty() && !cmHasLiteralSuffix(module_dir, "/")) { + module_dir += '/'; + } + Json::Value const& tdi_compiler_id = tdi["compiler-id"]; fc.Id = tdi_compiler_id.asString(); @@ -2448,6 +2462,13 @@ cm::optional cmcmd_cmake_ninja_depends_fortran( for (std::string const& provide : finfo.Provides) { cmSourceReqInfo src_info; src_info.LogicalName = provide; + if (!module_dir.empty()) { + std::string mod = cmStrCat(module_dir, provide); + if (!dir_top_bld.empty() && cmHasPrefix(mod, dir_top_bld)) { + mod = mod.substr(dir_top_bld.size()); + } + src_info.CompiledModulePath = std::move(mod); + } info->ScanDep.Provides.emplace_back(src_info); } for (std::string const& require : finfo.Requires) { -- cgit v0.12