1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2021-2024 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 "llvm-cov-profdata-out-path": self.llvm_profdata_out_path, 32 "llvm-cov-html-out-path": self.llvm_cov_html_out_path, 33 } 34 35 @cached_property 36 @value( 37 yaml_path="general.coverage.use-llvm-cov", 38 cli_name="use_llvm_cov", 39 cast_to_type=_to_bool 40 ) 41 def use_llvm_cov(self) -> bool: 42 return False 43 44 @cached_property 45 @value( 46 yaml_path="general.coverage.llvm-cov-profdata-out-path", 47 cli_name="llvm_profdata_out_path", 48 cast_to_type=_to_dir 49 ) 50 def llvm_profdata_out_path(self) -> Optional[str]: 51 return None 52 53 @cached_property 54 @value( 55 yaml_path="general.coverage.llvm-cov-html-out-path", 56 cli_name="llvm_cov_html_out_path", 57 cast_to_type=_to_dir 58 ) 59 def llvm_cov_html_out_path(self) -> Optional[str]: 60 return None 61 62 def get_command_line(self) -> str: 63 options = [ 64 '--use-llvm-cov' if self.use_llvm_cov else '', 65 f'--llvm-profdata-out-path="{self.llvm_profdata_out_path}"' 66 if self.llvm_profdata_out_path is not None else '', 67 f'--llvm-cov-html-out-path="{self.llvm_cov_html_out_path}"' 68 if self.llvm_cov_html_out_path is not None else '', 69 ] 70 return ' '.join(options) 71