Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clr_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_coreclr_command_line(
*,
entry_dll: StrOrPath,
dotnet_root: Optional[StrOrPath] = None,
properties: Optional[Dict[str, str]] = None
properties: Optional[Dict[str, str]] = None,
) -> Runtime:
"""Get a CoreCLR (.NET Core) runtime instance
The returned ``DotnetCoreRuntimeCommandLine`` also acts as a mapping of the config
Expand All @@ -178,7 +178,9 @@ def get_coreclr_command_line(
if dotnet_root is None:
dotnet_root = find_dotnet_root()

impl = DotnetCoreCommandRuntime(entry_dll=_maybe_path(entry_dll), dotnet_root=dotnet_root)
impl = DotnetCoreCommandRuntime(
entry_dll=_maybe_path(entry_dll), dotnet_root=dotnet_root
)
if properties:
for key, value in properties.items():
impl[key] = value
Expand Down
9 changes: 5 additions & 4 deletions clr_loader/ffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def load_hostfxr(dotnet_root: Path):
hostfxr_name = _get_dll_name("hostfxr")
dotnet_root = dotnet_root.absolute()

# This will fail as soon as .NET hits version 10, but hopefully by then
# we'll have a more robust way of finding the libhostfxr
# Find all hostfxr versions by looking for the library file in version subdirectories
hostfxr_path = dotnet_root / "host" / "fxr"
hostfxr_paths = hostfxr_path.glob(f"?.*/{hostfxr_name}")
hostfxr_paths = hostfxr_path.glob(f"*/{hostfxr_name}")

error_report = list()

Expand Down Expand Up @@ -69,7 +68,9 @@ def load_netfx():
def _path_to_version(path: Path) -> Tuple[int, int, int]:
name = path.parent.name
try:
res = list(map(int, name.split(".")))
# Handle pre-release versions like "10.0.0-rc.1" by taking only the version part
version_part = name.split("-")[0]
res = list(map(int, version_part.split(".")))
return tuple(res + [0, 0, 0])[:3]
except Exception:
return (0, 0, 0)
Expand Down
20 changes: 13 additions & 7 deletions clr_loader/hostfxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def info(self):
class DotnetCoreRuntime(DotnetCoreRuntimeBase):
def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str):
super().__init__(dotnet_root)
self._handle = _get_handle_for_runtime_config(self._dll, self._dotnet_root, runtime_config)
self._handle = _get_handle_for_runtime_config(
self._dll, self._dotnet_root, runtime_config
)

for key, value in params.items():
self[key] = value
Expand All @@ -132,7 +134,9 @@ def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str):
class DotnetCoreCommandRuntime(DotnetCoreRuntimeBase):
def __init__(self, entry_dll: Path, dotnet_root: Path, **params: str):
super().__init__(dotnet_root)
self._handle = _get_handle_for_dotnet_command_line(self._dll, self._dotnet_root, entry_dll)
self._handle = _get_handle_for_dotnet_command_line(
self._dll, self._dotnet_root, entry_dll
)

for key, value in params.items():
self[key] = value
Expand All @@ -141,7 +145,9 @@ def __init__(self, entry_dll: Path, dotnet_root: Path, **params: str):
self._version = "<undefined>"


def _get_handle_for_runtime_config(dll, dotnet_root: StrOrPath, runtime_config: StrOrPath):
def _get_handle_for_runtime_config(
dll, dotnet_root: StrOrPath, runtime_config: StrOrPath
):
params = ffi.new("hostfxr_initialize_parameters*")
params.size = ffi.sizeof("hostfxr_initialize_parameters")
# params.host_path = ffi.new("char_t[]", encode(sys.executable))
Expand All @@ -159,7 +165,9 @@ def _get_handle_for_runtime_config(dll, dotnet_root: StrOrPath, runtime_config:
return handle_ptr[0]


def _get_handle_for_dotnet_command_line(dll, dotnet_root: StrOrPath, entry_dll: StrOrPath):
def _get_handle_for_dotnet_command_line(
dll, dotnet_root: StrOrPath, entry_dll: StrOrPath
):
params = ffi.new("hostfxr_initialize_parameters*")
params.size = ffi.sizeof("hostfxr_initialize_parameters")
params.host_path = ffi.NULL
Expand All @@ -172,9 +180,7 @@ def _get_handle_for_dotnet_command_line(dll, dotnet_root: StrOrPath, entry_dll:
arg_ptr = ffi.new("char_t[]", encode(str(Path(entry_dll))))
args_ptr[0] = arg_ptr
res = dll.hostfxr_initialize_for_dotnet_command_line(
1,
args_ptr,
params, handle_ptr
1, args_ptr, params, handle_ptr
)

check_result(res)
Expand Down
Loading