@@ -265,11 +265,7 @@ def test_gen_launcher_and_venv(self):
265
265
util .check_ouput ("termcolor" , out , False )
266
266
267
267
# remove ujson pkg from plugin config and check if unistalled
268
- with open (os .path .join (target_dir , "pom.xml" ), "r" ) as f :
269
- contents = f .read ()
270
-
271
- with open (os .path .join (target_dir , "pom.xml" ), "w" ) as f :
272
- f .write (contents .replace ("<package>ujson</package>" , "" ))
268
+ replace_in_file (os .path .join (target_dir , "pom.xml" ), "<package>ujson</package>" , "" )
273
269
274
270
cmd = mvnw_cmd + ["process-resources" ]
275
271
out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
@@ -278,6 +274,11 @@ def test_gen_launcher_and_venv(self):
278
274
util .check_ouput ("Uninstalling ujson" , out )
279
275
util .check_ouput ("termcolor" , out , False )
280
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
+
281
282
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
282
283
def test_check_home (self ):
283
284
with tempfile .TemporaryDirectory () as tmpdir :
@@ -288,17 +289,85 @@ def test_check_home(self):
288
289
289
290
mvnw_cmd = util .get_mvn_wrapper (target_dir , self .env )
290
291
291
- cmd = mvnw_cmd + ["process-resources" ]
292
- 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 ' ])
293
316
294
- # 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
295
364
fl_path = os .path .join (target_dir , "target" , "classes" , VFS_PREFIX , "fileslist.txt" )
296
365
with open (fl_path ) as f :
297
366
for line in f :
298
367
line = f .readline ()
299
368
# string \n
300
369
line = line [:len (line )- 1 ]
301
- 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 ( "/" ) :
302
371
continue
303
372
assert line .endswith ("/__init__.py" )
304
373
assert not line .endswith ("html/__init__.py" )
0 commit comments