6
6
from .types import Runtime , RuntimeInfo , StrOrPath
7
7
from .util import check_result
8
8
9
- __all__ = ["DotnetCoreRuntime" ]
9
+ __all__ = ["DotnetCoreRuntime" , "DotnetCoreCommandRuntime" ]
10
10
11
11
_IS_SHUTDOWN = False
12
12
13
13
14
- class DotnetCoreRuntime (Runtime ):
15
- def __init__ (self , runtime_config : Path , dotnet_root : Path , ** params : str ):
14
+ class DotnetCoreRuntimeBase (Runtime ):
15
+ _version : str
16
+
17
+ def __init__ (self , dotnet_root : Path ):
16
18
self ._handle = None
17
19
18
20
if _IS_SHUTDOWN :
19
21
raise RuntimeError ("Runtime can not be reinitialized" )
20
22
21
23
self ._dotnet_root = Path (dotnet_root )
22
24
self ._dll = load_hostfxr (self ._dotnet_root )
23
- self ._handle = _get_handle (self ._dll , self ._dotnet_root , runtime_config )
24
25
self ._load_func = None
25
26
26
- for key , value in params .items ():
27
- self [key ] = value
28
-
29
- # TODO: Get version
30
- self ._version = "<undefined>"
31
-
32
27
@property
33
28
def dotnet_root (self ) -> Path :
34
29
return self ._dotnet_root
@@ -122,7 +117,31 @@ def info(self):
122
117
)
123
118
124
119
125
- def _get_handle (dll , dotnet_root : StrOrPath , runtime_config : StrOrPath ):
120
+ class DotnetCoreRuntime (DotnetCoreRuntimeBase ):
121
+ def __init__ (self , runtime_config : Path , dotnet_root : Path , ** params : str ):
122
+ super ().__init__ (dotnet_root )
123
+ self ._handle = _get_handle_for_runtime_config (self ._dll , self ._dotnet_root , runtime_config )
124
+
125
+ for key , value in params .items ():
126
+ self [key ] = value
127
+
128
+ # TODO: Get version
129
+ self ._version = "<undefined>"
130
+
131
+
132
+ class DotnetCoreCommandRuntime (DotnetCoreRuntimeBase ):
133
+ def __init__ (self , entry_dll : Path , dotnet_root : Path , ** params : str ):
134
+ super ().__init__ (dotnet_root )
135
+ self ._handle = _get_handle_for_dotnet_command_line (self ._dll , self ._dotnet_root , entry_dll )
136
+
137
+ for key , value in params .items ():
138
+ self [key ] = value
139
+
140
+ # TODO: Get version
141
+ self ._version = "<undefined>"
142
+
143
+
144
+ def _get_handle_for_runtime_config (dll , dotnet_root : StrOrPath , runtime_config : StrOrPath ):
126
145
params = ffi .new ("hostfxr_initialize_parameters*" )
127
146
params .size = ffi .sizeof ("hostfxr_initialize_parameters" )
128
147
# params.host_path = ffi.new("char_t[]", encode(sys.executable))
@@ -140,6 +159,29 @@ def _get_handle(dll, dotnet_root: StrOrPath, runtime_config: StrOrPath):
140
159
return handle_ptr [0 ]
141
160
142
161
162
+ def _get_handle_for_dotnet_command_line (dll , dotnet_root : StrOrPath , entry_dll : StrOrPath ):
163
+ params = ffi .new ("hostfxr_initialize_parameters*" )
164
+ params .size = ffi .sizeof ("hostfxr_initialize_parameters" )
165
+ params .host_path = ffi .NULL
166
+ dotnet_root_p = ffi .new ("char_t[]" , encode (str (Path (dotnet_root ))))
167
+ params .dotnet_root = dotnet_root_p
168
+
169
+ handle_ptr = ffi .new ("hostfxr_handle*" )
170
+
171
+ args_ptr = ffi .new ("char_t*[1]" )
172
+ arg_ptr = ffi .new ("char_t[]" , encode (str (Path (entry_dll ))))
173
+ args_ptr [0 ] = arg_ptr
174
+ res = dll .hostfxr_initialize_for_dotnet_command_line (
175
+ 1 ,
176
+ args_ptr ,
177
+ params , handle_ptr
178
+ )
179
+
180
+ check_result (res )
181
+
182
+ return handle_ptr [0 ]
183
+
184
+
143
185
def _get_load_func (dll , handle ):
144
186
delegate_ptr = ffi .new ("void**" )
145
187
0 commit comments