summaryrefslogtreecommitdiff
path: root/modules/mono/build_scripts
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-08-20 01:48:25 +0200
committerIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-08-22 03:36:51 +0200
commit315636e77c1cd9d39f5ca9c1eed7c60a4653afa7 (patch)
tree2c98af54e0a7d845ba3eaeb3f25a6a990f015b9c /modules/mono/build_scripts
parentf9a67ee9da1d6cc3562fa5a7443a2a66a673bd8c (diff)
C#: Fallback to `dotnet --info` to determine .NET RID
Some Linux distros use their distro name as the RID for directory names. If the .NET Host directory cannot be found with the generic RID, try to get the rid from `dotnet --info`. The generic RID should still be the first choice. Some platforms like Windows 10 define the RID as `win10-x64` but still use the generic `win-x64` for directory names. Co-authored-by: Lewis James <lewiji+github@gmail.com>
Diffstat (limited to 'modules/mono/build_scripts')
-rw-r--r--modules/mono/build_scripts/mono_configure.py54
1 files changed, 45 insertions, 9 deletions
diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py
index 071693d758..ca2fd9ba3c 100644
--- a/modules/mono/build_scripts/mono_configure.py
+++ b/modules/mono/build_scripts/mono_configure.py
@@ -96,15 +96,26 @@ def find_dotnet_app_host_dir(env):
if not app_host_version:
raise RuntimeError("Cannot find .NET app host for version: " + app_host_search_version)
- app_host_dir = os.path.join(
- dotnet_root,
- "packs",
- "Microsoft.NETCore.App.Host." + runtime_identifier,
- app_host_version,
- "runtimes",
- runtime_identifier,
- "native",
- )
+ def get_runtime_path():
+ return os.path.join(
+ dotnet_root,
+ "packs",
+ "Microsoft.NETCore.App.Host." + runtime_identifier,
+ app_host_version,
+ "runtimes",
+ runtime_identifier,
+ "native",
+ )
+
+ app_host_dir = get_runtime_path()
+
+ # Some Linux distros use their distro name as the RID in these paths.
+ # If the initial generic path doesn't exist, try to get the RID from `dotnet --info`.
+ # The generic RID should still be the first choice. Some platforms like Windows 10
+ # define the RID as `win10-x64` but still use the generic `win-x64` for directory names.
+ if not app_host_dir or not os.path.isdir(app_host_dir):
+ runtime_identifier = find_dotnet_cli_rid(dotnet_cmd)
+ app_host_dir = get_runtime_path()
return app_host_dir
@@ -160,6 +171,31 @@ def find_app_host_version(dotnet_cmd, search_version):
return ""
+def find_dotnet_cli_rid(dotnet_cmd):
+ import subprocess
+
+ try:
+ env = dict(os.environ, DOTNET_CLI_UI_LANGUAGE="en-US")
+ lines = subprocess.check_output([dotnet_cmd, "--info"], env=env).splitlines()
+
+ for line_bytes in lines:
+ line = line_bytes.decode("utf-8")
+ if not line.startswith(" RID:"):
+ continue
+
+ parts = line.split()
+ if len(parts) < 2:
+ continue
+
+ return parts[1]
+ except (subprocess.CalledProcessError, OSError) as e:
+ import sys
+
+ print(e, file=sys.stderr)
+
+ return ""
+
+
ENV_PATH_SEP = ";" if os.name == "nt" else ":"