Skip to content

Commit e48c8e7

Browse files
committed
Use build-time list only
1 parent 80ce3f2 commit e48c8e7

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

src/installer/tests/HostActivation.Tests/DependencyResolution/RidAssetResolution.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void RidSpecificAssemblyImpl(TestSetup setup, string includedPath, strin
102102
[InlineData("win10-x64", WindowsAssembly, $"{LinuxAssembly};{MacOSAssembly}")]
103103
[InlineData("linux-x64", LinuxAssembly, $"{MacOSAssembly};{WindowsAssembly}")]
104104
[InlineData("osx-x64", MacOSAssembly, $"{LinuxAssembly};{WindowsAssembly}")]
105-
public void RidSpecificAssembly(string rid, string includedPath, string excludedPath)
105+
public void RidSpecificAssembly_RidGraph(string rid, string includedPath, string excludedPath)
106106
{
107107
RidSpecificAssemblyImpl(
108108
new TestSetup() { Rid = rid, HasRuntimeFallbacks = true, ReadRidGraph = true },
@@ -190,7 +190,7 @@ private void RidSpecificNativeLibraryImpl(TestSetup setup, string includedPath,
190190
[InlineData("win10-x64", "win", "linux;osx")]
191191
[InlineData("linux-x64", "linux", "osx;win")]
192192
[InlineData("osx-x64", "osx", "linux;win")]
193-
public void RidSpecificNativeLibrary(string rid, string includedPath, string excludedPath)
193+
public void RidSpecificNativeLibrary_RidGraph(string rid, string includedPath, string excludedPath)
194194
{
195195
RidSpecificNativeLibraryImpl(
196196
new TestSetup() { Rid = rid, HasRuntimeFallbacks = true, ReadRidGraph = true },
@@ -265,7 +265,7 @@ public void RidSpecificNativeLibrary_UnknownRid(bool? readRidGraph)
265265
[InlineData("win10-x64", "win-x64/ManagedWin64.dll")]
266266
[InlineData("win10-x86", "win/ManagedWin.dll")]
267267
[InlineData("linux-x64", "any/ManagedAny.dll")]
268-
public void MostSpecificRidAssemblySelected(string rid, string expectedPath)
268+
public void MostSpecificRidAssemblySelected_RidGraph(string rid, string expectedPath)
269269
{
270270
RunTest(
271271
p => p
@@ -276,6 +276,7 @@ public void MostSpecificRidAssemblySelected(string rid, string expectedPath)
276276
new ResolvedPaths() { IncludedAssemblyPaths = expectedPath });
277277
}
278278

279+
// The build RID from the test context should match the build RID of the host under test
279280
private static string CurrentRid = RepoDirectoriesProvider.Default.BuildRID;
280281
private static string CurrentRidAsset = $"{CurrentRid}/{CurrentRid}Asset.dll";
281282

@@ -300,7 +301,7 @@ public void MostSpecificRidAssemblySelected(string rid, string expectedPath)
300301
[InlineData(false, false, true)]
301302
[InlineData(false, false, false)]
302303
[InlineData(false, false, null)]
303-
public void MostSpecificRidAssemblySelected_ComputedRid(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph)
304+
public void MostSpecificRidAssemblySelected(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph)
304305
{
305306
// When not using the RID graph, the host uses the target OS for which it was built to determine applicable
306307
// 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,
339340
[InlineData("win10-x64", "win-x64")]
340341
[InlineData("win10-x86", "win")]
341342
[InlineData("linux-x64", "any")]
342-
public void MostSpecificRidNativeLibrarySelected(string rid, string expectedPath)
343+
public void MostSpecificRidNativeLibrarySelected_RidGraph(string rid, string expectedPath)
343344
{
344345
RunTest(
345346
p => p
@@ -363,7 +364,7 @@ public void MostSpecificRidNativeLibrarySelected(string rid, string expectedPath
363364
[InlineData(false, false, true)]
364365
[InlineData(false, false, false)]
365366
[InlineData(false, false, null)]
366-
public void MostSpecificRidNativeLibrarySelected_ComputedRid(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph)
367+
public void MostSpecificRidNativeLibrarySelected(bool includeCurrentArch, bool hasRuntimeFallbacks, bool? readRidGraph)
367368
{
368369
// When not using the RID graph, the host uses the target OS for which it was built to determine applicable
369370
// 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
402403
[InlineData("win10-x64", "win/ManagedWin.dll", "native/win-x64")]
403404
[InlineData("win10-x86", "win/ManagedWin.dll", "native/win-x86")]
404405
[InlineData("linux-x64", "any/ManagedAny.dll", "native/linux")]
405-
public void MostSpecificRidAssemblySelectedPerType(string rid, string expectedAssemblyPath, string expectedNativePath)
406+
public void MostSpecificRidAssemblySelectedPerType_RidGraph(string rid, string expectedAssemblyPath, string expectedNativePath)
406407
{
407408
RunTest(
408409
p => p
@@ -422,7 +423,7 @@ public void MostSpecificRidAssemblySelectedPerType(string rid, string expectedAs
422423
[InlineData(false, true)]
423424
[InlineData(false, false)]
424425
[InlineData(false, null)]
425-
public void MostSpecificRidAssemblySelectedPerType_ComputedRid(bool hasRuntimeFallbacks, bool? readRidGraph)
426+
public void MostSpecificRidAssemblySelectedPerType(bool hasRuntimeFallbacks, bool? readRidGraph)
426427
{
427428
// When not using the RID graph, the host uses the target OS for which it was built to determine applicable
428429
// 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
462463
// For "linux" on the other hand the DependencyLib will be resolved because there are
463464
// no RID-specific assembly assets available.
464465
[InlineData("linux-x64", "DependencyLib.dll", "native/linux")]
465-
public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(string rid, string expectedAssemblyPath, string expectedNativePath)
466+
public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets_RidGraph(string rid, string expectedAssemblyPath, string expectedNativePath)
466467
{
467468
RunTest(
468469
assetsCustomizer: null,
@@ -496,7 +497,7 @@ public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(string rid, str
496497
[InlineData(false, true)]
497498
[InlineData(false, false)]
498499
[InlineData(false, null)]
499-
public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets_ComputedRid(bool hasRuntimeFallbacks, bool? readRidGraph)
500+
public void MostSpecificRidAssemblySelectedPerTypeMultipleAssets(bool hasRuntimeFallbacks, bool? readRidGraph)
500501
{
501502
// When not using the RID graph, the host uses the target OS for which it was built to determine applicable
502503
// RIDs that apply, so it can find both the arch-specific and the OS-only assets.

src/native/corehost/hostmisc/utils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const pal::char_t* get_current_arch_name()
252252
pal::string_t get_current_runtime_id(bool use_fallback)
253253
{
254254
pal::string_t rid;
255-
if (pal::getenv(_X("DOTNET_RUNTIME_ID"), &rid))
255+
if (try_get_runtime_id_from_env(rid))
256256
return rid;
257257

258258
rid = pal::get_current_os_rid_platform();
@@ -268,6 +268,11 @@ pal::string_t get_current_runtime_id(bool use_fallback)
268268
return rid;
269269
}
270270

271+
bool try_get_runtime_id_from_env(pal::string_t& out_rid)
272+
{
273+
return pal::getenv(_X("DOTNET_RUNTIME_ID"), &out_rid);
274+
}
275+
271276
/**
272277
* Multilevel Lookup is enabled by default
273278
* It can be disabled by setting DOTNET_MULTILEVEL_LOOKUP env var to a value that is not 1

src/native/corehost/hostmisc/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const pal::char_t* get_arch_name(pal::architecture arch);
8989
const pal::char_t* get_current_arch_name();
9090

9191
pal::string_t get_current_runtime_id(bool use_fallback);
92+
bool try_get_runtime_id_from_env(pal::string_t& out_rid);
93+
9294
bool multilevel_lookup_enabled();
9395
void get_framework_and_sdk_locations(const pal::string_t& dotnet_dir, const bool disable_multilevel_lookup, std::vector<pal::string_t>* locations);
9496
bool get_file_path_from_env(const pal::char_t* env_key, pal::string_t* recv);

src/native/corehost/hostpolicy/deps_format.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,17 @@ namespace
194194
#elif defined(TARGET_OSX)
195195
RID_CURRENT_ARCH_LIST("osx")
196196
RID_CURRENT_ARCH_LIST("unix")
197-
#elif defined(TARGET_LINUX_MUSL)
198-
RID_CURRENT_ARCH_LIST("linux-musl")
199-
RID_CURRENT_ARCH_LIST("linux")
200-
RID_CURRENT_ARCH_LIST("unix")
201197
#elif defined(TARGET_ANDROID)
202198
RID_CURRENT_ARCH_LIST("linux-bionic")
203199
RID_CURRENT_ARCH_LIST("linux")
204200
RID_CURRENT_ARCH_LIST("unix")
205201
#else
206202
// Covers non-portable RIDs
207203
RID_CURRENT_ARCH_LIST(FALLBACK_HOST_OS)
208-
#ifndef FALLBACK_OS_IS_SAME_AS_TARGET_OS
204+
#if defined(TARGET_LINUX_MUSL)
205+
RID_CURRENT_ARCH_LIST("linux-musl")
206+
RID_CURRENT_ARCH_LIST("linux")
207+
#elif !defined(FALLBACK_OS_IS_SAME_AS_TARGET_OS)
209208
// Covers "linux" and non-linux like "freebsd", "illumos"
210209
RID_CURRENT_ARCH_LIST(CURRENT_OS_NAME)
211210
#endif
@@ -236,14 +235,14 @@ namespace
236235
return currentRid;
237236
}
238237

239-
void print_host_rid_list(const pal::string_t& host_rid, const pal::string_t& host_rid_no_arch)
238+
void print_host_rid_list()
240239
{
241240
if (trace::is_enabled())
242241
{
243242
trace::verbose(_X("Host RID list = ["));
244-
trace::verbose(_X(" %s,"), host_rid.c_str());
245-
if (!host_rid_no_arch.empty())
246-
trace::verbose(_X(" %s,"), host_rid_no_arch.c_str());
243+
pal::string_t env_rid;
244+
if (try_get_runtime_id_from_env(env_rid))
245+
trace::verbose(_X(" %s,"), env_rid.c_str());
247246

248247
for (const pal::char_t* rid : s_host_rids)
249248
{
@@ -253,20 +252,17 @@ namespace
253252
}
254253
}
255254

256-
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)
255+
bool try_get_matching_rid(const std::unordered_map<pal::string_t, std::vector<deps_asset_t>>& rid_assets, pal::string_t& out_rid)
257256
{
258-
// Check for exact match with the host RID
259-
if (rid_assets.count(host_rid) != 0)
260-
{
261-
out_rid = host_rid;
262-
return true;
263-
}
264-
265-
// Host RID without architecture
266-
if (!host_rid_no_arch.empty() && rid_assets.count(host_rid_no_arch) != 0)
257+
// Check for match with environment variable RID value
258+
pal::string_t env_rid;
259+
if (try_get_runtime_id_from_env(env_rid))
267260
{
268-
out_rid = host_rid_no_arch;
269-
return true;
261+
if (rid_assets.count(env_rid) != 0)
262+
{
263+
out_rid = env_rid;
264+
return true;
265+
}
270266
}
271267

272268
// Use our list of known portable RIDs
@@ -322,15 +318,15 @@ namespace
322318
void deps_json_t::perform_rid_fallback(rid_specific_assets_t* portable_assets)
323319
{
324320
assert(!m_rid_resolution_options.use_fallback_graph || m_rid_resolution_options.rid_fallback_graph != nullptr);
325-
const pal::string_t host_rid = get_current_rid(m_rid_resolution_options.rid_fallback_graph);
326321

327-
pal::string_t host_rid_no_arch;
328-
if (!m_rid_resolution_options.use_fallback_graph)
322+
pal::string_t host_rid;
323+
if (m_rid_resolution_options.use_fallback_graph)
329324
{
330-
if (ends_with(host_rid, CURRENT_ARCH_SUFFIX, true))
331-
host_rid_no_arch = host_rid.substr(0, host_rid.size() - STRING_LENGTH(CURRENT_ARCH_SUFFIX));
332-
333-
print_host_rid_list(host_rid, host_rid_no_arch);
325+
host_rid = get_current_rid(m_rid_resolution_options.rid_fallback_graph);
326+
}
327+
else
328+
{
329+
print_host_rid_list();
334330
}
335331

336332
for (auto& package : portable_assets->libs)
@@ -345,7 +341,7 @@ void deps_json_t::perform_rid_fallback(rid_specific_assets_t* portable_assets)
345341
pal::string_t matched_rid;
346342
bool found_match = m_rid_resolution_options.use_fallback_graph
347343
? try_get_matching_rid_with_fallback_graph(rid_assets, host_rid, *m_rid_resolution_options.rid_fallback_graph, matched_rid)
348-
: try_get_matching_rid(rid_assets, host_rid, host_rid_no_arch, matched_rid);
344+
: try_get_matching_rid(rid_assets, matched_rid);
349345
if (!found_match)
350346
{
351347
trace::verbose(_X(" No matching %s assets for package %s"), deps_entry_t::s_known_asset_types[asset_type_index], package.first.c_str());

0 commit comments

Comments
 (0)