Merge topic 'backport-3.31-fileapi-initial-cache' into release-3.31

4d712cfc25 fileapi: Fix crash on cmake_file_api() call in initial cache

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11598
This commit is contained in:
Brad King
2026-01-16 09:26:18 -05:00
7 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -58,7 +58,8 @@ void cmFileAPI::ReadQueries()
{
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);
this->QueryExists =
this->QueryExists || cmSystemTools::FileIsDirectory(query_dir);
if (!this->UserAPIv1.empty()) {
this->QueryExists =
this->QueryExists || cmSystemTools::FileIsDirectory(user_query_dir);
+11 -1
View File
@@ -691,6 +691,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
// Resolve script path specified on command line
// relative to $PWD.
auto path = cmSystemTools::CollapseFullPath(value);
state->InitializeFileAPI();
state->ReadListFile(args, path);
return true;
} },
@@ -2549,7 +2550,7 @@ int cmake::ActualConfigure()
}
#if !defined(CMAKE_BOOTSTRAP)
this->FileAPI = cm::make_unique<cmFileAPI>(this);
this->InitializeFileAPI();
this->FileAPI->ReadQueries();
if (!this->GetIsInTryCompile()) {
@@ -2771,6 +2772,15 @@ void cmake::StopDebuggerIfNeeded(int exitCode)
#endif
void cmake::InitializeFileAPI()
{
#ifndef CMAKE_BOOTSTRAP
if (!this->FileAPI) {
this->FileAPI = cm::make_unique<cmFileAPI>(this);
}
#endif
}
// handle a command line invocation
int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
{
+1
View File
@@ -646,6 +646,7 @@ public:
#if !defined(CMAKE_BOOTSTRAP)
cmFileAPI* GetFileAPI() const { return this->FileAPI.get(); }
#endif
void InitializeFileAPI();
cmState* GetState() const { return this->State.get(); }
void SetCurrentSnapshot(cmStateSnapshot const& snapshot)
@@ -0,0 +1,8 @@
set(expect
reply
reply/codemodel-v2-[0-9a-f]+.json
.*reply/index-[0-9.T-]+.json.*
)
# Only need to check for existence. Other tests check the reply contents.
check_api("^${expect}$")
@@ -0,0 +1,5 @@
cmake_file_api(
QUERY
API_VERSION 1
CODEMODEL 2
)
@@ -52,6 +52,7 @@ run_cmake(ClientStateless)
run_cmake(MixedStateless)
run_cmake(DuplicateStateless)
run_cmake(ClientStateful)
run_cmake_with_options(InitialCache -C ${RunCMake_SOURCE_DIR}/InitialCache-script.cmake)
run_cmake(ProjectQueryGood)
run_cmake(ProjectQueryBad)