Skip to content

Commit 90e676a

Browse files
committed
Fix tools/emcoverage.py and EMSDK_PYTHON normalization
Resolve the minimal set of issues that prevented `tools/emcoverage.py` from collecting coverage: 1. In `tools/emcoverage.py`, strip `-E` passed by compiler entry point scripts, and resolve commands to root `.py` files. 2. In `tools/config.py`, normalize `EMSDK_PYTHON` with `os.path.abspath()` instead of `sys.executable`, which prevented child processes from executing under custom wrappers. 3. In `tools/emcoverage.py`, pass `ignore_errors=True` to `rmtree` during reset.
1 parent 2b6e96a commit 90e676a

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎tools/config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def normalize_relative_python_path():
7171
# reinitialize EMSDK_PYTHON here so that sub-tool spawns will use the same
7272
# Python interpreter as the parent.
7373
if os.environ.get('EMSDK_PYTHON'):
74-
os.environ['EMSDK_PYTHON'] = sys.executable
74+
os.environ['EMSDK_PYTHON'] = os.path.abspath(os.environ['EMSDK_PYTHON'])
7575

7676

7777
def set_config_from_tool_location(config_key, tool_binary, f):

‎tools/emcoverage.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import coverage.cmdline # type: ignore
4040

4141
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
42+
ROOT_DIR = os.path.dirname(SCRIPT_DIR)
4243

4344

4445
def main():
@@ -56,7 +57,7 @@ def main():
5657
return
5758

5859
if sys.argv[1] == 'reset':
59-
shutil.rmtree(store)
60+
shutil.rmtree(store, ignore_errors=True)
6061
return
6162

6263
if sys.argv[1] in {'html', 'report', 'xml'}:
@@ -67,10 +68,18 @@ def main():
6768
sys.argv = [*old_argv, '-i']
6869
return coverage.cmdline.main()
6970

70-
if not os.path.exists(sys.argv[1]):
71-
# If argv[1] is not a file path, instead try to interpret it as an emscripten command.
72-
# This allows `emcoverage.py emcc` or `emcoverage.py embuilder` to work.
73-
sys.argv[1] = os.path.join(os.path.dirname(sys.executable), '..', sys.argv[1] + '.py')
71+
if sys.argv[1] == '-E':
72+
sys.argv.pop(1)
73+
74+
# If argv[1] is an emscripten command rather than a python script path, resolve it
75+
# to the corresponding root python script. This allows `emcoverage.py emcc` or
76+
# `emcoverage.py embuilder` to work, even when launcher scripts (or binaries like
77+
# `emcc.exe` on Windows) exist with the same name.
78+
if not sys.argv[1].endswith('.py'):
79+
cmd = os.path.basename(sys.argv[1]).removesuffix('.exe')
80+
cmd_py = os.path.join(ROOT_DIR, cmd + '.py')
81+
if os.path.exists(cmd_py):
82+
sys.argv[1] = cmd_py
7483

7584
try:
7685
os.mkdir(store)

0 commit comments

Comments
 (0)