diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2023-01-15 19:17:29 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2023-01-18 18:10:56 -0600 |
| commit | d180bc6df297422f189ffd08a0dd558bfbeba1ca (patch) | |
| tree | 9eac5847ce2335548232480b0ccb197f5dda23a0 /src/ext/NetFx/be | |
| parent | 853887b4e84df1965794802b7683f3a9aca3e930 (diff) | |
| download | wix-d180bc6df297422f189ffd08a0dd558bfbeba1ca.tar.gz wix-d180bc6df297422f189ffd08a0dd558bfbeba1ca.tar.bz2 wix-d180bc6df297422f189ffd08a0dd558bfbeba1ca.zip | |
Add netfx:DotNetCoreSdkFeatureBandSearch.
7058
Diffstat (limited to 'src/ext/NetFx/be')
| -rw-r--r-- | src/ext/NetFx/be/detectnetcore.cpp | 91 | ||||
| -rw-r--r-- | src/ext/NetFx/be/detectnetcoresdk.cpp | 99 | ||||
| -rw-r--r-- | src/ext/NetFx/be/detectnetcoresdkfeatureband.cpp | 55 | ||||
| -rw-r--r-- | src/ext/NetFx/be/detectnetcoresdkfeatureband.h | 9 | ||||
| -rw-r--r-- | src/ext/NetFx/be/netfxbe.vcxproj | 4 | ||||
| -rw-r--r-- | src/ext/NetFx/be/netfxsearch.cpp | 32 | ||||
| -rw-r--r-- | src/ext/NetFx/be/netfxsearch.h | 10 | ||||
| -rw-r--r-- | src/ext/NetFx/be/precomp.h | 2 | ||||
| -rw-r--r-- | src/ext/NetFx/be/runnetcoresearch.cpp | 102 | ||||
| -rw-r--r-- | src/ext/NetFx/be/runnetcoresearch.h | 9 |
10 files changed, 238 insertions, 175 deletions
diff --git a/src/ext/NetFx/be/detectnetcore.cpp b/src/ext/NetFx/be/detectnetcore.cpp index aeb04203..3ed26549 100644 --- a/src/ext/NetFx/be/detectnetcore.cpp +++ b/src/ext/NetFx/be/detectnetcore.cpp | |||
| @@ -12,18 +12,7 @@ HRESULT DetectNetCore( | |||
| 12 | { | 12 | { |
| 13 | HRESULT hr = S_OK; | 13 | HRESULT hr = S_OK; |
| 14 | LPCWSTR wzRuntimeType = NULL; | 14 | LPCWSTR wzRuntimeType = NULL; |
| 15 | LPCWSTR wzPlatformName = NULL; | 15 | LPWSTR sczArguments = NULL; |
| 16 | LPWSTR sczExePath = NULL; | ||
| 17 | LPWSTR sczCommandLine = NULL; | ||
| 18 | HANDLE hProcess = NULL; | ||
| 19 | HANDLE hStdOutErr = INVALID_HANDLE_VALUE; | ||
| 20 | BYTE* rgbOutput = NULL; | ||
| 21 | DWORD cbOutput = 0; | ||
| 22 | DWORD cbTotalRead = 0; | ||
| 23 | DWORD cbRead = 0; | ||
| 24 | DWORD dwExitCode = 0; | ||
| 25 | |||
| 26 | ReleaseNullStr(*psczLatestVersion); | ||
| 27 | 16 | ||
| 28 | switch (runtimeType) | 17 | switch (runtimeType) |
| 29 | { | 18 | { |
| @@ -41,80 +30,14 @@ HRESULT DetectNetCore( | |||
| 41 | break; | 30 | break; |
| 42 | } | 31 | } |
| 43 | 32 | ||
| 44 | switch (platform) | 33 | hr = StrAllocFormatted(&sczArguments, L"runtime %ls %ls", wzMajorVersion, wzRuntimeType); |
| 45 | { | 34 | BextExitOnFailure(hr, "Failed to build runtime netcoresearch.exe arguments."); |
| 46 | case NETFX_NET_CORE_PLATFORM_ARM64: | ||
| 47 | wzPlatformName = L"arm64"; | ||
| 48 | break; | ||
| 49 | case NETFX_NET_CORE_PLATFORM_X64: | ||
| 50 | wzPlatformName = L"x64"; | ||
| 51 | break; | ||
| 52 | case NETFX_NET_CORE_PLATFORM_X86: | ||
| 53 | wzPlatformName = L"x86"; | ||
| 54 | break; | ||
| 55 | default: | ||
| 56 | BextExitWithRootFailure(hr, E_INVALIDARG, "Unknown platform: %u", platform); | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | |||
| 60 | hr = StrAllocFormatted(&sczExePath, L"%ls%ls\\netcoresearch.exe", wzBaseDirectory, wzPlatformName); | ||
| 61 | BextExitOnFailure(hr, "Failed to build netcoresearch.exe path."); | ||
| 62 | |||
| 63 | hr = StrAllocFormatted(&sczCommandLine, L"\"%ls\" runtime %ls %ls", sczExePath, wzMajorVersion, wzRuntimeType); | ||
| 64 | BextExitOnFailure(hr, "Failed to build netcoresearch.exe command line."); | ||
| 65 | |||
| 66 | hr = ProcExecute(sczExePath, sczCommandLine, &hProcess, NULL, &hStdOutErr); | ||
| 67 | if (HRESULT_FROM_WIN32(ERROR_EXE_MACHINE_TYPE_MISMATCH) == hr) | ||
| 68 | { | ||
| 69 | ExitFunction1(hr = S_FALSE); | ||
| 70 | } | ||
| 71 | BextExitOnFailure(hr, "Failed to run: %ls", sczCommandLine); | ||
| 72 | |||
| 73 | cbOutput = 64; | ||
| 74 | 35 | ||
| 75 | rgbOutput = reinterpret_cast<BYTE*>(MemAlloc(cbOutput, TRUE)); | 36 | hr = RunNetCoreSearch(platform, wzBaseDirectory, sczArguments, psczLatestVersion); |
| 76 | BextExitOnNull(rgbOutput, hr, E_OUTOFMEMORY, "Failed to alloc output string."); | 37 | BextExitOnFailure(hr, "Failed to run netcoresearch.exe for runtime."); |
| 77 | |||
| 78 | while (::ReadFile(hStdOutErr, rgbOutput + cbTotalRead, cbOutput - cbTotalRead, &cbRead, NULL)) | ||
| 79 | { | ||
| 80 | cbTotalRead += cbRead; | ||
| 81 | |||
| 82 | if (cbTotalRead == cbOutput) | ||
| 83 | { | ||
| 84 | cbOutput *= 2; | ||
| 85 | |||
| 86 | LPVOID pvNew = MemReAlloc(rgbOutput, cbOutput, TRUE); | ||
| 87 | BextExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to realloc output string."); | ||
| 88 | |||
| 89 | rgbOutput = reinterpret_cast<BYTE*>(pvNew); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | if (ERROR_BROKEN_PIPE != ::GetLastError()) | ||
| 94 | { | ||
| 95 | BextExitWithLastError(hr, "Failed to read netcoresearch.exe output."); | ||
| 96 | } | ||
| 97 | |||
| 98 | hr = ProcWaitForCompletion(hProcess, INFINITE, &dwExitCode); | ||
| 99 | BextExitOnFailure(hr, "Failed to wait for netcoresearch.exe to exit."); | ||
| 100 | |||
| 101 | if (0 != dwExitCode) | ||
| 102 | { | ||
| 103 | BextExitWithRootFailure(hr, E_UNEXPECTED, "netcoresearch.exe failed with exit code: 0x%x\r\nOutput:\r\n%hs", dwExitCode, rgbOutput); | ||
| 104 | } | ||
| 105 | |||
| 106 | if (*rgbOutput) | ||
| 107 | { | ||
| 108 | hr = StrAllocStringAnsi(psczLatestVersion, reinterpret_cast<LPSTR>(rgbOutput), 0, CP_UTF8); | ||
| 109 | BextExitOnFailure(hr, "Failed to widen output string: %hs", rgbOutput); | ||
| 110 | } | ||
| 111 | 38 | ||
| 112 | LExit: | 39 | LExit: |
| 113 | ReleaseFileHandle(hStdOutErr); | 40 | ReleaseStr(sczArguments); |
| 114 | ReleaseHandle(hProcess); | ||
| 115 | ReleaseMem(rgbOutput); | ||
| 116 | ReleaseStr(sczCommandLine); | ||
| 117 | ReleaseStr(sczExePath); | ||
| 118 | 41 | ||
| 119 | return hr; | 42 | return hr; |
| 120 | } | 43 | } |
| @@ -136,5 +59,7 @@ HRESULT NetfxPerformDetectNetCore( | |||
| 136 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); | 59 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); |
| 137 | 60 | ||
| 138 | LExit: | 61 | LExit: |
| 62 | ReleaseStr(sczLatestVersion); | ||
| 63 | |||
| 139 | return hr; | 64 | return hr; |
| 140 | } | 65 | } |
diff --git a/src/ext/NetFx/be/detectnetcoresdk.cpp b/src/ext/NetFx/be/detectnetcoresdk.cpp index 08b18334..332d8712 100644 --- a/src/ext/NetFx/be/detectnetcoresdk.cpp +++ b/src/ext/NetFx/be/detectnetcoresdk.cpp | |||
| @@ -4,99 +4,22 @@ | |||
| 4 | 4 | ||
| 5 | HRESULT DetectNetCoreSdk( | 5 | HRESULT DetectNetCoreSdk( |
| 6 | __in NETFX_NET_CORE_PLATFORM platform, | 6 | __in NETFX_NET_CORE_PLATFORM platform, |
| 7 | __in LPCWSTR wzVersion, | 7 | __in LPCWSTR wzMajorVersion, |
| 8 | __in LPCWSTR wzBaseDirectory, | 8 | __in LPCWSTR wzBaseDirectory, |
| 9 | __inout LPWSTR* psczLatestVersion | 9 | __inout LPWSTR* psczLatestVersion |
| 10 | ) | 10 | ) |
| 11 | { | 11 | { |
| 12 | HRESULT hr = S_OK; | 12 | HRESULT hr = S_OK; |
| 13 | LPCWSTR wzPlatformName = NULL; | 13 | LPWSTR sczArguments = 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 | 14 | ||
| 24 | ReleaseNullStr(*psczLatestVersion); | 15 | hr = StrAllocFormatted(&sczArguments, L"sdk %ls", wzMajorVersion); |
| 16 | BextExitOnFailure(hr, "Failed to build sdk netcoresearch.exe arguments."); | ||
| 25 | 17 | ||
| 26 | switch (platform) | 18 | hr = RunNetCoreSearch(platform, wzBaseDirectory, sczArguments, psczLatestVersion); |
| 27 | { | 19 | BextExitOnFailure(hr, "Failed to run netcoresearch.exe for sdk."); |
| 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 | 20 | ||
| 94 | LExit: | 21 | LExit: |
| 95 | ReleaseFileHandle(hStdOutErr); | 22 | ReleaseStr(sczArguments); |
| 96 | ReleaseHandle(hProcess); | ||
| 97 | ReleaseMem(rgbOutput); | ||
| 98 | ReleaseStr(sczCommandLine); | ||
| 99 | ReleaseStr(sczExePath); | ||
| 100 | 23 | ||
| 101 | return hr; | 24 | return hr; |
| 102 | } | 25 | } |
| @@ -109,14 +32,16 @@ HRESULT NetfxPerformDetectNetCoreSdk( | |||
| 109 | ) | 32 | ) |
| 110 | { | 33 | { |
| 111 | HRESULT hr = S_OK; | 34 | HRESULT hr = S_OK; |
| 112 | LPWSTR sczLatestVersion = nullptr; | 35 | LPWSTR sczLatestVersion = NULL; |
| 113 | const auto& searchParams = pSearch->NetCoreSdkSearch; | 36 | |
| 114 | hr = DetectNetCoreSdk(searchParams.platform, searchParams.sczVersion, wzBaseDirectory, &sczLatestVersion); | 37 | hr = DetectNetCoreSdk(pSearch->NetCoreSdkSearch.platform, pSearch->NetCoreSdkSearch.sczMajorVersion, wzBaseDirectory, &sczLatestVersion); |
| 115 | BextExitOnFailure(hr, "DetectNetCoreSdk failed."); | 38 | BextExitOnFailure(hr, "DetectNetCoreSdk failed."); |
| 116 | 39 | ||
| 117 | hr = pEngine->SetVariableVersion(wzVariable, sczLatestVersion); | 40 | hr = pEngine->SetVariableVersion(wzVariable, sczLatestVersion); |
| 118 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); | 41 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); |
| 119 | 42 | ||
| 120 | LExit: | 43 | LExit: |
| 44 | ReleaseStr(sczLatestVersion); | ||
| 45 | |||
| 121 | return hr; | 46 | return hr; |
| 122 | } | 47 | } |
diff --git a/src/ext/NetFx/be/detectnetcoresdkfeatureband.cpp b/src/ext/NetFx/be/detectnetcoresdkfeatureband.cpp new file mode 100644 index 00000000..d48c7a85 --- /dev/null +++ b/src/ext/NetFx/be/detectnetcoresdkfeatureband.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 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 | |||
| 5 | HRESULT DetectNetCoreSdkFeatureBand( | ||
| 6 | __in NETFX_NET_CORE_PLATFORM platform, | ||
| 7 | __in LPCWSTR wzMajorVersion, | ||
| 8 | __in LPCWSTR wzMinorVersion, | ||
| 9 | __in LPCWSTR wzPatchVersion, | ||
| 10 | __in LPCWSTR wzBaseDirectory, | ||
| 11 | __inout LPWSTR* psczLatestVersion | ||
| 12 | ) | ||
| 13 | { | ||
| 14 | HRESULT hr = S_OK; | ||
| 15 | LPWSTR sczArguments = NULL; | ||
| 16 | |||
| 17 | hr = StrAllocFormatted(&sczArguments, L"sdkfeatureband %ls %ls %ls", wzMajorVersion, wzMinorVersion, wzPatchVersion); | ||
| 18 | BextExitOnFailure(hr, "Failed to build sdkfeatureband netcoresearch.exe arguments."); | ||
| 19 | |||
| 20 | hr = RunNetCoreSearch(platform, wzBaseDirectory, sczArguments, psczLatestVersion); | ||
| 21 | BextExitOnFailure(hr, "Failed to run netcoresearch.exe for sdkfeatureband."); | ||
| 22 | |||
| 23 | LExit: | ||
| 24 | ReleaseStr(sczArguments); | ||
| 25 | |||
| 26 | return hr; | ||
| 27 | } | ||
| 28 | |||
| 29 | HRESULT NetfxPerformDetectNetCoreSdkFeatureBand( | ||
| 30 | __in LPCWSTR wzVariable, | ||
| 31 | __in NETFX_SEARCH* pSearch, | ||
| 32 | __in IBundleExtensionEngine* pEngine, | ||
| 33 | __in LPCWSTR wzBaseDirectory | ||
| 34 | ) | ||
| 35 | { | ||
| 36 | HRESULT hr = S_OK; | ||
| 37 | LPWSTR sczLatestVersion = NULL; | ||
| 38 | |||
| 39 | hr = DetectNetCoreSdkFeatureBand( | ||
| 40 | pSearch->NetCoreSdkFeatureBandSearch.platform, | ||
| 41 | pSearch->NetCoreSdkFeatureBandSearch.sczMajorVersion, | ||
| 42 | pSearch->NetCoreSdkFeatureBandSearch.sczMinorVersion, | ||
| 43 | pSearch->NetCoreSdkFeatureBandSearch.sczPatchVersion, | ||
| 44 | wzBaseDirectory, | ||
| 45 | &sczLatestVersion); | ||
| 46 | BextExitOnFailure(hr, "DetectNetCoreSdkFeatureBand failed."); | ||
| 47 | |||
| 48 | hr = pEngine->SetVariableVersion(wzVariable, sczLatestVersion); | ||
| 49 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); | ||
| 50 | |||
| 51 | LExit: | ||
| 52 | ReleaseStr(sczLatestVersion); | ||
| 53 | |||
| 54 | return hr; | ||
| 55 | } | ||
diff --git a/src/ext/NetFx/be/detectnetcoresdkfeatureband.h b/src/ext/NetFx/be/detectnetcoresdkfeatureband.h new file mode 100644 index 00000000..1f92cd58 --- /dev/null +++ b/src/ext/NetFx/be/detectnetcoresdkfeatureband.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 | |||
| 4 | HRESULT NetfxPerformDetectNetCoreSdkFeatureBand( | ||
| 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 0408da72..94026960 100644 --- a/src/ext/NetFx/be/netfxbe.vcxproj +++ b/src/ext/NetFx/be/netfxbe.vcxproj | |||
| @@ -48,20 +48,24 @@ | |||
| 48 | <ItemGroup> | 48 | <ItemGroup> |
| 49 | <ClCompile Include="detectnetcore.cpp" /> | 49 | <ClCompile Include="detectnetcore.cpp" /> |
| 50 | <ClCompile Include="detectnetcoresdk.cpp" /> | 50 | <ClCompile Include="detectnetcoresdk.cpp" /> |
| 51 | <ClCompile Include="detectnetcoresdkfeatureband.cpp" /> | ||
| 51 | <ClCompile Include="netfxbe.cpp" /> | 52 | <ClCompile Include="netfxbe.cpp" /> |
| 52 | <ClCompile Include="NetfxBundleExtension.cpp" /> | 53 | <ClCompile Include="NetfxBundleExtension.cpp" /> |
| 53 | <ClCompile Include="netfxsearch.cpp" /> | 54 | <ClCompile Include="netfxsearch.cpp" /> |
| 54 | <ClCompile Include="precomp.cpp"> | 55 | <ClCompile Include="precomp.cpp"> |
| 55 | <PrecompiledHeader>Create</PrecompiledHeader> | 56 | <PrecompiledHeader>Create</PrecompiledHeader> |
| 56 | </ClCompile> | 57 | </ClCompile> |
| 58 | <ClCompile Include="runnetcoresearch.cpp" /> | ||
| 57 | </ItemGroup> | 59 | </ItemGroup> |
| 58 | 60 | ||
| 59 | <ItemGroup> | 61 | <ItemGroup> |
| 60 | <ClInclude Include="detectnetcore.h" /> | 62 | <ClInclude Include="detectnetcore.h" /> |
| 61 | <ClInclude Include="detectnetcoresdk.h" /> | 63 | <ClInclude Include="detectnetcoresdk.h" /> |
| 64 | <ClInclude Include="detectnetcoresdkfeatureband.h" /> | ||
| 62 | <ClInclude Include="NetfxBundleExtension.h" /> | 65 | <ClInclude Include="NetfxBundleExtension.h" /> |
| 63 | <ClInclude Include="netfxsearch.h" /> | 66 | <ClInclude Include="netfxsearch.h" /> |
| 64 | <ClInclude Include="precomp.h" /> | 67 | <ClInclude Include="precomp.h" /> |
| 68 | <ClInclude Include="runnetcoresearch.h" /> | ||
| 65 | </ItemGroup> | 69 | </ItemGroup> |
| 66 | 70 | ||
| 67 | <ItemGroup> | 71 | <ItemGroup> |
diff --git a/src/ext/NetFx/be/netfxsearch.cpp b/src/ext/NetFx/be/netfxsearch.cpp index 671e7546..ffbf6ee0 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|NetFxNetCoreSdkSearch", &pixnNodes); | 18 | hr = XmlSelectNodes(pixnBundleExtension, L"NetFxNetCoreSearch|NetFxNetCoreSdkSearch|NetFxNetCoreSdkFeatureBandSearch", &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. |
| @@ -72,9 +72,30 @@ STDMETHODIMP NetfxSearchParseFromXml( | |||
| 72 | hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&netCoreSdkSearch.platform)); | 72 | hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&netCoreSdkSearch.platform)); |
| 73 | BextExitOnFailure(hr, "Failed to get @Platform."); | 73 | BextExitOnFailure(hr, "Failed to get @Platform."); |
| 74 | 74 | ||
| 75 | // @Version | 75 | // @MajorVersion |
| 76 | hr = XmlGetAttributeEx(pixnNode, L"Version", &netCoreSdkSearch.sczVersion); | 76 | hr = XmlGetAttributeEx(pixnNode, L"MajorVersion", &netCoreSdkSearch.sczMajorVersion); |
| 77 | BextExitOnFailure(hr, "Failed to get @Version."); | 77 | BextExitOnFailure(hr, "Failed to get @MajorVersion."); |
| 78 | } | ||
| 79 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"NetFxNetCoreSdkFeatureBandSearch", -1)) | ||
| 80 | { | ||
| 81 | pSearch->Type = NETFX_SEARCH_TYPE_NET_CORE_SDK_FEATURE_BAND_SEARCH; | ||
| 82 | |||
| 83 | auto& netCoreSdkSearch = pSearch->NetCoreSdkFeatureBandSearch; | ||
| 84 | // @Platform | ||
| 85 | hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&netCoreSdkSearch.platform)); | ||
| 86 | BextExitOnFailure(hr, "Failed to get @Platform."); | ||
| 87 | |||
| 88 | // @MajorVersion | ||
| 89 | hr = XmlGetAttributeEx(pixnNode, L"MajorVersion", &netCoreSdkSearch.sczMajorVersion); | ||
| 90 | BextExitOnFailure(hr, "Failed to get @MajorVersion."); | ||
| 91 | |||
| 92 | // @MinorVersion | ||
| 93 | hr = XmlGetAttributeEx(pixnNode, L"MinorVersion", &netCoreSdkSearch.sczMinorVersion); | ||
| 94 | BextExitOnFailure(hr, "Failed to get @MinorVersion."); | ||
| 95 | |||
| 96 | // @PatchVersion | ||
| 97 | hr = XmlGetAttributeEx(pixnNode, L"PatchVersion", &netCoreSdkSearch.sczPatchVersion); | ||
| 98 | BextExitOnFailure(hr, "Failed to get @PatchVersion."); | ||
| 78 | } | 99 | } |
| 79 | else | 100 | else |
| 80 | { | 101 | { |
| @@ -132,6 +153,9 @@ STDMETHODIMP NetfxSearchExecute( | |||
| 132 | case NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH: | 153 | case NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH: |
| 133 | hr = NetfxPerformDetectNetCoreSdk(wzVariable, pSearch, pEngine, wzBaseDirectory); | 154 | hr = NetfxPerformDetectNetCoreSdk(wzVariable, pSearch, pEngine, wzBaseDirectory); |
| 134 | break; | 155 | break; |
| 156 | case NETFX_SEARCH_TYPE_NET_CORE_SDK_FEATURE_BAND_SEARCH: | ||
| 157 | hr = NetfxPerformDetectNetCoreSdkFeatureBand(wzVariable, pSearch, pEngine, wzBaseDirectory); | ||
| 158 | break; | ||
| 135 | default: | 159 | default: |
| 136 | hr = E_UNEXPECTED; | 160 | hr = E_UNEXPECTED; |
| 137 | } | 161 | } |
diff --git a/src/ext/NetFx/be/netfxsearch.h b/src/ext/NetFx/be/netfxsearch.h index f4e4db01..5793dd55 100644 --- a/src/ext/NetFx/be/netfxsearch.h +++ b/src/ext/NetFx/be/netfxsearch.h | |||
| @@ -9,6 +9,7 @@ enum NETFX_SEARCH_TYPE | |||
| 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 | NETFX_SEARCH_TYPE_NET_CORE_SDK_SEARCH, |
| 12 | NETFX_SEARCH_TYPE_NET_CORE_SDK_FEATURE_BAND_SEARCH, | ||
| 12 | }; | 13 | }; |
| 13 | 14 | ||
| 14 | enum NETFX_NET_CORE_RUNTIME_TYPE | 15 | enum NETFX_NET_CORE_RUNTIME_TYPE |
| @@ -44,8 +45,15 @@ typedef struct _NETFX_SEARCH | |||
| 44 | struct | 45 | struct |
| 45 | { | 46 | { |
| 46 | NETFX_NET_CORE_PLATFORM platform; | 47 | NETFX_NET_CORE_PLATFORM platform; |
| 47 | LPWSTR sczVersion; | 48 | LPWSTR sczMajorVersion; |
| 48 | } NetCoreSdkSearch; | 49 | } NetCoreSdkSearch; |
| 50 | struct | ||
| 51 | { | ||
| 52 | NETFX_NET_CORE_PLATFORM platform; | ||
| 53 | LPWSTR sczMajorVersion; | ||
| 54 | LPWSTR sczMinorVersion; | ||
| 55 | LPWSTR sczPatchVersion; | ||
| 56 | } NetCoreSdkFeatureBandSearch; | ||
| 49 | }; | 57 | }; |
| 50 | } NETFX_SEARCH; | 58 | } NETFX_SEARCH; |
| 51 | 59 | ||
diff --git a/src/ext/NetFx/be/precomp.h b/src/ext/NetFx/be/precomp.h index 4a774200..c164834d 100644 --- a/src/ext/NetFx/be/precomp.h +++ b/src/ext/NetFx/be/precomp.h | |||
| @@ -31,4 +31,6 @@ | |||
| 31 | #include "netfxsearch.h" | 31 | #include "netfxsearch.h" |
| 32 | #include "detectnetcore.h" | 32 | #include "detectnetcore.h" |
| 33 | #include "detectnetcoresdk.h" | 33 | #include "detectnetcoresdk.h" |
| 34 | #include "detectnetcoresdkfeatureband.h" | ||
| 34 | #include "NetfxBundleExtension.h" | 35 | #include "NetfxBundleExtension.h" |
| 36 | #include "runnetcoresearch.h" | ||
diff --git a/src/ext/NetFx/be/runnetcoresearch.cpp b/src/ext/NetFx/be/runnetcoresearch.cpp new file mode 100644 index 00000000..8f38e0d2 --- /dev/null +++ b/src/ext/NetFx/be/runnetcoresearch.cpp | |||
| @@ -0,0 +1,102 @@ | |||
| 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 | |||
| 5 | HRESULT RunNetCoreSearch( | ||
| 6 | __in NETFX_NET_CORE_PLATFORM platform, | ||
| 7 | __in LPCWSTR wzBaseDirectory, | ||
| 8 | __in LPCWSTR wzArguments, | ||
| 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\" %ls", sczExePath, wzArguments); | ||
| 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 = reinterpret_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 | LPVOID pvNew = MemReAlloc(rgbOutput, cbOutput, TRUE); | ||
| 69 | BextExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to realloc output string."); | ||
| 70 | |||
| 71 | rgbOutput = reinterpret_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 | |||
| 94 | LExit: | ||
| 95 | ReleaseFileHandle(hStdOutErr); | ||
| 96 | ReleaseHandle(hProcess); | ||
| 97 | ReleaseMem(rgbOutput); | ||
| 98 | ReleaseStr(sczCommandLine); | ||
| 99 | ReleaseStr(sczExePath); | ||
| 100 | |||
| 101 | return hr; | ||
| 102 | } | ||
diff --git a/src/ext/NetFx/be/runnetcoresearch.h b/src/ext/NetFx/be/runnetcoresearch.h new file mode 100644 index 00000000..78e6b24a --- /dev/null +++ b/src/ext/NetFx/be/runnetcoresearch.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 | |||
| 4 | HRESULT RunNetCoreSearch( | ||
| 5 | __in NETFX_NET_CORE_PLATFORM platform, | ||
| 6 | __in LPCWSTR wzBaseDirectory, | ||
| 7 | __in LPCWSTR wzArguments, | ||
| 8 | __inout LPWSTR* psczLatestVersion | ||
| 9 | ); | ||
