()
| 42 | |
| 43 | |
| 44 | def main(): |
| 45 | # We set EMSDK_PYTHON to point to this file, which is executable via #! line. |
| 46 | # Emscripten uses EMSDK_PYTHON to invoke all python subprocesses. By making this |
| 47 | # script run all python subprocesses, all of them will execute under the |
| 48 | # watchful eye of emcoverage.py, and resulting in their code coverage being |
| 49 | # tracked. |
| 50 | os.environ['EMSDK_PYTHON'] = os.path.abspath(__file__) |
| 51 | |
| 52 | store = os.path.join(SCRIPT_DIR, 'coverage') |
| 53 | |
| 54 | if len(sys.argv) < 2 or sys.argv[1] == 'help': |
| 55 | print(__doc__.replace('emcoverage.py', sys.argv[0]).strip()) |
| 56 | return |
| 57 | |
| 58 | if sys.argv[1] == 'reset': |
| 59 | shutil.rmtree(store) |
| 60 | return |
| 61 | |
| 62 | if sys.argv[1] in {'html', 'report', 'xml'}: |
| 63 | old_argv = sys.argv |
| 64 | sys.argv = ['coverage', 'combine', *glob(os.path.join(store, '*'))] |
| 65 | with contextlib.suppress(SystemExit): |
| 66 | coverage.cmdline.main() |
| 67 | sys.argv = [*old_argv, '-i'] |
| 68 | return coverage.cmdline.main() |
| 69 | |
| 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') |
| 74 | |
| 75 | try: |
| 76 | os.mkdir(store) |
| 77 | except OSError as e: |
| 78 | if e.errno != errno.EEXIST: |
| 79 | raise |
| 80 | os.environ['COVERAGE_FILE'] = os.path.join(store, str(uuid.uuid4())) |
| 81 | sys.argv[0:1] = ['coverage', 'run', '--parallel-mode', '--'] |
| 82 | |
| 83 | return coverage.cmdline.main() |
| 84 | |
| 85 | |
| 86 | if __name__ == '__main__': |
no test coverage detected