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