Bug 1739680 [wpt PR 31525] - Move some tests to external/wpt/web-animations/responsiv...
[gecko.git] / testing / parse_build_tests_ccov.py
blob79382e7f4a0b55b3caf2f5e619ef5dad679e4f4e
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 pathlib
11 import shutil
12 import subprocess
13 import tempfile
14 import zipfile
15 import buildconfig
18 def main():
19 if not buildconfig.substs.get("MOZ_CODE_COVERAGE") or not buildconfig.substs.get(
20 "MOZ_RUST_TESTS"
22 return
24 assert (
25 "GRCOV_PATH" in os.environ
26 ), "The environment variable GRCOV_PATH should contain a path to grcov"
27 grcov_path = os.environ["GRCOV_PATH"]
28 assert os.path.exists(grcov_path), "grcov should exist"
30 grcov_command = [
31 grcov_path,
32 "-t",
33 "lcov",
34 "-p",
35 buildconfig.topsrcdir,
36 buildconfig.topobjdir,
39 # We want to ignore system headers in our reports.
40 if buildconfig.substs["OS_TARGET"] == "WINNT":
41 # We use WINDOWSSDKDIR to find the directory holding the system headers on Windows.
42 windows_sdk_dir = None
43 config_opts = buildconfig.substs["MOZ_CONFIGURE_OPTIONS"].split(" ")
44 for opt in config_opts:
45 if opt.startswith("WINDOWSSDKDIR="):
46 windows_sdk_dir = opt[len("WINDOWSSDKDIR=") :]
47 break
49 assert (
50 windows_sdk_dir is not None
51 ), "WINDOWSSDKDIR should be in MOZ_CONFIGURE_OPTIONS"
53 ignore_dir_abs = pathlib.Path(windows_sdk_dir).parent
55 # globs passed to grcov must exist and must be relative to the source directory.
56 # If it doesn't exist, maybe it has moved and we need to update the paths above.
57 # If it is no longer relative to the source directory, we no longer need to ignore it and
58 # this code can be removed.
59 assert ignore_dir_abs.is_dir(), f"{ignore_dir_abs} is not a directory"
60 ignore_dir_rel = ignore_dir_abs.relative_to(buildconfig.topsrcdir)
62 grcov_command += [
63 "--ignore",
64 f"{ignore_dir_rel}*",
67 if buildconfig.substs["OS_TARGET"] == "Linux":
68 gcc_dir = os.path.join(os.environ["MOZ_FETCHES_DIR"], "gcc")
69 if "LD_LIBRARY_PATH" in os.environ:
70 os.environ["LD_LIBRARY_PATH"] = "{}/lib64/:{}".format(
71 gcc_dir, os.environ["LD_LIBRARY_PATH"]
73 else:
74 os.environ["LD_LIBRARY_PATH"] = "{}/lib64/".format(gcc_dir)
76 os.environ["PATH"] = "{}/bin/:{}".format(gcc_dir, os.environ["PATH"])
78 grcov_output = subprocess.check_output(grcov_command)
80 grcov_zip_path = os.path.join(buildconfig.topobjdir, "code-coverage-grcov.zip")
81 with zipfile.ZipFile(grcov_zip_path, "a", zipfile.ZIP_DEFLATED) as z:
82 z.writestr("grcov_lcov_output.info", grcov_output)
85 if __name__ == "__main__":
86 main()