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
19 if not buildconfig
.substs
.get("MOZ_CODE_COVERAGE") or not buildconfig
.substs
.get(
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"
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=") :]
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
)
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"]
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__":