pytorch/tools/code_coverage/package/oss/cov_json.py
Yujun Zhao 49e979bfde Set default compiler differently according to platform (#43890)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/43890

1. auto-detect `CXX` default compiler type in oss, and `clang` as default compiler type in fbcode (because auto-detecting will say `gcc` is the default compiler on devserver).

2. change `compiler type` from str `"CLANG" "GCC"` to enum type
3. rename function `get_cov_type` to `detect_compiler_type`
4. auto-set the default pytorch folder for users in oss

Test Plan:
on devserver:
```
buck run :coverage //caffe2/c10:
```

on oss:
```
python oss_coverage.py --run-only=atest
```

Reviewed By: malfet

Differential Revision: D23420034

fbshipit-source-id: c0ea88188578bb1343a286f2090eb8a74cdf3982
2020-09-08 14:57:35 -07:00

35 lines
1.1 KiB
Python

import time
from ..tool import clang_coverage, gcc_coverage
from ..util.setting import CompilerType, Option, TestList, TestPlatform
from ..util.utils import check_compiler_type, print_time
from .init import detect_compiler_type, gcc_export_init
from .run import clang_run, gcc_run
def get_json_report(test_list: TestList, options: Option):
start_time = time.time()
cov_type = detect_compiler_type()
check_compiler_type(cov_type)
if cov_type == CompilerType.CLANG:
# run
if options.need_run:
clang_run(test_list)
# merge && export
if options.need_merge:
clang_coverage.merge(test_list, TestPlatform.OSS)
if options.need_export:
clang_coverage.export(test_list, TestPlatform.OSS)
elif cov_type == CompilerType.GCC:
# run
if options.need_run:
gcc_run(test_list)
# export
if options.need_export:
gcc_export_init()
gcc_coverage.export()
print_time(
"collect coverage for cpp tests take time: ", start_time, summary_time=True
)