From e48c8e7e5f652a7431834589106aa940ecae30b6 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 9 May 2023 09:42:31 -0700 Subject: [PATCH] Use build-time list only --- .../RidAssetResolution.cs | 21 ++++---- src/native/corehost/hostmisc/utils.cpp | 7 ++- src/native/corehost/hostmisc/utils.h | 2 + .../corehost/hostpolicy/deps_format.cpp | 54 +++++++++---------- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs b/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs index 55a990f4280e7..ebabc7ae4f2d4 100644 --- a/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs +++ b/src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs @@ -102,7 +102,7 @@ private void RidSpecificAssemblyImpl(TestSetup setup, string includedPath, strin [InlineData("win10-x64", WindowsAssembly, $"{LinuxAssembly};{MacOSAssembly}")] [InlineData("linux-x64", LinuxAssembly, $"{MacOSAssembly};{WindowsAssembly}")] [InlineData("osx-x64", MacOSAssembly, $"{LinuxAssembly};{WindowsAssembly}")] - public void RidSpecificAssembly(string rid, string includedPath, string excludedPath) + public void RidSpecificAssembly_RidGraph(string rid, string includedPath, string excludedPath) { RidSpecificAssemblyImpl( new TestSetup() { Rid = rid, HasRuntimeFallbacks = true, ReadRidGraph = true }, @@ -190,7 +190,7 @@ private void RidSpecificNativeLibraryImpl(TestSetup setup, string includedPath, [InlineData("win10-x64", "win", "linux;osx")] [InlineData("linux-x64", "linux", "osx;win")] [InlineData("osx-x64", "osx", "linux;win")] - public void RidSpecificNativeLibrary(string rid, string includedPath, string excludedPath) + public void RidSpecificNativeLibrary_RidGraph(string rid, string includedPath, string excludedPath) { RidSpecificNativeLibraryImpl( new TestSetup() { Rid = rid, HasRuntimeFallbacks = true, ReadRidGraph = true }, @@ -265,7 +265,7 @@ public void RidSpecificNativeLibrary_UnknownRid(bool? readRidGraph) [InlineData("win10-x64", "win-x64/ManagedWin64.dll")] [InlineData("win10-x86", "win/ManagedWin.dll")] [InlineData("linux-x64", "any/ManagedAny.dll")] - public void MostSpecificRidAssemblySelected(string rid, string expectedPath) + public void MostSpecificRidAssemblySelected_RidGraph(string rid, string expectedPath) { RunTest( p => p @@ -276,6 +276,7 @@ public void MostSpecificRidAssemblySelected(string rid, string expectedPath) new ResolvedPaths() { IncludedAssemblyPaths = expectedPath }); } + // The build RID from the test context should match the build RID of the host under test private static string CurrentRid = RepoDirectoriesProvider.Default.BuildRID; private static string CurrentRidAsset = $"{CurrentRid}/{CurrentRid}Asset.dll"; @@ -300,7 +301,7 @@ public void MostSpecificRidAssemblySelected(string rid, string expectedPath) [InlineData(false, false, true)] [InlineData(false, false, false)] [InlineData(false, false, null)] - public void MostSpecificRidAssemblySelected_ComputedRid(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph) + public void MostSpecificRidAssemblySelected(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph) { // When not using the RID graph, the host uses the target OS for which it was built to determine applicable // RIDs that apply, so it can find both the arch-specific and the OS-only assets. @@ -339,7 +340,7 @@ public void MostSpecificRidAssemblySelected_ComputedRid(bool includeCurrentArch, [InlineData("win10-x64", "win-x64")] [InlineData("win10-x86", "win")] [InlineData("linux-x64", "any")] - public void MostSpecificRidNativeLibrarySelected(string rid, string expectedPath) + public void MostSpecificRidNativeLibrarySelected_RidGraph(string rid, string expectedPath) { RunTest( p => p @@ -363,7 +364,7 @@ public void MostSpecificRidNativeLibrarySelected(string rid, string expectedPath [InlineData(false, false, true)] [InlineData(false, false, false)] [InlineData(false, false, null)] - public void MostSpecificRidNativeLibrarySelected_ComputedRid(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph) + public void MostSpecificRidNativeLibrarySelected(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph) { // When not using the RID graph, the host uses the target OS for which it was built to determine applicable // RIDs that apply, so it can find both the arch-specific and the OS-only assets. @@ -402,7 +403,7 @@ public void MostSpecificRidNativeLibrarySelected_ComputedRid(bool includeCurrent [InlineData("win10-x64", "win/ManagedWin.dll", "native/win-x64")] [InlineData("win10-x86", "win/ManagedWin.dll", "native/win-x86")] [InlineData("linux-x64", "any/ManagedAny.dll", "native/linux")] - public void MostSpecificRidAssemblySelectedPerType(string rid, string expectedAssemblyPath, string expectedNativePath) + public void MostSpecificRidAssemblySelectedPerType_RidGraph(string rid, string expectedAssemblyPath, string expectedNativePath) { RunTest( p => p @@ -422,7 +423,7 @@ public void MostSpecificRidAssemblySelectedPerType(string rid, string expectedAs [InlineData(false, true)] [InlineData(false, false)] [InlineData(false, null)] - public void MostSpecificRidAssemblySelectedPerType_ComputedRid(bool hasRuntimeFallbacks, bool? readRidGraph) + public void MostSpecificRidAssemblySelectedPerType(bool hasRuntimeFallbacks, bool? readRidGraph) { // When not using the RID graph, the host uses the target OS for which it was built to determine applicable // RIDs that apply, so it can find both the arch-specific and the OS-only assets. @@ -462,7 +463,7 @@ public void MostSpecificRidAssemblySelectedPerType_ComputedRid(bool hasRuntimeFa // For "linux" on the other hand the DependencyLib will be resolved because there are // no RID-specific assembly assets available. [InlineData("linux-x64", "DependencyLib.dll", "native/linux")] - public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(string rid, string expectedAssemblyPath, string expectedNativePath) + public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets_RidGraph(string rid, string expectedAssemblyPath, string expectedNativePath) { RunTest( assetsCustomizer: null, @@ -496,7 +497,7 @@ public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(string rid, str [InlineData(false, true)] [InlineData(false, false)] [InlineData(false, null)] - public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets_ComputedRid(bool hasRuntimeFallbacks, bool? readRidGraph) + public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(bool hasRuntimeFallbacks, bool? readRidGraph) { // When not using the RID graph, the host uses the target OS for which it was built to determine applicable // RIDs that apply, so it can find both the arch-specific and the OS-only assets. diff --git a/src/native/corehost/hostmisc/utils.cpp b/src/native/corehost/hostmisc/utils.cpp index c452d9d7525bb..81245a1d85b45 100644 --- a/src/native/corehost/hostmisc/utils.cpp +++ b/src/native/corehost/hostmisc/utils.cpp @@ -252,7 +252,7 @@ const pal::char_t* get_current_arch_name() pal::string_t get_current_runtime_id(bool use_fallback) { pal::string_t rid; - if (pal::getenv(_X("DOTNET_RUNTIME_ID"), &rid)) + if (try_get_runtime_id_from_env(rid)) return rid; rid = pal::get_current_os_rid_platform(); @@ -268,6 +268,11 @@ pal::string_t get_current_runtime_id(bool use_fallback) return rid; } +bool try_get_runtime_id_from_env(pal::string_t& out_rid) +{ + return pal::getenv(_X("DOTNET_RUNTIME_ID"), &out_rid); +} + /** * Multilevel Lookup is enabled by default * It can be disabled by setting DOTNET_MULTILEVEL_LOOKUP env var to a value that is not 1 diff --git a/src/native/corehost/hostmisc/utils.h b/src/native/corehost/hostmisc/utils.h index b890265029aa4..564bffa235d1b 100644 --- a/src/native/corehost/hostmisc/utils.h +++ b/src/native/corehost/hostmisc/utils.h @@ -89,6 +89,8 @@ const pal::char_t* get_arch_name(pal::architecture arch); const pal::char_t* get_current_arch_name(); pal::string_t get_current_runtime_id(bool use_fallback); +bool try_get_runtime_id_from_env(pal::string_t& out_rid); + bool multilevel_lookup_enabled(); void get_framework_and_sdk_locations(const pal::string_t& dotnet_dir, const bool disable_multilevel_lookup, std::vector* locations); bool get_file_path_from_env(const pal::char_t* env_key, pal::string_t* recv); diff --git a/src/native/corehost/hostpolicy/deps_format.cpp b/src/native/corehost/hostpolicy/deps_format.cpp index 44645b265d7f5..774a58cf1e321 100644 --- a/src/native/corehost/hostpolicy/deps_format.cpp +++ b/src/native/corehost/hostpolicy/deps_format.cpp @@ -194,10 +194,6 @@ namespace #elif defined(TARGET_OSX) RID_CURRENT_ARCH_LIST("osx") RID_CURRENT_ARCH_LIST("unix") -#elif defined(TARGET_LINUX_MUSL) - RID_CURRENT_ARCH_LIST("linux-musl") - RID_CURRENT_ARCH_LIST("linux") - RID_CURRENT_ARCH_LIST("unix") #elif defined(TARGET_ANDROID) RID_CURRENT_ARCH_LIST("linux-bionic") RID_CURRENT_ARCH_LIST("linux") @@ -205,7 +201,10 @@ namespace #else // Covers non-portable RIDs RID_CURRENT_ARCH_LIST(FALLBACK_HOST_OS) -#ifndef FALLBACK_OS_IS_SAME_AS_TARGET_OS +#if defined(TARGET_LINUX_MUSL) + RID_CURRENT_ARCH_LIST("linux-musl") + RID_CURRENT_ARCH_LIST("linux") +#elif !defined(FALLBACK_OS_IS_SAME_AS_TARGET_OS) // Covers "linux" and non-linux like "freebsd", "illumos" RID_CURRENT_ARCH_LIST(CURRENT_OS_NAME) #endif @@ -236,14 +235,14 @@ namespace return currentRid; } - void print_host_rid_list(const pal::string_t& host_rid, const pal::string_t& host_rid_no_arch) + void print_host_rid_list() { if (trace::is_enabled()) { trace::verbose(_X("Host RID list = [")); - trace::verbose(_X(" %s,"), host_rid.c_str()); - if (!host_rid_no_arch.empty()) - trace::verbose(_X(" %s,"), host_rid_no_arch.c_str()); + pal::string_t env_rid; + if (try_get_runtime_id_from_env(env_rid)) + trace::verbose(_X(" %s,"), env_rid.c_str()); for (const pal::char_t* rid : s_host_rids) { @@ -253,20 +252,17 @@ namespace } } - bool try_get_matching_rid(const std::unordered_map>& rid_assets, const pal::string_t& host_rid, const pal::string_t& host_rid_no_arch, pal::string_t& out_rid) + bool try_get_matching_rid(const std::unordered_map>& rid_assets, pal::string_t& out_rid) { - // Check for exact match with the host RID - if (rid_assets.count(host_rid) != 0) - { - out_rid = host_rid; - return true; - } - - // Host RID without architecture - if (!host_rid_no_arch.empty() && rid_assets.count(host_rid_no_arch) != 0) + // Check for match with environment variable RID value + pal::string_t env_rid; + if (try_get_runtime_id_from_env(env_rid)) { - out_rid = host_rid_no_arch; - return true; + if (rid_assets.count(env_rid) != 0) + { + out_rid = env_rid; + return true; + } } // Use our list of known portable RIDs @@ -322,15 +318,15 @@ namespace void deps_json_t::perform_rid_fallback(rid_specific_assets_t* portable_assets) { assert(!m_rid_resolution_options.use_fallback_graph || m_rid_resolution_options.rid_fallback_graph != nullptr); - const pal::string_t host_rid = get_current_rid(m_rid_resolution_options.rid_fallback_graph); - pal::string_t host_rid_no_arch; - if (!m_rid_resolution_options.use_fallback_graph) + pal::string_t host_rid; + if (m_rid_resolution_options.use_fallback_graph) { - if (ends_with(host_rid, CURRENT_ARCH_SUFFIX, true)) - host_rid_no_arch = host_rid.substr(0, host_rid.size() - STRING_LENGTH(CURRENT_ARCH_SUFFIX)); - - print_host_rid_list(host_rid, host_rid_no_arch); + host_rid = get_current_rid(m_rid_resolution_options.rid_fallback_graph); + } + else + { + print_host_rid_list(); } for (auto& package : portable_assets->libs) @@ -345,7 +341,7 @@ void deps_json_t::perform_rid_fallback(rid_specific_assets_t* portable_assets) pal::string_t matched_rid; bool found_match = m_rid_resolution_options.use_fallback_graph ? try_get_matching_rid_with_fallback_graph(rid_assets, host_rid, *m_rid_resolution_options.rid_fallback_graph, matched_rid) - : try_get_matching_rid(rid_assets, host_rid, host_rid_no_arch, matched_rid); + : try_get_matching_rid(rid_assets, matched_rid); if (!found_match) { trace::verbose(_X(" No matching %s assets for package %s"), deps_entry_t::s_known_asset_types[asset_type_index], package.first.c_str());