1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2021-2025 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18from functools import cached_property 19from typing import Dict, Optional 20 21from runner.options.decorator_value import value, _to_bool, _to_str, _to_dir 22 23 24class CoverageOptions: 25 def __str__(self) -> str: 26 return _to_str(self, 2) 27 28 def to_dict(self) -> Dict[str, object]: 29 return { 30 "use-llvm-cov": self.use_llvm_cov, 31 "use-lcov": self.use_lcov, 32 "profdata-files-dir": self.profdata_files_dir, 33 "coverage-html-report-dir": self.coverage_html_report_dir, 34 "coverage-per-binary": self.coverage_per_binary, 35 "llvm-cov-exclude": self.llvm_cov_exclude, 36 "lcov-exclude": self.lcov_exclude, 37 } 38 39 @cached_property 40 @value( 41 yaml_path="general.coverage.use-llvm-cov", 42 cli_name="use_llvm_cov", 43 cast_to_type=_to_bool 44 ) 45 def use_llvm_cov(self) -> bool: 46 return False 47 48 @cached_property 49 @value( 50 yaml_path="general.coverage.use-lcov", 51 cli_name="use_lcov", 52 cast_to_type=_to_bool 53 ) 54 def use_lcov(self) -> bool: 55 return False 56 57 @cached_property 58 @value( 59 yaml_path="general.coverage.profdata-files-dir", 60 cli_name="profdata_files_dir", 61 cast_to_type=_to_dir 62 ) 63 def profdata_files_dir(self) -> Optional[str]: 64 return None 65 66 @cached_property 67 @value( 68 yaml_path="general.coverage.coverage-html-report-dir", 69 cli_name="coverage_html_report_dir", 70 cast_to_type=_to_dir 71 ) 72 def coverage_html_report_dir(self) -> Optional[str]: 73 return None 74 75 @cached_property 76 @value( 77 yaml_path="general.coverage.coverage-per-binary", 78 cli_name="coverage_per_binary", 79 cast_to_type=_to_bool 80 ) 81 def coverage_per_binary(self) -> bool: 82 return False 83 84 @cached_property 85 @value( 86 yaml_path="general.coverage.llvm-cov-exclude", 87 cli_name="llvm_cov_exclude", 88 ) 89 def llvm_cov_exclude(self) -> Optional[str]: 90 return None 91 92 @cached_property 93 @value( 94 yaml_path="general.coverage.lcov-exclude", 95 cli_name="lcov_exclude", 96 ) 97 def lcov_exclude(self) -> Optional[str]: 98 return None 99 100 def get_command_line(self) -> str: 101 options = [ 102 '--use-llvm-cov' if self.use_llvm_cov else '', 103 104 '--use-lcov' if self.use_lcov else '', 105 106 '--coverage-per-binary' if self.coverage_per_binary else '', 107 108 f'--profdata-files-dir="{self.profdata_files_dir}"' 109 if self.profdata_files_dir is not None else '', 110 111 f'--coverage-html-report-dir="{self.coverage_html_report_dir}"' 112 if self.coverage_html_report_dir is not None else '', 113 114 f'--llvm-cov-exclude="{self.llvm_cov_exclude}"' 115 if self.llvm_cov_exclude is not None else '', 116 117 f'--lcov-exclude="{self.lcov_exclude}"' 118 if self.lcov_exclude is not None else '', 119 ] 120 return ' '.join(options) 121