42
42
import sys
43
43
import textwrap
44
44
import unittest
45
- import platform
46
45
47
46
from tests .standalone import util
48
47
from tests .standalone .util import TemporaryTestDirectory , Logger
49
48
50
-
51
49
def append (file , txt ):
52
50
with open (file , "a" ) as f :
53
51
f .write (txt )
@@ -102,6 +100,11 @@ def generate_app(self, target_dir):
102
100
103
101
self .copy_build_files (target_dir )
104
102
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
+
105
108
def check_filelist (self , target_dir , log , check_lib = True ):
106
109
fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
107
110
with open (fl_path ) as f :
@@ -126,26 +129,20 @@ def check_gradle_generated_app(self, community):
126
129
127
130
# build
128
131
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 )
130
133
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
131
134
self .check_filelist (target_dir , log , check_lib = True )
132
135
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 )
149
146
150
147
# import struct from python file triggers extract of native extension files in VirtualFileSystem
151
148
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):
156
153
157
154
# rebuild and exec
158
155
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 )
160
157
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
161
158
util .check_ouput ("hello java" , out , logger = log )
162
159
self .check_filelist (target_dir , log , check_lib = True )
@@ -175,7 +172,7 @@ def check_gradle_generated_app(self, community):
175
172
176
173
gradlew_cmd2 = util .get_gradle_wrapper (target_dir2 , self .env )
177
174
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 )
179
176
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
180
177
util .check_ouput ("hello java" , out , logger = log )
181
178
self .check_filelist (target_dir2 , log , check_lib = True )
@@ -210,33 +207,27 @@ def check_gradle_generated_app_external_resources(self):
210
207
gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
211
208
212
209
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 )
214
211
util .check_ouput ("BUILD SUCCESS" , out )
215
212
216
213
# check java exec
217
214
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 )
219
216
util .check_ouput ("hello java" , out )
220
217
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 )
240
231
241
232
def check_gradle_fail_with_mismatching_graalpy_dep (self ):
242
233
pass # TODO: once the CI job builds enterprise
@@ -253,15 +244,15 @@ def check_gradle_gen_launcher_and_venv(self, community):
253
244
append (build_file , self .packages_termcolor_ujson (community ))
254
245
255
246
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 )
257
248
util .check_ouput ("-m venv" , out )
258
249
util .check_ouput ("-m ensurepip" ,out )
259
250
util .check_ouput ("ujson" , out )
260
251
util .check_ouput ("termcolor" , out )
261
252
262
253
# run again and assert that we do not regenerate the venv
263
254
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 )
265
256
util .check_ouput ("-m venv" , out , False )
266
257
util .check_ouput ("-m ensurepip" , out , False )
267
258
util .check_ouput ("ujson" , out , False )
@@ -272,7 +263,7 @@ def check_gradle_gen_launcher_and_venv(self, community):
272
263
append (build_file , self .packages_termcolor (community ))
273
264
274
265
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 )
276
267
util .check_ouput ("-m venv" , out , False )
277
268
util .check_ouput ("-m ensurepip" , out , False )
278
269
util .check_ouput ("Uninstalling ujson" , out )
@@ -297,7 +288,7 @@ def check_gradle_check_home(self, community):
297
288
298
289
# 1. process-resources with no pythonHome config
299
290
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 )
301
292
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
302
293
util .check_ouput ("Copying std lib to " , out , logger = log )
303
294
@@ -314,31 +305,31 @@ def check_gradle_check_home(self, community):
314
305
# 2. process-resources with empty pythonHome
315
306
self .copy_build_files (target_dir )
316
307
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 )
318
309
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
319
310
util .check_ouput ("Copying std lib to " , out , False , logger = log )
320
311
self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
321
312
322
313
# 3. process-resources with empty pythonHome includes and excludes
323
314
self .copy_build_files (target_dir )
324
315
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 )
326
317
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
327
318
util .check_ouput ("Copying std lib to " , out , False , logger = log )
328
319
self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ], log = log )
329
320
330
321
# 4. process-resources with pythonHome includes and excludes
331
322
self .copy_build_files (target_dir )
332
323
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 )
334
325
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
335
326
util .check_ouput ("Deleting GraalPy home due to changed includes or excludes" , out , logger = log )
336
327
util .check_ouput ("Copying std lib to " , out , logger = log )
337
328
self .check_tagfile (home_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*__init__.py\n ' , 'exclude:.*html/__init__.py\n ' ], log = log )
338
329
339
330
# 5. check fileslist.txt
340
331
# 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 )
342
333
util .check_ouput ("BUILD SUCCESS" , out , logger = log )
343
334
fl_path = os .path .join (target_dir , "build" , "resources" , "main" , util .VFS_PREFIX , "fileslist.txt" )
344
335
with open (fl_path ) as f :
@@ -363,7 +354,7 @@ def check_gradle_empty_packages(self):
363
354
364
355
gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
365
356
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 )
367
358
util .check_ouput ("BUILD SUCCESS" , out )
368
359
369
360
class GradlePluginGroovyTest (GradlePluginTestBase ):
0 commit comments