From 84e76fedb0255ac4d0524f47268be79598b096fc Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 10 Aug 2023 17:31:07 -0400 Subject: get_property(TEST): Add DIRECTORY option --- Help/command/get_property.rst | 13 ++++++++++- Help/release/dev/test-properties-directory.rst | 3 +++ Source/cmGetPropertyCommand.cxx | 32 ++++++++++++++++++++------ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Help/command/get_property.rst b/Help/command/get_property.rst index 6b9931e..a0a12bb 100644 --- a/Help/command/get_property.rst +++ b/Help/command/get_property.rst @@ -12,7 +12,8 @@ Get a property. SOURCE [DIRECTORY | TARGET_DIRECTORY ] | INSTALL | - TEST | + TEST + [DIRECTORY ] | CACHE | VARIABLE > PROPERTY @@ -73,6 +74,16 @@ It must be one of the following: Scope must name one existing test. See also the :command:`get_test_property` command. + .. versionadded:: 3.28 + Directory scope can be overridden with the following sub-option: + + ``DIRECTORY `` + The test property will be read from the ```` directory's + scope. CMake must already know about the directory, either by having added + it through a call to :command:`add_subdirectory` or ```` being the top + level directory. Relative paths are treated as relative to the current + source directory. ```` may reference a binary directory. + ``CACHE`` Scope must name one cache entry. diff --git a/Help/release/dev/test-properties-directory.rst b/Help/release/dev/test-properties-directory.rst index 7a36372..2daa533 100644 --- a/Help/release/dev/test-properties-directory.rst +++ b/Help/release/dev/test-properties-directory.rst @@ -7,3 +7,6 @@ test-properties-directory * The :command:`set_tests_properties` command gained a ``DIRECTORY`` sub-option, which allows you to set properties on tests in other directories. +* The ``TEST`` mode of the :command:`get_property` command gained a + ``DIRECTORY`` sub-option, which allows you to get properties on tests in + other directories. diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 943ce1d..880756d 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -49,7 +49,8 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, bool source_file_paths_should_be_absolute); bool HandleTestMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, - const std::string& propertyName); + const std::string& propertyName, + cmMakefile& directory_makefile); bool HandleVariableMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, const std::string& propertyName); @@ -81,6 +82,9 @@ bool cmGetPropertyCommand(std::vector const& args, bool source_file_directory_option_enabled = false; bool source_file_target_option_enabled = false; + std::string test_directory; + bool test_directory_option_enabled = false; + // Get the scope from which to get the property. cmProperty::ScopeType scope; if (args[1] == "GLOBAL") { @@ -116,7 +120,8 @@ bool cmGetPropertyCommand(std::vector const& args, DoingProperty, DoingType, DoingSourceDirectory, - DoingSourceTargetDirectory + DoingSourceTargetDirectory, + DoingTestDirectory, }; Doing doing = DoingName; for (unsigned int i = 2; i < args.size(); ++i) { @@ -145,12 +150,19 @@ bool cmGetPropertyCommand(std::vector const& args, args[i] == "TARGET_DIRECTORY") { doing = DoingSourceTargetDirectory; source_file_target_option_enabled = true; + } else if (doing == DoingNone && scope == cmProperty::TEST && + args[i] == "DIRECTORY") { + doing = DoingTestDirectory; + test_directory_option_enabled = true; } else if (doing == DoingSourceDirectory) { source_file_directories.push_back(args[i]); doing = DoingNone; } else if (doing == DoingSourceTargetDirectory) { source_file_target_directories.push_back(args[i]); doing = DoingNone; + } else if (doing == DoingTestDirectory) { + test_directory = args[i]; + doing = DoingNone; } else if (doing == DoingProperty) { doing = DoingNone; propertyName = args[i]; @@ -167,12 +179,17 @@ bool cmGetPropertyCommand(std::vector const& args, } std::vector source_file_directory_makefiles; - bool file_scopes_handled = + bool source_file_scopes_handled = SetPropertyCommand::HandleAndValidateSourceFileDirectoryScopes( status, source_file_directory_option_enabled, source_file_target_option_enabled, source_file_directories, source_file_target_directories, source_file_directory_makefiles); - if (!file_scopes_handled) { + cmMakefile* test_directory_makefile; + bool test_scopes_handled = + SetPropertyCommand::HandleAndValidateTestDirectoryScopes( + status, test_directory_option_enabled, test_directory, + test_directory_makefile); + if (!(source_file_scopes_handled && test_scopes_handled)) { return false; } @@ -231,7 +248,8 @@ bool cmGetPropertyCommand(std::vector const& args, directory_scope_mf, source_file_paths_should_be_absolute); case cmProperty::TEST: - return HandleTestMode(status, name, infoType, variable, propertyName); + return HandleTestMode(status, name, infoType, variable, propertyName, + *test_directory_makefile); case cmProperty::VARIABLE: return HandleVariableMode(status, name, infoType, variable, propertyName); @@ -404,7 +422,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name, bool HandleTestMode(cmExecutionStatus& status, const std::string& name, OutType infoType, const std::string& variable, - const std::string& propertyName) + const std::string& propertyName, cmMakefile& test_makefile) { if (name.empty()) { status.SetError("not given name for TEST scope."); @@ -412,7 +430,7 @@ bool HandleTestMode(cmExecutionStatus& status, const std::string& name, } // Loop over all tests looking for matching names. - if (cmTest* test = status.GetMakefile().GetTest(name)) { + if (cmTest* test = test_makefile.GetTest(name)) { return StoreResult(infoType, status.GetMakefile(), variable, test->GetProperty(propertyName)); } -- cgit v0.12