Bug 1726781 [wpt PR 30110] - Fix column spanner inline-size:auto issues., a=testonly
[gecko.git] / testing / parse_build_tests_ccov.py
blob215a61d7220cc9f2104b0051de6ee710024c0dcd
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(
19 "MOZ_RUST_TESTS"
21 return
23 assert (
24 "GRCOV_PATH" in os.environ
25 ), "The environment variable GRCOV_PATH should contain a path to grcov"
26 grcov_path = os.environ["GRCOV_PATH"]
27 assert os.path.exists(grcov_path), "grcov should exist"
29 grcov_command = [
30 grcov_path,
31 "-t",
32 "lcov",
33 "-p",
34 buildconfig.topsrcdir,
35 buildconfig.topobjdir,
38 # We want to ignore system headers in our reports.
39 if buildconfig.substs["OS_TARGET"] == "WINNT":
40 # We use WINDOWSSDKDIR to find the directory holding the system headers on Windows.
41 windows_sdk_dir = None
42 config_opts = buildconfig.substs["MOZ_CONFIGURE_OPTIONS"].split(" ")
43 for opt in config_opts:
44 if opt.startswith("WINDOWSSDKDIR="):
45 windows_sdk_dir = opt[len("WINDOWSSDKDIR=") :]
46 break
48 assert (
49 windows_sdk_dir is not None
50 ), "WINDOWSSDKDIR should be in MOZ_CONFIGURE_OPTIONS"
52 ignore_dir_abs = os.path.dirname(windows_sdk_dir)
54 # globs passed to grcov must exist and must be relative to the source directory.
55 # If it doesn't exist, maybe it has moved and we need to update the paths above.
56 # If it is no longer relative to the source directory, we no longer need to ignore it and
57 # this code can be removed.
58 assert os.path.isdir(ignore_dir_abs), "{} is not a directory".format(
59 ignore_dir_abs
61 assert ignore_dir_abs.startswith(
62 buildconfig.topsrcdir
63 ), "{} should start with {}".format(ignore_dir_abs, buildconfig.topsrcdir)
65 grcov_command += [
66 "--ignore",
67 os.path.relpath(ignore_dir_abs, buildconfig.topsrcdir) + "*",
70 if buildconfig.substs["OS_TARGET"] == "Linux":
71 gcc_dir = os.path.join(os.environ["MOZ_FETCHES_DIR"], "gcc")
72 if "LD_LIBRARY_PATH" in os.environ:
73 os.environ["LD_LIBRARY_PATH"] = "{}/lib64/:{}".format(
74 gcc_dir, os.environ["LD_LIBRARY_PATH"]
76 else:
77 os.environ["LD_LIBRARY_PATH"] = "{}/lib64/".format(gcc_dir)
79 os.environ["PATH"] = "{}/bin/:{}".format(gcc_dir, os.environ["PATH"])
81 grcov_output = subprocess.check_output(grcov_command)
83 grcov_zip_path = os.path.join(buildconfig.topobjdir, "code-coverage-grcov.zip")
84 with zipfile.ZipFile(grcov_zip_path, "a", zipfile.ZIP_DEFLATED) as z:
85 z.writestr("grcov_lcov_output.info", grcov_output)
88 if __name__ == "__main__":
89 main()