Browse Source

get_property(TEST): Add DIRECTORY option

Kyle Edwards 2 years ago
parent
commit
84e76fedb0

+ 12 - 1
Help/command/get_property.rst

@@ -12,7 +12,8 @@ Get a property.
                 SOURCE    <source>
                 SOURCE    <source>
                           [DIRECTORY <dir> | TARGET_DIRECTORY <target>] |
                           [DIRECTORY <dir> | TARGET_DIRECTORY <target>] |
                 INSTALL   <file>   |
                 INSTALL   <file>   |
-                TEST      <test>   |
+                TEST      <test>
+                          [DIRECTORY <dir>] |
                 CACHE     <entry>  |
                 CACHE     <entry>  |
                 VARIABLE           >
                 VARIABLE           >
                PROPERTY <name>
                PROPERTY <name>
@@ -73,6 +74,16 @@ It must be one of the following:
   Scope must name one existing test.
   Scope must name one existing test.
   See also the :command:`get_test_property` command.
   See also the :command:`get_test_property` command.
 
 
+  .. versionadded:: 3.28
+    Directory scope can be overridden with the following sub-option:
+
+    ``DIRECTORY <dir>``
+      The test property will be read from the ``<dir>`` directory's
+      scope.  CMake must already know about the directory, either by having added
+      it through a call to :command:`add_subdirectory` or ``<dir>`` being the top
+      level directory. Relative paths are treated as relative to the current
+      source directory. ``<dir>`` may reference a binary directory.
+
 ``CACHE``
 ``CACHE``
   Scope must name one cache entry.
   Scope must name one cache entry.
 
 

+ 3 - 0
Help/release/dev/test-properties-directory.rst

@@ -7,3 +7,6 @@ test-properties-directory
 * The :command:`set_tests_properties` command gained a ``DIRECTORY``
 * The :command:`set_tests_properties` command gained a ``DIRECTORY``
   sub-option, which allows you to set properties on tests in other
   sub-option, which allows you to set properties on tests in other
   directories.
   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.

+ 25 - 7
Source/cmGetPropertyCommand.cxx

@@ -49,7 +49,8 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
                       bool source_file_paths_should_be_absolute);
                       bool source_file_paths_should_be_absolute);
 bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
 bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
                     OutType infoType, const std::string& variable,
                     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,
 bool HandleVariableMode(cmExecutionStatus& status, const std::string& name,
                         OutType infoType, const std::string& variable,
                         OutType infoType, const std::string& variable,
                         const std::string& propertyName);
                         const std::string& propertyName);
@@ -81,6 +82,9 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
   bool source_file_directory_option_enabled = false;
   bool source_file_directory_option_enabled = false;
   bool source_file_target_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.
   // Get the scope from which to get the property.
   cmProperty::ScopeType scope;
   cmProperty::ScopeType scope;
   if (args[1] == "GLOBAL") {
   if (args[1] == "GLOBAL") {
@@ -116,7 +120,8 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
     DoingProperty,
     DoingProperty,
     DoingType,
     DoingType,
     DoingSourceDirectory,
     DoingSourceDirectory,
-    DoingSourceTargetDirectory
+    DoingSourceTargetDirectory,
+    DoingTestDirectory,
   };
   };
   Doing doing = DoingName;
   Doing doing = DoingName;
   for (unsigned int i = 2; i < args.size(); ++i) {
   for (unsigned int i = 2; i < args.size(); ++i) {
@@ -145,12 +150,19 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
                args[i] == "TARGET_DIRECTORY") {
                args[i] == "TARGET_DIRECTORY") {
       doing = DoingSourceTargetDirectory;
       doing = DoingSourceTargetDirectory;
       source_file_target_option_enabled = true;
       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) {
     } else if (doing == DoingSourceDirectory) {
       source_file_directories.push_back(args[i]);
       source_file_directories.push_back(args[i]);
       doing = DoingNone;
       doing = DoingNone;
     } else if (doing == DoingSourceTargetDirectory) {
     } else if (doing == DoingSourceTargetDirectory) {
       source_file_target_directories.push_back(args[i]);
       source_file_target_directories.push_back(args[i]);
       doing = DoingNone;
       doing = DoingNone;
+    } else if (doing == DoingTestDirectory) {
+      test_directory = args[i];
+      doing = DoingNone;
     } else if (doing == DoingProperty) {
     } else if (doing == DoingProperty) {
       doing = DoingNone;
       doing = DoingNone;
       propertyName = args[i];
       propertyName = args[i];
@@ -167,12 +179,17 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
   }
   }
 
 
   std::vector<cmMakefile*> source_file_directory_makefiles;
   std::vector<cmMakefile*> source_file_directory_makefiles;
-  bool file_scopes_handled =
+  bool source_file_scopes_handled =
     SetPropertyCommand::HandleAndValidateSourceFileDirectoryScopes(
     SetPropertyCommand::HandleAndValidateSourceFileDirectoryScopes(
       status, source_file_directory_option_enabled,
       status, source_file_directory_option_enabled,
       source_file_target_option_enabled, source_file_directories,
       source_file_target_option_enabled, source_file_directories,
       source_file_target_directories, source_file_directory_makefiles);
       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;
     return false;
   }
   }
 
 
@@ -231,7 +248,8 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
                                 directory_scope_mf,
                                 directory_scope_mf,
                                 source_file_paths_should_be_absolute);
                                 source_file_paths_should_be_absolute);
       case cmProperty::TEST:
       case cmProperty::TEST:
-        return HandleTestMode(status, name, infoType, variable, propertyName);
+        return HandleTestMode(status, name, infoType, variable, propertyName,
+                              *test_directory_makefile);
       case cmProperty::VARIABLE:
       case cmProperty::VARIABLE:
         return HandleVariableMode(status, name, infoType, variable,
         return HandleVariableMode(status, name, infoType, variable,
                                   propertyName);
                                   propertyName);
@@ -404,7 +422,7 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
 
 
 bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
 bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
                     OutType infoType, const std::string& variable,
                     OutType infoType, const std::string& variable,
-                    const std::string& propertyName)
+                    const std::string& propertyName, cmMakefile& test_makefile)
 {
 {
   if (name.empty()) {
   if (name.empty()) {
     status.SetError("not given name for TEST scope.");
     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.
   // 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,
     return StoreResult(infoType, status.GetMakefile(), variable,
                        test->GetProperty(propertyName));
                        test->GetProperty(propertyName));
   }
   }