| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 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/. |
| 6 |
|
| 7 |
import sys |
| 8 |
import os |
| 9 |
import pathlib |
| 10 |
import shutil |
| 11 |
import subprocess |
| 12 |
import tempfile |
| 13 |
import zipfile |
| 14 |
import buildconfig |
| 15 |
|
| 16 |
|
| 17 |
def main(): |
| 18 |
if not buildconfig.substs.get("MOZ_CODE_COVERAGE") or not buildconfig.substs.get( |
| 19 |
"MOZ_RUST_TESTS" |
| 20 |
): |
| 21 |
return |
| 22 |
|
| 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" |
| 28 |
|
| 29 |
grcov_command = [ |
| 30 |
grcov_path, |
| 31 |
"-t", |
| 32 |
"lcov", |
| 33 |
"-p", |
| 34 |
buildconfig.topsrcdir, |
| 35 |
buildconfig.topobjdir, |
| 36 |
] |
| 37 |
|
| 38 |
if buildconfig.substs["OS_TARGET"] == "Linux": |
| 39 |
gcc_dir = os.path.join(os.environ["MOZ_FETCHES_DIR"], "gcc") |
| 40 |
if "LD_LIBRARY_PATH" in os.environ: |
| 41 |
os.environ["LD_LIBRARY_PATH"] = "{}/lib64/:{}".format( |
| 42 |
gcc_dir, os.environ["LD_LIBRARY_PATH"] |
| 43 |
) |
| 44 |
else: |
| 45 |
os.environ["LD_LIBRARY_PATH"] = "{}/lib64/".format(gcc_dir) |
| 46 |
|
| 47 |
os.environ["PATH"] = "{}/bin/{}{}".format( |
| 48 |
gcc_dir, os.pathsep, os.environ["PATH"] |
| 49 |
) |
| 50 |
|
| 51 |
grcov_output = subprocess.check_output(grcov_command) |
| 52 |
|
| 53 |
grcov_zip_path = os.path.join(buildconfig.topobjdir, "code-coverage-grcov.zip") |
| 54 |
with zipfile.ZipFile(grcov_zip_path, "a", zipfile.ZIP_DEFLATED) as z: |
| 55 |
z.writestr("grcov_lcov_output.info", grcov_output) |
| 56 |
|
| 57 |
|
| 58 |
if __name__ == "__main__": |
| 59 |
main() |