Skip to content

Commit

Permalink
Use build-time list only
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed May 9, 2023
1 parent 80ce3f2 commit e48c8e7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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
Expand All @@ -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";

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/native/corehost/hostmisc/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/native/corehost/hostmisc/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<pal::string_t>* locations);
bool get_file_path_from_env(const pal::char_t* env_key, pal::string_t* recv);
Expand Down
54 changes: 25 additions & 29 deletions src/native/corehost/hostpolicy/deps_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,17 @@ 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")
RID_CURRENT_ARCH_LIST("unix")
#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
Expand Down Expand Up @@ -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)
{
Expand All @@ -253,20 +252,17 @@ namespace
}
}

bool try_get_matching_rid(const std::unordered_map<pal::string_t, std::vector<deps_asset_t>>& 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<pal::string_t, std::vector<deps_asset_t>>& 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
Expand Down Expand Up @@ -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)
Expand All @@ -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());
Expand Down

0 comments on commit e48c8e7

Please sign in to comment.