summaryrefslogtreecommitdiff
path: root/modules/mono
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2021-12-28 23:25:16 +0100
committerIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-08-22 03:36:51 +0200
commitf16c8e3759a636cdc55c8beda998a3c3ba63e3af (patch)
tree7f3bc112dcbc6ed81547fe429d0ea52b2a646ffe /modules/mono
parent315636e77c1cd9d39f5ca9c1eed7c60a4653afa7 (diff)
Fix detection of .NET Sdk from snap and allow higher versions
Diffstat (limited to 'modules/mono')
-rw-r--r--modules/mono/build_scripts/mono_configure.py77
1 files changed, 60 insertions, 17 deletions
diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py
index ca2fd9ba3c..5d2030f756 100644
--- a/modules/mono/build_scripts/mono_configure.py
+++ b/modules/mono/build_scripts/mono_configure.py
@@ -73,15 +73,19 @@ def configure(env, env_mono):
def find_dotnet_app_host_dir(env):
+ dotnet_version = "5.0"
+
dotnet_root = env["dotnet_root"]
if not dotnet_root:
- dotnet_exe = find_executable("dotnet")
- if dotnet_exe:
- dotnet_exe_realpath = os.path.realpath(dotnet_exe) # Eliminate symbolic links
- dotnet_root = os.path.abspath(os.path.join(dotnet_exe_realpath, os.pardir))
- else:
- raise RuntimeError("Cannot find .NET Core Sdk")
+ dotnet_cmd = find_executable("dotnet")
+ if dotnet_cmd:
+ sdk_path = find_dotnet_sdk(dotnet_cmd, dotnet_version)
+ if sdk_path:
+ dotnet_root = os.path.abspath(os.path.join(sdk_path, os.pardir))
+
+ if not dotnet_root:
+ raise RuntimeError("Cannot find .NET Core Sdk")
print("Found .NET Core Sdk root directory: " + dotnet_root)
@@ -91,10 +95,9 @@ def find_dotnet_app_host_dir(env):
# TODO: In the future, if it can't be found this way, we want to obtain it
# from the runtime.{runtime_identifier}.Microsoft.NETCore.DotNetAppHost NuGet package.
- app_host_search_version = "5.0"
- app_host_version = find_app_host_version(dotnet_cmd, app_host_search_version)
+ app_host_version = find_app_host_version(dotnet_cmd, dotnet_version)
if not app_host_version:
- raise RuntimeError("Cannot find .NET app host for version: " + app_host_search_version)
+ raise RuntimeError("Cannot find .NET app host for version: " + dotnet_version)
def get_runtime_path():
return os.path.join(
@@ -146,8 +149,11 @@ def determine_runtime_identifier(env):
raise NotImplementedError()
-def find_app_host_version(dotnet_cmd, search_version):
+def find_app_host_version(dotnet_cmd, search_version_str):
import subprocess
+ from distutils.version import LooseVersion
+
+ search_version = LooseVersion(search_version_str)
try:
lines = subprocess.check_output([dotnet_cmd, "--list-runtimes"]).splitlines()
@@ -157,17 +163,54 @@ def find_app_host_version(dotnet_cmd, search_version):
if not line.startswith("Microsoft.NETCore.App "):
continue
- parts = line.split(" ")
+ parts = line.split(" ", 2)
+ if len(parts) < 3:
+ continue
+
+ version_str = parts[1]
+
+ version = LooseVersion(version_str)
+
+ if version >= search_version:
+ return version_str
+ except (subprocess.CalledProcessError, OSError) as e:
+ import sys
+
+ print(e, file=sys.stderr)
+
+ return ""
+
+
+def find_dotnet_sdk(dotnet_cmd, search_version_str):
+ import subprocess
+ from distutils.version import LooseVersion
+
+ search_version = LooseVersion(search_version_str)
+
+ try:
+ lines = subprocess.check_output([dotnet_cmd, "--list-sdks"]).splitlines()
+
+ for line_bytes in lines:
+ line = line_bytes.decode("utf-8")
+
+ parts = line.split(" ", 1)
if len(parts) < 2:
continue
- version = parts[1]
+ version_str = parts[0]
+
+ version = LooseVersion(version_str)
+
+ if version < search_version:
+ continue
+
+ path_part = parts[1]
+ return path_part[1 : path_part.find("]")]
+ except (subprocess.CalledProcessError, OSError) as e:
+ import sys
+
+ print(e, file=sys.stderr)
- # Look for 6.0.0 or 6.0.0-*
- if version.startswith(search_version + "."):
- return version
- except (subprocess.CalledProcessError, OSError):
- pass
return ""