@@ -1292,15 +1292,44 @@ def python_coverage(args):
12921292 else :
12931293 run_python_unittests (executable , ** kwds )
12941294
1295- # some code runs in the suite dir, some in the graalvm home. we merge these manually
1296- local_dir = os .path .join (SUITE .dir , "graalpython" )
1297- graalvm_dir = os .path .join (os .path .dirname (os .path .dirname (executable )), "jre" , "languages" , "python" )
1295+ # generate a synthetic lcov file that includes all sources with 0
1296+ # coverage. this is to ensure all sources actuall show up - otherwise,
1297+ # only loaded sources will be part of the coverage
1298+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = '.py' ) as f :
1299+ f .write ("""
1300+ import os
1301+
1302+ for dirpath, dirnames, filenames in os.walk('{0}'):
1303+ if "test" in dirnames:
1304+ dirnames.remove("test")
1305+ if "tests" in dirnames:
1306+ dirnames.remove("tests")
1307+ for filename in filenames:
1308+ if filename.endswith(".py"):
1309+ fullname = os.path.join(dirpath, filename)
1310+ with open(fullname, 'r') as f:
1311+ try:
1312+ compile(f.read(), fullname, 'exec')
1313+ except BaseException as e:
1314+ print('Could not compile', fullname, e)
1315+ """ .format (os .path .join (prefix , "lib-python" )))
1316+ f .flush ()
1317+ with _dev_pythonhome_context ():
1318+ mx .run ([
1319+ executable ,
1320+ "-S" ,
1321+ "--experimental-options" ,
1322+ "--coverage" ,
1323+ "--coverage.TrackInternal" ,
1324+ "--coverage.FilterFile=%s/*.py" % prefix ,
1325+ "--coverage.Output=lcov" ,
1326+ "--coverage.OutputFile=zero.lcov" ,
1327+ f .name
1328+ ])
1329+
1330+ # merge all generated lcov files
12981331 for f in os .listdir (SUITE .dir ):
12991332 if f .endswith (".lcov" ):
1300- # with open(f, "r") as lcovfile:
1301- # contents = lcovfile.read()
1302- # with open(f, "w") as lcovfile:
1303- # lcovfile.write(contents.replace(graalvm_dir, local_dir))
13041333 cmdargs += ["-a" , f ]
13051334
13061335 mx .run (cmdargs )
0 commit comments