4242import sys
4343import textwrap
4444import unittest
45- import platform
4645
4746from tests .standalone import util
4847from tests .standalone .util import TemporaryTestDirectory , Logger
4948
50-
5149def append (file , txt ):
5250 with open (file , "a" ) as f :
5351 f .write (txt )
@@ -102,6 +100,11 @@ def generate_app(self, target_dir):
102100
103101 self .copy_build_files (target_dir )
104102
103+ # at the moment the gradle demon does not run with jdk <= 22
104+ gradle_java_home = self .env .get ("GRADLE_JAVA_HOME" )
105+ assert gradle_java_home , "in order to run standalone gradle tests, the 'GRADLE_JAVA_HOME' env var has to be set to a jdk <= 22"
106+ util .replace_in_file (os .path .join (target_dir , "gradle.properties" ), "{GRADLE_JAVA_HOME}" , gradle_java_home .replace ("\\ " , "\\ \\ " ))
107+
105108 def check_filelist (self , target_dir , log , check_lib = True ):
106109 fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
107110 with open (fl_path ) as f :
@@ -126,26 +129,20 @@ def check_gradle_generated_app(self, community):
126129
127130 # build
128131 cmd = gradlew_cmd + ["build" ]
129- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True , logger = log )
132+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
130133 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
131134 self .check_filelist (target_dir , log , check_lib = True )
132135
133- if not (sys .platform == 'darwin' and (platform .machine () == 'aarch64' or platform .machine () == 'arm64' )):
134- # TODO: temporarily disabled native image build as it is causing timeouts on gate
135- cmd = gradlew_cmd + ["nativeCompile" ]
136- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
137- # which is fine, because we need to build the native binary with a graalvm build
138- # and the one we have set in JAVA_HOME is at least jdk24
139- # => run without gradle = True
140- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
141- util .check_ouput ("BUILD SUCCESS" , out , logger = log )
142- self .check_filelist (target_dir , log , check_lib = True )
143-
144- # execute and check native image
145- cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
146- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
147- util .check_ouput ("hello java" , out , logger = log )
148- self .check_filelist (target_dir , log , check_lib = True )
136+ cmd = gradlew_cmd + ["nativeCompile" ]
137+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
138+ util .check_ouput ("BUILD SUCCESS" , out , logger = log )
139+ self .check_filelist (target_dir , log , check_lib = True )
140+
141+ # execute and check native image
142+ cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
143+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
144+ util .check_ouput ("hello java" , out , logger = log )
145+ self .check_filelist (target_dir , log , check_lib = True )
149146
150147 # import struct from python file triggers extract of native extension files in VirtualFileSystem
151148 hello_src = os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" , "src" , "hello.py" )
@@ -156,7 +153,7 @@ def check_gradle_generated_app(self, community):
156153
157154 # rebuild and exec
158155 cmd = gradlew_cmd + ["build" , "run" ]
159- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True , logger = log )
156+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
160157 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
161158 util .check_ouput ("hello java" , out , logger = log )
162159 self .check_filelist (target_dir , log , check_lib = True )
@@ -175,7 +172,7 @@ def check_gradle_generated_app(self, community):
175172
176173 gradlew_cmd2 = util .get_gradle_wrapper (target_dir2 , self .env )
177174 cmd = gradlew_cmd2 + ["build" , "run" ]
178- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 , gradle = True , logger = log )
175+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 , logger = log )
179176 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
180177 util .check_ouput ("hello java" , out , logger = log )
181178 self .check_filelist (target_dir2 , log , check_lib = True )
@@ -210,33 +207,27 @@ def check_gradle_generated_app_external_resources(self):
210207 gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
211208
212209 cmd = gradle_cmd + ["clean" , "build" ]
213- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
210+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
214211 util .check_ouput ("BUILD SUCCESS" , out )
215212
216213 # check java exec
217214 cmd = gradle_cmd + ["run" ]
218- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
215+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
219216 util .check_ouput ("hello java" , out )
220217
221- if not (sys .platform == 'darwin' and (platform .machine () == 'aarch64' or platform .machine () == 'arm64' )):
222- # TODO: temporarily disabled native image build as it is causing timeouts on gate
223- # prepare for native build
224- meta_inf = os .path .join (target_dir , "src" , "main" , "resources" , "META-INF" , "native-image" )
225- os .makedirs (meta_inf , exist_ok = True )
226- shutil .copyfile (os .path .join (self .test_prj_path , "src" , "main" , "resources" , "META-INF" , "native-image" , "proxy-config.json" ), os .path .join (meta_inf , "proxy-config.json" ))
227-
228- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
229- # which is fine, because we need to build the native binary with a graalvm build
230- # and the one we have set in JAVA_HOME is at least jdk24
231- # => run without gradle = True
232- cmd = gradle_cmd + ["nativeCompile" ]
233- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
234- util .check_ouput ("BUILD SUCCESS" , out )
235-
236- # execute and check native image
237- cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
238- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
239- util .check_ouput ("hello java" , out )
218+ # prepare for native build
219+ meta_inf = os .path .join (target_dir , "src" , "main" , "resources" , "META-INF" , "native-image" )
220+ os .makedirs (meta_inf , exist_ok = True )
221+ shutil .copyfile (os .path .join (self .test_prj_path , "src" , "main" , "resources" , "META-INF" , "native-image" , "proxy-config.json" ), os .path .join (meta_inf , "proxy-config.json" ))
222+
223+ cmd = gradle_cmd + ["nativeCompile" ]
224+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
225+ util .check_ouput ("BUILD SUCCESS" , out )
226+
227+ # execute and check native image
228+ cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
229+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
230+ util .check_ouput ("hello java" , out )
240231
241232 def check_gradle_fail_with_mismatching_graalpy_dep (self ):
242233 pass # TODO: once the CI job builds enterprise
@@ -253,15 +244,15 @@ def check_gradle_gen_launcher_and_venv(self, community):
253244 append (build_file , self .packages_termcolor_ujson (community ))
254245
255246 cmd = gradle_cmd + ["graalPyResources" ]
256- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
247+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
257248 util .check_ouput ("-m venv" , out )
258249 util .check_ouput ("-m ensurepip" ,out )
259250 util .check_ouput ("ujson" , out )
260251 util .check_ouput ("termcolor" , out )
261252
262253 # run again and assert that we do not regenerate the venv
263254 cmd = gradle_cmd + ["graalPyResources" ]
264- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
255+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
265256 util .check_ouput ("-m venv" , out , False )
266257 util .check_ouput ("-m ensurepip" , out , False )
267258 util .check_ouput ("ujson" , out , False )
@@ -272,7 +263,7 @@ def check_gradle_gen_launcher_and_venv(self, community):
272263 append (build_file , self .packages_termcolor (community ))
273264
274265 cmd = gradle_cmd + ["graalPyResources" ]
275- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
266+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
276267 util .check_ouput ("-m venv" , out , False )
277268 util .check_ouput ("-m ensurepip" , out , False )
278269 util .check_ouput ("Uninstalling ujson" , out )
@@ -297,7 +288,7 @@ def check_gradle_check_home(self, community):
297288
298289 # 1. process-resources with no pythonHome config
299290 append (build_file , self .empty_plugin (community ))
300- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
291+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
301292 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
302293 util .check_ouput ("Copying std lib to " , out , logger = log )
303294
@@ -314,31 +305,31 @@ def check_gradle_check_home(self, community):
314305 # 2. process-resources with empty pythonHome
315306 self .copy_build_files (target_dir )
316307 append (build_file , self .empty_python_home (community ))
317- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
308+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
318309 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
319310 util .check_ouput ("Copying std lib to " , out , False , logger = log )
320311 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
321312
322313 # 3. process-resources with empty pythonHome includes and excludes
323314 self .copy_build_files (target_dir )
324315 append (build_file , self .empty_home_includes (community ))
325- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
316+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
326317 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
327318 util .check_ouput ("Copying std lib to " , out , False , logger = log )
328319 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
329320
330321 # 4. process-resources with pythonHome includes and excludes
331322 self .copy_build_files (target_dir )
332323 append (build_file , self .home_includes (community ))
333- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
324+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
334325 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
335326 util .check_ouput ("Deleting GraalPy home due to changed includes or excludes" , out , logger = log )
336327 util .check_ouput ("Copying std lib to " , out , logger = log )
337328 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*__init__.py\n ' , 'exclude:.*html/__init__.py\n ' ], log = log )
338329
339330 # 5. check fileslist.txt
340331 # XXX build vs graalPyVFSFilesList task?
341- out , return_code = util .run_cmd (gradle_cmd + ["build" ], self .env , cwd = target_dir , gradle = True , logger = log )
332+ out , return_code = util .run_cmd (gradle_cmd + ["build" ], self .env , cwd = target_dir , logger = log )
342333 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
343334 fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
344335 with open (fl_path ) as f :
@@ -363,7 +354,7 @@ def check_gradle_empty_packages(self):
363354
364355 gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
365356 cmd = gradle_cmd + ["graalPyResources" ]
366- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
357+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
367358 util .check_ouput ("BUILD SUCCESS" , out )
368359
369360class GradlePluginGroovyTest (GradlePluginTestBase ):
0 commit comments