Bug 1651439 [wpt PR 24515] - [NativeFS] Rename getFile/Directory to getXXXHandle...
[gecko.git] / testing / parse_build_tests_ccov.py
blobd85571aad77434ce37d0ab084612d18a43995b04
1 #!/usr/bin/env python
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from __future__ import absolute_import
8 import sys
9 import os
10 import shutil
11 import subprocess
12 import tempfile
13 import zipfile
14 import buildconfig
17 def main():
18 if not buildconfig.substs.get('MOZ_CODE_COVERAGE') or not buildconfig.substs.get('MOZ_RUST_TESTS'):
19 return
21 assert 'GRCOV_PATH' in os.environ, 'The environment variable GRCOV_PATH should contain a path to grcov'
22 grcov_path = os.environ['GRCOV_PATH']
23 assert os.path.exists(grcov_path), 'grcov should exist'
25 grcov_command = [
26 grcov_path,
27 '-t', 'lcov',
28 '-p', buildconfig.topsrcdir,
29 buildconfig.topobjdir
32 # We want to ignore system headers in our reports.
33 if buildconfig.substs['OS_TARGET'] == 'WINNT':
34 # We use WINDOWSSDKDIR to find the directory holding the system headers on Windows.
35 windows_sdk_dir = None
36 config_opts = buildconfig.substs['MOZ_CONFIGURE_OPTIONS'].split(' ')
37 for opt in config_opts:
38 if opt.startswith('WINDOWSSDKDIR='):
39 windows_sdk_dir = opt[len('WINDOWSSDKDIR='):]
40 break
42 assert windows_sdk_dir is not None, 'WINDOWSSDKDIR should be in MOZ_CONFIGURE_OPTIONS'
44 ignore_dir_abs = os.path.dirname(windows_sdk_dir)
46 # globs passed to grcov must exist and must be relative to the source directory.
47 # If it doesn't exist, maybe it has moved and we need to update the paths above.
48 # If it is no longer relative to the source directory, we no longer need to ignore it and
49 # this code can be removed.
50 assert os.path.isdir(ignore_dir_abs), '{} is not a directory'.format(ignore_dir_abs)
51 assert ignore_dir_abs.startswith(buildconfig.topsrcdir), '{} should start with {}'.format(ignore_dir_abs, buildconfig.topsrcdir)
53 grcov_command += ['--ignore', os.path.relpath(ignore_dir_abs, buildconfig.topsrcdir) + '*']
55 if buildconfig.substs['OS_TARGET'] == 'Linux':
56 gcc_dir = os.path.join(os.environ['MOZ_FETCHES_DIR'], 'gcc')
57 if 'LD_LIBRARY_PATH' in os.environ:
58 os.environ['LD_LIBRARY_PATH'] = '{}/lib64/:{}'.format(gcc_dir, os.environ['LD_LIBRARY_PATH'])
59 else:
60 os.environ['LD_LIBRARY_PATH'] = '{}/lib64/'.format(gcc_dir)
62 os.environ['PATH'] = '{}/bin/:{}'.format(gcc_dir, os.environ['PATH'])
64 grcov_output = subprocess.check_output(grcov_command)
66 grcov_zip_path = os.path.join(buildconfig.topobjdir, 'code-coverage-grcov.zip')
67 with zipfile.ZipFile(grcov_zip_path, 'a', zipfile.ZIP_DEFLATED) as z:
68 z.writestr('grcov_lcov_output.info', grcov_output)
71 if __name__ == '__main__':
72 main()