• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2021-2023 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# This file does only contain a selection of the most common options. For a
18# full list see the documentation:
19# http://www.sphinx-doc.org/en/master/config
20
21from functools import cached_property
22from typing import Dict, Optional
23
24from runner.options.decorator_value import value, _to_bool, _to_str, _to_dir
25
26
27class CoverageOptions:
28    def __str__(self) -> str:
29        return _to_str(self, 2)
30
31    def to_dict(self) -> Dict[str, object]:
32        return {
33            "use-llvm-cov": self.use_llvm_cov,
34            "llvm-cov-profdata-out-path": self.llvm_profdata_out_path,
35            "llvm-cov-html-out-path": self.llvm_cov_html_out_path,
36        }
37
38    @cached_property
39    @value(
40        yaml_path="general.coverage.use-llvm-cov",
41        cli_name="use_llvm_cov",
42        cast_to_type=_to_bool
43    )
44    def use_llvm_cov(self) -> bool:
45        return False
46
47    @cached_property
48    @value(
49        yaml_path="general.coverage.llvm-cov-profdata-out-path",
50        cli_name="llvm_profdata_out_path",
51        cast_to_type=_to_dir
52    )
53    def llvm_profdata_out_path(self) -> Optional[str]:
54        return None
55
56    @cached_property
57    @value(
58        yaml_path="general.coverage.llvm-cov-html-out-path",
59        cli_name="llvm_cov_html_out_path",
60        cast_to_type=_to_dir
61    )
62    def llvm_cov_html_out_path(self) -> Optional[str]:
63        return None
64
65    def get_command_line(self) -> str:
66        options = [
67            '--use-llvm-cov' if self.use_llvm_cov else '',
68            f'--llvm-profdata-out-path="{self.llvm_profdata_out_path}"'
69            if self.llvm_profdata_out_path is not None else '',
70            f'--llvm-cov-html-out-path="{self.llvm_cov_html_out_path}"'
71            if self.llvm_cov_html_out_path is not None else '',
72        ]
73        return ' '.join(options)
74