diff options
author | Martin Duffy <martin.duffy@kitware.com> | 2024-08-16 12:49:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-08-22 14:24:23 (GMT) |
commit | 1df94443fe5a24e43325b95d93043e8bf5565fa2 (patch) | |
tree | 8657e1e1d54ed7ccdac6b249fb09b4bc65d709c8 /Source | |
parent | a991a5019b87ab7119b2e7b92434c8f006404519 (diff) | |
download | CMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.zip CMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.tar.gz CMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.tar.bz2 |
fileapi: Add support for user-wide queries
Fixes: #19168
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileAPI.cxx | 23 | ||||
-rw-r--r-- | Source/cmFileAPI.h | 3 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 4 |
3 files changed, 27 insertions, 3 deletions
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index d4a7175..1f15612 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -7,9 +7,13 @@ #include <chrono> #include <ctime> #include <iomanip> +#include <iterator> #include <sstream> #include <utility> +#include <cm/optional> +#include <cmext/string_view> + #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" @@ -29,7 +33,12 @@ cmFileAPI::cmFileAPI(cmake* cm) : CMakeInstance(cm) { this->APIv1 = - this->CMakeInstance->GetHomeOutputDirectory() + "/.cmake/api/v1"; + cmStrCat(this->CMakeInstance->GetHomeOutputDirectory(), "/.cmake/api/v1"); + + if (cm::optional<std::string> cmakeConfigDir = + cmSystemTools::GetCMakeConfigDirectory()) { + this->UserAPIv1 = cmStrCat(std::move(*cmakeConfigDir), "/api/v1"_s); + } Json::CharReaderBuilder rbuilder; rbuilder["collectComments"] = false; @@ -47,14 +56,24 @@ cmFileAPI::cmFileAPI(cmake* cm) void cmFileAPI::ReadQueries() { - std::string const query_dir = this->APIv1 + "/query"; + std::string const query_dir = cmStrCat(this->APIv1, "/query"); + std::string const user_query_dir = cmStrCat(this->UserAPIv1, "/query"); this->QueryExists = cmSystemTools::FileIsDirectory(query_dir); + if (!this->UserAPIv1.empty()) { + this->QueryExists = + this->QueryExists || cmSystemTools::FileIsDirectory(user_query_dir); + } if (!this->QueryExists) { return; } // Load queries at the top level. std::vector<std::string> queries = cmFileAPI::LoadDir(query_dir); + if (!this->UserAPIv1.empty()) { + std::vector<std::string> user_queries = cmFileAPI::LoadDir(user_query_dir); + std::move(user_queries.begin(), user_queries.end(), + std::back_inserter(queries)); + } // Read the queries and save for later. for (std::string& query : queries) { diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h index 1c13d7b..ace19ee 100644 --- a/Source/cmFileAPI.h +++ b/Source/cmFileAPI.h @@ -61,6 +61,9 @@ private: /** The api/v1 directory location. */ std::string APIv1; + /** api/v1 directory in the user's shared CMake config directory. */ + std::string UserAPIv1; + /** The set of files we have just written to the reply directory. */ std::unordered_set<std::string> ReplyFiles; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 69b5a16..408e5d2 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -71,7 +71,7 @@ const cmDocumentationEntry cmDocumentationUsageNote = { "Run 'cmake --help' for more information." }; -const cmDocumentationEntry cmDocumentationOptions[33] = { +const cmDocumentationEntry cmDocumentationOptions[34] = { { "--preset <preset>,--preset=<preset>", "Specify a configure preset." }, { "--list-presets[=<type>]", "List available presets." }, { "--workflow [<options>]", "Run a workflow preset." }, @@ -90,6 +90,8 @@ const cmDocumentationEntry cmDocumentationOptions[33] = { "Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for " "more." }, { "--system-information [file]", "Dump information about this system." }, + { "--print-config-dir", + "Print CMake config directory for user-wide FileAPI queries." }, { "--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>", "Set the verbosity of messages from CMake files. " "--loglevel is also accepted for backward compatibility reasons." }, |