Bladeren bron

FileAPI: Add integration for runtime dependency installers

Kyle Edwards 4 jaren geleden
bovenliggende
commit
8d898cb3e1

+ 24 - 0
Help/manual/cmake-file-api.7.rst

@@ -752,6 +752,12 @@ with members:
       The ``destination`` member is populated. The ``isOptional`` member may
       exist. This type has no additional members.
 
+    ``runtimeDependencySet``
+      An :command:`install(RUNTIME_DEPENDENCY_SET)` call or an
+      :command:`install(TARGETS)` call with ``RUNTIME_DEPENDENCIES``. The
+      ``destination`` member is populated. This type has additional members
+      ``runtimeDependencySetName`` and ``runtimeDependencySetType``.
+
   ``isExcludeFromAll``
     Optional member that is present with boolean value ``true`` when
     :command:`install` is called with the ``EXCLUDE_FROM_ALL`` option.
@@ -811,6 +817,24 @@ with members:
       An unsigned integer 0-based index into the main "codemodel"
       object's ``targets`` array for the target.
 
+  ``runtimeDependencySetName``
+    Optional member that is present when ``type`` is ``runtimeDependencySet``
+    and the installer was created by an
+    :command:`install(RUNTIME_DEPENDENCY_SET)` call. The value is a string
+    specifying the name of the runtime dependency set that was installed.
+
+  ``runtimeDependencySetType``
+    Optional member that is present when ``type`` is ``runtimeDependencySet``.
+    The value is a string with one of the following values:
+
+    ``library``
+      Indicates that this installer installs dependencies that are not macOS
+      frameworks.
+
+    ``framework``
+      Indicates that this installer installs dependencies that are macOS
+      frameworks.
+
   ``scriptFile``
     Optional member that is present when ``type`` is ``script``.
     The value is a string specifying the path to the script file on disk,

+ 26 - 2
Source/cmFileAPICodemodel.cxx

@@ -15,6 +15,7 @@
 #include <utility>
 #include <vector>
 
+#include <cm/string_view>
 #include <cmext/algorithm>
 
 #include <cm3p/json/value.h>
@@ -29,7 +30,10 @@
 #include "cmInstallExportGenerator.h"
 #include "cmInstallFilesGenerator.h"
 #include "cmInstallGenerator.h"
+#include "cmInstallGetRuntimeDependenciesGenerator.h"
 #include "cmInstallImportedRuntimeArtifactsGenerator.h"
+#include "cmInstallRuntimeDependencySet.h"
+#include "cmInstallRuntimeDependencySetGenerator.h"
 #include "cmInstallScriptGenerator.h"
 #include "cmInstallSubdirectoryGenerator.h"
 #include "cmInstallTargetGenerator.h"
@@ -876,8 +880,10 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
 {
   Json::Value installer = Json::objectValue;
 
-  // Exclude subdirectory installers.  They are implementation details.
-  if (dynamic_cast<cmInstallSubdirectoryGenerator*>(gen)) {
+  // Exclude subdirectory installers and file(GET_RUNTIME_DEPENDENCIES)
+  // installers. They are implementation details.
+  if (dynamic_cast<cmInstallSubdirectoryGenerator*>(gen) ||
+      dynamic_cast<cmInstallGetRuntimeDependenciesGenerator*>(gen)) {
     return installer;
   }
 
@@ -1019,6 +1025,24 @@ Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen)
     if (installImportedRuntimeArtifacts->GetOptional()) {
       installer["isOptional"] = true;
     }
+  } else if (auto* installRuntimeDependencySet =
+               dynamic_cast<cmInstallRuntimeDependencySetGenerator*>(gen)) {
+    installer["type"] = "runtimeDependencySet";
+    installer["destination"] =
+      installRuntimeDependencySet->GetDestination(this->Config);
+    std::string name(
+      installRuntimeDependencySet->GetRuntimeDependencySet()->GetName());
+    if (!name.empty()) {
+      installer["runtimeDependencySetName"] = name;
+    }
+    switch (installRuntimeDependencySet->GetDependencyType()) {
+      case cmInstallRuntimeDependencySetGenerator::DependencyType::Framework:
+        installer["runtimeDependencySetType"] = "framework";
+        break;
+      case cmInstallRuntimeDependencySetGenerator::DependencyType::Library:
+        installer["runtimeDependencySetType"] = "library";
+        break;
+    }
   }
 
   // Add fields common to all install generators.

+ 16 - 0
Tests/RunCMake/FileAPI/codemodel-v2-check.py

@@ -180,6 +180,14 @@ def check_directory(c):
                 expected_keys.append("scriptFile")
                 assert is_string(a["scriptFile"], e["scriptFile"])
 
+            if e.get("runtimeDependencySetName", None) is not None:
+                expected_keys.append("runtimeDependencySetName")
+                assert is_string(a["runtimeDependencySetName"], e["runtimeDependencySetName"])
+
+            if e.get("runtimeDependencySetType", None) is not None:
+                expected_keys.append("runtimeDependencySetType")
+                assert is_string(a["runtimeDependencySetType"], e["runtimeDependencySetType"])
+
             if e["backtrace"] is not None:
                 expected_keys.append("backtrace")
                 check_backtrace(d, a["backtrace"], e["backtrace"])
@@ -650,6 +658,14 @@ def gen_check_directories(c, g):
                     if "pathsNamelink" in i:
                         i["paths"] = i["pathsNamelink"]
 
+    if sys.platform not in ("win32", "darwin") and "linux" not in sys.platform:
+        for e in expected:
+            e["installers"] = list(filter(lambda i: i["type"] != "runtimeDependencySet", e["installers"]))
+
+    if sys.platform != "darwin":
+        for e in expected:
+            e["installers"] = list(filter(lambda i: i.get("runtimeDependencySetType", None) != "framework", e["installers"]))
+
     return expected
 
 def check_directories(c, g):

+ 161 - 2
Tests/RunCMake/FileAPI/codemodel-v2-data/directories/cxx.json

@@ -17,6 +17,165 @@
     ],
     "projectName": "Cxx",
     "minimumCMakeVersion": "3.12",
-    "hasInstallRule": null,
-    "installers": []
+    "hasInstallRule": true,
+    "installers": [
+        {
+            "component": "Unspecified",
+            "type": "target",
+            "destination": "lib",
+            "paths": [
+                "^cxx/((Debug|Release|MinSizeRel|RelWithDebInfo)/)?cxx_exe(\\.exe)?$"
+            ],
+            "isExcludeFromAll": null,
+            "isForAllComponents": null,
+            "isOptional": null,
+            "targetId": "^cxx_exe::@a56b12a3f5c0529fb296$",
+            "targetIndex": "cxx_exe",
+            "targetIsImportLibrary": null,
+            "targetInstallNamelink": null,
+            "exportName": null,
+            "exportTargets": null,
+            "scriptFile": null,
+            "backtrace": [
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": 38,
+                    "command": "install",
+                    "hasParent": true
+                },
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": null,
+                    "command": null,
+                    "hasParent": false
+                }
+            ]
+        },
+        {
+            "component": "Unspecified",
+            "type": "runtimeDependencySet",
+            "destination": "lib",
+            "paths": null,
+            "isExcludeFromAll": null,
+            "isForAllComponents": null,
+            "isOptional": null,
+            "targetId": null,
+            "targetIndex": null,
+            "targetIsImportLibrary": null,
+            "targetInstallNamelink": null,
+            "exportName": null,
+            "exportTargets": null,
+            "scriptFile": null,
+            "runtimeDependencySetType": "library",
+            "backtrace": [
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": 38,
+                    "command": "install",
+                    "hasParent": true
+                },
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": null,
+                    "command": null,
+                    "hasParent": false
+                }
+            ]
+        },
+        {
+            "component": "Unspecified",
+            "type": "runtimeDependencySet",
+            "destination": "fw",
+            "paths": null,
+            "isExcludeFromAll": null,
+            "isForAllComponents": null,
+            "isOptional": null,
+            "targetId": null,
+            "targetIndex": null,
+            "targetIsImportLibrary": null,
+            "targetInstallNamelink": null,
+            "exportName": null,
+            "exportTargets": null,
+            "scriptFile": null,
+            "runtimeDependencySetType": "framework",
+            "backtrace": [
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": 38,
+                    "command": "install",
+                    "hasParent": true
+                },
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": null,
+                    "command": null,
+                    "hasParent": false
+                }
+            ]
+        },
+        {
+            "component": "Unspecified",
+            "type": "runtimeDependencySet",
+            "destination": "lib",
+            "paths": null,
+            "isExcludeFromAll": null,
+            "isForAllComponents": null,
+            "isOptional": null,
+            "targetId": null,
+            "targetIndex": null,
+            "targetIsImportLibrary": null,
+            "targetInstallNamelink": null,
+            "exportName": null,
+            "exportTargets": null,
+            "scriptFile": null,
+            "runtimeDependencySetType": "library",
+            "runtimeDependencySetName": "deps",
+            "backtrace": [
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": 43,
+                    "command": "install",
+                    "hasParent": true
+                },
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": null,
+                    "command": null,
+                    "hasParent": false
+                }
+            ]
+        },
+        {
+            "component": "Unspecified",
+            "type": "runtimeDependencySet",
+            "destination": "fw",
+            "paths": null,
+            "isExcludeFromAll": null,
+            "isForAllComponents": null,
+            "isOptional": null,
+            "targetId": null,
+            "targetIndex": null,
+            "targetIsImportLibrary": null,
+            "targetInstallNamelink": null,
+            "exportName": null,
+            "exportTargets": null,
+            "scriptFile": null,
+            "runtimeDependencySetType": "framework",
+            "runtimeDependencySetName": "deps",
+            "backtrace": [
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": 43,
+                    "command": "install",
+                    "hasParent": true
+                },
+                {
+                    "file": "^cxx/CMakeLists\\.txt$",
+                    "line": null,
+                    "command": null,
+                    "hasParent": false
+                }
+            ]
+        }
+    ]
 }

+ 17 - 0
Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json

@@ -114,6 +114,23 @@
     "install": {
         "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$",
         "destinations": [
+            {
+                "path": "lib",
+                "backtrace": [
+                    {
+                        "file": "^cxx/CMakeLists\\.txt$",
+                        "line": 38,
+                        "command": "install",
+                        "hasParent": true
+                    },
+                    {
+                        "file": "^cxx/CMakeLists\\.txt$",
+                        "line": null,
+                        "command": null,
+                        "hasParent": false
+                    }
+                ]
+            },
             {
                 "path": "bin",
                 "backtrace": [

+ 15 - 0
Tests/RunCMake/FileAPI/cxx/CMakeLists.txt

@@ -30,3 +30,18 @@ if(CMAKE_CXX_STANDARD_DEFAULT AND DEFINED CMAKE_CXX11_STANDARD_COMPILE_OPTION)
   target_compile_features(cxx_standard_compile_feature_exe PRIVATE cxx_decltype)
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_std_11.txt" "")
 endif()
+
+set(_rdeps)
+if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|Windows|Darwin)$")
+  set(_rdeps RUNTIME_DEPENDENCIES)
+endif()
+install(TARGETS cxx_exe ${_rdeps}
+  DESTINATION lib
+  FRAMEWORK DESTINATION fw
+  )
+if(_rdeps)
+  install(RUNTIME_DEPENDENCY_SET deps
+    DESTINATION lib
+    FRAMEWORK DESTINATION fw
+    )
+endif()