aboutsummaryrefslogtreecommitdiff
path: root/src/ext/NetFx/netcoresearch
diff options
context:
space:
mode:
authorStaffan Gustafsson <staffangu@outlook.com>2022-11-30 17:15:12 +0100
committerSean Hall <r.sean.hall@gmail.com>2023-01-18 18:10:56 -0600
commit853887b4e84df1965794802b7683f3a9aca3e930 (patch)
treec2db272b63381c94186712c0029ed0e000ec3391 /src/ext/NetFx/netcoresearch
parent9f368d76848e31d21ec3c193fa8c92849b1362a1 (diff)
downloadwix-853887b4e84df1965794802b7683f3a9aca3e930.tar.gz
wix-853887b4e84df1965794802b7683f3a9aca3e930.tar.bz2
wix-853887b4e84df1965794802b7683f3a9aca3e930.zip
Adding support for DotNetCoreSdkSearch and DotNetCoreSdkCompatibilityCheck
Diffstat (limited to 'src/ext/NetFx/netcoresearch')
-rw-r--r--src/ext/NetFx/netcoresearch/netcoresearch.cpp216
1 files changed, 175 insertions, 41 deletions
diff --git a/src/ext/NetFx/netcoresearch/netcoresearch.cpp b/src/ext/NetFx/netcoresearch/netcoresearch.cpp
index 517f6ac4..5cf6d10b 100644
--- a/src/ext/NetFx/netcoresearch/netcoresearch.cpp
+++ b/src/ext/NetFx/netcoresearch/netcoresearch.cpp
@@ -2,16 +2,36 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5enum class NETCORESEARCHKIND
6{
7 None,
8 Runtime,
9 Sdk,
10};
11
5struct NETCORESEARCH_STATE 12struct NETCORESEARCH_STATE
6{ 13{
7 LPCWSTR wzTargetName; 14 NETCORESEARCHKIND Kind = NETCORESEARCHKIND::None;
8 DWORD dwMajorVersion; 15 union
16 {
17 struct
18 {
19 LPCWSTR wzTargetName;
20 DWORD dwMajorVersion;
21 } Runtime;
22 struct
23 {
24 DWORD dwMajorVersion;
25 DWORD dwMinorVersion;
26 DWORD dwFeatureBand;
27 }
28 Sdk;
29 } Data;
9 VERUTIL_VERSION* pVersion; 30 VERUTIL_VERSION* pVersion;
10}; 31};
11 32
12static HRESULT GetDotnetEnvironmentInfo( 33static HRESULT GetDotnetEnvironmentInfo(
13 __in DWORD dwMajorVersion, 34 __in NETCORESEARCH_STATE& pSearchState,
14 __in_z LPCWSTR wzTargetName,
15 __inout VERUTIL_VERSION** ppVersion 35 __inout VERUTIL_VERSION** ppVersion
16 ); 36 );
17static void HOSTFXR_CALLTYPE GetDotnetEnvironmentInfoResult( 37static void HOSTFXR_CALLTYPE GetDotnetEnvironmentInfoResult(
@@ -19,24 +39,28 @@ static void HOSTFXR_CALLTYPE GetDotnetEnvironmentInfoResult(
19 __in LPVOID pvContext 39 __in LPVOID pvContext
20 ); 40 );
21 41
42bool string_equal_invariant(__in PCWSTR const x,__in PCWSTR const y) { return CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, x, -1, y, -1); }
43
44HRESULT get_search_state_from_arguments(__in int argc, __in LPWSTR argv[], __out NETCORESEARCH_STATE& searchState);
45
22int __cdecl wmain(int argc, LPWSTR argv[]) 46int __cdecl wmain(int argc, LPWSTR argv[])
23{ 47{
24 HRESULT hr = S_OK; 48 HRESULT hr = S_OK;
25 DWORD dwMajorVersion = 0;
26 VERUTIL_VERSION* pVersion = NULL; 49 VERUTIL_VERSION* pVersion = NULL;
50 NETCORESEARCH_STATE searchState = {};
51
52 ::SetConsoleCP(CP_UTF8);
27 53
28 ConsoleInitialize(); 54 ConsoleInitialize();
29 55
30 if (argc != 3) 56 hr = get_search_state_from_arguments(argc, argv, OUT searchState);
57 if (FAILED(hr))
31 { 58 {
32 ExitFunction1(hr = E_INVALIDARG); 59 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to parse arguments.");
33 } 60 }
34 61
35 hr = StrStringToUInt32(argv[1], 0, reinterpret_cast<UINT*>(&dwMajorVersion)); 62 hr = GetDotnetEnvironmentInfo(searchState, &pVersion);
36 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to get target version from: %ls", argv[1]);
37 63
38 hr = GetDotnetEnvironmentInfo(dwMajorVersion, argv[2], &pVersion);
39 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to search for .NET Core.");
40 64
41 if (pVersion) 65 if (pVersion)
42 { 66 {
@@ -49,9 +73,65 @@ LExit:
49 return hr; 73 return hr;
50} 74}
51 75
76HRESULT get_search_state_from_arguments(int argc, LPWSTR argv[], __out NETCORESEARCH_STATE& searchState)
77{
78 HRESULT hr = S_OK;
79 searchState = {};
80 const auto searchKind = argv[1];
81
82 if (argc < 3)
83 {
84 ExitFunction1(hr = E_INVALIDARG);
85 }
86
87
88 if (string_equal_invariant(searchKind, L"runtime"))
89 {
90 if (argc != 4)
91 {
92 ExitFunction1(hr = E_INVALIDARG);
93 }
94 searchState.Kind = NETCORESEARCHKIND::Runtime;
95
96 const PCWSTR majorVersion = argv[2];
97 const PCWSTR targetName = argv[3];
98
99 auto& data = searchState.Data.Runtime;
100
101 data.wzTargetName = targetName;
102 hr = StrStringToUInt32(majorVersion, 0, reinterpret_cast<UINT*>(&data.dwMajorVersion));
103 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to get target version from: %ls", majorVersion);
104 }
105 else if(string_equal_invariant(searchKind, L"sdk"))
106 {
107 searchState.Kind = NETCORESEARCHKIND::Sdk;
108
109 const PCWSTR version = argv[2];
110
111 VERUTIL_VERSION* sdkVersion = nullptr;
112 hr = VerParseVersion(version, 0, FALSE, &sdkVersion);
113 if (FAILED(hr))
114 {
115 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to parse version from: %ls", version);
116 }
117
118 auto& data = searchState.Data.Sdk;
119
120 data.dwMajorVersion = sdkVersion->dwMajor;
121 data.dwMinorVersion = sdkVersion->dwMinor;
122 data.dwFeatureBand = sdkVersion->dwPatch;
123
124 VerFreeVersion(sdkVersion);
125 }
126
127LExit:
128 return hr;
129}
130
131
132
52static HRESULT GetDotnetEnvironmentInfo( 133static HRESULT GetDotnetEnvironmentInfo(
53 __in DWORD dwMajorVersion, 134 __in NETCORESEARCH_STATE& state,
54 __in_z LPCWSTR wzTargetName,
55 __inout VERUTIL_VERSION** ppVersion 135 __inout VERUTIL_VERSION** ppVersion
56 ) 136 )
57{ 137{
@@ -60,10 +140,6 @@ static HRESULT GetDotnetEnvironmentInfo(
60 LPWSTR sczHostfxrPath = NULL; 140 LPWSTR sczHostfxrPath = NULL;
61 HMODULE hModule = NULL; 141 HMODULE hModule = NULL;
62 hostfxr_get_dotnet_environment_info_fn pfnGetDotnetEnvironmentInfo = NULL; 142 hostfxr_get_dotnet_environment_info_fn pfnGetDotnetEnvironmentInfo = NULL;
63 NETCORESEARCH_STATE state = { };
64
65 state.dwMajorVersion = dwMajorVersion;
66 state.wzTargetName = wzTargetName;
67 143
68 hr = PathForCurrentProcess(&sczProcessPath, NULL); 144 hr = PathForCurrentProcess(&sczProcessPath, NULL);
69 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to get process path."); 145 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to get process path.");
@@ -102,50 +178,108 @@ LExit:
102 return hr; 178 return hr;
103} 179}
104 180
181bool matches_feature_band(const int requested, const int actual)
182{
183 // we have not requested a match on feature band, so skip the check
184 if (requested == 0) return true;
185
186 const int requestedBand = requested / 100;
187 const int actualBand = actual / 100;
188
189 if (actualBand != requestedBand) return false;
190
191 return actual >= requested;
192}
193
105static void HOSTFXR_CALLTYPE GetDotnetEnvironmentInfoResult( 194static void HOSTFXR_CALLTYPE GetDotnetEnvironmentInfoResult(
106 __in const hostfxr_dotnet_environment_info* pInfo, 195 __in const hostfxr_dotnet_environment_info* pInfo,
107 __in LPVOID pvContext 196 __in LPVOID pvContext
108 ) 197 )
109{ 198{
110 NETCORESEARCH_STATE* pState = reinterpret_cast<NETCORESEARCH_STATE*>(pvContext); 199 NETCORESEARCH_STATE* pState = static_cast<NETCORESEARCH_STATE*>(pvContext);
111 HRESULT hr = S_OK; 200 HRESULT hr = S_OK;
112 VERUTIL_VERSION* pFrameworkVersion = NULL; 201 VERUTIL_VERSION* pDotnetVersion = nullptr;
113 int nCompare = 0; 202 int nCompare = 0;
114 203
115 for (size_t i = 0; i < pInfo->framework_count; ++i)
116 {
117 const hostfxr_dotnet_environment_framework_info* pFrameworkInfo = pInfo->frameworks + i;
118 ReleaseVerutilVersion(pFrameworkVersion);
119 204
120 if (CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pState->wzTargetName, -1, pFrameworkInfo->name, -1)) 205 if (pState->Kind == NETCORESEARCHKIND::Sdk)
206 {
207 auto& sdkData = pState->Data.Sdk;
208 for (size_t i = 0; i < pInfo->sdk_count; ++i)
121 { 209 {
122 continue; 210 const hostfxr_dotnet_environment_sdk_info* pSdkInfo = pInfo->sdks + i;
123 } 211 ReleaseVerutilVersion(pDotnetVersion);
124 212
125 hr = VerParseVersion(pFrameworkInfo->version, 0, FALSE, &pFrameworkVersion); 213 hr = VerParseVersion(pSdkInfo->version, 0, FALSE, &pDotnetVersion);
126 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to parse framework version: %ls", pFrameworkInfo->version); 214 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to parse sdk version: %ls", pSdkInfo->version);
127 215
128 if (pFrameworkVersion->dwMajor != pState->dwMajorVersion) 216 if (pDotnetVersion->dwMajor != sdkData.dwMajorVersion)
129 { 217 {
130 continue; 218 continue;
131 } 219 }
220 if (!matches_feature_band(sdkData.dwFeatureBand, pDotnetVersion->dwPatch))
221 {
222 continue;
223 }
132 224
133 if (pState->pVersion) 225 if (pState->pVersion)
226 {
227 hr = VerCompareParsedVersions(pState->pVersion, pDotnetVersion, &nCompare);
228 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to compare versions.");
229
230 if (nCompare > -1)
231 {
232 continue;
233 }
234 }
235
236 ReleaseVerutilVersion(pState->pVersion);
237 pState->pVersion = pDotnetVersion;
238 pDotnetVersion = nullptr;
239 }
240 }
241 else if(pState->Kind == NETCORESEARCHKIND::Runtime)
242 {
243 auto& runtimeData = pState->Data.Runtime;
244 for (size_t i = 0; i < pInfo->framework_count; ++i)
134 { 245 {
135 hr = VerCompareParsedVersions(pState->pVersion, pFrameworkVersion, &nCompare); 246 const hostfxr_dotnet_environment_framework_info* pFrameworkInfo = pInfo->frameworks + i;
136 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to compare versions."); 247 ReleaseVerutilVersion(pDotnetVersion);
137 248
138 if (nCompare > -1) 249 if (string_equal_invariant(runtimeData.wzTargetName, pFrameworkInfo->name))
139 { 250 {
140 continue; 251 continue;
141 } 252 }
142 }
143 253
144 ReleaseVerutilVersion(pState->pVersion); 254 hr = VerParseVersion(pFrameworkInfo->version, 0, FALSE, &pDotnetVersion);
145 pState->pVersion = pFrameworkVersion; 255 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to parse framework version: %ls", pFrameworkInfo->version);
146 pFrameworkVersion = NULL; 256
257 if (pDotnetVersion->dwMajor != runtimeData.dwMajorVersion)
258 {
259 continue;
260 }
261
262 if (pState->pVersion)
263 {
264 hr = VerCompareParsedVersions(pState->pVersion, pDotnetVersion, &nCompare);
265 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to compare versions.");
266
267 if (nCompare > -1)
268 {
269 continue;
270 }
271 }
272
273 ReleaseVerutilVersion(pState->pVersion);
274 pState->pVersion = pDotnetVersion;
275 pDotnetVersion = nullptr;
276 }
277 }
278 else
279 {
280 ConsoleWriteError(E_INVALIDARG, CONSOLE_COLOR_RED, "Invalid NETCORESEARCHKIND.");
147 } 281 }
148 282
149LExit: 283LExit:
150 ReleaseVerutilVersion(pFrameworkVersion); 284 ReleaseVerutilVersion(pDotnetVersion);
151} 285}