mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-28 10:48:07 +00:00
ctest: Pass CTEST_SITE/CTEST_BUILD_NAME to configure step
When performing the configure step in dashboard client mode, propagate `CTEST_SITE` and `CTEST_BUILD_NAME` as the `SITE` and `BUILDNAME` respective cache variables. This causes the values recorded in `DartConfiguration.tcl` to match those specified by the user, allowing subsequent ctest calls to reuse them automatically.
This commit is contained in:
@@ -125,6 +125,22 @@ bool ConstructConfigureCommand(cmExecutionStatus& status, cmMakefile& mf,
|
||||
configureCommand += " \"-DCTEST_USE_LAUNCHERS:BOOL=TRUE\"";
|
||||
}
|
||||
|
||||
// Propagate CTEST_SITE / CTEST_BUILD_NAME into the SITE / BUILDNAME
|
||||
// cache variables so DartConfiguration.tcl gets generated with
|
||||
// correct values.
|
||||
cmValue site = mf.GetDefinition("CTEST_SITE");
|
||||
if (cmNonempty(site)) {
|
||||
configureCommand += " \"-DSITE:STRING=";
|
||||
configureCommand += *site;
|
||||
configureCommand += "\"";
|
||||
}
|
||||
cmValue buildName = mf.GetDefinition("CTEST_BUILD_NAME");
|
||||
if (cmNonempty(buildName)) {
|
||||
configureCommand += " \"-DBUILDNAME:STRING=";
|
||||
configureCommand += *buildName;
|
||||
configureCommand += "\"";
|
||||
}
|
||||
|
||||
cmValue cmakeGeneratorPlatform =
|
||||
mf.GetDefinition("CTEST_CMAKE_GENERATOR_PLATFORM");
|
||||
if (cmNonempty(cmakeGeneratorPlatform)) {
|
||||
|
||||
@@ -796,6 +796,9 @@ int cmCTest::ProcessSteps()
|
||||
this->Impl->BinaryDir = binaryDir;
|
||||
cmSystemTools::SetLogicalWorkingDirectory(binaryDir);
|
||||
mf.AddDefinition("CTEST_BINARY_DIRECTORY", binaryDir);
|
||||
// Re-parse DartConfiguration.tcl since we changed BinaryDir.
|
||||
this->UpdateCTestConfiguration();
|
||||
this->SetCMakeVariables(mf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
set(dart_file "${RunCMake_TEST_BINARY_DIR}/DartConfiguration.tcl")
|
||||
if(NOT EXISTS "${dart_file}")
|
||||
set(RunCMake_TEST_FAILED "DartConfiguration.tcl not found in build dir")
|
||||
return()
|
||||
endif()
|
||||
file(READ "${dart_file}" dart_content)
|
||||
if(NOT dart_content MATCHES "BuildName: cli-build-name")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"DartConfiguration.tcl does not contain BuildName: cli-build-name")
|
||||
elseif(NOT dart_content MATCHES "Site: cli-site")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"DartConfiguration.tcl does not contain Site: cli-site")
|
||||
endif()
|
||||
@@ -0,0 +1,14 @@
|
||||
# The preset's binaryDir is "${sourceDir}/build".
|
||||
set(dart_file "${RunCMake_TEST_SOURCE_DIR}/build/DartConfiguration.tcl")
|
||||
if(NOT EXISTS "${dart_file}")
|
||||
set(RunCMake_TEST_FAILED "DartConfiguration.tcl not found in preset binaryDir")
|
||||
return()
|
||||
endif()
|
||||
file(READ "${dart_file}" dart_content)
|
||||
if(NOT dart_content MATCHES "BuildName: cli-build-name")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"DartConfiguration.tcl does not contain BuildName: cli-build-name")
|
||||
elseif(NOT dart_content MATCHES "Site: cli-site")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"DartConfiguration.tcl does not contain Site: cli-site")
|
||||
endif()
|
||||
@@ -0,0 +1 @@
|
||||
^Cannot find file: .*/DartConfiguration\.tcl$
|
||||
@@ -0,0 +1 @@
|
||||
^Cannot find file: .*/DartConfiguration\.tcl$
|
||||
@@ -0,0 +1,18 @@
|
||||
# Check that Site and BuildName in Update.xml match what was passed via -D
|
||||
# for the Configure step.
|
||||
file(GLOB update_xml_files
|
||||
"${RunCMake_TEST_BINARY_DIR}/Testing/*/Update.xml")
|
||||
if(NOT update_xml_files)
|
||||
set(RunCMake_TEST_FAILED
|
||||
"Update.xml not found in ${RunCMake_TEST_BINARY_DIR}/Testing/")
|
||||
return()
|
||||
endif()
|
||||
list(GET update_xml_files 0 update_xml)
|
||||
file(READ "${update_xml}" content)
|
||||
if(NOT content MATCHES "<Site>my-site</Site>")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"Update.xml does not contain <Site>my-site</Site>\nActual content:\n${content}")
|
||||
elseif(NOT content MATCHES "<BuildName>my-build-name</BuildName>")
|
||||
set(RunCMake_TEST_FAILED
|
||||
"Update.xml does not contain <BuildName>my-build-name</BuildName>\nActual content:\n${content}")
|
||||
endif()
|
||||
@@ -719,8 +719,10 @@ run_configure_no_cmakelists()
|
||||
# SOURCE_DIR -- pass --source-dir to ctest
|
||||
# BUILD_DIR -- create a separate <CASE_NAME>-build dir with
|
||||
# DartConfiguration.tcl and pass --build-dir to ctest
|
||||
# DART_VARS -- seed DartConfiguration.tcl with BuildName/Site originals
|
||||
# and pass -D CTEST_BUILD_NAME/CTEST_SITE overrides to ctest
|
||||
function(run_ctest_configure_cli_preset CASE_NAME)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 ARG "SOURCE_DIR;BUILD_DIR;BAD_PRESETS" "PRESET_NAME" "")
|
||||
cmake_parse_arguments(PARSE_ARGV 1 ARG "SOURCE_DIR;BUILD_DIR;BAD_PRESETS;DART_VARS" "PRESET_NAME" "")
|
||||
set(src "${RunCMake_BINARY_DIR}/${CASE_NAME}")
|
||||
set(bin "${src}")
|
||||
if(ARG_BUILD_DIR)
|
||||
@@ -743,9 +745,14 @@ function(run_ctest_configure_cli_preset CASE_NAME)
|
||||
if(ARG_BUILD_DIR)
|
||||
file(REMOVE_RECURSE "${bin}")
|
||||
file(MAKE_DIRECTORY "${bin}")
|
||||
set(dart_extra "")
|
||||
if(ARG_DART_VARS)
|
||||
set(dart_extra "BuildName: original-build-name\nSite: original-site\n")
|
||||
endif()
|
||||
file(WRITE "${bin}/DartConfiguration.tcl"
|
||||
"BuildDirectory: ${bin}\n"
|
||||
"SourceDirectory: ${src}\n"
|
||||
"${dart_extra}"
|
||||
"ConfigureCommand: \"${CMAKE_COMMAND}\" -S\"${src}\" -B\"${bin}\"\n")
|
||||
endif()
|
||||
set(extra_args "")
|
||||
@@ -755,6 +762,11 @@ function(run_ctest_configure_cli_preset CASE_NAME)
|
||||
if(ARG_BUILD_DIR)
|
||||
list(APPEND extra_args --build-dir "${bin}")
|
||||
endif()
|
||||
if(ARG_DART_VARS)
|
||||
list(APPEND extra_args
|
||||
-D "CTEST_BUILD_NAME=cli-build-name"
|
||||
-D "CTEST_SITE=cli-site")
|
||||
endif()
|
||||
set(RunCMake_TEST_SOURCE_DIR "${src}")
|
||||
set(RunCMake_TEST_BINARY_DIR "${bin}")
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
@@ -784,6 +796,52 @@ run_ctest_configure_cli_preset(ConfigurePresetCLIVarBadPresets SOURCE_DIR BAD_PR
|
||||
run_ctest_configure_cli_preset(ConfigurePresetCLIVarUnknownPreset SOURCE_DIR
|
||||
PRESET_NAME nonexistent-preset)
|
||||
|
||||
# -D CTEST_BUILD_NAME and -D CTEST_SITE are recorded in DartConfiguration.tcl,
|
||||
# overriding pre-existing values (pre-existing binary dir).
|
||||
run_ctest_configure_cli_preset(ConfigureCLIVarDartPersist BUILD_DIR DART_VARS)
|
||||
|
||||
# -D CTEST_BUILD_NAME and -D CTEST_SITE are recorded in DartConfiguration.tcl
|
||||
# when cmake creates it fresh (empty binary dir via --source-dir).
|
||||
run_ctest_configure_cli_preset(ConfigureCLIVarDartPersistSourceDir SOURCE_DIR DART_VARS)
|
||||
|
||||
# The following end-to-end test demonstrates that:
|
||||
# 1) ctest -T Configure writes user-specified Site and BuildName in
|
||||
# preset.binaryDir/DartConfiguration.tcl.
|
||||
# 2) ctest -T Update correctly loads this data.
|
||||
block()
|
||||
set(src "${RunCMake_BINARY_DIR}/ReuseBuildNameFromPresetBinaryDir")
|
||||
set(bin "${src}/build")
|
||||
configure_file("${RunCMake_SOURCE_DIR}/CMakeLists.txt.in"
|
||||
"${src}/CMakeLists.txt" @ONLY)
|
||||
configure_file("${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
|
||||
"${src}/CMakePresets.json" @ONLY)
|
||||
file(REMOVE_RECURSE "${bin}")
|
||||
ctest_source_dir_generator_args(generator_args)
|
||||
set(RunCMake_TEST_SOURCE_DIR "${src}")
|
||||
set(RunCMake_TEST_BINARY_DIR "${bin}")
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
# Step 1: ctest -T Configure sets Site/BuildName in DartConfiguration.tcl.
|
||||
run_cmake_command(ReuseBuildNameFromPresetBinaryDir-configure
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
--source-dir "${src}"
|
||||
${generator_args}
|
||||
-M Experimental
|
||||
-T Configure
|
||||
-D "CTEST_PRESET=my-preset"
|
||||
-D "CTEST_SITE=my-site"
|
||||
-D "CTEST_BUILD_NAME=my-build-name")
|
||||
# Step 2: ctest -T Update reuses Site/BuildName from above.
|
||||
run_cmake_command(ReuseBuildNameFromPresetBinaryDir-update
|
||||
${CMAKE_CTEST_COMMAND}
|
||||
--source-dir "${src}"
|
||||
-M Experimental
|
||||
-T Update
|
||||
-D "CTEST_PRESET=my-preset"
|
||||
-D "CTEST_UPDATE_COMMAND=${CMAKE_COMMAND}"
|
||||
-D "CTEST_UPDATE_VERSION_ONLY=1"
|
||||
-V)
|
||||
endblock()
|
||||
|
||||
# Test --output-junit
|
||||
function(run_output_junit)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/output-junit)
|
||||
|
||||
Reference in New Issue
Block a user