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
18 if not buildconfig
.substs
.get("MOZ_CODE_COVERAGE") or not buildconfig
.substs
.get(
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"
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=") :]
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(
61 assert ignore_dir_abs
.startswith(
63 ), "{} should start with {}".format(ignore_dir_abs
, buildconfig
.topsrcdir
)
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"]
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__":