• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, List
20
21from runner.options.decorator_value import value, _to_int, _to_str, _to_path, _to_bool
22
23
24class Es2PandaOptions:
25    __DEFAULT_TIMEOUT = 60
26    __DEFAULT_OPT_LEVEL = 2
27
28    def __str__(self) -> str:
29        return _to_str(self, 1)
30
31    def to_dict(self) -> Dict[str, object]:
32        return {
33            "timeout": self.timeout,
34            "opt-level": self.opt_level,
35            "custom-path": self.custom_path,
36            "arktsconfig": self.arktsconfig,
37            "es2panda-args": self.es2panda_args,
38            "system": self.system
39        }
40
41    @cached_property
42    @value(yaml_path="es2panda.timeout", cli_name="es2panda_timeout", cast_to_type=_to_int)
43    def timeout(self) -> int:
44        return Es2PandaOptions.__DEFAULT_TIMEOUT
45
46    @cached_property
47    @value(yaml_path="es2panda.opt-level", cli_name="es2panda_opt_level", cast_to_type=_to_int)
48    def opt_level(self) -> int:
49        return Es2PandaOptions.__DEFAULT_OPT_LEVEL
50
51    @cached_property
52    @value(yaml_path="es2panda.custom-path", cli_name="custom_es2panda_path", cast_to_type=_to_path)
53    def custom_path(self) -> Optional[str]:
54        return None
55
56    @cached_property
57    @value(yaml_path="es2panda.arktsconfig", cli_name="arktsconfig", cast_to_type=_to_path)
58    def arktsconfig(self) -> Optional[str]:
59        return None
60
61    @cached_property
62    @value(yaml_path="es2panda.es2panda-args", cli_name="es2panda_args")
63    def es2panda_args(self) -> List[str]:
64        return []
65
66    @cached_property
67    @value(yaml_path="es2panda.system", cli_name="system", cast_to_type=_to_bool)
68    def system(self) -> bool:
69        return False
70
71    def get_command_line(self) -> str:
72        options = [
73            f'--es2panda-timeout={self.timeout}' if self.timeout != Es2PandaOptions.__DEFAULT_TIMEOUT else '',
74            f'--es2panda-opt-level={self.opt_level}' if self.opt_level != Es2PandaOptions.__DEFAULT_OPT_LEVEL else '',
75            f'--custom-es2panda="{self.custom_path}"' if self.custom_path is not None else '',
76            f'--arktsconfig="{self.arktsconfig}"' if self.arktsconfig is not None else '',
77        ]
78        return ' '.join(options)
79