86
86
87
87
MVN_REPOSITORY = os .getenv ("MVN_REPOSITORY" )
88
88
MVN_GRAALPY_VERSION = os .getenv ("MVN_GRAALPY_VERSION" ) if os .getenv ("MVN_GRAALPY_VERSION" ) else __graalpython__ .get_graalvm_version ()
89
+ LEGACY_EMBEDDING_VERSION = '24.2.2'
89
90
90
91
CMD_NATIVE_EXECUTABLE = "native"
91
92
CMD_JAVA_PYTHON_APP = "polyglot_app"
@@ -139,8 +140,7 @@ def create_polyglot_app(parsed_args):
139
140
exit (1 )
140
141
141
142
142
- def get_download_dir (parsed_args ):
143
- subdir = "downloaded_standalone_resources"
143
+ def get_download_dir (parsed_args , subdir = "downloaded_standalone_resources" ):
144
144
mp = os .path .join (__graalpython__ .home , subdir )
145
145
try :
146
146
if not os .path .exists (mp ):
@@ -159,25 +159,28 @@ def get_download_dir(parsed_args):
159
159
160
160
161
161
def create_native_exec (parsed_args ):
162
- artifacts = ["org.graalvm.python.python-embedding" ]
163
-
164
162
target_dir = tempfile .mkdtemp ()
165
163
try :
166
164
ni , jc = get_tools (target_dir , parsed_args )
167
165
if parsed_args .ce :
168
- artifacts . append ( "org.graalvm.polyglot.python-community" )
166
+ artifact = "org.graalvm.polyglot.python-community"
169
167
else :
170
- artifacts . append ( "org.graalvm.polyglot.python" )
168
+ artifact = "org.graalvm.polyglot.python"
171
169
172
170
modules_path = get_download_dir (parsed_args )
173
- for artifact in artifacts :
174
- download_maven_artifact (modules_path , artifact , parsed_args )
171
+ legacy_embedding_path = None
172
+ if not download_maven_artifact (modules_path , "org.graalvm.python.python-embedding" , parsed_args , version = MVN_GRAALPY_VERSION , fail_if_not_found = False ):
173
+ legacy_embedding_dir = get_download_dir (parsed_args , subdir = 'downloaded_standalone_resources_legacy' )
174
+ download_maven_artifact (legacy_embedding_dir , "org.graalvm.python.python-embedding" , parsed_args , version = LEGACY_EMBEDDING_VERSION )
175
+ legacy_embedding_path = os .path .join (legacy_embedding_dir , f"org.graalvm.python-python-embedding-{ LEGACY_EMBEDDING_VERSION } .jar" )
176
+
177
+ download_maven_artifact (modules_path , artifact , parsed_args , version = MVN_GRAALPY_VERSION )
175
178
176
179
launcher_file = os .path .join (target_dir , NATIVE_EXEC_LAUNCHER_FILE )
177
180
create_target_directory (target_dir , launcher_file , parsed_args )
178
181
179
182
index_vfs (target_dir )
180
- build_binary (target_dir , ni , jc , modules_path , launcher_file , parsed_args )
183
+ build_binary (target_dir , ni , jc , modules_path , legacy_embedding_path , launcher_file , parsed_args )
181
184
finally :
182
185
if not parsed_args .keep_temp :
183
186
shutil .rmtree (target_dir )
@@ -368,16 +371,17 @@ def get_tools(target_dir, parsed_args):
368
371
return ni , jc
369
372
370
373
371
- def download_maven_artifact (modules_path , artifact , parsed_args ):
374
+ def download_maven_artifact (modules_path , artifact , parsed_args , version = MVN_GRAALPY_VERSION , fail_if_not_found = True ):
372
375
mvnd = get_executable (os .path .join (__graalpython__ .home , "libexec" , "graalpy-polyglot-get" ))
373
376
cmd = [mvnd ]
374
377
375
378
if MVN_REPOSITORY :
376
379
cmd += ["-r" , MVN_REPOSITORY ]
377
380
cmd += ["-a" , artifact .rsplit ("." , 1 )[1 ]]
378
381
cmd += ["-g" , artifact .rsplit ("." , 1 )[0 ]]
379
- cmd += ["-v" , MVN_GRAALPY_VERSION ]
382
+ cmd += ["-v" , version ]
380
383
cmd += ["-o" , modules_path ]
384
+
381
385
if parsed_args .verbose :
382
386
print (f"downloading graalpython maven artifacts: { ' ' .join (cmd )} " )
383
387
@@ -387,19 +391,28 @@ def download_maven_artifact(modules_path, artifact, parsed_args):
387
391
p = subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
388
392
389
393
if p .returncode != 0 :
390
- if not parsed_args .verbose :
394
+ if fail_if_not_found and not parsed_args .verbose :
391
395
print (p .stdout .decode ())
392
396
print (p .stderr .decode ())
393
- exit (1 )
397
+ if fail_if_not_found :
398
+ exit (1 )
399
+ return False
400
+ return True
394
401
395
402
396
- def build_binary (target_dir , ni , jc , modules_path , launcher_file , parsed_args ):
403
+ def build_binary (target_dir , ni , jc , modules_path , legacy_embedding_path , launcher_file , parsed_args ):
397
404
cwd = os .getcwd ()
398
405
output = os .path .abspath (parsed_args .output )
399
406
os .chdir (target_dir )
400
407
401
408
try :
402
- cmd = [jc , "-cp" , f"{ modules_path } /*" , launcher_file ]
409
+ legacy_embedding_cp = ''
410
+ legacy_embedding_modules = []
411
+ if legacy_embedding_path :
412
+ legacy_embedding_cp = f"{ os .pathsep } { legacy_embedding_path } "
413
+ legacy_embedding_modules = [legacy_embedding_path ]
414
+
415
+ cmd = [jc , "-cp" , f"{ modules_path } /*{ legacy_embedding_cp } " , launcher_file ]
403
416
if parsed_args .verbose :
404
417
print (f"Compiling code for Python standalone entry point: { ' ' .join (cmd )} " )
405
418
p = subprocess .run (cmd , cwd = target_dir , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -408,7 +421,7 @@ def build_binary(target_dir, ni, jc, modules_path, launcher_file, parsed_args):
408
421
print (p .stderr .decode ())
409
422
exit (1 )
410
423
411
- ni_modules = os .pathsep .join ([os .path .join (modules_path , f ) for f in os .listdir (modules_path ) if f .endswith (".jar" )] + [target_dir ])
424
+ ni_modules = os .pathsep .join ([os .path .join (modules_path , f ) for f in os .listdir (modules_path ) if f .endswith (".jar" )] + legacy_embedding_modules + [target_dir ])
412
425
cmd = [ni , "-cp" , ni_modules ] + parsed_args .ni_args [:]
413
426
414
427
if parsed_args .Os :
0 commit comments