• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#
5# Copyright (c) 2020 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20
21from hb_internal.common.config import Config
22from hb_internal.common.utils import get_input
23from hb_internal.common.utils import OHOSException
24from hb_internal.common.utils import hb_info
25from hb_internal.common.product import Product
26from hb_internal.common.device import Device
27
28
29def add_options(parser):
30    parser.add_argument('-root',
31                        '--root_path',
32                        nargs='?',
33                        default=None,
34                        help='Set OHOS root path')
35    parser.add_argument('-p', '--product', help='Set OHOS board and kernel')
36
37
38def exec_command(args):
39    ret = set_root_path(root_path=args.root_path)
40    if ret != 0:
41        return ret
42    if args.product:
43        return set_product(product_name=args.product) == 0
44    else:
45        return set_product() == 0
46
47
48def set_root_path(root_path=None):
49    config = Config()
50    if root_path is None:
51        try:
52            hb_info(f'hb root path: {config.root_path}')
53            return 0
54        except OHOSException:
55            root_path = get_input('[OHOS INFO] Input code path: ')
56    config.root_path = root_path
57    return 0
58
59
60def set_product(product_name=None, company=None):
61    if product_name is None and company is None:
62        product_info = Product.product_menuconfig()
63    elif product_name is None:
64        product_info = Product.get_product_info(product_name)
65    else:
66        product_info = Product.get_product_info(product_name, company)
67
68    config = Config()
69    config.product = product_info.get('name')
70    config.product_path = product_info.get('path')
71    config.version = product_info.get('version')
72    config.os_level = product_info.get('os_level')
73    config.product_json = product_info.get('config')
74
75    device_info = Product.get_device_info(config.product_json)
76    config.board = device_info.get('board')
77    config.kernel = device_info.get('kernel')
78    config.target_cpu = device_info.get('target_cpu')
79    config.target_os = device_info.get('target_os')
80    kernel_version = device_info.get('kernel_version')
81    config.device_company = device_info.get('company')
82    board_path = device_info.get('board_path')
83
84    if config.os_level == 'standard':
85        config.out_path = os.path.join(config.root_path, 'out', config.board)
86    else:
87        config.out_path = os.path.join(config.root_path, 'out', config.board,
88                                       config.product)
89
90    if config.version == '2.0':
91        config.device_path = board_path
92    else:
93        if config.os_level == "standard":
94            config.device_path = board_path
95        else:
96            config.device_path = Device.get_device_path(
97                board_path, config.kernel, kernel_version)
98
99    return 0
100