@@ -75,6 +75,12 @@ def get_gp():
75
75
76
76
return graalpy
77
77
78
+ def replace_in_file (file , str , replace_str ):
79
+ with open (file , "r" ) as f :
80
+ contents = f .read ()
81
+ with open (file , "w" ) as f :
82
+ f .write (contents .replace (str , replace_str ))
83
+
78
84
class PolyglotAppTest (unittest .TestCase ):
79
85
80
86
def setUpClass (self ):
@@ -259,11 +265,7 @@ def test_gen_launcher_and_venv(self):
259
265
util .check_ouput ("termcolor" , out , False )
260
266
261
267
# remove ujson pkg from plugin config and check if unistalled
262
- with open (os .path .join (target_dir , "pom.xml" ), "r" ) as f :
263
- contents = f .read ()
264
-
265
- with open (os .path .join (target_dir , "pom.xml" ), "w" ) as f :
266
- f .write (contents .replace ("<package>ujson</package>" , "" ))
268
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "<package>ujson</package>" , "" )
267
269
268
270
cmd = mvnw_cmd + ["process-resources" ]
269
271
out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
@@ -272,31 +274,124 @@ def test_gen_launcher_and_venv(self):
272
274
util .check_ouput ("Uninstalling ujson" , out )
273
275
util .check_ouput ("termcolor" , out , False )
274
276
277
+ def check_tagfile (self , target_dir , expected ):
278
+ with open (os .path .join (target_dir , "target" , "classes" , VFS_PREFIX , "home" , "tagfile" )) as f :
279
+ lines = f .readlines ()
280
+ assert lines == expected , "expected tagfile " + str (expected ) + ", but got " + str (lines )
281
+
275
282
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
276
283
def test_check_home (self ):
277
- with tempfile .TemporaryDirectory () as tmpdir :
284
+ with tempfile .TemporaryDirectory () as tmpdir :
278
285
target_name = "check_home_test"
279
286
target_dir = os .path .join (str (tmpdir ), target_name )
280
287
pom_template = os .path .join (os .path .dirname (__file__ ), "check_home_pom.xml" )
281
288
self .generate_app (tmpdir , target_dir , target_name , pom_template )
282
289
283
290
mvnw_cmd = util .get_mvn_wrapper (target_dir , self .env )
284
291
285
- cmd = mvnw_cmd + ["process-resources" ]
286
- out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
292
+ # 1. process-resources with no pythonHome config
293
+ process_resources_cmd = mvnw_cmd + ["process-resources" ]
294
+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
295
+ util .check_ouput ("BUILD SUCCESS" , out )
296
+ util .check_ouput ("Copying std lib to " , out )
297
+
298
+ home_dir = os .path .join (target_dir , "target" , "classes" , VFS_PREFIX , "home" )
299
+ assert os .path .exists (home_dir )
300
+ assert os .path .exists (os .path .join (home_dir , "lib-graalpython" ))
301
+ assert os .path .isdir (os .path .join (home_dir , "lib-graalpython" ))
302
+ assert os .path .exists (os .path .join (home_dir , "lib-python" ))
303
+ assert os .path .isdir (os .path .join (home_dir , "lib-python" ))
304
+ assert os .path .exists (os .path .join (home_dir , "tagfile" ))
305
+ assert os .path .isfile (os .path .join (home_dir , "tagfile" ))
306
+ self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ])
307
+
308
+ # 2. process-resources with empty pythonHome includes and excludes
309
+ shutil .copyfile (pom_template , os .path .join (target_dir , "pom.xml" ))
310
+ util .patch_pom_repositories (os .path .join (target_dir , "pom.xml" ))
311
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome></pythonHome></configuration>" )
312
+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
313
+ util .check_ouput ("BUILD SUCCESS" , out )
314
+ util .check_ouput ("Copying std lib to " , out , False )
315
+ self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ])
287
316
288
- # check fileslist.txt
317
+ shutil .copyfile (pom_template , os .path .join (target_dir , "pom.xml" ))
318
+ util .patch_pom_repositories (os .path .join (target_dir , "pom.xml" ))
319
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome><includes></includes><excludes></excludes></pythonHome></configuration>" )
320
+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
321
+ util .check_ouput ("BUILD SUCCESS" , out )
322
+ util .check_ouput ("Copying std lib to " , out , False )
323
+ self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ])
324
+
325
+ shutil .copyfile (pom_template , os .path .join (target_dir , "pom.xml" ))
326
+ util .patch_pom_repositories (os .path .join (target_dir , "pom.xml" ))
327
+ home_tag = """
328
+ <pythonHome>
329
+ <includes>
330
+ <include></include>
331
+ <include> </include>
332
+ </includes>
333
+ <excludes>
334
+ <exclude></exclude>
335
+ <exclude> </exclude>
336
+ </excludes>
337
+ </pythonHome>
338
+ """
339
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
340
+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
341
+ util .check_ouput ("BUILD SUCCESS" , out )
342
+ util .check_ouput ("Copying std lib to " , out , False )
343
+ self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ])
344
+
345
+ # 3. process-resources with pythonHome includes and excludes
346
+ home_tag = """
347
+ <pythonHome>
348
+ <includes>
349
+ <include>.*__init__\.py</include>
350
+ </includes>
351
+ <excludes>
352
+ <exclude>.*html/__init__\.py</exclude>
353
+ </excludes>
354
+ </pythonHome>
355
+ """
356
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
357
+ out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
358
+ util .check_ouput ("BUILD SUCCESS" , out )
359
+ util .check_ouput ("Deleting GraalPy home due to changed includes or excludes" , out )
360
+ util .check_ouput ("Copying std lib to " , out )
361
+ self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*__init__\\ .py\n ' , 'exclude:.*html/__init__\\ .py\n ' ])
362
+
363
+ # 4. check fileslist.txt
289
364
fl_path = os .path .join (target_dir , "target" , "classes" , VFS_PREFIX , "fileslist.txt" )
290
365
with open (fl_path ) as f :
291
366
for line in f :
292
367
line = f .readline ()
293
368
# string \n
294
369
line = line [:len (line )- 1 ]
295
- if line .endswith ("/" ) or line == "/" + VFS_PREFIX + "/home/tagfile" or line == "/" + VFS_PREFIX + "/proj/hello.py" :
370
+ if not line .startswith ("/" + VFS_PREFIX + "/home/" ) or line . endswith ( "/" ) :
296
371
continue
297
372
assert line .endswith ("/__init__.py" )
298
373
assert not line .endswith ("html/__init__.py" )
299
374
375
+ @unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
376
+ def test_empty_packages (self ):
377
+ with tempfile .TemporaryDirectory () as tmpdir :
378
+ target_name = "empty_packages_test"
379
+ target_dir = os .path .join (str (tmpdir ), target_name )
380
+ pom_template = os .path .join (os .path .dirname (__file__ ), "check_packages_pom.xml" )
381
+ self .generate_app (tmpdir , target_dir , target_name , pom_template )
382
+
383
+ mvnw_cmd = util .get_mvn_wrapper (target_dir , self .env )
384
+
385
+ cmd = mvnw_cmd + ["process-resources" ]
386
+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
387
+ util .check_ouput ("BUILD SUCCESS" , out )
388
+
389
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "</packages>" , "<package></package><package> </package></packages>" )
390
+
391
+ cmd = mvnw_cmd + ["process-resources" ]
392
+ out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
393
+ util .check_ouput ("BUILD SUCCESS" , out )
394
+
300
395
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
301
396
def test_native_executable_one_file ():
302
397
graalpy = util .get_gp ()
0 commit comments