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 )
@@ -101,6 +99,11 @@ def generate_app(self, target_dir):
10199 util .override_gradle_properties_file (target_dir )
102100 self .copy_build_files (target_dir )
103101
102+ # at the moment the gradle demon does not run with jdk <= 22
103+ gradle_java_home = self .env .get ("GRADLE_JAVA_HOME" )
104+ 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"
105+ util .replace_in_file (os .path .join (target_dir , "gradle.properties" ), "{GRADLE_JAVA_HOME}" , gradle_java_home .replace ("\\ " , "\\ \\ " ))
106+
104107 def check_filelist (self , target_dir , log , check_lib = True ):
105108 fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
106109 with open (fl_path ) as f :
@@ -125,26 +128,20 @@ def check_gradle_generated_app(self, community):
125128
126129 # build
127130 cmd = gradlew_cmd + ["build" ]
128- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True , logger = log )
131+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
129132 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
130133 self .check_filelist (target_dir , log , check_lib = True )
131134
132- if not (sys .platform == 'darwin' and (platform .machine () == 'aarch64' or platform .machine () == 'arm64' )):
133- # TODO: temporarily disabled native image build as it is causing timeouts on gate
134- cmd = gradlew_cmd + ["nativeCompile" ]
135- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
136- # which is fine, because we need to build the native binary with a graalvm build
137- # and the one we have set in JAVA_HOME is at least jdk24
138- # => run without gradle = True
139- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
140- util .check_ouput ("BUILD SUCCESS" , out , logger = log )
141- self .check_filelist (target_dir , log , check_lib = True )
142-
143- # execute and check native image
144- cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
145- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
146- util .check_ouput ("hello java" , out , logger = log )
147- self .check_filelist (target_dir , log , check_lib = True )
135+ cmd = gradlew_cmd + ["nativeCompile" ]
136+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
137+ util .check_ouput ("BUILD SUCCESS" , out , logger = log )
138+ self .check_filelist (target_dir , log , check_lib = True )
139+
140+ # execute and check native image
141+ cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
142+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
143+ util .check_ouput ("hello java" , out , logger = log )
144+ self .check_filelist (target_dir , log , check_lib = True )
148145
149146 # import struct from python file triggers extract of native extension files in VirtualFileSystem
150147 hello_src = os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" , "src" , "hello.py" )
@@ -155,7 +152,7 @@ def check_gradle_generated_app(self, community):
155152
156153 # rebuild and exec
157154 cmd = gradlew_cmd + ["build" , "run" ]
158- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True , logger = log )
155+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , logger = log )
159156 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
160157 util .check_ouput ("hello java" , out , logger = log )
161158 self .check_filelist (target_dir , log , check_lib = True )
@@ -174,7 +171,7 @@ def check_gradle_generated_app(self, community):
174171
175172 gradlew_cmd2 = util .get_gradle_wrapper (target_dir2 , self .env )
176173 cmd = gradlew_cmd2 + ["build" , "run" ]
177- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 , gradle = True , logger = log )
174+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir2 , logger = log )
178175 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
179176 util .check_ouput ("hello java" , out , logger = log )
180177 self .check_filelist (target_dir2 , log , check_lib = True )
@@ -209,33 +206,27 @@ def check_gradle_generated_app_external_resources(self):
209206 gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
210207
211208 cmd = gradle_cmd + ["clean" , "build" ]
212- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
209+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
213210 util .check_ouput ("BUILD SUCCESS" , out )
214211
215212 # check java exec
216213 cmd = gradle_cmd + ["run" ]
217- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
214+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
218215 util .check_ouput ("hello java" , out )
219216
220- if not (sys .platform == 'darwin' and (platform .machine () == 'aarch64' or platform .machine () == 'arm64' )):
221- # TODO: temporarily disabled native image build as it is causing timeouts on gate
222- # prepare for native build
223- meta_inf = os .path .join (target_dir , "src" , "main" , "resources" , "META-INF" , "native-image" )
224- os .makedirs (meta_inf , exist_ok = True )
225- 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" ))
226-
227- # gradle needs jdk <= 22, but it looks like the 'gradle nativeCompile' cmd does not complain if higher,
228- # which is fine, because we need to build the native binary with a graalvm build
229- # and the one we have set in JAVA_HOME is at least jdk24
230- # => run without gradle = True
231- cmd = gradle_cmd + ["nativeCompile" ]
232- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
233- util .check_ouput ("BUILD SUCCESS" , out )
234-
235- # execute and check native image
236- cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
237- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
238- util .check_ouput ("hello java" , out )
217+ # prepare for native build
218+ meta_inf = os .path .join (target_dir , "src" , "main" , "resources" , "META-INF" , "native-image" )
219+ os .makedirs (meta_inf , exist_ok = True )
220+ 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" ))
221+
222+ cmd = gradle_cmd + ["nativeCompile" ]
223+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
224+ util .check_ouput ("BUILD SUCCESS" , out )
225+
226+ # execute and check native image
227+ cmd = [os .path .join (target_dir , "build" , "native" , "nativeCompile" , "graalpy-gradle-test-project" )]
228+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
229+ util .check_ouput ("hello java" , out )
239230
240231 def check_gradle_fail_with_mismatching_graalpy_dep (self ):
241232 pass # TODO: once the CI job builds enterprise
@@ -252,15 +243,15 @@ def check_gradle_gen_launcher_and_venv(self, community):
252243 append (build_file , self .packages_termcolor_ujson (community ))
253244
254245 cmd = gradle_cmd + ["graalPyResources" ]
255- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
246+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
256247 util .check_ouput ("-m venv" , out )
257248 util .check_ouput ("-m ensurepip" ,out )
258249 util .check_ouput ("ujson" , out )
259250 util .check_ouput ("termcolor" , out )
260251
261252 # run again and assert that we do not regenerate the venv
262253 cmd = gradle_cmd + ["graalPyResources" ]
263- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
254+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
264255 util .check_ouput ("-m venv" , out , False )
265256 util .check_ouput ("-m ensurepip" , out , False )
266257 util .check_ouput ("ujson" , out , False )
@@ -271,7 +262,7 @@ def check_gradle_gen_launcher_and_venv(self, community):
271262 append (build_file , self .packages_termcolor (community ))
272263
273264 cmd = gradle_cmd + ["graalPyResources" ]
274- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
265+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
275266 util .check_ouput ("-m venv" , out , False )
276267 util .check_ouput ("-m ensurepip" , out , False )
277268 util .check_ouput ("Uninstalling ujson" , out )
@@ -296,7 +287,7 @@ def check_gradle_check_home(self, community):
296287
297288 # 1. process-resources with no pythonHome config
298289 append (build_file , self .empty_plugin (community ))
299- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
290+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
300291 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
301292 util .check_ouput ("Copying std lib to " , out , logger = log )
302293
@@ -313,31 +304,31 @@ def check_gradle_check_home(self, community):
313304 # 2. process-resources with empty pythonHome
314305 self .copy_build_files (target_dir )
315306 append (build_file , self .empty_python_home (community ))
316- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
307+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
317308 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
318309 util .check_ouput ("Copying std lib to " , out , False , logger = log )
319310 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
320311
321312 # 3. process-resources with empty pythonHome includes and excludes
322313 self .copy_build_files (target_dir )
323314 append (build_file , self .empty_home_includes (community ))
324- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
315+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
325316 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
326317 util .check_ouput ("Copying std lib to " , out , False , logger = log )
327318 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
328319
329320 # 4. process-resources with pythonHome includes and excludes
330321 self .copy_build_files (target_dir )
331322 append (build_file , self .home_includes (community ))
332- out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , gradle = True , logger = log )
323+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir , logger = log )
333324 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
334325 util .check_ouput ("Deleting GraalPy home due to changed includes or excludes" , out , logger = log )
335326 util .check_ouput ("Copying std lib to " , out , logger = log )
336327 self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*__init__.py\n ' , 'exclude:.*html/__init__.py\n ' ], log = log )
337328
338329 # 5. check fileslist.txt
339330 # XXX build vs graalPyVFSFilesList task?
340- out , return_code = util .run_cmd (gradle_cmd + ["build" ], self .env , cwd = target_dir , gradle = True , logger = log )
331+ out , return_code = util .run_cmd (gradle_cmd + ["build" ], self .env , cwd = target_dir , logger = log )
341332 util .check_ouput ("BUILD SUCCESS" , out , logger = log )
342333 fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
343334 with open (fl_path ) as f :
@@ -362,7 +353,7 @@ def check_gradle_empty_packages(self):
362353
363354 gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
364355 cmd = gradle_cmd + ["graalPyResources" ]
365- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir , gradle = True )
356+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
366357 util .check_ouput ("BUILD SUCCESS" , out )
367358
368359class GradlePluginGroovyTest (GradlePluginTestBase ):
0 commit comments