Jelajahi Sumber

Merge topic 'fileapi-instrumentation-initial-cache' into release-4.2

ed023e0cfc Merge branch 'backport-4.0-fileapi-instrumentation-initial-cache'
5b63ea9ad3 instrumentation: Fix crash on cmake_instrumentation() call in initial cache
1bd6e70430 Merge branch 'backport-4.0-fileapi-instrumentation-initial-cache'
bb23f65928 instrumentation: Fix crash on cmake_instrumentation() call in initial cache
8523e579dc Merge branch 'backport-3.31-fileapi-initial-cache'
4d712cfc25 fileapi: Fix crash on cmake_file_api() call in initial cache

Acked-by: Kitware Robot <[email protected]>
Merge-request: !11598
Brad King 6 hari lalu
induk
melakukan
cdbd7bf2f2

+ 2 - 1
Source/cmFileAPI.cxx

@@ -72,7 +72,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);

+ 25 - 6
Source/cmake.cxx

@@ -718,6 +718,8 @@ bool cmake::SetCacheArgs(std::vector<std::string> const& args)
         // Resolve script path specified on command line
         // relative to $PWD.
         auto path = cmSystemTools::ToNormalizedPathOnDisk(value);
+        state->InitializeFileAPI();
+        state->InitializeInstrumentation();
         state->ReadListFile(args, path);
         return true;
       } },
@@ -2665,13 +2667,9 @@ int cmake::ActualConfigure()
   }
 
 #if !defined(CMAKE_BOOTSTRAP)
-  this->FileAPI = cm::make_unique<cmFileAPI>(this);
+  this->InitializeFileAPI();
   this->FileAPI->ReadQueries();
-
-  this->Instrumentation = cm::make_unique<cmInstrumentation>(
-    this->State->GetBinaryDirectory(),
-    cmInstrumentation::LoadQueriesAfter::No);
-  this->Instrumentation->ClearGeneratedQueries();
+  this->InitializeInstrumentation();
 
   if (!this->GetIsInTryCompile()) {
     this->TruncateOutputLog("CMakeConfigureLog.yaml");
@@ -2929,6 +2927,27 @@ void cmake::StopDebuggerIfNeeded(int exitCode)
 
 #endif
 
+void cmake::InitializeFileAPI()
+{
+#ifndef CMAKE_BOOTSTRAP
+  if (!this->FileAPI) {
+    this->FileAPI = cm::make_unique<cmFileAPI>(this);
+  }
+#endif
+}
+
+void cmake::InitializeInstrumentation()
+{
+#ifndef CMAKE_BOOTSTRAP
+  if (!this->Instrumentation) {
+    this->Instrumentation = cm::make_unique<cmInstrumentation>(
+      this->State->GetBinaryDirectory(),
+      cmInstrumentation::LoadQueriesAfter::No);
+    this->Instrumentation->ClearGeneratedQueries();
+  }
+#endif
+}
+
 // handle a command line invocation
 int cmake::Run(std::vector<std::string> const& args, bool noconfigure)
 {

+ 2 - 0
Source/cmake.h

@@ -708,6 +708,8 @@ public:
     return this->Instrumentation.get();
   }
 #endif
+  void InitializeFileAPI();
+  void InitializeInstrumentation();
 
   cmState* GetState() const { return this->State.get(); }
   void SetCurrentSnapshot(cmStateSnapshot const& snapshot)

+ 8 - 0
Tests/RunCMake/FileAPI/InitialCache-check.cmake

@@ -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}$")

+ 5 - 0
Tests/RunCMake/FileAPI/InitialCache-script.cmake

@@ -0,0 +1,5 @@
+cmake_file_api(
+  QUERY
+  API_VERSION 1
+  CODEMODEL 2
+)

+ 0 - 0
Tests/RunCMake/FileAPI/InitialCache.cmake


+ 1 - 0
Tests/RunCMake/FileAPI/RunCMakeTest.cmake

@@ -140,6 +140,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)
 run_cmake(FailConfigure)

+ 5 - 0
Tests/RunCMake/Instrumentation/RunCMakeTest.cmake

@@ -28,6 +28,7 @@ function(instrument test)
   set(v1 ${RunCMake_TEST_BINARY_DIR}/.cmake/instrumentation-${uuid}/v1)
   set(v1 ${v1} PARENT_SCOPE)
   set(query_dir ${CMAKE_CURRENT_LIST_DIR}/query)
+  configure_file(${RunCMake_SOURCE_DIR}/initial.cmake.in ${RunCMake_BINARY_DIR}/initial.cmake)
 
   # Clear previous instrumentation data
   # We can't use RunCMake_TEST_NO_CLEAN 0 because we preserve queries placed in the build tree after
@@ -189,6 +190,10 @@ instrument(cmake-command-bad-arg NO_WARN)
 instrument(cmake-command-parallel-install
   BUILD INSTALL TEST NO_WARN INSTALL_PARALLEL DYNAMIC_QUERY
   CHECK_SCRIPT check-data-dir.cmake)
+instrument(cmake-command-initial-cache
+  CONFIGURE_ARG "-C ${RunCMake_BINARY_DIR}/initial.cmake"
+  CHECK_SCRIPT check-data-dir.cmake
+)
 instrument(cmake-command-resets-generated
   NO_WARN COPY_QUERIES_GENERATED
   CHECK_SCRIPT check-data-dir.cmake

+ 4 - 0
Tests/RunCMake/Instrumentation/cmake-command-initial-cache-stderr.txt

@@ -0,0 +1,4 @@
+CMake Warning \(dev\) at .*
+  CMake's support for collecting instrumentation data is experimental.  It is
+  meant only for experimentation and feedback to CMake developers.
+This warning is for project developers.  Use -Wno-dev to suppress it.

+ 5 - 0
Tests/RunCMake/Instrumentation/initial.cmake.in

@@ -0,0 +1,5 @@
+set(CMAKE_EXPERIMENTAL_INSTRUMENTATION @uuid@)
+cmake_instrumentation(
+  API_VERSION 1
+  DATA_VERSION 1
+)

+ 0 - 0
Tests/RunCMake/Instrumentation/query/cmake-command-initial-cache.cmake