• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding: utf-8
3# Copyright (c) 2024 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17import argparse
18import os
19
20
21def parse_arguments() -> argparse.Namespace:
22    parser = argparse.ArgumentParser(description="Cpp headers parser to .yaml")
23
24    parser.add_argument(
25        "--lib-gen-dir",
26        "-d",
27        type=str,
28        required=True,
29        help="Path to es2panda_lib generation directory (aka <build>/tools/es2panda/es2panda_lib)",
30    )
31    parser.add_argument(
32        "--es2panda-root",
33        "-e",
34        type=str,
35        required=True,
36        help="Path to es2panda_root (aka <runtime_core>/static_core/tools/es2panda)",
37    )
38    parser.add_argument(
39        "--headers",
40        "-l",
41        type=str,
42        required=True,
43        nargs="+",
44        help="List of headers to be parsed. Full paths, via <runtime_core>/static_core/tools/es2panda",
45    )
46
47    return parser.parse_args()
48
49
50def check_arguments(args: argparse.Namespace) -> argparse.Namespace:
51    if not os.path.isdir(args.lib_gen_dir):
52        raise RuntimeError(f"Bad path to lib_gen_dir: '{args.lib_gen_dir}'\nSee --help for more.")
53    if not os.path.isdir(args.es2panda_root):
54        raise RuntimeError(f"Bad path to es2panda_root: '{args.es2panda_root}'\nSee --help for more.")
55    for header in args.headers:
56        if not os.path.isfile(header) or os.path.splitext(header)[1] != ".h":
57            raise RuntimeError(f"Bad path to header: '{header}'. See --help for more.")
58
59    return args
60