summaryrefslogtreecommitdiff
path: root/src/ext/NetFx/be
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/be
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/be')
-rw-r--r--src/ext/NetFx/be/detectnetcore.cpp2
-rw-r--r--src/ext/NetFx/be/detectnetcoresdk.cpp122
-rw-r--r--src/ext/NetFx/be/detectnetcoresdk.h9
-rw-r--r--src/ext/NetFx/be/netfxbe.vcxproj2
-rw-r--r--src/ext/NetFx/be/netfxsearch.cpp25
-rw-r--r--src/ext/NetFx/be/netfxsearch.h6
-rw-r--r--src/ext/NetFx/be/precomp.h1
7 files changed, 162 insertions, 5 deletions
diff --git a/src/ext/NetFx/be/detectnetcore.cpp b/src/ext/NetFx/be/detectnetcore.cpp
index 42156692..aeb04203 100644
--- a/src/ext/NetFx/be/detectnetcore.cpp
+++ b/src/ext/NetFx/be/detectnetcore.cpp
@@ -60,7 +60,7 @@ HRESULT DetectNetCore(
60 hr = StrAllocFormatted(&sczExePath, L"%ls%ls\\netcoresearch.exe", wzBaseDirectory, wzPlatformName); 60 hr = StrAllocFormatted(&sczExePath, L"%ls%ls\\netcoresearch.exe", wzBaseDirectory, wzPlatformName);
61 BextExitOnFailure(hr, "Failed to build netcoresearch.exe path."); 61 BextExitOnFailure(hr, "Failed to build netcoresearch.exe path.");
62 62
63 hr = StrAllocFormatted(&sczCommandLine, L"\"%ls\" %ls %ls", sczExePath, wzMajorVersion, wzRuntimeType); 63 hr = StrAllocFormatted(&sczCommandLine, L"\"%ls\" runtime %ls %ls", sczExePath, wzMajorVersion, wzRuntimeType);
64 BextExitOnFailure(hr, "Failed to build netcoresearch.exe command line."); 64 BextExitOnFailure(hr, "Failed to build netcoresearch.exe command line.");
65 65
66 hr = ProcExecute(sczExePath, sczCommandLine, &hProcess, NULL, &hStdOutErr); 66 hr = ProcExecute(sczExePath, sczCommandLine, &hProcess, NULL, &hStdOutErr);
diff --git a/src/ext/NetFx/be/detectnetcoresdk.cpp b/src/ext/NetFx/be/detectnetcoresdk.cpp
new file mode 100644
index 00000000..08b18334
--- /dev/null
+++ b/src/ext/NetFx/be/detectnetcoresdk.cpp
@@ -0,0 +1,122 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5HRESULT DetectNetCoreSdk(
6 __in NETFX_NET_CORE_PLATFORM platform,
7 __in LPCWSTR wzVersion,
8 __in LPCWSTR wzBaseDirectory,
9 __inout LPWSTR* psczLatestVersion
10 )
11{
12 HRESULT hr = S_OK;
13 LPCWSTR wzPlatformName = NULL;
14 LPWSTR sczExePath = NULL;
15 LPWSTR sczCommandLine = NULL;
16 HANDLE hProcess = NULL;
17 HANDLE hStdOutErr = INVALID_HANDLE_VALUE;
18 BYTE* rgbOutput = NULL;
19 DWORD cbOutput = 0;
20 DWORD cbTotalRead = 0;
21 DWORD cbRead = 0;
22 DWORD dwExitCode = 0;
23
24 ReleaseNullStr(*psczLatestVersion);
25
26 switch (platform)
27 {
28 case NETFX_NET_CORE_PLATFORM_ARM64:
29 wzPlatformName = L"arm64";
30 break;
31 case NETFX_NET_CORE_PLATFORM_X64:
32 wzPlatformName = L"x64";
33 break;
34 case NETFX_NET_CORE_PLATFORM_X86:
35 wzPlatformName = L"x86";
36 break;
37 default:
38 BextExitWithRootFailure(hr, E_INVALIDARG, "Unknown platform: %u", platform);
39 break;
40 }
41
42 hr = StrAllocFormatted(&sczExePath, L"%ls%ls\\netcoresearch.exe", wzBaseDirectory, wzPlatformName);
43 BextExitOnFailure(hr, "Failed to build netcoresearch.exe path.");
44
45 hr = StrAllocFormatted(&sczCommandLine, L"\"%ls\" sdk %ls", sczExePath, wzVersion);
46 BextExitOnFailure(hr, "Failed to build netcoresearch.exe command line.");
47
48 hr = ProcExecute(sczExePath, sczCommandLine, &hProcess, NULL, &hStdOutErr);
49 if (HRESULT_FROM_WIN32(ERROR_EXE_MACHINE_TYPE_MISMATCH) == hr)
50 {
51 ExitFunction1(hr = S_FALSE);
52 }
53 BextExitOnFailure(hr, "Failed to run: %ls", sczCommandLine);
54
55 cbOutput = 64;
56
57 rgbOutput = static_cast<BYTE*>(MemAlloc(cbOutput, TRUE));
58 BextExitOnNull(rgbOutput, hr, E_OUTOFMEMORY, "Failed to alloc output string.");
59
60 while (::ReadFile(hStdOutErr, rgbOutput + cbTotalRead, cbOutput - cbTotalRead, &cbRead, NULL))
61 {
62 cbTotalRead += cbRead;
63
64 if (cbTotalRead == cbOutput)
65 {
66 cbOutput *= 2;
67
68 const LPVOID pvNew = MemReAlloc(rgbOutput, cbOutput, TRUE);
69 BextExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to realloc output string.");
70
71 rgbOutput = static_cast<BYTE*>(pvNew);
72 }
73 }
74
75 if (ERROR_BROKEN_PIPE != ::GetLastError())
76 {
77 BextExitWithLastError(hr, "Failed to read netcoresearch.exe output.");
78 }
79
80 hr = ProcWaitForCompletion(hProcess, INFINITE, &dwExitCode);
81 BextExitOnFailure(hr, "Failed to wait for netcoresearch.exe to exit.");
82
83 if (0 != dwExitCode)
84 {
85 BextExitWithRootFailure(hr, E_UNEXPECTED, "netcoresearch.exe failed with exit code: 0x%x\r\nOutput:\r\n%hs", dwExitCode, rgbOutput);
86 }
87
88 if (*rgbOutput)
89 {
90 hr = StrAllocStringAnsi(psczLatestVersion, reinterpret_cast<LPSTR>(rgbOutput), 0, CP_UTF8);
91 BextExitOnFailure(hr, "Failed to widen output string: %hs", rgbOutput);
92 }
93
94LExit:
95 ReleaseFileHandle(hStdOutErr);
96 ReleaseHandle(hProcess);
97 ReleaseMem(rgbOutput);
98 ReleaseStr(sczCommandLine);
99 ReleaseStr(sczExePath);
100
101 return hr;
102}
103
104HRESULT NetfxPerformDetectNetCoreSdk(
105 __in LPCWSTR wzVariable,
106 __in NETFX_SEARCH* pSearch,
107 __in IBundleExtensionEngine* pEngine,
108 __in LPCWSTR wzBaseDirectory
109 )
110{
111 HRESULT hr = S_OK;
112 LPWSTR sczLatestVersion = nullptr;
113 const auto& searchParams = pSearch->NetCoreSdkSearch;
114 hr = DetectNetCoreSdk(searchParams.platform, searchParams.sczVersion, wzBaseDirectory, &sczLatestVersion);
115 BextExitOnFailure(hr, "DetectNetCoreSdk failed.");
116
117 hr = pEngine->SetVariableVersion(wzVariable, sczLatestVersion);
118 BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion);
119
120LExit:
121 return hr;
122}
diff --git a/src/ext/NetFx/be/detectnetcoresdk.h b/src/ext/NetFx/be/detectnetcoresdk.h
new file mode 100644
index 00000000..025deaa2
--- /dev/null
+++ b/src/ext/NetFx/be/detectnetcoresdk.h
@@ -0,0 +1,9 @@
1#pragma once
2// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4HRESULT NetfxPerformDetectNetCoreSdk(
5 __in LPCWSTR wzVariable,
6 __in NETFX_SEARCH* pSearch,
7 __in IBundleExtensionEngine* pEngine,
8 __in LPCWSTR wzBaseDirectory
9 );
diff --git a/src/ext/NetFx/be/netfxbe.vcxproj b/src/ext/NetFx/be/netfxbe.vcxproj
index d1084dd1..0408da72 100644
--- a/src/ext/NetFx/be/netfxbe.vcxproj
+++ b/src/ext/NetFx/be/netfxbe.vcxproj
@@ -47,6 +47,7 @@
47 47
48 <ItemGroup> 48 <ItemGroup>
49 <ClCompile Include="detectnetcore.cpp" /> 49 <ClCompile Include="detectnetcore.cpp" />
50 <ClCompile Include="detectnetcoresdk.cpp" />
50 <ClCompile Include="netfxbe.cpp" /> 51 <ClCompile Include="netfxbe.cpp" />
51 <ClCompile Include="NetfxBundleExtension.cpp" /> 52 <ClCompile Include="NetfxBundleExtension.cpp" />
52 <ClCompile Include="netfxsearch.cpp" /> 53 <ClCompile Include="netfxsearch.cpp" />
@@ -57,6 +58,7 @@
57 58
58 <ItemGroup> 59 <ItemGroup>
59 <ClInclude Include="detectnetcore.h" /> 60 <ClInclude Include="detectnetcore.h" />
61 <ClInclude Include="detectnetcoresdk.h" />
60 <ClInclude Include="NetfxBundleExtension.h" /> 62 <ClInclude Include="NetfxBundleExtension.h" />
61 <ClInclude Include="netfxsearch.h" /> 63 <ClInclude Include="netfxsearch.h" />
62 <ClInclude Include="precomp.h" /> 64 <ClInclude Include="precomp.h" />
diff --git a/src/ext/NetFx/be/netfxsearch.cpp b/src/ext/NetFx/be/netfxsearch.cpp
index 3c12161d..671e7546 100644
--- a/src/ext/NetFx/be/netfxsearch.cpp
+++ b/src/ext/NetFx/be/netfxsearch.cpp
@@ -15,7 +15,7 @@ STDMETHODIMP NetfxSearchParseFromXml(
15 BSTR bstrNodeName = NULL; 15 BSTR bstrNodeName = NULL;
16 16
17 // Select Netfx search nodes. 17 // Select Netfx search nodes.
18 hr = XmlSelectNodes(pixnBundleExtension, L"NetFxNetCoreSearch", &pixnNodes); 18 hr = XmlSelectNodes(pixnBundleExtension, L"NetFxNetCoreSearch|NetFxNetCoreSdkSearch", &pixnNodes);
19 BextExitOnFailure(hr, "Failed to select Netfx search nodes."); 19 BextExitOnFailure(hr, "Failed to select Netfx search nodes.");
20 20
21 // Get Netfx search node count. 21 // Get Netfx search node count.
@@ -50,18 +50,32 @@ STDMETHODIMP NetfxSearchParseFromXml(
50 { 50 {
51 pSearch->Type = NETFX_SEARCH_TYPE_NET_CORE_SEARCH; 51 pSearch->Type = NETFX_SEARCH_TYPE_NET_CORE_SEARCH;
52 52
53 auto& netCoreSearch = pSearch->NetCoreSearch;
53 // @RuntimeType 54 // @RuntimeType
54 hr = XmlGetAttributeUInt32(pixnNode, L"RuntimeType", reinterpret_cast<DWORD*>(&pSearch->NetCoreSearch.runtimeType)); 55 hr = XmlGetAttributeUInt32(pixnNode, L"RuntimeType", reinterpret_cast<DWORD*>(&netCoreSearch.runtimeType));
55 BextExitOnFailure(hr, "Failed to get @RuntimeType."); 56 BextExitOnFailure(hr, "Failed to get @RuntimeType.");
56 57
57 // @Platform 58 // @Platform
58 hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&pSearch->NetCoreSearch.platform)); 59 hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&netCoreSearch.platform));
59 BextExitOnFailure(hr, "Failed to get @Platform."); 60 BextExitOnFailure(hr, "Failed to get @Platform.");
60 61
61 // @MajorVersion 62 // @MajorVersion
62 hr = XmlGetAttributeEx(pixnNode, L"MajorVersion", &pSearch->NetCoreSearch.sczMajorVersion); 63 hr = XmlGetAttributeEx(pixnNode, L"MajorVersion", &netCoreSearch.sczMajorVersion);
63 BextExitOnFailure(hr, "Failed to get @MajorVersion."); 64 BextExitOnFailure(hr, "Failed to get @MajorVersion.");
64 } 65 }
66 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"NetFxNetCoreSdkSearch", -1))
67 {
68 pSearch->Type = NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH;
69
70 auto& netCoreSdkSearch = pSearch->NetCoreSdkSearch;
71 // @Platform
72 hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&netCoreSdkSearch.platform));
73 BextExitOnFailure(hr, "Failed to get @Platform.");
74
75 // @Version
76 hr = XmlGetAttributeEx(pixnNode, L"Version", &netCoreSdkSearch.sczVersion);
77 BextExitOnFailure(hr, "Failed to get @Version.");
78 }
65 else 79 else
66 { 80 {
67 BextExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected element name: %ls", bstrNodeName); 81 BextExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected element name: %ls", bstrNodeName);
@@ -115,6 +129,9 @@ STDMETHODIMP NetfxSearchExecute(
115 case NETFX_SEARCH_TYPE_NET_CORE_SEARCH: 129 case NETFX_SEARCH_TYPE_NET_CORE_SEARCH:
116 hr = NetfxPerformDetectNetCore(wzVariable, pSearch, pEngine, wzBaseDirectory); 130 hr = NetfxPerformDetectNetCore(wzVariable, pSearch, pEngine, wzBaseDirectory);
117 break; 131 break;
132 case NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH:
133 hr = NetfxPerformDetectNetCoreSdk(wzVariable, pSearch, pEngine, wzBaseDirectory);
134 break;
118 default: 135 default:
119 hr = E_UNEXPECTED; 136 hr = E_UNEXPECTED;
120 } 137 }
diff --git a/src/ext/NetFx/be/netfxsearch.h b/src/ext/NetFx/be/netfxsearch.h
index ae250690..f4e4db01 100644
--- a/src/ext/NetFx/be/netfxsearch.h
+++ b/src/ext/NetFx/be/netfxsearch.h
@@ -8,6 +8,7 @@ enum NETFX_SEARCH_TYPE
8{ 8{
9 NETFX_SEARCH_TYPE_NONE, 9 NETFX_SEARCH_TYPE_NONE,
10 NETFX_SEARCH_TYPE_NET_CORE_SEARCH, 10 NETFX_SEARCH_TYPE_NET_CORE_SEARCH,
11 NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH,
11}; 12};
12 13
13enum NETFX_NET_CORE_RUNTIME_TYPE 14enum NETFX_NET_CORE_RUNTIME_TYPE
@@ -40,6 +41,11 @@ typedef struct _NETFX_SEARCH
40 NETFX_NET_CORE_PLATFORM platform; 41 NETFX_NET_CORE_PLATFORM platform;
41 LPWSTR sczMajorVersion; 42 LPWSTR sczMajorVersion;
42 } NetCoreSearch; 43 } NetCoreSearch;
44 struct
45 {
46 NETFX_NET_CORE_PLATFORM platform;
47 LPWSTR sczVersion;
48 } NetCoreSdkSearch;
43 }; 49 };
44} NETFX_SEARCH; 50} NETFX_SEARCH;
45 51
diff --git a/src/ext/NetFx/be/precomp.h b/src/ext/NetFx/be/precomp.h
index 33aea9bc..4a774200 100644
--- a/src/ext/NetFx/be/precomp.h
+++ b/src/ext/NetFx/be/precomp.h
@@ -30,4 +30,5 @@
30#include "..\..\beDecor.h" 30#include "..\..\beDecor.h"
31#include "netfxsearch.h" 31#include "netfxsearch.h"
32#include "detectnetcore.h" 32#include "detectnetcore.h"
33#include "detectnetcoresdk.h"
33#include "NetfxBundleExtension.h" 34#include "NetfxBundleExtension.h"