1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2023 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 containers.arg import Arg 22from containers.arg import ModuleType 23from resolver.interface.args_resolver_interface import ArgsResolverInterface 24from modules.interface.set_module_interface import SetModuleInterface 25from resources.config import Config 26from util.product_util import ProductUtil 27from util.device_util import DeviceUtil 28 29 30class SetArgsResolver(ArgsResolverInterface): 31 32 def __init__(self, args_dict: dict): 33 super().__init__(args_dict) 34 35 @staticmethod 36 def resolve_product_name(target_arg: Arg, set_module: SetModuleInterface): 37 config = Config() 38 product_info = dict() 39 device_info = dict() 40 if target_arg.arg_value == '': 41 product_info = set_module._menu.select_product() 42 elif target_arg.arg_value.__contains__('@'): 43 product_name, company_name = target_arg.arg_value.split('@', 2) 44 product_info = ProductUtil.get_product_info( 45 product_name, company_name) 46 else: 47 product_info = ProductUtil.get_product_info(target_arg.arg_value) 48 49 config.product = product_info.get('name') 50 config.product_path = product_info.get('product_path') 51 config.version = product_info.get('version') 52 config.os_level = product_info.get('os_level') 53 config.product_json = product_info.get('config') 54 config.component_type = product_info.get('component_type') 55 if product_info.get('product_config_path'): 56 config.product_config_path = product_info.get( 57 'product_config_path') 58 else: 59 config.product_config_path = product_info.get('path') 60 61 device_info = ProductUtil.get_device_info(config.product_json) 62 config.board = device_info.get('board') 63 config.kernel = device_info.get('kernel') 64 config.target_cpu = device_info.get('target_cpu') 65 config.target_os = device_info.get('target_os') 66 config.support_cpu = device_info.get("support_cpu") 67 kernel_version = device_info.get('kernel_version') 68 config.device_company = device_info.get('company') 69 board_path = device_info.get('board_path') 70 71 if product_info.get('build_out_path'): 72 config.out_path = os.path.join(config.root_path, 73 product_info.get('build_out_path')) 74 else: 75 if config.os_level == 'standard': 76 config.out_path = os.path.join(config.root_path, 'out', 77 config.board) 78 else: 79 config.out_path = os.path.join(config.root_path, 'out', 80 config.board, config.product) 81 82 if product_info.get('subsystem_config_json'): 83 config.subsystem_config_json = product_info.get( 84 'subsystem_config_json') 85 else: 86 config.subsystem_config_json = 'build/subsystem_config.json' 87 88 subsystem_config_overlay_path = os.path.join( 89 config.product_path, 'subsystem_config_overlay.json') 90 if os.path.isfile(subsystem_config_overlay_path): 91 if product_info.get('subsystem_config_overlay_json'): 92 config.subsystem_config_overlay_json = product_info.get( 93 'subsystem_config_overlay_json') 94 else: 95 config.subsystem_config_overlay_json = subsystem_config_overlay_path 96 97 if config.version == '2.0': 98 config.device_path = board_path 99 else: 100 if config.os_level == "standard": 101 config.device_path = board_path 102 else: 103 config.device_path = DeviceUtil.get_device_path( 104 board_path, config.kernel, kernel_version) 105 106 if device_info.get('board_config_path'): 107 config.device_config_path = device_info.get('board_config_path') 108 else: 109 config.device_config_path = config.device_path 110 111 Arg.write_args_file(target_arg.arg_name, 112 product_info.get('name'), ModuleType.BUILD) 113 Arg.write_args_file(target_arg.arg_name, 114 f"{product_info.get('name')}@{product_info.get('company')}", ModuleType.SET) 115 116 @staticmethod 117 def resolve_set_parameter(target_arg: Arg, set_module: SetModuleInterface): 118 if target_arg.arg_value: 119 SetArgsResolver.resolve_product_name( 120 set_module.args_dict['product_name'], set_module) 121 options = set_module.menu.select_compile_option() 122 for arg_name, arg_value in options.items(): 123 Arg.write_args_file(arg_name, arg_value, ModuleType.BUILD) 124