From 85ad1a82f47d73fccd79533136daa550e9e9a5d7 Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Tue, 12 Oct 2021 10:42:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0hdf=5Fdev=5Feco=5Ftool?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenpan0560 --- .../hdf_dev_eco_tool/command_line/__init__.py | 0 .../command_line/hdf_add_handler.py | 301 ++++++++++++++ .../command_line/hdf_command_error_code.py | 38 ++ .../command_line/hdf_command_handler_base.py | 105 +++++ .../command_line/hdf_command_line_server.py | 142 +++++++ .../command_line/hdf_defconfig_patch.py | 99 +++++ .../command_line/hdf_delete_handler.py | 190 +++++++++ .../command_line/hdf_device_info_hcs.py | 143 +++++++ .../command_line/hdf_dot_config_file.py | 152 +++++++ .../command_line/hdf_driver_config_file.py | 92 +++++ .../command_line/hdf_get_handler.py | 201 ++++++++++ .../command_line/hdf_hcs_file.py | 102 +++++ .../command_line/hdf_lite_kconfig_file.py | 86 ++++ .../command_line/hdf_lite_mk_file.py | 106 +++++ .../command_line/hdf_lite_settings_mk_file.py | 108 +++++ .../command_line/hdf_manager_config_file.py | 172 ++++++++ .../command_line/hdf_module_kconfig_file.py | 201 ++++++++++ .../command_line/hdf_module_mk_file.py | 88 ++++ .../command_line/hdf_ping_handler.py | 41 ++ .../command_line/hdf_set_handler.py | 142 +++++++ .../command_line/hdf_tool_argument_parser.py | 45 +++ .../command_line/hdf_tool_commands.py | 63 +++ .../command_line/hdf_vendor_build_file.py | 80 ++++ .../command_line/hdf_vendor_kconfig_file.py | 116 ++++++ .../command_line/hdf_vendor_makefile.py | 113 ++++++ .../command_line/hdf_vendor_mk_file.py | 95 +++++ .../hdf_tool_daemon_server.py | 51 +++ tools/hdf_dev_eco_tool/hdf_tool_exception.py | 39 ++ tools/hdf_dev_eco_tool/hdf_tool_settings.py | 122 ++++++ tools/hdf_dev_eco_tool/hdf_tool_version.py | 36 ++ tools/hdf_dev_eco_tool/hdf_utils.py | 377 ++++++++++++++++++ tools/hdf_dev_eco_tool/main.py | 74 ++++ .../resources/create_model.config | 1 + .../hdf_dev_eco_tool/resources/settings.json | 23 ++ .../templates/lite/Linux_Kconfig.template | 34 ++ .../templates/lite/Linux_Makefile.template | 33 ++ .../templates/lite/Linux_built-in.template | 4 + .../templates/lite/Liteos_BUILD_gn.template | 41 ++ .../lite/Liteos_Device_Info_Hcs.template | 15 + .../templates/lite/Liteos_Kconfig.template | 34 ++ .../templates/lite/Liteos_Makefile.template | 39 ++ .../templates/lite/device_info_hcs.template | 15 + .../templates/lite/hdf_driver.c.template | 41 ++ .../templates/lite/hdf_driver.h.template | 10 + .../templates/lite/hdf_driver_config.template | 3 + .../lite/hdf_driver_kconfig.template | 6 + .../lite/hdf_driver_makefile.template | 10 + .../lite/hdf_driver_manager_config.template | 38 ++ .../hdf_driver_manager_config_device.template | 10 + .../hdf_driver_manager_config_host.template | 3 + .../templates/lite/hdf_hcs_makefile.template | 7 + .../lite/hdf_module_kconfig.template | 6 + .../templates/lite/hdf_module_mk.template | 4 + .../lite/hdf_module_mk_driver.template | 5 + .../lite/hdf_vendor_kconfig.template | 1 + .../templates/lite/hdf_vendor_mk.template | 2 + .../lite/hdf_vendor_mk_module.template | 4 + 57 files changed, 4109 insertions(+) create mode 100755 tools/hdf_dev_eco_tool/command_line/__init__.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_module_kconfig_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_module_mk_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_ping_handler.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_tool_argument_parser.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_tool_commands.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_vendor_mk_file.py create mode 100755 tools/hdf_dev_eco_tool/hdf_tool_daemon_server.py create mode 100755 tools/hdf_dev_eco_tool/hdf_tool_exception.py create mode 100755 tools/hdf_dev_eco_tool/hdf_tool_settings.py create mode 100755 tools/hdf_dev_eco_tool/hdf_tool_version.py create mode 100755 tools/hdf_dev_eco_tool/hdf_utils.py create mode 100755 tools/hdf_dev_eco_tool/main.py create mode 100755 tools/hdf_dev_eco_tool/resources/create_model.config create mode 100755 tools/hdf_dev_eco_tool/resources/settings.json create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Kconfig.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Makefile.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Linux_built-in.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_BUILD_gn.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Device_Info_Hcs.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Kconfig.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Makefile.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.h.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_config.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_kconfig.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_makefile.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_device.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_host.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_hcs_makefile.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_kconfig.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk_driver.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_kconfig.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk.template create mode 100755 tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk_module.template diff --git a/tools/hdf_dev_eco_tool/command_line/__init__.py b/tools/hdf_dev_eco_tool/command_line/__init__.py new file mode 100755 index 000000000..e69de29bb diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py new file mode 100755 index 000000000..d16976c99 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -0,0 +1,301 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import json +import platform +from string import Template + +from .hdf_command_handler_base import HdfCommandHandlerBase +from .hdf_command_error_code import CommandErrorCode +from .hdf_device_info_hcs import HdfDeviceInfoHcsFile +from .hdf_vendor_build_file import HdfVendorBuildFile +from .hdf_vendor_kconfig_file import HdfVendorKconfigFile +from .hdf_vendor_mk_file import HdfVendorMkFile +from .hdf_module_kconfig_file import HdfModuleKconfigFile +from .hdf_module_mk_file import HdfModuleMkFile +from .hdf_driver_config_file import HdfDriverConfigFile +from hdf_tool_settings import HdfToolSettings +from hdf_tool_exception import HdfToolException +from .hdf_vendor_makefile import HdfVendorMakeFile +from .hdf_defconfig_patch import HdfDefconfigAndPatch +import hdf_utils + + +class HdfAddHandler(HdfCommandHandlerBase): + def __init__(self, args): + super(HdfAddHandler, self).__init__() + self.cmd = 'add' + self.handlers = { + 'vendor': self._add_vendor_handler, + 'module': self._add_module_handler, + 'driver': self._add_driver_handler, + 'config': self._add_config_handler, + } + self.parser.add_argument("--action_type", + help=' '.join(self.handlers.keys()), + required=True) + self.parser.add_argument("--root_dir", required=True) # 路径 + self.parser.add_argument("--vendor_name") # 厂商 + self.parser.add_argument("--module_name") # 模块名 + self.parser.add_argument("--driver_name") # 驱动名称 + self.parser.add_argument("--board_name") # 板子名称 + self.parser.add_argument("--kernel_name") # 内核名称 + self.args = self.parser.parse_args(args) + + @staticmethod + def _render(template_path, output_path, data_model): + if not os.path.exists(template_path): + return + raw_content = hdf_utils.read_file(template_path) + contents = Template(raw_content).safe_substitute(data_model) + hdf_utils.write_file(output_path, contents) + + def _file_gen_lite(self, template, out_dir, filename, model): + templates_dir = hdf_utils.get_templates_lite_dir() + template_path = os.path.join(templates_dir, template) + file_path = os.path.join(out_dir, filename) + self._render(template_path, file_path, model) + + def _add_vendor_handler(self): + self.check_arg_raise_if_not_exist("vendor_name") + root, vendor, _, _, board = self.get_args() + target_dir = hdf_utils.get_vendor_hdf_dir(root, vendor) + if os.path.exists(target_dir): + raise HdfToolException("%s already exists" % target_dir, + CommandErrorCode.TARGET_ALREADY_EXIST) + os.makedirs(target_dir) + self._file_gen_lite('hdf_vendor_kconfig.template', target_dir, + 'Kconfig', {}) + board_parent_path = HdfToolSettings().get_board_parent_path(board) + if not board_parent_path: + board_parent_path = 'vendor/hisilicon' + data_model = { + "board_parent_path": board_parent_path + } + self._file_gen_lite('hdf_vendor_mk.template', target_dir, + 'hdf_vendor.mk', data_model) + + def _add_module_handler(self): + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("module_name") + self.check_arg_raise_if_not_exist("kernel_name") + self.check_arg_raise_if_not_exist("board_name") + self.check_arg_raise_if_not_exist("driver_name") + + args_tuple = self.get_args() + root, vendor, module, driver, board, kernel = args_tuple + converter = hdf_utils.WordsConverter(self.args.module_name) + driver_name_converter = hdf_utils.WordsConverter(self.args.driver_name) + framework_hdf = hdf_utils.get_vendor_hdf_dir_framework(root) + if not os.path.exists(framework_hdf): + raise HdfToolException(' framework model path "%s" not exist' % framework_hdf, + CommandErrorCode.TARGET_NOT_EXIST) + # 在 framework 目录下创建对应的 module 的文件目录用于存放 .c 驱动文件 + framework_drv_root_dir = hdf_utils.get_drv_root_dir(root, vendor, module) + if os.path.exists(framework_drv_root_dir): + raise HdfToolException('module "%s" already exist' % module, + CommandErrorCode.TARGET_ALREADY_EXIST) + os.makedirs(framework_drv_root_dir) + + # 创建 .c 模板驱动 + state, driver_file_path = self._add_driver_handler(*args_tuple) + if not state: + raise HdfToolException('create drivers file fail "%s" ' % driver_file_path.split("\\")[-1]) + adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter(root, kernel) + if not os.path.exists(adapter_hdf): + raise HdfToolException(' adapter model path "%s" not exist' % adapter_hdf, + CommandErrorCode.TARGET_NOT_EXIST) + + # 创建 adapter 路径下的 module 文件夹 + adapter_model_path = os.path.join(adapter_hdf, 'model', module) + if not os.path.exists(adapter_model_path): + os.makedirs(adapter_model_path) + + data_model = { + "module_upper_case": converter.upper_case(), + "module_lower_case": converter.lower_case(), + "driver_file_name": ("%s_driver.c" % driver_name_converter.lower_case()), + "driver_name": driver_name_converter.lower_case() + } + # 创建 adapter 下的 module中的三个文件 + if kernel == 'liteos': + file_path, model_level_config_file_path = self._add_module_handler_liteos(framework_hdf, adapter_model_path, + data_model, converter, *args_tuple) + elif kernel == "linux": + file_path, model_level_config_file_path = self._add_module_handler_linux(framework_hdf, adapter_model_path, + data_model, *args_tuple) + else: + file_path = {} + model_level_config_file_path = {} + config_item = { + 'module_name': module, + 'module_path': file_path, + 'driver_name': "%s_driver.c" % driver, + 'driver_file_path': driver_file_path, + 'enabled': True + } + config_file_out = { + 'module_name': module, + 'module_path': file_path, + # 'module_path': file_path.update({driver_file_path.split("\\")[-1]: driver_file_path}), + 'driver_name': driver_file_path.split("\\")[-1], + 'driver_file_path': driver_file_path, + 'module_level_config_path': model_level_config_file_path + } + config_file = hdf_utils.read_file(os.path.join('resources', 'create_model.config')) + config_file_json = json.loads(config_file) + config_file_json[module] = config_file_out + if platform.system() == "Windows": + config_file_replace = json.dumps(config_file_json, indent=4).replace(root.replace('\\', '\\\\') + '\\\\', "") + hdf_utils.write_file(os.path.join('resources', 'create_model.config'), config_file_replace.replace('\\\\', '/')) + if platform.system() == "Linux": + config_file_replace = json.dumps(config_file_json, indent=4).replace(root + '/', "") + hdf_utils.write_file(os.path.join('resources', 'create_model.config'), config_file_replace) + return json.dumps(config_item) + + def _add_module_handler_liteos(self, framework_hdf, adapter_model_path, data_model, converter, *args_tuple): + root, vendor, module, driver, board, kernel = args_tuple + liteos_file_path = {} + liteos_level_config_file_path = {} + liteos_file_name = ['BUILD.gn', 'Kconfig', 'Makefile'] + # template_path = os.path.join(adapter_hdf, "tools", "hdf_dev_eco_tool", "resources", "templates", "lite") + template_path = "/".join([framework_hdf] + ["tools", "hdf_dev_eco_tool", "resources", "templates", "lite"]) + for file_name in liteos_file_name: + for i in os.listdir(template_path): + if i.find(file_name.split(".")[0]) > 0: + out_path = os.path.join(adapter_model_path, file_name) + self._render(os.path.join(template_path, i), out_path, data_model) + liteos_file_path[file_name] = out_path + # 修改 liteos 下的 Kconfig 文件 + vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") + vendor_k_path = vendor_k.add_module([module, 'Kconfig']) + liteos_level_config_file_path[module+"_Kconfig"] = vendor_k_path + + # 修改 liteos 下的 hdf_lite.mk 文件 + vendor_mk = HdfVendorMkFile(root, vendor) + vendor_mk_path = vendor_mk.add_module(module) + liteos_level_config_file_path[module + "_hdf_lite"] = vendor_mk_path + + # 修改 liteos 下的 Build.gn 文件 + vendor_gn = HdfVendorBuildFile(root, vendor) + vendor_gn_path = vendor_gn.add_module(module) + liteos_level_config_file_path[module + "Build"] = vendor_gn_path + + # 修改 vendor/hisilicon/hispark_taurus/hdf_config/device_info 下的 device_info.hcs 文件 + device_info = HdfDeviceInfoHcsFile(root, vendor, module, board, driver, path="") + hcs_file_path = device_info.add_model_hcs_file_config() + liteos_file_path["devices_info.hcs"] = hcs_file_path + + # 修改 dot_configs 的配置文件 + dot_file_list = hdf_utils.get_dot_configs_path(root, vendor, board) + template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" + new_demo_config = Template(template_string).substitute( + {"module_upper_case": converter.upper_case()}) + for dot_file in dot_file_list: + file_lines = hdf_utils.read_file_lines(dot_file) + file_lines[-1] = file_lines[-1].strip() + "\n" + if new_demo_config != file_lines[-1]: + file_lines.append(new_demo_config) + hdf_utils.write_file_lines(dot_file, file_lines) + liteos_level_config_file_path[module + "_dot_configs"] = dot_file_list + return liteos_file_path, liteos_level_config_file_path + + def _add_module_handler_linux(self, framework_hdf, adapter_model_path, data_model, *args_tuple): + root, vendor, module, driver, board, kernel = args_tuple + linux_file_path = {} + linux_level_config_file_path = {} + # linux_file_name = ['built-in.a', 'Kconfig', 'Makefile'] + linux_file_name = ['Kconfig', 'Makefile'] + # template_path = "/".join([adapter_hdf.strip(kernel)[:-1]] + ["liteos", "tools", "hdf_dev_eco_tool", + # "resources", "templates", "lite"]) + template_path = "/".join([framework_hdf] + ["tools", "hdf_dev_eco_tool", "resources", "templates", "lite"]) + for file_name in linux_file_name: + for i in hdf_utils.template_filename_filtrate(template_path, kernel): + if i.find(file_name.split(".")[0]) > 0: + out_path = os.path.join(adapter_model_path, file_name) + self._render(os.path.join(template_path, i), out_path, data_model) + linux_file_path[file_name] = out_path + # 修改 linux 下的 Kconfig 文件 + vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") + vendor_k_path = vendor_k.add_module([module, 'Kconfig']) + linux_level_config_file_path[module + "_Kconfig"] = vendor_k_path + + # 修改 linux 下的 Makefile 文件 + vendor_mk = HdfVendorMakeFile(root, vendor, kernel, path='') + vendor_mk_path = vendor_mk.add_module(data_model) + linux_level_config_file_path[module + "_Makefile"] = vendor_mk_path + + # 修改 vendor/hisilicon/hispark_taurus_linux/hdf_config/device_info 下的 device_info.hcs 文件 + device_info = HdfDeviceInfoHcsFile(root, vendor, module, board, driver, path="") + hcs_file_path = device_info.add_model_hcs_file_config() + linux_file_path["devices_info.hcs"] = hcs_file_path + + # 修改 dot_configs 的配置文件 + template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" + new_demo_config = Template(template_string).substitute(data_model) + defconfig_patch = HdfDefconfigAndPatch(root, vendor, kernel, board, data_model, new_demo_config) + + config_path = defconfig_patch.get_config_config() + patch_list = defconfig_patch.add_module(config_path) + config_path = defconfig_patch.get_config_patch() + defconfig_list = defconfig_patch.add_module(config_path) + linux_level_config_file_path[module + "_dot_configs"] = list(set(patch_list + defconfig_list)) + return linux_file_path, linux_level_config_file_path + + def _add_driver_handler(self, *args_tuple): + root, vendor, module, driver, board, kernel = args_tuple + drv_converter = hdf_utils.WordsConverter(self.args.driver_name) + drv_src_dir = hdf_utils.get_drv_src_dir(root, vendor, module) + if os.path.exists(os.path.join(drv_src_dir, '%s_driver.c' % driver)): + raise HdfToolException('driver "%s" already exist' % driver, + CommandErrorCode.TARGET_ALREADY_EXIST) + data_model = { + 'driver_lower_case': drv_converter.lower_case(), + 'driver_upper_camel_case': drv_converter.upper_camel_case(), + 'driver_lower_camel_case': drv_converter.lower_camel_case(), + 'driver_upper_case': drv_converter.upper_case() + } + self._file_gen_lite('hdf_driver.c.template', drv_src_dir, + '%s_driver.c' % driver, data_model) + driver_file_path = os.path.join(drv_src_dir, '%s_driver.c' % driver) + return True, driver_file_path + + def _add_config_handler(self): + self.check_arg_raise_if_not_exist("module_name") + self.check_arg_raise_if_not_exist("driver_name") + self.check_arg_raise_if_not_exist("board_name") + root, _, module, driver, board = self.get_args() + drv_config = HdfDriverConfigFile(root, board, module, driver) + drv_config.create_driver() + return drv_config.get_drv_config_path() + + diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py new file mode 100755 index 000000000..4c46b6701 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +class CommandErrorCode(object): + MESSAGE_FORMAT_WRONG = 1001 + INTERFACE_ERROR = 1002 + TARGET_NOT_EXIST = 1003 + TARGET_ALREADY_EXIST = 1004 + FILE_FORMAT_WRONG = 1005 + UNKNOWN_ERROR = 1111 diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py new file mode 100755 index 000000000..3402b2665 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os + +from .hdf_command_error_code import CommandErrorCode +from .hdf_tool_argument_parser import HdfToolArgumentParser +from hdf_tool_exception import HdfToolException +import hdf_utils + + +class HdfCommandHandlerBase(object): + def __init__(self): + self.cmd = 'base' + self.action_type = 'base_action_type' + self.handlers = {} + self.args = {} + self.parser = HdfToolArgumentParser() + + def run(self): + self.action_type = self._get_action_type() + if self.action_type in self.handlers: + return self.handlers[self.action_type]() + else: + raise HdfToolException('unknown action_type: "%s" for "%s" cmd' % + (self.action_type, self.cmd), + CommandErrorCode.INTERFACE_ERROR) + + def _get_action_type(self): + try: + return getattr(self.args, 'action_type') + except AttributeError: + return '' + + def check_arg_raise_if_not_exist(self, arg): + try: + value = getattr(self.args, arg) + if not value: + raise AttributeError() + except AttributeError: + raise HdfToolException('argument "--%s" is required for "%s" cmd' % + (arg, self.cmd), + CommandErrorCode.INTERFACE_ERROR) + + def _get_arg(self, arg): + try: + value = getattr(self.args, arg) + return value + except AttributeError: + return '' + + def get_args(self): + args = ['vendor_name', 'module_name', 'driver_name', 'board_name', 'kernel_name'] + ret = [self._get_arg('root_dir')] + for arg in args: + value = self._get_arg(arg) + if value: + value = hdf_utils.WordsConverter(value).lower_case() + ret.append(value) + return tuple(ret) + """ + def get_args(self): + args = ['root_dir', 'vendor_name', 'module_name', 'driver_name', 'board_name', 'kernel_name'] + ret = {"root": self._get_arg('root_dir')} + for arg in args: + value = self._get_arg(arg) + if value: + value = hdf_utils.WordsConverter(value).lower_case() + ret[arg.split("_")[0]] = value + return ret + """ + + @staticmethod + def check_path_raise_if_not_exist(full_path): + if not os.path.exists(full_path): + raise HdfToolException('%s not exist' % full_path, + CommandErrorCode.TARGET_NOT_EXIST) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py new file mode 100755 index 000000000..d49f078bf --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import sys +import argparse + +from .hdf_tool_commands import HdfToolCommands +from .hdf_tool_argument_parser import HdfToolArgumentParser +from command_line.hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException + + +class Message(object): + TYPE_REQ = 'request' + TYPE_QUIT = 'quit' + TYPE_ERROR = 'error' + TYPE_SUCCESS = 'success' + + def __init__(self, msg_type, content): + self.msg_type = msg_type + self.content = content + + def is_quit(self): + return self.msg_type.lower() == Message.TYPE_ERROR + + +def pack_message(msg_type, content, err_code=None): + body = bytearray(content, 'utf-8') + if not err_code: + header = bytearray('{},{}\n'.format(msg_type, len(body)), 'utf-8') + else: + header = bytearray('{},{},{}\n'.format(msg_type, len(body), err_code), + 'utf-8') + bytes_packet = bytearray().join([header, body]) + return bytes_packet + + +def decode_header(header): + header_parts = header.split(',') + if len(header_parts) < 2: + return -1, '', 0 + msg_type = header_parts[0] + body_len = int(header_parts[1]) + return 0, msg_type, body_len + + +def decode_body(body): + arg_parser = HdfToolArgumentParser() + arg_parser.add_argument('cmd') + arg_parser.add_argument('remainder_args', nargs=argparse.REMAINDER) + args = arg_parser.parse_args(body.strip().split(' ')) + remainder = [arg for arg in args.remainder_args if len(arg) != 0] + return args.cmd, remainder + + +class HdfCommandLineServer(object): + def __init__(self, input_obj, output_obj): + self.input_obj = input_obj + self.output_obj = output_obj + self.commands = HdfToolCommands() + + def _send_back(self, msg_type, content, error_code=None): + message_bytes = pack_message(msg_type, content, error_code) + self.output_obj.write(message_bytes) + self.output_obj.flush() + + def _send_back_success(self, content): + self._send_back(Message.TYPE_SUCCESS, content) + + def _send_back_error(self, error_code, content): + self._send_back(Message.TYPE_ERROR, content, error_code) + + def _read_header(self): + head_bytes = self.input_obj.readline() + msg_header = str(head_bytes, encoding="utf-8") + return decode_header(msg_header) + + def _read_body(self, body_len): + body_bytes = self.input_obj.read(body_len) + body = str(body_bytes, encoding='utf-8') + return decode_body(body) + + def run(self): + while True: + try: + ret, msg_type, body_len = self._read_header() + if ret != 0: + err_code = CommandErrorCode.MESSAGE_FORMAT_WRONG + self._send_back_error(err_code, 'header wrong') + continue + if msg_type == Message.TYPE_QUIT: + self._send_back_success('Bye bye!') + break + if body_len < 0: + err_code = CommandErrorCode.MESSAGE_FORMAT_WRONG + self._send_back_error(err_code, 'body len wrong') + continue + cmd, args = self._read_body(body_len) + ret = self.commands.run(cmd, args) + if ret: + self._send_back_success(str(ret)) + else: + self._send_back_success('') + except HdfToolException as exc: + try: + self._send_back_error(exc.error_code, exc.exc_msg) + except OSError: + sys.exit(-1) + except Exception as exc: + try: + self._send_back_error(CommandErrorCode.UNKNOWN_ERROR, + str(exc)) + except OSError: + sys.exit(-1) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py new file mode 100755 index 000000000..7efe0328b --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re +from string import Template + +from hdf_tool_settings import HdfToolSettings +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +import hdf_utils + + +class HdfDefconfigAndPatch(object): + def __init__(self, root, vendor, kernel, board, data_model, new_demo_config): + self.root = root + self.vendor = vendor + self.kernel = kernel + self.board = board + self.data_model = data_model + self.new_demo_config = new_demo_config + self.file_path = hdf_utils.get_template_file_path(root, vendor) + self.drivers_path_list = HdfToolSettings().get_board_parent_file(self.board) + + def get_config_config(self): + return os.path.join(self.root, "kernel", self.kernel, "config") + + def get_config_patch(self): + return os.path.join(self.root, "kernel", self.kernel, "patches") + + def add_module(self, path, files=[]): + for filename in os.listdir(path): + new_path = os.path.join(path, filename) + if not os.path.isdir(new_path): + if new_path.split("\\")[-1] in self.drivers_path_list or new_path.split("/")[-1] in self.drivers_path_list: + files.append(new_path) + with open(new_path, "r+", encoding="utf-8") as f: + data = f.readlines() + insert_index = None + state = False + for index, line in enumerate(data): + if line.find("CONFIG_DRIVERS_HDF_INPUT=y") >= 0: + insert_index = index + elif line.find(self.new_demo_config) >= 0: + state = True + if not state: + if new_path.split(".")[-1] != "patch": + data.insert(insert_index + 1, self.new_demo_config) + else: + data.insert(insert_index + 1, "+"+self.new_demo_config) + + with open(new_path, "w", encoding="utf-8") as f: + f.writelines(data) + else: + self.add_module(new_path, files) + return files + + def delete_module(self, path): + lines = hdf_utils.read_file_lines(path) + if self.new_demo_config in lines or ("+" + self.new_demo_config) in lines: + if path.split(".")[-1] != "patch": + lines.remove(self.new_demo_config) + else: + lines.remove("+" + self.new_demo_config) + hdf_utils.write_file_lines(path, lines) + + def rename_vendor(self): + pattern = r'vendor/([a-zA-Z0-9_\-]+)/' + replacement = 'vendor/%s/' % self.vendor + new_content = re.sub(pattern, replacement, self.contents) + hdf_utils.write_file(self.file_path, new_content) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py new file mode 100755 index 000000000..4a9357947 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import json +import os +import shutil +from string import Template + +from hdf_tool_exception import HdfToolException +from .hdf_command_error_code import CommandErrorCode +from .hdf_command_handler_base import HdfCommandHandlerBase +from .hdf_defconfig_patch import HdfDefconfigAndPatch +from .hdf_device_info_hcs import HdfDeviceInfoHcsFile +from .hdf_get_handler import HdfGetHandler +from .hdf_vendor_build_file import HdfVendorBuildFile +from .hdf_vendor_kconfig_file import HdfVendorKconfigFile +from .hdf_vendor_makefile import HdfVendorMakeFile +from .hdf_vendor_mk_file import HdfVendorMkFile +from .hdf_module_kconfig_file import HdfModuleKconfigFile +from .hdf_module_mk_file import HdfModuleMkFile +from .hdf_driver_config_file import HdfDriverConfigFile +import hdf_utils + + +class HdfDeleteHandler(HdfCommandHandlerBase): + def __init__(self, args): + super(HdfDeleteHandler, self).__init__() + self.cmd = 'delete' + self.handlers = { + 'vendor': self._delete_vendor_handler, + 'module': self._delete_module_handler, + 'driver': self._delete_driver_handler, + } + self.parser.add_argument("--action_type", + help=' '.join(self.handlers.keys()), + required=True) + self.parser.add_argument("--root_dir", required=True) + self.parser.add_argument("--vendor_name") + self.parser.add_argument("--module_name") + self.parser.add_argument("--driver_name") + self.parser.add_argument("--board_name") + self.parser.add_argument("--kernel_name") + self.args = self.parser.parse_args(args) + + def _delete_vendor_handler(self): + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("board_name") + root, vendor, _, _, _ = self.get_args() + vendor_hdf_dir = hdf_utils.get_vendor_hdf_dir(root, vendor) + print(vendor_hdf_dir) + if not os.path.exists(vendor_hdf_dir): + return + for module in os.listdir(vendor_hdf_dir): + mod_dir = os.path.join(vendor_hdf_dir, module) + if os.path.isdir(mod_dir): + self._delete_module(root, module) + shutil.rmtree(vendor_hdf_dir) + + def _delete_module(self, root, model, model_info): + for key, path_value in model_info.items(): + if key.split("_")[-1] == "name": + pass + elif key == "driver_file_path": + driver_file = os.path.join(root, path_value.split(model)[0], model) + if os.path.exists(driver_file): + shutil.rmtree(driver_file) + else: + if key == "module_level_config_path": + for k, v in model_info["module_level_config_path"].items(): + if k == "%s_Makefile" % model: + HdfVendorMakeFile(root, vendor="", kernel="", path=os.path.join(root, v)).delete_module(model) + elif k == "%s_Kconfig" % model: + HdfVendorKconfigFile(root, vendor="", kernel="", path=os.path.join(root, v)).delete_module(model) + elif k == "%sBuild" % model: + HdfVendorBuildFile(root, vendor="").delete_module(file_path=os.path.join(root, v), model=model) + elif k == "%s_hdf_lite" % model: + HdfVendorMkFile(root, vendor="").delete_module(file_path=os.path.join(root, v), module=model) + elif k == "%s_dot_configs" % model: + for dot_path in v: + if dot_path.split(".")[-1] == "config": + template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" + else: + template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" + new_demo_config = Template(template_string).substitute({"module_upper_case": model.upper()}) + defconfig_patch = HdfDefconfigAndPatch(root=root, vendor="", kernel="", board="", + data_model="", new_demo_config=new_demo_config) + defconfig_patch.delete_module(path=os.path.join(root, dot_path)) + elif key == "module_path": + for k, v in model_info["module_path"].items(): + if v.endswith("hcs"): + hcs_path = os.path.join(root, v) + HdfDeviceInfoHcsFile(root=root, vendor="", module="", board="", driver="", path=hcs_path)\ + .delete_driver(module=model) + else: + if v: + file_path = os.path.join(root, v) + if os.path.exists(file_path): + os.remove(file_path) + model_dir_path = "/".join(file_path.split("/")[:-1]) + if os.path.exists(model_dir_path): + file_list = os.listdir(model_dir_path) + if not file_list: + shutil.rmtree(model_dir_path) + create_model_data = self._delete_model_info() + delete_model_info = hdf_utils.get_create_model_info(root=root, create_data=json.dumps(create_model_data)) + return delete_model_info + + def _delete_model_info(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("module_name") + root, _, module, _, _, _ = self.get_args() + adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) + if not os.path.exists(adapter_framework): + raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, + CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", + "resources", "create_model.config") + if not os.path.exists(create_file_save_path): + raise HdfToolException('create file config "%s" not exist' % create_file_save_path, + CommandErrorCode.TARGET_NOT_EXIST) + data = hdf_utils.read_file(create_file_save_path) + write_data = json.loads(data) + write_data.pop(module) + hdf_utils.write_file(create_file_save_path, json.dumps(write_data, indent=4)) + return write_data + + def _delete_module_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("module_name") + root, _, module, _, _, _ = self.get_args() + adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) + if not os.path.exists(adapter_framework): + raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, + CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", "resources", "create_model.config") + if not os.path.exists(create_file_save_path): + raise HdfToolException('create file config "%s" not exist' % create_file_save_path, + CommandErrorCode.TARGET_NOT_EXIST) + data = hdf_utils.read_file(create_file_save_path) + file_info = json.loads(data) + model_info = file_info.get(module, None) + if model_info == None: + raise HdfToolException(' delete model "%s" not exist' % module, CommandErrorCode.TARGET_NOT_EXIST) + else: + return self._delete_module(root, module, model_info) + + def _delete_driver(self, module, driver): + root, vendor, _, _, board = self.get_args() + drv_dir = hdf_utils.get_drv_dir(root, vendor, module, driver) + if os.path.exists(drv_dir): + shutil.rmtree(drv_dir) + k_path = hdf_utils.get_module_kconfig_path(root, vendor, module) + HdfModuleKconfigFile(root, module, k_path).delete_driver(driver) + HdfModuleMkFile(root, vendor, module).delete_driver(driver) + HdfDriverConfigFile(root, board, module, driver).delete_driver() + + def _delete_driver_handler(self): + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("module_name") + self.check_arg_raise_if_not_exist("driver_name") + self.check_arg_raise_if_not_exist("board_name") + _, _, module, driver, _ = self.get_args() + self._delete_driver(module, driver) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py new file mode 100755 index 000000000..6fa209c90 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import ast +import json +import os +import re +from string import Template + + +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +from hdf_tool_settings import HdfToolSettings +import hdf_utils + + +class HdfDeviceInfoHcsFile(object): + def __init__(self, root, vendor, module, board, driver, path): + if not path: + self.module = module + self.vendor = vendor + self.board = board + self.root = root + self.driver = driver + self.lines = None + self.hcs_path = hdf_utils.get_hcs_file_path(self.root, self.vendor, self.board) + else: + self.hcs_path = path + self.root = root + self.file_path = hdf_utils.get_template_file_path(root) + if not os.path.exists(self.file_path): + raise HdfToolException('template file: %s not exist' % self.file_path, + CommandErrorCode.TARGET_NOT_EXIST) + if not os.path.exists(self.hcs_path): + raise HdfToolException('hcs file: %s not exist' % self.hcs_path, + CommandErrorCode.TARGET_NOT_EXIST) + + def _save(self): + if self.lines: + hdf_utils.write_file(self.hcs_path, ''.join(self.lines)) + + def _find_line(self, pattern): + for index, line in enumerate(self.lines): + if re.search(pattern, line): + return index, line + return 0, '' + + def _find_last_include(self): + if not self.lines: + return 0 + i = len(self.lines) - 1 + while i >= 0: + line = self.lines[i] + if re.search(self.include_pattern, line): + return i + 1 + i -= 1 + return 0 + + def _create_makefile(self): + mk_path = os.path.join(self.file_dir, 'Makefile') + template_str = hdf_utils.get_template('hdf_hcs_makefile.template') + hdf_utils.write_file(mk_path, template_str) + + def check_and_create(self): + if self.lines: + return + if not os.path.exists(self.file_dir): + os.makedirs(self.file_dir) + self._create_makefile() + self.lines.append('#include "hdf_manager/manager_config.hcs"\n') + self._save() + + def add_driver(self, module, driver): + target_line = self.line_template % (module, driver) + target_pattern = self.line_pattern % (module, driver) + idx, line = self._find_line(target_pattern) + if line: + self.lines[idx] = target_line + else: + pos = self._find_last_include() + self.lines.insert(pos, target_line) + self._save() + + def delete_driver(self, module): + hcs_config = hdf_utils.read_file_lines(self.hcs_path) + index_info = {} + count = 0 + for index, line in enumerate(hcs_config): + if line.find("%s :: host" % module) > 0: + index_info["start_index"] = index + for child_index in range(index_info["start_index"], len(hcs_config)): + if hcs_config[child_index].strip().endswith("{"): + count += 1 + elif hcs_config[child_index].strip() == "}": + count -= 1 + if count == 0: + index_info["end_index"] = child_index + break + break + if index_info: + self.lines = hcs_config[0:index_info["start_index"]] + hcs_config[index_info["end_index"] + 1:] + self._save() + return True + + def add_model_hcs_file_config(self): + template_path = os.path.join(self.file_path, 'device_info_hcs.template') + lines = list(map(lambda x: "\t\t" + x, hdf_utils.read_file_lines(template_path))) + old_lines = list(filter(lambda x: x != "\n", hdf_utils.read_file_lines(self.hcs_path))) + new_data = old_lines[:-2] + lines + old_lines[-2:] + d = {'driver_name': self.driver, 'model_name': self.module} + for i in range(len(new_data)): + new_data[i] = Template(new_data[i]).substitute(d) + with open(self.hcs_path, "w+", encoding="utf-8") as l: + for j in new_data: + l.write(j) + return self.hcs_path diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py new file mode 100755 index 000000000..5be918eb9 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +import hdf_utils + + +class ConfigItem(object): + def __init__(self, index, line): + self.index = index + self.line = line + + +class HdfDotConfigFile(object): + def __init__(self, dot_config_path): + self.file_path = dot_config_path + if os.path.exists(dot_config_path): + self.lines = hdf_utils.read_file_lines(dot_config_path) + self.dot_config_exist = True + else: + self.lines = [] + self.dot_config_exist = False + self.cache = {} + self.hdf_item = 'LOSCFG_DRIVERS_HDF' + self.prefix = 'LOSCFG_' + + def save(self): + if not self.dot_config_exist: + return + with open(self.file_path, 'r+', newline='\n') as file: + file.truncate() + file.write(''.join(self.lines)) + + def _update_cache(self, item, index, line): + self.cache[item] = ConfigItem(index, line) + + def _find(self, item): + if item in self.cache: + index = self.cache[item].index + line = self.cache[item].line + return index, line + for index, line in enumerate(self.lines): + item_pattern = r'%s\s*(=|is)' % item + if re.search(item_pattern, line): + line_ = line.strip() + self._update_cache(item, index, line_) + return index, line_ + return 0, '' + + @staticmethod + def _is_line_enabled(line): + if line.strip().startswith('#'): + return False + return True + + def _enable(self, item): + if not item: + return + new_line = '%s=y\n' % item + index, line = self._find(item) + if line: + if self._is_line_enabled(line): + return + self.lines[index] = new_line + self._update_cache(item, index, new_line) + return + else: + count = len(self.lines) + self.lines.append(new_line) + self._update_cache(item, count, new_line) + + def _disable(self, item): + if not item: + return + new_line = '# %s is not set\n' % item + index, line = self._find(item) + if not line: + return + if not self._is_line_enabled(line): + return + self.lines[index] = new_line + self._update_cache(item, index, new_line) + + def _is_enabled(self, item): + if not item: + return False + index, line = self._find(item) + if not line: + return False + return self._is_line_enabled(line) + + def _add_prefix(self, item): + if not item.startswith(self.prefix): + item = '%s%s' % (self.prefix, item) + return item + + def is_enabled(self, item, depends_on_item): + if item: + item = self._add_prefix(item) + if depends_on_item: + depends_on_item = self._add_prefix(depends_on_item) + if depends_on_item: + if not self._is_enabled(depends_on_item): + return False + return self._is_enabled(item) + + def enable(self, item, depends_on_item): + if item: + item = self._add_prefix(item) + if depends_on_item: + depends_on_item = self._add_prefix(depends_on_item) + self._enable(self.hdf_item) + self._enable(depends_on_item) + self._enable(item) + + def disable(self, item): + if item: + item = self._add_prefix(item) + self._disable(item) + + def add_dot_config(self): + hdf_utils.get_dot_configs_path() diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py new file mode 100755 index 000000000..a60505a29 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +from string import Template + +from .hdf_manager_config_file import HdfManagerConfigFile +from .hdf_hcs_file import HdfHcsFile +from hdf_tool_settings import HdfToolSettings +from hdf_tool_exception import HdfToolException +from command_line.hdf_command_error_code import CommandErrorCode +import hdf_utils + + +class HdfDriverConfigFile(object): + def __init__(self, root, board, module, driver, kernel, only_path=False): + self.root = root + self.board = board + self.module = module + self.driver = driver + self.kernel = kernel + bpp = HdfToolSettings().get_board_parent_path(self.board) + board_path = os.path.join(self.root, bpp, self.board) + + if not os.path.exists(board_path): + raise HdfToolException('board: %s not exist' % board_path, + CommandErrorCode.TARGET_NOT_EXIST) + self.config_dir = os.path.join(board_path, 'hdf_config') + self.drv_dir = os.path.join(self.config_dir, self.module) + self.drv_config_path = os.path.join(self.drv_dir, '%s_config.hcs' % self.driver) + if only_path: + return + manager_hcs_path = os.path.join(self.config_dir, 'device_info', + 'device_info.hcs') + self.manager_hcs = HdfManagerConfigFile(manager_hcs_path) + hdf_hcs_path = os.path.join(self.config_dir, 'hdf.hcs') + self.hdf_hcs = HdfHcsFile(hdf_hcs_path) + + def _check_and_create_common_config(self): + self.manager_hcs.check_and_create() + self.hdf_hcs.check_and_create() + if not os.path.exists(self.drv_dir): + os.makedirs(self.drv_dir) + + def create_driver(self): + self._check_and_create_common_config() + template_str = hdf_utils.get_template('hdf_driver_config.template') + config_content = Template(template_str).safe_substitute({}) + hdf_utils.write_file(self.drv_config_path, config_content) + self.manager_hcs.add_device(self.module, self.driver) + self.hdf_hcs.add_driver(self.module, self.driver) + + def delete_driver(self): + if not os.path.exists(self.drv_config_path): + return + os.remove(self.drv_config_path) + self.manager_hcs.delete_device(self.module, self.driver) + self.hdf_hcs.delete_driver(self.module, self.driver) + + def get_drv_config_path(self): + if os.path.exists(self.drv_config_path): + return os.path.realpath(self.drv_config_path) + else: + return '' diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py new file mode 100755 index 000000000..d00cb5fdf --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py @@ -0,0 +1,201 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import json + +from .hdf_command_handler_base import HdfCommandHandlerBase +from .hdf_lite_mk_file import HdfLiteMkFile +from .hdf_vendor_kconfig_file import HdfVendorKconfigFile +from .hdf_module_kconfig_file import HdfModuleKconfigFile +from .hdf_driver_config_file import HdfDriverConfigFile +from command_line.hdf_command_error_code import CommandErrorCode +from hdf_tool_settings import HdfToolSettings +from hdf_tool_exception import HdfToolException +import hdf_tool_version +import hdf_utils + + +class HdfGetHandler(HdfCommandHandlerBase): + def __init__(self, args): + super(HdfGetHandler, self).__init__() + self.HDF_VERSION_MAJOR = 0 + self.HDF_VERSION_MINOR = 1 + self.cmd = 'get' + self.handlers = { + 'vendor_list': self._get_vendor_list_handler, + 'current_vendor': self._get_current_vendor_handler, + 'vendor_parent_path': self._get_vendor_parent_path_handler, + 'individual_vendor_path': self._get_individual_vendor_path_handler, + 'board_list': self._get_board_list_handler, + 'driver_list': self._get_driver_list_handler, + 'driver_file': self._get_driver_file_handler, + 'drv_config_file': self._get_drv_config_file_handler, + 'hdf_tool_core_version': self._get_version_handler, + 'model_list': self._get_model_dict, + 'version': self.__get_version, + } + self.parser.add_argument("--action_type", + help=' '.join(self.handlers.keys()), + required=True) + self.parser.add_argument("--root_dir") + self.parser.add_argument("--vendor_name") + self.parser.add_argument("--module_name") + self.parser.add_argument("--driver_name") + self.parser.add_argument("--board_name") + self.args = self.parser.parse_args(args) + + def _get_vendor_list_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + root = self.args.root_dir + vendor_root_dir = hdf_utils.get_vendor_root_dir(root) + vendors = [] + if os.path.exists(vendor_root_dir): + for vendor in os.listdir(vendor_root_dir): + hdf = hdf_utils.get_vendor_hdf_dir(root, vendor) + if os.path.exists(hdf): + vendors.append(vendor) + return ','.join(vendors) + + def _get_current_vendor_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + return HdfLiteMkFile(self.args.root_dir).get_current_vendor() + + @staticmethod + def _get_board_list_handler(): + settings = HdfToolSettings() + return settings.get_supported_boards() + + def _get_vendor_parent_path_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + target = hdf_utils.get_vendor_root_dir(self.args.root_dir) + return os.path.realpath(target) + + def _get_individual_vendor_path_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + root, vendor, _, _, _ = self.get_args() + target = hdf_utils.get_vendor_dir(root, vendor) + return os.path.realpath(target) + + @staticmethod + def _get_version_handler(): + return hdf_tool_version.get_version() + + def _get_driver_list_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + root, vendor, _, _, _ = self.get_args() + hdf_dir = hdf_utils.get_vendor_hdf_dir(root, vendor) + if not os.path.exists(hdf_dir): + raise HdfToolException('vendor "%s" not exist' % vendor, + CommandErrorCode.TARGET_NOT_EXIST) + modules = os.listdir(hdf_dir) + vendor_k = HdfVendorKconfigFile(root, vendor) + module_items = vendor_k.get_module_and_config_path() + drivers = {} + for item in module_items: + module, k_path = item + if module in modules: + models = \ + HdfModuleKconfigFile(root, module, k_path).get_models() + drivers[module] = models + return json.dumps(drivers) + + def _get_driver_file_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("module_name") + self.check_arg_raise_if_not_exist("driver_name") + root = os.path.realpath(self.args.root_dir) + _, vendor, module, driver, _ = self.get_args() + drv_dir = hdf_utils.get_drv_dir(root, vendor, module, driver) + if not os.path.exists(drv_dir): + raise HdfToolException('driver directory: %s not exist' % drv_dir, + CommandErrorCode.TARGET_NOT_EXIST) + for root_path, dirs, files in os.walk(drv_dir): + for file in files: + if file.endswith('.c'): + return os.path.realpath(os.path.join(root_path, file)) + return '' + + def _get_drv_config_file_handler(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("module_name") + self.check_arg_raise_if_not_exist("driver_name") + self.check_arg_raise_if_not_exist("board_name") + root, _, module, driver, board = self.get_args() + drv_config = HdfDriverConfigFile(root, board, module, driver, True) + return drv_config.get_drv_config_path() + + def _get_model_dict(self): + self.check_arg_raise_if_not_exist("root_dir") + root, _, _, _, _, _ = self.get_args() + adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) + if not os.path.exists(adapter_framework): + raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, + CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", "resources", "create_model.config") + if not os.path.exists(create_file_save_path): + raise HdfToolException('create file config "%s" not exist' % create_file_save_path, + CommandErrorCode.TARGET_NOT_EXIST) + out_model_list = [] + data = hdf_utils.read_file(create_file_save_path) + json_type_data = json.loads(data) + if not json_type_data: + return out_model_list + file_key_list = list(list(json_type_data.items())[0][-1].keys())[:-1] + for k, v in json_type_data.items(): + model_file_path = {} + for key in file_key_list: + if key.split("_")[-1] == "path": + path_dict = json_type_data[k][key] + if isinstance(path_dict, dict): + for k_filename, file_path in path_dict.items(): + if not os.path.exists(os.path.join(root, file_path)): + model_file_path[k_filename] = " " + else: + model_file_path[k_filename] = path_dict[k_filename] + else: + hcs_file_path = os.path.join(root, path_dict) + if not os.path.exists(hcs_file_path): + model_file_path[key] = " " + else: + model_file_path[key] = path_dict + out_model_list.append({k: model_file_path}) + return out_model_list + + def __get_version(self): + version_end = "\nCopyright (c) 2020-2021 Huawei Device Co., Ltd." + version_head = "hdf_dev_eco_tool version : " + return version_head + str(self.HDF_VERSION_MAJOR) + "." + str(self.HDF_VERSION_MINOR) + version_end + + diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py new file mode 100755 index 000000000..2c6de04ea --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +import hdf_utils + + +class HdfHcsFile(object): + def __init__(self, file_path): + self.file_path = file_path + self.file_dir = os.path.dirname(self.file_path) + if os.path.exists(self.file_path): + self.lines = hdf_utils.read_file_lines(self.file_path) + else: + self.lines = [] + self.line_template = '#include "%s/%s_config.hcs"\n' + self.line_pattern = r'^\s*#include\s+"%s/%s_config.hcs"' + self.include_pattern = r'^\s*#include' + + def _save(self): + if self.lines: + hdf_utils.write_file(self.file_path, ''.join(self.lines)) + + def _find_line(self, pattern): + for index, line in enumerate(self.lines): + if re.search(pattern, line): + return index, line + return 0, '' + + def _find_last_include(self): + if not self.lines: + return 0 + i = len(self.lines) - 1 + while i >= 0: + line = self.lines[i] + if re.search(self.include_pattern, line): + return i + 1 + i -= 1 + return 0 + + def _create_makefile(self): + mk_path = os.path.join(self.file_dir, 'Makefile') + template_str = hdf_utils.get_template('hdf_hcs_makefile.template') + hdf_utils.write_file(mk_path, template_str) + + def check_and_create(self): + if self.lines: + return + if not os.path.exists(self.file_dir): + os.makedirs(self.file_dir) + self._create_makefile() + self.lines.append('#include "hdf_manager/manager_config.hcs"\n') + self._save() + + def add_driver(self, module, driver): + target_line = self.line_template % (module, driver) + target_pattern = self.line_pattern % (module, driver) + idx, line = self._find_line(target_pattern) + if line: + self.lines[idx] = target_line + else: + pos = self._find_last_include() + self.lines.insert(pos, target_line) + self._save() + + def delete_driver(self, module, driver): + target_pattern = self.line_pattern % (module, driver) + idx, line = self._find_line(target_pattern) + if not line: + return + self.lines[idx] = '' + self._save() diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py new file mode 100755 index 000000000..635cbcbe8 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +from hdf_tool_settings import HdfToolSettings +import hdf_utils + + +class HdfLiteKconfigFile(object): + def __init__(self, root): + self.file_path = hdf_utils.get_hdf_lite_kconfig_path(root) + self.orig_exist = False + if os.path.exists(self.file_path): + self.lines = hdf_utils.read_file_lines(self.file_path) + self.orig_exist = True + else: + self.lines = [] + self.vendor_pattern = r'source\s+".*/vendor/.*/Kconfig"' + self.target_pattern_format = r'source\s+".*/vendor/%s/.*/Kconfig"' + self.target_index = -1 + + def _save(self): + if self.orig_exist: + hdf_utils.write_file(self.file_path, ''.join(self.lines)) + + def _find_all_vendors(self, target_vendor): + vendors = [] + for index, line in enumerate(self.lines): + if self.target_index == -1: + if re.search(self.target_pattern_format % target_vendor, line): + self.target_index = index + continue + if re.search(self.vendor_pattern, line): + vendors.append(index) + return vendors + + def _comment_other_vendors(self, other_vendors): + for index in other_vendors: + if not hdf_utils.is_commented_line(self.lines[index], '#'): + self.lines[index] = '# %s' % self.lines[index] + + def set_vendor(self, current_vendor): + other_vendors = self._find_all_vendors(current_vendor) + self._comment_other_vendors(other_vendors) + drivers_path = HdfToolSettings().get_drivers_path() + new_line = 'source "../../vendor/%s/%s/Kconfig"\n' % \ + (current_vendor, drivers_path) + if self.target_index != -1: + self.lines[self.target_index] = new_line + else: + pos = len(self.lines) - 1 + while pos > 0 and len(self.lines[pos].strip()) == 0: + pos -= 1 + pos += 1 + self.lines.insert(pos, new_line) + self._save() diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py new file mode 100755 index 000000000..89726e963 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +from hdf_tool_settings import HdfToolSettings +import hdf_utils + + +class HdfLiteMkFile(object): + def __init__(self, root): + self.file_path = hdf_utils.get_hdf_lite_mk_path(root) + self.orig_exist = False + if os.path.exists(self.file_path): + self.lines = hdf_utils.read_file_lines(self.file_path) + self.orig_exist = True + else: + self.lines = [] + self.end_line_pattern = r'LITEOS_BASELIB\s*[+]=\s*--no-whole-archive' + self.vendor_pattern = r'include.*hdf_vendor[.]mk' + self.target_format = r'include .*vendor/%s/.*/hdf_vendor[.]mk' + self.end_line_index = -1 + self.target_line_index = -1 + # self.current_vendor_pattern = \ + # r'^\s*include.*/vendor/(.*)/hdf_vendor.mk' + self.current_vendor_pattern = \ + r'^\s*include.*/device/(.*)/lite.mk' + + def _save(self): + if self.orig_exist: + hdf_utils.write_file(self.file_path, ''.join(self.lines)) + + def _find_all_vendors(self, current_vendor): + vendor_lines = [] + for index, line in enumerate(self.lines): + if self.target_line_index == -1: + if re.search(self.target_format % current_vendor, line): + self.target_line_index = index + continue + if self.end_line_index == -1: + if re.search(self.end_line_pattern, line): + self.end_line_index = index + continue + if re.search(self.vendor_pattern, line): + vendor_lines.append(index) + return vendor_lines + + def _comment_other_vendors(self, other_vendors): + for index in other_vendors: + if not hdf_utils.is_commented_line(self.lines[index], '#'): + self.lines[index] = '# %s' % self.lines[index] + + def set_vendor(self, current_vendor): + other_vendors = self._find_all_vendors(current_vendor) + self._comment_other_vendors(other_vendors) + drivers_path = HdfToolSettings().get_drivers_path() + new_line = \ + 'include $(LITEOSTOPDIR)/../../vendor/%s/%s/hdf_vendor.mk\n' % \ + (current_vendor, drivers_path) + if self.target_line_index != -1: + self.lines[self.target_line_index] = new_line + elif self.end_line_index != -1: + self.lines.insert(self.end_line_index, new_line) + else: + self.lines.append(new_line) + self._save() + + def get_current_vendor(self): + for line in self.lines: + match_obj = re.search(self.current_vendor_pattern, line) + if match_obj: + vendor_drivers_path = match_obj.group(1) + parts = vendor_drivers_path.split('/') + valid_parts = [part for part in parts if part] + if valid_parts: + return valid_parts[0] + return '' diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py new file mode 100755 index 000000000..d25ad76c2 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +import hdf_utils + + +class HdfLiteSettingsMkFile(object): + def __init__(self, root_dir): + self.root_dir = root_dir + self.file_path = hdf_utils.get_hdf_lite_settings_mk_path(root_dir) + if os.path.exists(self.file_path): + self.lines = hdf_utils.read_file_lines(self.file_path) + else: + dir_path = os.path.dirname(self.file_path) + if not os.path.exists(dir_path): + os.makedirs(dir_path) + self.lines = [] + self.line_pattern = r'(%s\s*:=\s*)(.*)' + self.hdf_vendor_var_name = 'HDF_COMPILE_VENDOR' + self.board_vendor_path_var_name = 'HDF_SET_BOARD_VENDOR_PATH' + + def _save(self): + if self.lines: + hdf_utils.write_file(self.file_path, ''.join(self.lines)) + + def _append(self, new_line): + self.lines.append(new_line) + self._save() + + def _find_var_line(self, var_name): + for index, line in enumerate(self.lines): + if var_name in line: + return index, line + return 0, '' + + def _is_vendor_valid(self, vendor_name): + vendor_hdf_path = \ + hdf_utils.get_vendor_hdf_dir(self.root_dir, vendor_name) + if os.path.exists(vendor_hdf_path): + return True + return False + + def _set_var_value(self, var_name, var_value): + idx, var_line = self._find_var_line(var_name) + if var_line: + self.lines[idx] = re.sub(self.line_pattern % var_name, + r'\g<1>%s' % var_value, var_line) + self._save() + else: + new_line = '\n%s := %s' % (var_name, var_value) + self._append(new_line) + + def _get_var_value(self, var_name): + idx, var_line = self._find_var_line(var_name) + var_value = '' + if var_line: + match_obj = re.search(self.line_pattern % var_name, var_line) + if match_obj: + var_value = match_obj.group(2) + return var_value.strip() + + def set_vendor(self, vendor_name): + if not self._is_vendor_valid(vendor_name): + raise HdfToolException('vendor: "%s" not exist' % vendor_name, + CommandErrorCode.TARGET_NOT_EXIST) + self._set_var_value(self.hdf_vendor_var_name, vendor_name) + + def get_vendor(self): + vendor_name = self._get_var_value(self.hdf_vendor_var_name) + if self._is_vendor_valid(vendor_name): + return vendor_name + return '' + + def set_board_vendor_path(self, board_vendor_path): + self._set_var_value(self.board_vendor_path_var_name, board_vendor_path) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py new file mode 100755 index 000000000..5de6a0c51 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re +from string import Template + +from hdf_tool_exception import HdfToolException +from command_line.hdf_command_error_code import CommandErrorCode +import hdf_utils + + +class HdfManagerConfigFile(object): + def __init__(self, file_path): + self.file_path = file_path + self.file_dir = os.path.dirname(self.file_path) + self.host_pattern = r'%s\s*::\s*host\s*{' + self.hdf_manager_pattern = r'device_info\s*{' + self.contents = '' + self._read_contents() + + def _read_contents(self): + if os.path.exists(self.file_path): + self.contents = hdf_utils.read_file(self.file_path) + else: + self.contents = '' + + def check_and_create(self): + if self.contents: + return + template_str = \ + hdf_utils.get_template('hdf_driver_manager_config.template') + self.contents = Template(template_str).safe_substitute({}) + if not os.path.exists(self.file_dir): + os.makedirs(self.file_dir) + hdf_utils.write_file(self.file_path, self.contents) + + def _find_range(self, pattern): + match_obj = re.search(pattern, self.contents) + if not match_obj: + return None + start = match_obj.start() + if start == -1: + return None + braces = [] + start += len(match_obj.group(0)) - 1 + end = start + for i in range(start, len(self.contents)): + if '{' == self.contents[i]: + braces.append('{') + elif '}' == self.contents[i]: + count = len(braces) + if count == 0: + return None + if count == 1: + end = i + break + braces.pop() + if end != start: + while end > start + 1: + end -= 1 + if self.contents[end] not in [' ', '\t']: + break + return hdf_utils.SectionRange(start, end) + return None + + @staticmethod + def _begin_end(module, driver): + dev_id = hdf_utils.get_id(module, driver) + device_begin = '\n/* 0: + del lines[index] + hdf_utils.write_file_lines(file_path, lines) + + def rename_vendor(self): + pattern = r'vendor/([a-zA-Z0-9_\-]+)/' + replacement = 'vendor/%s/' % self.vendor + new_content = re.sub(pattern, replacement, self.contents) + hdf_utils.write_file(self.file_path, new_content) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py new file mode 100755 index 000000000..a490b8170 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re + +from hdf_tool_settings import HdfToolSettings +import hdf_utils + + +class HdfVendorKconfigFile(object): + def __init__(self, root, vendor, kernel, path): + if not path: + self.kernel = kernel + self.root = root + self.vendor = vendor + self.kconfig_path = hdf_utils.get_vendor_kconfig_path(self.root, self.kernel) + else: + self.kconfig_path = path + if os.path.exists(self.kconfig_path): + self.lines = hdf_utils.read_file_lines(self.kconfig_path) + else: + self.lines = [] + drivers_path = HdfToolSettings().get_drivers_path_adapter() + if kernel.capitalize() == "Liteos" or re.search(r'liteos/Kconfig', self.kconfig_path): + line_pattern = r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"' % (drivers_path) + self.line_re = re.compile(line_pattern) + self.line_prefix = 'source "../../%s/%s/%s"' % (drivers_path, 'liteos', 'model') + elif kernel.capitalize() == "Linux" or re.search(r'linux/Kconfig', self.kconfig_path): + line_pattern = r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"' % (drivers_path) + self.line_re = re.compile(line_pattern) + self.line_prefix = 'source "drivers/hdf/khdf/model/%s/Kconfig"\n' + + def _save(self): + if self.lines: + hdf_utils.write_file(self.kconfig_path, ''.join(self.lines)) + + def get_module_and_config_path(self): + tuples = [] + for line in self.lines: + match_obj = self.line_re.search(line) + if match_obj: + k_path_raw = match_obj.group(1).replace('/', os.sep) + k_path = os.path.join(self.root, k_path_raw) + tuples.append((match_obj.group(2), k_path)) + return tuples + + def _find_line(self, line_part): + for index, line in enumerate(self.lines): + if line_part in line: + return index, line + return 0, '' + + def add_module(self, module_to_k_path_parts): + module_k_part = '/'.join(module_to_k_path_parts) + index, line = self._find_line(module_k_part) + if line: + return + line = '\n%s/%s"\n' % (self.line_prefix, module_k_part) + if self.lines: + if self.lines[-1].endswith('\n'): + if self.kernel.capitalize() == "Liteos": + line = '%s/%s"\n' % (self.line_prefix[:-1], module_k_part) + elif self.kernel.capitalize() == "Linux": + line = self.line_prefix % (module_to_k_path_parts[0]) + for file_index, file_line in enumerate(self.lines): + if file_line.strip() == "endif": + self.lines.insert(file_index - 1, line) + break + self._save() + return self.kconfig_path + + def delete_module(self, module): + if self.line_prefix.find("Kconfig") > 0: + line_part = self.line_prefix % module + else: + line_part = '%s/%s/Kconfig"\n' % (self.line_prefix[:-1], module) + index, line = self._find_line(line_part) + if line: + self.lines[index] = '' + self._save() + + def rename_vendor(self, ): + for i, line in enumerate(self.lines): + pattern = r'vendor/([a-zA-Z0-9_\-]+)/' + replacement = 'vendor/%s/' % self.vendor + self.lines[i] = re.sub(pattern, replacement, line) + self._save() diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py new file mode 100755 index 000000000..c4a500934 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import re +from string import Template + +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +from hdf_tool_settings import HdfToolSettings +import hdf_utils + + +class HdfVendorMakeFile(object): + def __init__(self, root, vendor, kernel, path): + if path: + self.file_path = path + else: + self.vendor = vendor + self.kernel = kernel + self.file_path = hdf_utils.get_vendor_makefile_path(root, self.kernel) + if not os.path.exists(self.file_path): + raise HdfToolException('file: %s not exist' % self.file_path, + CommandErrorCode.TARGET_NOT_EXIST) + self.contents = hdf_utils.read_file_lines(self.file_path) + self.template_str = "obj-$(CONFIG_DRIVERS_HDF_${module_upper_case}) += model/${module_lower_case}/\n" + + def _begin_end(self, module): + module_id = hdf_utils.get_id(self.vendor, module) + begin = '\n# pos_range.end_pos + 1: + file.write(file_content[pos_range.end_pos + 1:]) + + +def append_and_save(file_content, file_path, new_section): + if not file_content or not file_path or not new_section: + return + with open(file_path, 'w', newline='\n') as file: + file.write(file_content) + _write_one_section(file, new_section) + + +def delete_and_save(file_content, file_path, delete_range): + if not file_content or not file_path or not delete_range: + return + length = len(file_content) + with open(file_path, 'w', newline='\n') as file: + file.write(file_content[:delete_range.start_pos]) + if delete_range.end_pos + 1 < length: + file.write(file_content[delete_range.end_pos + 1:]) + + +def replace_and_save(file_content, file_path, old_range, new_section): + if not file_content or not file_path or not old_range or not new_section: + return + with open(file_path, 'w', newline='\n') as file: + file.write(file_content[:old_range.start_pos]) + _write_one_section(file, new_section) + file.write(file_content[old_range.end_pos + 1:]) + + +def get_id(part2): + full_name = part2 + return hashlib.sha256(full_name.encode('utf8')).hexdigest()[:32] + + +def create_dirs(dir_path): + if dir_path and not os.path.exists(dir_path): + try: + os.makedirs(dir_path) + except Exception: + raise HdfToolException('create dirs fail: %s' % dir_path) + + +def read_file(file_path): + with open(file_path, encoding="utf-8") as file: + content = file.read() + return content + + +def read_file_lines(file_path, code_type="utf-8"): + with open(file_path, encoding=code_type) as file: + lines = file.readlines() + return lines + + +def write_file(file_path, content): + with open(file_path, 'w+', newline='\n') as file: + file.write(content) + + +def write_file_lines(file_path, content, code_type="utf-8"): + with open(file_path, 'w', encoding=code_type) as file: + file.writelines(content) + + +def get_framework_lite_dir(root): + """ + return os.path.join(root, 'drivers', 'hdf', 'lite') + """ + return os.path.join(root, 'drivers', 'adapter', 'khdf', 'liteos') + + +def get_vendor_root_dir(root): + return os.path.join(root, 'vendor') + + +def get_vendor_dir(root, vendor): + return os.path.join(get_vendor_root_dir(root), vendor) + + +def get_vendor_hdf_dir_framework(root): + relative_path = HdfToolSettings().get_drivers_path_framework() + return os.path.join(root, relative_path) + + +def get_vendor_hdf_dir_adapter(root, kernel='liteos'): + relative_path = HdfToolSettings().get_drivers_path_adapter() + return os.path.join(root, relative_path, kernel) + + +def get_vendor_lite_mk_path(root): + # return os.path.join(get_vendor_hdf_dir(root, vendor), 'hdf_vendor.mk') + return os.path.join(get_vendor_hdf_dir_adapter(root), 'hdf_lite.mk') + + +def get_vendor_makefile_path(root, kernel): + return os.path.join(get_vendor_hdf_dir_adapter(root, kernel), 'Makefile') + + +def get_dot_configs_path(root, vendor, board): + # relative_path = HdfToolSettings().get_dot_configs(board) + # return get_vendor_hdf_dir_adapter(root, relative_path) + + path = os.path.join(root, "vendor", vendor, board, 'kernel_configs') + # return ([os.path.join(path, i) for i in os.listdir(path)] + + # [os.path.join(root, path) for path in relative_path]) + return [os.path.join(path, i) for i in os.listdir(path)] + + +def get_module_dir(root, vendor, module): + return os.path.join(get_vendor_hdf_dir_framework(root), 'model', module) + + +def get_drv_root_dir(root, vendor, module): + return os.path.join(get_module_dir(root, vendor, module), 'driver') + + +def get_drv_dir(root, vendor, module, driver): + return os.path.join(get_drv_root_dir(root, vendor, module), driver) + + +def get_drv_src_dir(root, vendor, module): + # return os.path.join(get_drv_dir(root, vendor, module, driver), 'src') + return get_drv_root_dir(root, vendor, module) + + +def get_drv_include_dir(root, vendor, module, driver): + return os.path.join(get_drv_dir(root, vendor, module, driver), 'include') + + +def get_vendor_kconfig_path(root, kernel): + hdf_dir = get_vendor_hdf_dir_adapter(root, kernel) + return os.path.join(hdf_dir, 'Kconfig') + + +def get_module_kconfig_path(root, vendor, module): + return os.path.join(get_drv_root_dir(root, vendor, module), 'Kconfig') + + +def get_module_mk_path(root, vendor, module): + return os.path.join(get_drv_root_dir(root, vendor, module), 'Makefile') + + +def get_liteos_a_dot_config_path(root): + return os.path.join(root, 'kernel', 'liteos_a', '.config') + + +def get_resources_dir(): + cur_dir = os.path.realpath(os.path.dirname(__file__)) + return os.path.join(cur_dir, 'resources') + + +def get_templates_dir(): + return os.path.join(get_resources_dir(), 'templates') + + +def get_templates_lite_dir(): + return os.path.join(get_templates_dir(), 'lite') + + +def get_template(template_name, type_='lite'): + templates_dir = os.path.join(get_templates_dir(), type_) + template = os.path.join(templates_dir, template_name) + with open(template) as file: + template_str = file.read() + return template_str + + +def get_hdf_lite_settings_mk_path(root_dir): + return os.path.join(get_framework_lite_dir(root_dir), + 'hdf_lite_settings.mk') + + +def get_hdf_lite_mk_path(root_dir): + return os.path.join(get_framework_lite_dir(root_dir), + 'hdf_lite.mk') + + +def get_hdf_lite_kconfig_path(root_dir): + return os.path.join(get_framework_lite_dir(root_dir), + 'Kconfig') + + +def is_commented_line(line, comment_start): + if line.strip().startswith(comment_start): + return True + else: + return False + + +def get_vendor_gn_path(root): + # return os.path.join(get_vendor_hdf_dir(root, vendor), 'hdf_vendor.mk') + return os.path.join(get_vendor_hdf_dir_adapter(root), 'BUILD.gn') + + +def get_template_file_path(root, kernel='liteos'): + template_relative_path = HdfToolSettings().get_template_path() + relative_path2 = HdfToolSettings().get_drivers_path_framework() + return os.path.join(root, relative_path2, template_relative_path) + + +# "hdf_config", "device_info", "device_info.hcs" +def get_hcs_file_path(root, vendor, board): + return os.path.join(root, "vendor", vendor, board, "hdf_config", "device_info", "device_info.hcs") + + +def template_filename_filtrate(dir_path, kernal): + filename_list = [] + for filename in os.listdir(dir_path): + if filename.split("_")[0] == kernal.capitalize(): + filename_list.append(filename) + return filename_list + + +def get_create_model_info(root, create_data): + json_type_data = json.loads(create_data) + out_model_list = [] + if not json_type_data: + return [] + file_key_list = list(list(json_type_data.items())[0][-1].keys())[:-1] + for k, v in json_type_data.items(): + model_file_path = {} + for key in file_key_list: + if key.split("_")[-1] == "path": + path_dict = json_type_data[k][key] + if isinstance(path_dict, dict): + for k_filename, file_path in path_dict.items(): + if not os.path.exists(os.path.join(root, file_path)): + model_file_path[k_filename] = " " + else: + model_file_path[k_filename] = path_dict[k_filename] + else: + hcs_file_path = os.path.join(root, path_dict) + if not os.path.exists(hcs_file_path): + model_file_path[key] = " " + else: + model_file_path[key] = path_dict + out_model_list.append({k: model_file_path}) + return out_model_list \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/main.py b/tools/hdf_dev_eco_tool/main.py new file mode 100755 index 000000000..339c1cff9 --- /dev/null +++ b/tools/hdf_dev_eco_tool/main.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with th +# e distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import sys +import argparse +import hdf_utils + +from command_line.hdf_tool_commands import HdfToolCommands +from hdf_tool_daemon_server import HdfToolDaemonServer +from hdf_tool_exception import HdfToolException +from command_line.hdf_command_error_code import CommandErrorCode + + +def check_python_version(): + if sys.version_info < (3, 0): + print('Please run with python version >= 3.0') + sys.exit(-1) + + +def main(): + check_python_version() + commands = HdfToolCommands() + help_info = 'Tools backend for hdf driver development.' + arg_parser = argparse.ArgumentParser(description=help_info) + arg_parser.add_argument('--run_as_daemon', action='store_true') + arg_parser.add_argument('--server_type', help='command_line or ls_hcs,' + 'default command_line', default='command_line') + arg_parser.add_argument('command', help=commands.help()) + arg_parser.add_argument('remainder_args', nargs=argparse.REMAINDER) + args = arg_parser.parse_args() + if args.run_as_daemon: + HdfToolDaemonServer(args.server_type).run() + return + try: + ret = commands.run(args.command, args.remainder_args) + if ret or isinstance(ret, list): + print(ret) + except HdfToolException as exc: + print('error: {}, {}'.format(exc.error_code, exc.exc_msg)) + except Exception as exc: + print('error: {}, {}'.format(CommandErrorCode.UNKNOWN_ERROR, str(exc))) + + +if __name__ == "__main__": + main() diff --git a/tools/hdf_dev_eco_tool/resources/create_model.config b/tools/hdf_dev_eco_tool/resources/create_model.config new file mode 100755 index 000000000..9e26dfeeb --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/create_model.config @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/settings.json b/tools/hdf_dev_eco_tool/resources/settings.json new file mode 100755 index 000000000..ecbf0e137 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/settings.json @@ -0,0 +1,23 @@ +{ + "supported_boards": { + "hispark_taurus": { + "board_parent_path": "vendor/hisilicon/hispark_taurus", + "dot_config_path": "kernel/liteos_a/tools/build/config", + "dot_configs": ["hispark_taurus_debug_shell_tee.config", "hispark_taurus_debug_shell.config" + ,"hispark_taurus_release_tee.config", "hispark_taurus_release.config" + , "hispark_taurus_clang_release_tee.config", "hispark_taurus_clang_release.config"] + }, + "hispark_taurus_linux": { + "patch_and_config": ["hi3516dv300.patch", "hi3516dv300_small_defconfig", "hi3516dv300_standard_defconfig", + "small_common_defconfig", "standard_common_defconfig"] + }, + "hispark_aries": { + "board_parent_path": "vendor/hisilicon/hispark_aries", + "dot_config_path": "kernel/liteos_a/tools/build/config", + "dot_configs": ["hispark_aries_clang_release.config", "hispark_aries_release.config", "hispark_aries_debug_shell.config"] + } + }, + "drivers_path_relative_to_vendor": "drivers/framework", + "drivers_path_relative_adapter": "drivers/adapter/khdf", + "template_file_path": "tools/hdf_dev_eco_tool/resources/templates/lite" +} diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Kconfig.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Kconfig.template new file mode 100755 index 000000000..952d17e01 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Kconfig.template @@ -0,0 +1,34 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +config DRIVERS_HDF_${module_upper_case} + bool "Enable HDF ${module_lower_case} driver" + default n + depends on DRIVERS_HDF + help + Answer Y to enable HDF ${module_lower_case} driver. \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Makefile.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Makefile.template new file mode 100755 index 000000000..d1a0267eb --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_Makefile.template @@ -0,0 +1,33 @@ +# +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# +# This software is licensed under the terms of the GNU General Public +# License version 2, as published by the Free Software Foundation, and +# may be copied, distributed, and modified under those terms. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# + +${module_upper_case}_ROOT_DIR = ../../../../../framework/model/${module_lower_case}/driver + +obj-$(CONFIG_DRIVERS_HDF_${module_upper_case}) += \ + $(${module_upper_case}_ROOT_DIR)/${driver_name}_driver.o + +ccflags-y += -I$(srctree)/drivers/hdf/framework/include/core \ + -I$(srctree)/drivers/hdf/framework/core/common/include/host \ + -I$(srctree)/drivers/hdf/framework/include/utils \ + -I$(srctree)/drivers/hdf/framework/include/osal \ + -I$(srctree)/drivers/hdf/framework/ability/sbuf/include \ + -I$(srctree)/drivers/hdf/framework/include/platform \ + -I$(srctree)/drivers/hdf/framework/include/config \ + -I$(srctree)/drivers/hdf/framework/core/host/include \ + -I$(srctree)/drivers/hdf/framework/core/shared/include \ + -I$(srctree)/drivers/hdf/framework/utils/include \ + -I$(srctree)/drivers/hdf/khdf/osal/include + +ccflags-y +=-I$(srctree)/bounds_checking_function/include \ + -I$(srctree)/drivers/hdf/evdev \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_built-in.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_built-in.template new file mode 100755 index 000000000..9cf4aa1b4 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Linux_built-in.template @@ -0,0 +1,4 @@ +! +// 56 ` +../../../../../framework/model/${module_lower_case}/${module_lower_case}.o/ +/0 0 0 0 644 1912 ` \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_BUILD_gn.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_BUILD_gn.template new file mode 100755 index 000000000..9b648355e --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_BUILD_gn.template @@ -0,0 +1,41 @@ +# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//drivers/adapter/khdf/liteos/hdf.gni") +module_switch = defined(LOSCFG_DRIVERS_HDF_${module_upper_case}) +module_name = "hdf_${module_lower_case}_driver" +hdf_driver(module_name) { + FRAMEWORKS_${module_upper_case}_ROOT = "$HDF_FRAMEWORKS_PATH/model/${module_lower_case}" + sources = ["$FRAMEWORKS_${module_upper_case}_ROOT/driver/${driver_file_name}"] + + include_dirs = [ + "//third_party/FreeBSD/sys/dev/evdev/" + ] +} + diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Device_Info_Hcs.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Device_Info_Hcs.template new file mode 100755 index 000000000..64e5b0c46 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Device_Info_Hcs.template @@ -0,0 +1,15 @@ +${driver_name} :: host{ + hostName = "${driver_name}_host"; // hostƣhostڵijһ + priority = 100; // hostȼ0-200ֵԽȼԽͣĬ100ȼͬ򲻱֤hostļ˳ + device_${driver_name} :: device { // ${driver_name}豸ڵ + device0 :: deviceNode { // ${driver_name}DeviceNodeڵ + policy = 2; // policyֶ񷢲IJ + priority= 100; // ȼ0-200ֵԽȼԽͣĬ100ȼͬ򲻱֤deviceļ˳ + preload = 0; // ֶ + permission = 0664; // 豸ڵȨ + moduleName = "${driver_name}_driver"; // ƣֶεֵڽṹmoduleNameֵһ + serviceName = "${driver_name}_service"; // ⷢƣΨһ + deviceMatchAttr = ""; // ˽ƥĹؼ֣˽ñеmatch_attrֵ + } + } +} diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Kconfig.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Kconfig.template new file mode 100755 index 000000000..bb09830c8 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Kconfig.template @@ -0,0 +1,34 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +config DRIVERS_HDF_${module_upper_case} + bool "Enable HDF ${module_lower_case} driver" + default n + depends on DRIVERS_HDF + help + Answer Y to enable HDF ${module_lower_case} driver. \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Makefile.template b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Makefile.template new file mode 100755 index 000000000..e4574aff0 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/Liteos_Makefile.template @@ -0,0 +1,39 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk + +${module_upper_case}_ROOT_DIR = $(LITEOSTOPDIR)/../../drivers/framework/model/${module_lower_case} + +ifeq ($(LOSCFG_DRIVERS_HDF_${module_upper_case}), y) +MODULE_NAME := hdf_${module_lower_case}_driver +LOCAL_INCLUDE := $(${module_upper_case}_ROOT_DIR)/../../../../../third_party/FreeBSD/sys/dev/evdev +LOCAL_SRCS += $(${module_upper_case}_ROOT_DIR)/driver/${driver_file_name} + +endif +include $(HDF_DRIVER) diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template b/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template new file mode 100755 index 000000000..edf95d033 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template @@ -0,0 +1,15 @@ +${model_name} :: host{ + hostName = "${model_name}_host"; + priority = 100; + device_${model_name} :: device { + device0 :: deviceNode { + policy = 2; + priority= 100; + preload = 0; + permission = 0664; + moduleName = "${driver_name}_driver"; + serviceName = "${driver_name}_service"; + deviceMatchAttr = ""; + } + } +} diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template new file mode 100755 index 000000000..9d890166d --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template @@ -0,0 +1,41 @@ +#include "hdf_device_desc.h" // HDF框架对驱动开放相关能力接口的头文件 +#include "hdf_log.h" // HDF 框架提供的日志接口头文件 + +#define HDF_LOG_TAG ${driver_lower_case}_driver // 打印日志所包含的标签,如果不定义则用默认定义的HDF_TAG标签 + +//驱动服务结构的定义 +struct ITestDriverService { + struct IDeviceIoService ioService; // 服务结构的首个成员必须是IDeviceIoService类型的成员 + //以下可添加自定义的驱动的服务接口 +}; + +//驱动对外提供的服务能力,将相关的服务接口绑定到HDF框架 +static int32_t Hdf${driver_upper_camel_case}DriverBind(struct HdfDeviceObject *deviceObject) { + // deviceObject为HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口 + HDF_LOGI("${driver_lower_case} driver bind success"); + return 0; +} + +// 驱动自身业务初始的接口 +static int32_t Hdf${driver_upper_camel_case}DriverInit(struct HdfDeviceObject *deviceObject) { + HDF_LOGI("Hello world"); + return 0; +} + +// 驱动资源释放的接口 +static void Hdf${driver_upper_camel_case}DriverRelease(struct HdfDeviceObject *deviceObject) { + HDF_LOGI("${driver_lower_case} driver Release success"); + return; +} + +// 定义驱动入口的对象,必须为HdfDriverEntry(在hdf_device_desc.h中定义)类型的全局变量 +struct HdfDriverEntry g_${driver_lower_case}DriverEntry = { + .moduleVersion = 1, + .moduleName = "${driver_lower_case}_driver", + .Bind = Hdf${driver_upper_camel_case}DriverBind, + .Init = Hdf${driver_upper_camel_case}DriverInit, + .Release = Hdf${driver_upper_camel_case}DriverRelease, +}; + +// 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 +HDF_INIT(g_${driver_lower_case}DriverEntry); diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.h.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.h.template new file mode 100755 index 000000000..3e4624094 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.h.template @@ -0,0 +1,10 @@ +#ifndef _${driver_upper_case}_DRIVER_H +#define _${driver_upper_case}_DRIVER_H + +#include "hdf_device_desc.h" + +struct ${driver_upper_camel_case}DriverService { + struct IDeviceIoService ${driver_lower_camel_case}Service; +}; + +#endif/*_${driver_upper_case}_DRIVER_H*/ diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_config.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_config.template new file mode 100755 index 000000000..0657e42b7 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_config.template @@ -0,0 +1,3 @@ +root { + +} \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_kconfig.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_kconfig.template new file mode 100755 index 000000000..ade08c636 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_kconfig.template @@ -0,0 +1,6 @@ +config DRIVERS_HDF_${driver_upper_case} + bool "Enable HDF ${driver_lower_case} driver" + default n + depends on DRIVERS_HDF_${module_upper_case} + help + Answer Y to enable HDF ${driver_lower_case} driver. \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_makefile.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_makefile.template new file mode 100755 index 000000000..19d4f048c --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_makefile.template @@ -0,0 +1,10 @@ +include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk + +MODULE_NAME := hdf${module_lower_case} + +LOCAL_INCLUDE := ./include +LOCAL_INCLUDE += ./src + +LOCAL_SRCS += $(wildcard ./src/*.c) + +include $(HDF_DRIVER) diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config.template new file mode 100755 index 000000000..2695a43a1 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config.template @@ -0,0 +1,38 @@ +root { + device_info { + match_attr = "hdf_manager"; + template host { + hostName = ""; + priority = 100; + template device { + template deviceNode { + policy = 0; + priority = 100; + preload = 0; + permission = 0666; + moduleName = ""; + serviceName = ""; + deviceMatchAttr = ""; + } + } + } + platform :: host { + hostName = "platform_host"; + } + display :: host { + hostName = "display_host"; + } + network :: host { + hostName = "network_host"; + } + storage :: host { + hostName = "storage_host"; + } + media :: host { + hostName = "media_host"; + } + common :: host { + hostName = "common_host"; + } + } +} diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_device.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_device.template new file mode 100755 index 000000000..04806197d --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_device.template @@ -0,0 +1,10 @@ + device_${driver_lower_case} :: device { + device0 :: deviceNode { + policy = 1; + priority = 100; + preload = 0; + permission = 0666; + moduleName = "${driver_lower_case}"; + serviceName = "${driver_lower_camel_case}Service"; + } + } \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_host.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_host.template new file mode 100755 index 000000000..1dac297e3 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver_manager_config_host.template @@ -0,0 +1,3 @@ + ${module_lower_case} :: host { + hostName = "${module_lower_case}_host"; + } \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_hcs_makefile.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_hcs_makefile.template new file mode 100755 index 000000000..33e9df73b --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_hcs_makefile.template @@ -0,0 +1,7 @@ +include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk + +MODULE_NAME := hdf_config + +LOCAL_PLATFORM_HCS_SRC := hdf.hcs + +include $(HDF_DRIVER) diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_kconfig.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_kconfig.template new file mode 100755 index 000000000..3a5127a05 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_kconfig.template @@ -0,0 +1,6 @@ +config DRIVERS_HDF_${module_upper_case} + bool "Enable HDF ${module_lower_case} module" + default n + depends on DRIVERS_HDF + help + Answer Y to enable HDF ${module_lower_case} module. diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk.template new file mode 100755 index 000000000..a2c985934 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk.template @@ -0,0 +1,4 @@ +include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk + +MODULE_NAME := hdf${module_lower_case} +include $(HDF_DRIVER) diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk_driver.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk_driver.template new file mode 100755 index 000000000..6502fecbd --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_module_mk_driver.template @@ -0,0 +1,5 @@ +ifeq ($(LOSCFG_DRIVERS_HDF_${driver_upper_case}), y) + LOCAL_INCLUDE += ./${driver_lower_case}/include + LOCAL_INCLUDE += ./${driver_lower_case}/src + LOCAL_SRCS += $(wildcard ./${driver_lower_case}/src/*.c) +endif \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_kconfig.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_kconfig.template new file mode 100755 index 000000000..8b1378917 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_kconfig.template @@ -0,0 +1 @@ + diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk.template new file mode 100755 index 000000000..5c51b1ec4 --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk.template @@ -0,0 +1,2 @@ +LITEOS_BASELIB += -lhdf_config +LIB_SUBDIRS += $(LITEOSTOPDIR)/../../${board_parent_path}/$(LITEOS_PLATFORM)/config diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk_module.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk_module.template new file mode 100755 index 000000000..14e31ffdd --- /dev/null +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_vendor_mk_module.template @@ -0,0 +1,4 @@ +ifeq ($(LOSCFG_DRIVERS_HDF_${module_upper_case}), y) + LITEOS_BASELIB += -lhdf_${module_lower_case}_driver + LIB_SUBDIRS += $(LITEOS_DRIVERS_HDF)/model/${module_lower_case} +endif \ No newline at end of file -- Gitee From 472c3ef708291d881c0bb1a0df2c2d7f597592ef Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Tue, 12 Oct 2021 17:19:41 +0800 Subject: [PATCH 2/2] new Modify warning Signed-off-by: chenpan0560 --- .../command_line/hdf_add_handler.py | 156 +++++++++------ .../command_line/hdf_command_error_code.py | 49 ++--- .../command_line/hdf_command_handler_base.py | 78 ++++---- .../command_line/hdf_command_line_server.py | 46 ++--- .../command_line/hdf_defconfig_patch.py | 99 +++++----- .../command_line/hdf_delete_handler.py | 183 +++++++++++------- .../command_line/hdf_device_info_hcs.py | 90 +++++---- .../command_line/hdf_dot_config_file.py | 46 ++--- .../command_line/hdf_driver_config_file.py | 49 ++--- .../command_line/hdf_get_handler.py | 118 ++++++----- .../command_line/hdf_hcs_file.py | 46 ++--- .../command_line/hdf_lite_kconfig_file.py | 46 ++--- .../command_line/hdf_lite_mk_file.py | 51 +++-- .../command_line/hdf_lite_settings_mk_file.py | 46 ++--- .../command_line/hdf_manager_config_file.py | 46 ++--- .../command_line/hdf_module_kconfig_file.py | 46 ++--- .../command_line/hdf_module_mk_file.py | 46 ++--- .../command_line/hdf_ping_handler.py | 47 ++--- .../command_line/hdf_set_handler.py | 46 ++--- .../command_line/hdf_tool_argument_parser.py | 46 ++--- .../command_line/hdf_tool_commands.py | 46 ++--- .../command_line/hdf_vendor_build_file.py | 48 ++--- .../command_line/hdf_vendor_kconfig_file.py | 66 ++++--- .../command_line/hdf_vendor_makefile.py | 94 ++++----- .../command_line/hdf_vendor_mk_file.py | 46 ++--- .../hdf_tool_daemon_server.py | 46 ++--- tools/hdf_dev_eco_tool/hdf_tool_exception.py | 46 ++--- tools/hdf_dev_eco_tool/hdf_tool_settings.py | 46 ++--- tools/hdf_dev_eco_tool/hdf_tool_version.py | 46 ++--- tools/hdf_dev_eco_tool/hdf_utils.py | 73 ++++--- tools/hdf_dev_eco_tool/main.py | 48 ++--- 31 files changed, 1049 insertions(+), 936 deletions(-) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index d16976c99..9f3438e53 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import json @@ -40,8 +42,6 @@ from .hdf_device_info_hcs import HdfDeviceInfoHcsFile from .hdf_vendor_build_file import HdfVendorBuildFile from .hdf_vendor_kconfig_file import HdfVendorKconfigFile from .hdf_vendor_mk_file import HdfVendorMkFile -from .hdf_module_kconfig_file import HdfModuleKconfigFile -from .hdf_module_mk_file import HdfModuleMkFile from .hdf_driver_config_file import HdfDriverConfigFile from hdf_tool_settings import HdfToolSettings from hdf_tool_exception import HdfToolException @@ -90,8 +90,9 @@ class HdfAddHandler(HdfCommandHandlerBase): root, vendor, _, _, board = self.get_args() target_dir = hdf_utils.get_vendor_hdf_dir(root, vendor) if os.path.exists(target_dir): - raise HdfToolException("%s already exists" % target_dir, - CommandErrorCode.TARGET_ALREADY_EXIST) + raise HdfToolException( + "%s already exists" % + target_dir, CommandErrorCode.TARGET_ALREADY_EXIST) os.makedirs(target_dir) self._file_gen_lite('hdf_vendor_kconfig.template', target_dir, 'Kconfig', {}) @@ -117,10 +118,12 @@ class HdfAddHandler(HdfCommandHandlerBase): driver_name_converter = hdf_utils.WordsConverter(self.args.driver_name) framework_hdf = hdf_utils.get_vendor_hdf_dir_framework(root) if not os.path.exists(framework_hdf): - raise HdfToolException(' framework model path "%s" not exist' % framework_hdf, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + ' framework model path "%s" not exist' % + framework_hdf, CommandErrorCode.TARGET_NOT_EXIST) # 在 framework 目录下创建对应的 module 的文件目录用于存放 .c 驱动文件 - framework_drv_root_dir = hdf_utils.get_drv_root_dir(root, vendor, module) + framework_drv_root_dir = hdf_utils.get_drv_root_dir( + root, vendor, module) if os.path.exists(framework_drv_root_dir): raise HdfToolException('module "%s" already exist' % module, CommandErrorCode.TARGET_ALREADY_EXIST) @@ -129,11 +132,14 @@ class HdfAddHandler(HdfCommandHandlerBase): # 创建 .c 模板驱动 state, driver_file_path = self._add_driver_handler(*args_tuple) if not state: - raise HdfToolException('create drivers file fail "%s" ' % driver_file_path.split("\\")[-1]) + raise HdfToolException( + 'create drivers file fail "%s" ' % + driver_file_path.split("\\")[-1]) adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter(root, kernel) if not os.path.exists(adapter_hdf): - raise HdfToolException(' adapter model path "%s" not exist' % adapter_hdf, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + ' adapter model path "%s" not exist' % + adapter_hdf, CommandErrorCode.TARGET_NOT_EXIST) # 创建 adapter 路径下的 module 文件夹 adapter_model_path = os.path.join(adapter_hdf, 'model', module) @@ -143,16 +149,21 @@ class HdfAddHandler(HdfCommandHandlerBase): data_model = { "module_upper_case": converter.upper_case(), "module_lower_case": converter.lower_case(), - "driver_file_name": ("%s_driver.c" % driver_name_converter.lower_case()), + "driver_file_name": ("%s_driver.c" % + driver_name_converter.lower_case()), "driver_name": driver_name_converter.lower_case() } # 创建 adapter 下的 module中的三个文件 if kernel == 'liteos': - file_path, model_level_config_file_path = self._add_module_handler_liteos(framework_hdf, adapter_model_path, - data_model, converter, *args_tuple) + file_path, model_level_config_file_path = \ + self._add_module_handler_liteos( + framework_hdf, adapter_model_path, + data_model, converter, *args_tuple) elif kernel == "linux": - file_path, model_level_config_file_path = self._add_module_handler_linux(framework_hdf, adapter_model_path, - data_model, *args_tuple) + file_path, model_level_config_file_path = \ + self._add_module_handler_linux( + framework_hdf, adapter_model_path, + data_model, *args_tuple) else: file_path = {} model_level_config_file_path = {} @@ -166,34 +177,42 @@ class HdfAddHandler(HdfCommandHandlerBase): config_file_out = { 'module_name': module, 'module_path': file_path, - # 'module_path': file_path.update({driver_file_path.split("\\")[-1]: driver_file_path}), 'driver_name': driver_file_path.split("\\")[-1], 'driver_file_path': driver_file_path, 'module_level_config_path': model_level_config_file_path } - config_file = hdf_utils.read_file(os.path.join('resources', 'create_model.config')) + config_file = hdf_utils.read_file( + os.path.join('resources', 'create_model.config')) config_file_json = json.loads(config_file) config_file_json[module] = config_file_out if platform.system() == "Windows": - config_file_replace = json.dumps(config_file_json, indent=4).replace(root.replace('\\', '\\\\') + '\\\\', "") - hdf_utils.write_file(os.path.join('resources', 'create_model.config'), config_file_replace.replace('\\\\', '/')) + config_file_replace = json.dumps(config_file_json, indent=4).\ + replace(root.replace('\\', '\\\\') + '\\\\', "") + hdf_utils.write_file( + os.path.join('resources', 'create_model.config'), + config_file_replace.replace('\\\\', '/')) if platform.system() == "Linux": - config_file_replace = json.dumps(config_file_json, indent=4).replace(root + '/', "") - hdf_utils.write_file(os.path.join('resources', 'create_model.config'), config_file_replace) + config_file_replace = json.dumps(config_file_json, indent=4).\ + replace(root + '/', "") + hdf_utils.write_file( + os.path.join('resources', 'create_model.config'), + config_file_replace) return json.dumps(config_item) - def _add_module_handler_liteos(self, framework_hdf, adapter_model_path, data_model, converter, *args_tuple): + def _add_module_handler_liteos(self, framework_hdf, adapter_model_path, + data_model, converter, *args_tuple): root, vendor, module, driver, board, kernel = args_tuple liteos_file_path = {} liteos_level_config_file_path = {} liteos_file_name = ['BUILD.gn', 'Kconfig', 'Makefile'] - # template_path = os.path.join(adapter_hdf, "tools", "hdf_dev_eco_tool", "resources", "templates", "lite") - template_path = "/".join([framework_hdf] + ["tools", "hdf_dev_eco_tool", "resources", "templates", "lite"]) + template_path = "/".join([framework_hdf] + ["tools", + "hdf_dev_eco_tool", "resources", "templates", "lite"]) for file_name in liteos_file_name: for i in os.listdir(template_path): if i.find(file_name.split(".")[0]) > 0: out_path = os.path.join(adapter_model_path, file_name) - self._render(os.path.join(template_path, i), out_path, data_model) + self._render(os.path.join(template_path, i), + out_path, data_model) liteos_file_path[file_name] = out_path # 修改 liteos 下的 Kconfig 文件 vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") @@ -210,8 +229,10 @@ class HdfAddHandler(HdfCommandHandlerBase): vendor_gn_path = vendor_gn.add_module(module) liteos_level_config_file_path[module + "Build"] = vendor_gn_path - # 修改 vendor/hisilicon/hispark_taurus/hdf_config/device_info 下的 device_info.hcs 文件 - device_info = HdfDeviceInfoHcsFile(root, vendor, module, board, driver, path="") + # 修改 vendor/hisilicon/hispark_taurus/hdf_config/ + # device_info 下的 device_info.hcs 文件 + device_info = HdfDeviceInfoHcsFile( + root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() liteos_file_path["devices_info.hcs"] = hcs_file_path @@ -229,20 +250,22 @@ class HdfAddHandler(HdfCommandHandlerBase): liteos_level_config_file_path[module + "_dot_configs"] = dot_file_list return liteos_file_path, liteos_level_config_file_path - def _add_module_handler_linux(self, framework_hdf, adapter_model_path, data_model, *args_tuple): + def _add_module_handler_linux(self, framework_hdf, adapter_model_path, + data_model, *args_tuple): root, vendor, module, driver, board, kernel = args_tuple linux_file_path = {} linux_level_config_file_path = {} - # linux_file_name = ['built-in.a', 'Kconfig', 'Makefile'] linux_file_name = ['Kconfig', 'Makefile'] - # template_path = "/".join([adapter_hdf.strip(kernel)[:-1]] + ["liteos", "tools", "hdf_dev_eco_tool", - # "resources", "templates", "lite"]) - template_path = "/".join([framework_hdf] + ["tools", "hdf_dev_eco_tool", "resources", "templates", "lite"]) + template_path = "/".join([framework_hdf] + + ["tools", "hdf_dev_eco_tool", + "resources", "templates", "lite"]) for file_name in linux_file_name: - for i in hdf_utils.template_filename_filtrate(template_path, kernel): + for i in hdf_utils.template_filename_filtrate( + template_path, kernel): if i.find(file_name.split(".")[0]) > 0: out_path = os.path.join(adapter_model_path, file_name) - self._render(os.path.join(template_path, i), out_path, data_model) + self._render(os.path.join(template_path, i), + out_path, data_model) linux_file_path[file_name] = out_path # 修改 linux 下的 Kconfig 文件 vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") @@ -254,21 +277,26 @@ class HdfAddHandler(HdfCommandHandlerBase): vendor_mk_path = vendor_mk.add_module(data_model) linux_level_config_file_path[module + "_Makefile"] = vendor_mk_path - # 修改 vendor/hisilicon/hispark_taurus_linux/hdf_config/device_info 下的 device_info.hcs 文件 - device_info = HdfDeviceInfoHcsFile(root, vendor, module, board, driver, path="") + # 修改 vendor/hisilicon/hispark_taurus_linux/ + # hdf_config/device_info 下的 device_info.hcs 文件 + device_info = HdfDeviceInfoHcsFile( + root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() linux_file_path["devices_info.hcs"] = hcs_file_path # 修改 dot_configs 的配置文件 template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" new_demo_config = Template(template_string).substitute(data_model) - defconfig_patch = HdfDefconfigAndPatch(root, vendor, kernel, board, data_model, new_demo_config) + defconfig_patch = HdfDefconfigAndPatch( + root, vendor, kernel, board, + data_model, new_demo_config) config_path = defconfig_patch.get_config_config() patch_list = defconfig_patch.add_module(config_path) config_path = defconfig_patch.get_config_patch() defconfig_list = defconfig_patch.add_module(config_path) - linux_level_config_file_path[module + "_dot_configs"] = list(set(patch_list + defconfig_list)) + linux_level_config_file_path[module + "_dot_configs"] = \ + list(set(patch_list + defconfig_list)) return linux_file_path, linux_level_config_file_path def _add_driver_handler(self, *args_tuple): @@ -276,8 +304,9 @@ class HdfAddHandler(HdfCommandHandlerBase): drv_converter = hdf_utils.WordsConverter(self.args.driver_name) drv_src_dir = hdf_utils.get_drv_src_dir(root, vendor, module) if os.path.exists(os.path.join(drv_src_dir, '%s_driver.c' % driver)): - raise HdfToolException('driver "%s" already exist' % driver, - CommandErrorCode.TARGET_ALREADY_EXIST) + raise HdfToolException( + 'driver "%s" already exist' % + driver, CommandErrorCode.TARGET_ALREADY_EXIST) data_model = { 'driver_lower_case': drv_converter.lower_case(), 'driver_upper_camel_case': drv_converter.upper_camel_case(), @@ -286,7 +315,8 @@ class HdfAddHandler(HdfCommandHandlerBase): } self._file_gen_lite('hdf_driver.c.template', drv_src_dir, '%s_driver.c' % driver, data_model) - driver_file_path = os.path.join(drv_src_dir, '%s_driver.c' % driver) + driver_file_path = os.path.join( + drv_src_dir, '%s_driver.c' % driver) return True, driver_file_path def _add_config_handler(self): diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py index 4c46b6701..06b64a938 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_error_code.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. class CommandErrorCode(object): MESSAGE_FORMAT_WRONG = 1001 @@ -36,3 +38,6 @@ class CommandErrorCode(object): TARGET_ALREADY_EXIST = 1004 FILE_FORMAT_WRONG = 1005 UNKNOWN_ERROR = 1111 + + def __init__(self): + pass diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py index 3402b2665..93eee0c1c 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_handler_base.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os @@ -50,9 +52,10 @@ class HdfCommandHandlerBase(object): if self.action_type in self.handlers: return self.handlers[self.action_type]() else: - raise HdfToolException('unknown action_type: "%s" for "%s" cmd' % - (self.action_type, self.cmd), - CommandErrorCode.INTERFACE_ERROR) + raise HdfToolException( + 'unknown action_type: "%s" for "%s" cmd' % + (self.action_type, self.cmd), + CommandErrorCode.INTERFACE_ERROR) def _get_action_type(self): try: @@ -66,9 +69,9 @@ class HdfCommandHandlerBase(object): if not value: raise AttributeError() except AttributeError: - raise HdfToolException('argument "--%s" is required for "%s" cmd' % - (arg, self.cmd), - CommandErrorCode.INTERFACE_ERROR) + raise HdfToolException( + 'argument "--%s" is required for "%s" cmd' % + (arg, self.cmd), CommandErrorCode.INTERFACE_ERROR) def _get_arg(self, arg): try: @@ -78,7 +81,8 @@ class HdfCommandHandlerBase(object): return '' def get_args(self): - args = ['vendor_name', 'module_name', 'driver_name', 'board_name', 'kernel_name'] + args = ['vendor_name', 'module_name', + 'driver_name', 'board_name', 'kernel_name'] ret = [self._get_arg('root_dir')] for arg in args: value = self._get_arg(arg) @@ -86,20 +90,10 @@ class HdfCommandHandlerBase(object): value = hdf_utils.WordsConverter(value).lower_case() ret.append(value) return tuple(ret) - """ - def get_args(self): - args = ['root_dir', 'vendor_name', 'module_name', 'driver_name', 'board_name', 'kernel_name'] - ret = {"root": self._get_arg('root_dir')} - for arg in args: - value = self._get_arg(arg) - if value: - value = hdf_utils.WordsConverter(value).lower_case() - ret[arg.split("_")[0]] = value - return ret - """ @staticmethod def check_path_raise_if_not_exist(full_path): if not os.path.exists(full_path): - raise HdfToolException('%s not exist' % full_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + '%s not exist' % + full_path, CommandErrorCode.TARGET_NOT_EXIST) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py b/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py index d49f078bf..060c0c9fa 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_command_line_server.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import sys import argparse diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py index 7efe0328b..2e85740d5 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re @@ -40,7 +42,8 @@ import hdf_utils class HdfDefconfigAndPatch(object): - def __init__(self, root, vendor, kernel, board, data_model, new_demo_config): + def __init__(self, root, vendor, kernel, + board, data_model, new_demo_config): self.root = root self.vendor = vendor self.kernel = kernel @@ -48,7 +51,8 @@ class HdfDefconfigAndPatch(object): self.data_model = data_model self.new_demo_config = new_demo_config self.file_path = hdf_utils.get_template_file_path(root, vendor) - self.drivers_path_list = HdfToolSettings().get_board_parent_file(self.board) + self.drivers_path_list = HdfToolSettings().\ + get_board_parent_file(self.board) def get_config_config(self): return os.path.join(self.root, "kernel", self.kernel, "config") @@ -60,32 +64,15 @@ class HdfDefconfigAndPatch(object): for filename in os.listdir(path): new_path = os.path.join(path, filename) if not os.path.isdir(new_path): - if new_path.split("\\")[-1] in self.drivers_path_list or new_path.split("/")[-1] in self.drivers_path_list: - files.append(new_path) - with open(new_path, "r+", encoding="utf-8") as f: - data = f.readlines() - insert_index = None - state = False - for index, line in enumerate(data): - if line.find("CONFIG_DRIVERS_HDF_INPUT=y") >= 0: - insert_index = index - elif line.find(self.new_demo_config) >= 0: - state = True - if not state: - if new_path.split(".")[-1] != "patch": - data.insert(insert_index + 1, self.new_demo_config) - else: - data.insert(insert_index + 1, "+"+self.new_demo_config) - - with open(new_path, "w", encoding="utf-8") as f: - f.writelines(data) + self.find_file(new_path, files) else: self.add_module(new_path, files) return files def delete_module(self, path): lines = hdf_utils.read_file_lines(path) - if self.new_demo_config in lines or ("+" + self.new_demo_config) in lines: + if self.new_demo_config in lines or \ + ("+" + self.new_demo_config) in lines: if path.split(".")[-1] != "patch": lines.remove(self.new_demo_config) else: @@ -97,3 +84,27 @@ class HdfDefconfigAndPatch(object): replacement = 'vendor/%s/' % self.vendor new_content = re.sub(pattern, replacement, self.contents) hdf_utils.write_file(self.file_path, new_content) + + def find_file(self, path, files): + if path.split("\\")[-1] in self.drivers_path_list or \ + path.split("/")[-1] in self.drivers_path_list: + files.append(path) + codetype = "utf-8" + with open(path, "r+", encoding=codetype) as f: + data = f.readlines() + insert_index = None + state = False + for index, line in enumerate(data): + if line.find("CONFIG_DRIVERS_HDF_INPUT=y") >= 0: + insert_index = index + elif line.find(self.new_demo_config) >= 0: + state = True + if not state: + if path.split(".")[-1] != "patch": + data.insert(insert_index + 1, + self.new_demo_config) + else: + data.insert(insert_index + 1, + "+" + self.new_demo_config) + with open(path, "w", encoding=codetype) as f: + f.writelines(data) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py index 4a9357947..876d76bdb 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_delete_handler.py @@ -1,33 +1,37 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + + import json import os import shutil @@ -38,7 +42,6 @@ from .hdf_command_error_code import CommandErrorCode from .hdf_command_handler_base import HdfCommandHandlerBase from .hdf_defconfig_patch import HdfDefconfigAndPatch from .hdf_device_info_hcs import HdfDeviceInfoHcsFile -from .hdf_get_handler import HdfGetHandler from .hdf_vendor_build_file import HdfVendorBuildFile from .hdf_vendor_kconfig_file import HdfVendorKconfigFile from .hdf_vendor_makefile import HdfVendorMakeFile @@ -88,48 +91,15 @@ class HdfDeleteHandler(HdfCommandHandlerBase): if key.split("_")[-1] == "name": pass elif key == "driver_file_path": - driver_file = os.path.join(root, path_value.split(model)[0], model) + driver_file = os.path.join( + root, path_value.split(model)[0], model) if os.path.exists(driver_file): shutil.rmtree(driver_file) else: - if key == "module_level_config_path": - for k, v in model_info["module_level_config_path"].items(): - if k == "%s_Makefile" % model: - HdfVendorMakeFile(root, vendor="", kernel="", path=os.path.join(root, v)).delete_module(model) - elif k == "%s_Kconfig" % model: - HdfVendorKconfigFile(root, vendor="", kernel="", path=os.path.join(root, v)).delete_module(model) - elif k == "%sBuild" % model: - HdfVendorBuildFile(root, vendor="").delete_module(file_path=os.path.join(root, v), model=model) - elif k == "%s_hdf_lite" % model: - HdfVendorMkFile(root, vendor="").delete_module(file_path=os.path.join(root, v), module=model) - elif k == "%s_dot_configs" % model: - for dot_path in v: - if dot_path.split(".")[-1] == "config": - template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" - else: - template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" - new_demo_config = Template(template_string).substitute({"module_upper_case": model.upper()}) - defconfig_patch = HdfDefconfigAndPatch(root=root, vendor="", kernel="", board="", - data_model="", new_demo_config=new_demo_config) - defconfig_patch.delete_module(path=os.path.join(root, dot_path)) - elif key == "module_path": - for k, v in model_info["module_path"].items(): - if v.endswith("hcs"): - hcs_path = os.path.join(root, v) - HdfDeviceInfoHcsFile(root=root, vendor="", module="", board="", driver="", path=hcs_path)\ - .delete_driver(module=model) - else: - if v: - file_path = os.path.join(root, v) - if os.path.exists(file_path): - os.remove(file_path) - model_dir_path = "/".join(file_path.split("/")[:-1]) - if os.path.exists(model_dir_path): - file_list = os.listdir(model_dir_path) - if not file_list: - shutil.rmtree(model_dir_path) + self._delete_file_func(root, key, model_info, model) create_model_data = self._delete_model_info() - delete_model_info = hdf_utils.get_create_model_info(root=root, create_data=json.dumps(create_model_data)) + delete_model_info = hdf_utils.get_create_model_info( + root=root, create_data=json.dumps(create_model_data)) return delete_model_info def _delete_model_info(self): @@ -138,17 +108,21 @@ class HdfDeleteHandler(HdfCommandHandlerBase): root, _, module, _, _, _ = self.get_args() adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) if not os.path.exists(adapter_framework): - raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, - CommandErrorCode.TARGET_NOT_EXIST) - create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", - "resources", "create_model.config") + raise HdfToolException( + ' adapter model path "%s" not exist' % + adapter_framework, CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join( + adapter_framework, "tools", "hdf_dev_eco_tool", + "resources", "create_model.config") if not os.path.exists(create_file_save_path): - raise HdfToolException('create file config "%s" not exist' % create_file_save_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'create file config "%s" not exist' % + create_file_save_path, CommandErrorCode.TARGET_NOT_EXIST) data = hdf_utils.read_file(create_file_save_path) write_data = json.loads(data) write_data.pop(module) - hdf_utils.write_file(create_file_save_path, json.dumps(write_data, indent=4)) + hdf_utils.write_file(create_file_save_path, + json.dumps(write_data, indent=4)) return write_data def _delete_module_handler(self): @@ -157,17 +131,23 @@ class HdfDeleteHandler(HdfCommandHandlerBase): root, _, module, _, _, _ = self.get_args() adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) if not os.path.exists(adapter_framework): - raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, - CommandErrorCode.TARGET_NOT_EXIST) - create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", "resources", "create_model.config") + raise HdfToolException( + ' adapter model path "%s" not exist' % + adapter_framework, CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join( + adapter_framework, "tools", "hdf_dev_eco_tool", + "resources", "create_model.config") if not os.path.exists(create_file_save_path): - raise HdfToolException('create file config "%s" not exist' % create_file_save_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'create file config "%s" not exist' % + create_file_save_path, CommandErrorCode.TARGET_NOT_EXIST) data = hdf_utils.read_file(create_file_save_path) file_info = json.loads(data) model_info = file_info.get(module, None) - if model_info == None: - raise HdfToolException(' delete model "%s" not exist' % module, CommandErrorCode.TARGET_NOT_EXIST) + if model_info is None: + raise HdfToolException( + ' delete model "%s" not exist' % + module, CommandErrorCode.TARGET_NOT_EXIST) else: return self._delete_module(root, module, model_info) @@ -188,3 +168,56 @@ class HdfDeleteHandler(HdfCommandHandlerBase): self.check_arg_raise_if_not_exist("board_name") _, _, module, driver, _ = self.get_args() self._delete_driver(module, driver) + + def _delete_file_func(self, key, model_info, model, root): + if key == "module_level_config_path": + for k, v in model_info[key].items(): + if k == "%s_Makefile" % model: + HdfVendorMakeFile( + root, vendor="", kernel="", + path=os.path.join(root, v)).delete_module(model) + elif k == "%s_Kconfig" % model: + HdfVendorKconfigFile( + root, vendor="", kernel="", + path=os.path.join(root, v)).delete_module(model) + elif k == "%sBuild" % model: + HdfVendorBuildFile( + root, vendor="").delete_module( + file_path=os.path.join(root, v), model=model) + elif k == "%s_hdf_lite" % model: + HdfVendorMkFile( + root, vendor="").delete_module( + file_path=os.path.join(root, v), module=model) + elif k == "%s_dot_configs" % model: + for dot_path in v: + if dot_path.split(".")[-1] == "config": + template_string = \ + "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" + else: + template_string = \ + "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" + new_demo_config = Template(template_string).\ + substitute({"module_upper_case": model.upper()}) + defconfig_patch = HdfDefconfigAndPatch( + root=root, vendor="", kernel="", board="", + data_model="", new_demo_config=new_demo_config) + defconfig_patch.delete_module( + path=os.path.join(root, dot_path)) + elif key == "module_path": + for k, v in model_info[key].items(): + if v.endswith("hcs"): + hcs_path = os.path.join(root, v) + HdfDeviceInfoHcsFile( + root=root, vendor="", module="", + board="", driver="", path=hcs_path). \ + delete_driver(module=model) + else: + if v: + file_path = os.path.join(root, v) + if os.path.exists(file_path): + os.remove(file_path) + model_dir_path = "/".join(file_path.split("/")[:-1]) + if os.path.exists(model_dir_path): + file_list = os.listdir(model_dir_path) + if not file_list: + shutil.rmtree(model_dir_path) diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py index 6fa209c90..b183dd77c 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py @@ -1,35 +1,36 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import ast -import json +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + import os import re from string import Template @@ -37,7 +38,6 @@ from string import Template from .hdf_command_error_code import CommandErrorCode from hdf_tool_exception import HdfToolException -from hdf_tool_settings import HdfToolSettings import hdf_utils @@ -50,17 +50,20 @@ class HdfDeviceInfoHcsFile(object): self.root = root self.driver = driver self.lines = None - self.hcs_path = hdf_utils.get_hcs_file_path(self.root, self.vendor, self.board) + self.hcs_path = hdf_utils.get_hcs_file_path( + self.root, self.vendor, self.board) else: self.hcs_path = path self.root = root self.file_path = hdf_utils.get_template_file_path(root) if not os.path.exists(self.file_path): - raise HdfToolException('template file: %s not exist' % self.file_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'template file: %s not exist' % + self.file_path, CommandErrorCode.TARGET_NOT_EXIST) if not os.path.exists(self.hcs_path): - raise HdfToolException('hcs file: %s not exist' % self.hcs_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'hcs file: %s not exist' % + self.hcs_path, CommandErrorCode.TARGET_NOT_EXIST) def _save(self): if self.lines: @@ -115,7 +118,8 @@ class HdfDeviceInfoHcsFile(object): for index, line in enumerate(hcs_config): if line.find("%s :: host" % module) > 0: index_info["start_index"] = index - for child_index in range(index_info["start_index"], len(hcs_config)): + for child_index in range( + index_info["start_index"], len(hcs_config)): if hcs_config[child_index].strip().endswith("{"): count += 1 elif hcs_config[child_index].strip() == "}": @@ -125,19 +129,27 @@ class HdfDeviceInfoHcsFile(object): break break if index_info: - self.lines = hcs_config[0:index_info["start_index"]] + hcs_config[index_info["end_index"] + 1:] + self.lines = hcs_config[0:index_info["start_index"]] \ + + hcs_config[index_info["end_index"] + 1:] self._save() return True def add_model_hcs_file_config(self): - template_path = os.path.join(self.file_path, 'device_info_hcs.template') - lines = list(map(lambda x: "\t\t" + x, hdf_utils.read_file_lines(template_path))) - old_lines = list(filter(lambda x: x != "\n", hdf_utils.read_file_lines(self.hcs_path))) + template_path = os.path.join(self.file_path, + 'device_info_hcs.template') + lines = list(map(lambda x: "\t\t" + x, + hdf_utils.read_file_lines(template_path))) + old_lines = list(filter(lambda x: x != "\n", + hdf_utils.read_file_lines(self.hcs_path))) new_data = old_lines[:-2] + lines + old_lines[-2:] - d = {'driver_name': self.driver, 'model_name': self.module} - for i in range(len(new_data)): - new_data[i] = Template(new_data[i]).substitute(d) - with open(self.hcs_path, "w+", encoding="utf-8") as l: + data = { + "driver_name": self.driver, + "model_name": self.module, + } + for index, _ in enumerate(new_data): + new_data[index] = Template(new_data[index]).substitute(data) + codetype = "utf-8" + with open(self.hcs_path, "w+", encoding=codetype) as l: for j in new_data: l.write(j) return self.hcs_path diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py index 5be918eb9..a40f64210 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_dot_config_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py index a60505a29..a4d045e45 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_driver_config_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os from string import Template @@ -55,7 +57,8 @@ class HdfDriverConfigFile(object): CommandErrorCode.TARGET_NOT_EXIST) self.config_dir = os.path.join(board_path, 'hdf_config') self.drv_dir = os.path.join(self.config_dir, self.module) - self.drv_config_path = os.path.join(self.drv_dir, '%s_config.hcs' % self.driver) + self.drv_config_path = os.path.join( + self.drv_dir, '%s_config.hcs' % self.driver) if only_path: return manager_hcs_path = os.path.join(self.config_dir, 'device_info', diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py index d00cb5fdf..e12ca7798 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import json @@ -45,10 +47,11 @@ import hdf_utils class HdfGetHandler(HdfCommandHandlerBase): + HDF_VERSION_MAJOR = 0 + HDF_VERSION_MINOR = 1 + def __init__(self, args): super(HdfGetHandler, self).__init__() - self.HDF_VERSION_MAJOR = 0 - self.HDF_VERSION_MINOR = 1 self.cmd = 'get' self.handlers = { 'vendor_list': self._get_vendor_list_handler, @@ -126,7 +129,8 @@ class HdfGetHandler(HdfCommandHandlerBase): module, k_path = item if module in modules: models = \ - HdfModuleKconfigFile(root, module, k_path).get_models() + HdfModuleKconfigFile(root, module, + k_path).get_models() drivers[module] = models return json.dumps(drivers) @@ -139,8 +143,9 @@ class HdfGetHandler(HdfCommandHandlerBase): _, vendor, module, driver, _ = self.get_args() drv_dir = hdf_utils.get_drv_dir(root, vendor, module, driver) if not os.path.exists(drv_dir): - raise HdfToolException('driver directory: %s not exist' % drv_dir, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'driver directory: %s not exist' % + drv_dir, CommandErrorCode.TARGET_NOT_EXIST) for root_path, dirs, files in os.walk(drv_dir): for file in files: if file.endswith('.c'): @@ -161,41 +166,50 @@ class HdfGetHandler(HdfCommandHandlerBase): root, _, _, _, _, _ = self.get_args() adapter_framework = hdf_utils.get_vendor_hdf_dir_framework(root=root) if not os.path.exists(adapter_framework): - raise HdfToolException(' adapter model path "%s" not exist' % adapter_framework, - CommandErrorCode.TARGET_NOT_EXIST) - create_file_save_path = os.path.join(adapter_framework, "tools", "hdf_dev_eco_tool", "resources", "create_model.config") + raise HdfToolException( + ' adapter model path "%s" not exist' % + adapter_framework, CommandErrorCode.TARGET_NOT_EXIST) + create_file_save_path = os.path.join( + adapter_framework, "tools", "hdf_dev_eco_tool", + "resources", "create_model.config") if not os.path.exists(create_file_save_path): - raise HdfToolException('create file config "%s" not exist' % create_file_save_path, - CommandErrorCode.TARGET_NOT_EXIST) + raise HdfToolException( + 'create file config "%s" not exist' % + create_file_save_path, CommandErrorCode.TARGET_NOT_EXIST) out_model_list = [] data = hdf_utils.read_file(create_file_save_path) - json_type_data = json.loads(data) - if not json_type_data: + json_type = json.loads(data) + if not json_type: return out_model_list - file_key_list = list(list(json_type_data.items())[0][-1].keys())[:-1] - for k, v in json_type_data.items(): + file_key_list = list(list(json_type. + items())[0][-1].keys())[:-1] + for k, _ in json_type.items(): model_file_path = {} for key in file_key_list: if key.split("_")[-1] == "path": - path_dict = json_type_data[k][key] - if isinstance(path_dict, dict): - for k_filename, file_path in path_dict.items(): - if not os.path.exists(os.path.join(root, file_path)): - model_file_path[k_filename] = " " - else: - model_file_path[k_filename] = path_dict[k_filename] - else: - hcs_file_path = os.path.join(root, path_dict) - if not os.path.exists(hcs_file_path): - model_file_path[key] = " " - else: - model_file_path[key] = path_dict + path_dict = json_type[k][key] + model_file_path = self._model_info( + path_dict, root, model_file_path, key) out_model_list.append({k: model_file_path}) return out_model_list def __get_version(self): version_end = "\nCopyright (c) 2020-2021 Huawei Device Co., Ltd." version_head = "hdf_dev_eco_tool version : " - return version_head + str(self.HDF_VERSION_MAJOR) + "." + str(self.HDF_VERSION_MINOR) + version_end - - + return version_head + str(self.HDF_VERSION_MAJOR) \ + + "." + str(self.HDF_VERSION_MINOR) + version_end + + def _model_info(self, path_dict, root, model_file_path, key): + if isinstance(path_dict, dict): + for k_filename, file_path in path_dict.items(): + if not os.path.exists(os.path.join(root, file_path)): + model_file_path[k_filename] = " " + else: + model_file_path[k_filename] = path_dict[k_filename] + else: + hcs_file_path = os.path.join(root, path_dict) + if not os.path.exists(hcs_file_path): + model_file_path[key] = " " + else: + model_file_path[key] = path_dict + return model_file_path diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py index 2c6de04ea..9cb614cfe 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_hcs_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py index 635cbcbe8..077d7f200 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_kconfig_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py index 89726e963..e7dc12e82 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_mk_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re @@ -50,10 +52,7 @@ class HdfLiteMkFile(object): self.target_format = r'include .*vendor/%s/.*/hdf_vendor[.]mk' self.end_line_index = -1 self.target_line_index = -1 - # self.current_vendor_pattern = \ - # r'^\s*include.*/vendor/(.*)/hdf_vendor.mk' - self.current_vendor_pattern = \ - r'^\s*include.*/device/(.*)/lite.mk' + self.current_vendor_pattern = r'^\s*include.*/device/(.*)/lite.mk' def _save(self): if self.orig_exist: diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py index d25ad76c2..e163130ea 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_lite_settings_mk_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py index 5de6a0c51..d856a393e 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_manager_config_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_module_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_module_kconfig_file.py index 458780a2a..764e71fb2 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_module_kconfig_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_module_kconfig_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_module_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_module_mk_file.py index 5a1a74604..52493c206 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_module_mk_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_module_mk_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_ping_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_ping_handler.py index 544f7730e..8e63ab4fc 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_ping_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_ping_handler.py @@ -1,34 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. from .hdf_command_handler_base import HdfCommandHandlerBase diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py index 1533782b5..5e296978c 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import json diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_tool_argument_parser.py b/tools/hdf_dev_eco_tool/command_line/hdf_tool_argument_parser.py index 4c4f1293f..46487ff7c 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_tool_argument_parser.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_tool_argument_parser.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import argparse diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_tool_commands.py b/tools/hdf_dev_eco_tool/command_line/hdf_tool_commands.py index 413611867..a55b9b2e1 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_tool_commands.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_tool_commands.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. from .hdf_add_handler import HdfAddHandler from .hdf_delete_handler import HdfDeleteHandler diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py index 904fc82c0..67ca94bfe 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py @@ -1,41 +1,41 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re -from string import Template from .hdf_command_error_code import CommandErrorCode from hdf_tool_exception import HdfToolException -from hdf_tool_settings import HdfToolSettings import hdf_utils diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py index a490b8170..2359dab2c 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re @@ -42,7 +44,8 @@ class HdfVendorKconfigFile(object): self.kernel = kernel self.root = root self.vendor = vendor - self.kconfig_path = hdf_utils.get_vendor_kconfig_path(self.root, self.kernel) + self.kconfig_path = hdf_utils.\ + get_vendor_kconfig_path(self.root, self.kernel) else: self.kconfig_path = path if os.path.exists(self.kconfig_path): @@ -50,12 +53,19 @@ class HdfVendorKconfigFile(object): else: self.lines = [] drivers_path = HdfToolSettings().get_drivers_path_adapter() - if kernel.capitalize() == "Liteos" or re.search(r'liteos/Kconfig', self.kconfig_path): - line_pattern = r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"' % (drivers_path) + if kernel.capitalize() == "Liteos" or re.search( + r'liteos/Kconfig', self.kconfig_path): + line_pattern = \ + r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"'\ + % (drivers_path) self.line_re = re.compile(line_pattern) - self.line_prefix = 'source "../../%s/%s/%s"' % (drivers_path, 'liteos', 'model') - elif kernel.capitalize() == "Linux" or re.search(r'linux/Kconfig', self.kconfig_path): - line_pattern = r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"' % (drivers_path) + self.line_prefix = 'source "../../%s/%s/%s"'\ + % (drivers_path, 'liteos', 'model') + elif kernel.capitalize() == "Linux" or re.search( + r'linux/Kconfig', self.kconfig_path): + line_pattern = \ + r'^\s*source\s+"../../(%s/([a-zA-Z0-9_\-]+)/.*)"'\ + % (drivers_path) self.line_re = re.compile(line_pattern) self.line_prefix = 'source "drivers/hdf/khdf/model/%s/Kconfig"\n' diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py index c4a500934..7153cc7e4 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_makefile.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re @@ -35,7 +37,6 @@ from string import Template from .hdf_command_error_code import CommandErrorCode from hdf_tool_exception import HdfToolException -from hdf_tool_settings import HdfToolSettings import hdf_utils @@ -46,12 +47,15 @@ class HdfVendorMakeFile(object): else: self.vendor = vendor self.kernel = kernel - self.file_path = hdf_utils.get_vendor_makefile_path(root, self.kernel) + self.file_path = hdf_utils.\ + get_vendor_makefile_path(root, self.kernel) if not os.path.exists(self.file_path): raise HdfToolException('file: %s not exist' % self.file_path, CommandErrorCode.TARGET_NOT_EXIST) self.contents = hdf_utils.read_file_lines(self.file_path) - self.template_str = "obj-$(CONFIG_DRIVERS_HDF_${module_upper_case}) += model/${module_lower_case}/\n" + self.template_str = \ + "obj-$(CONFIG_DRIVERS_HDF_${module_upper_case}) " \ + "+= model/${module_lower_case}/\n" def _begin_end(self, module): module_id = hdf_utils.get_id(self.vendor, module) @@ -59,52 +63,24 @@ class HdfVendorMakeFile(object): end = '\n# %s end>\n' % module_id return begin, end - # def _create_module(self, module, need_content=True): - # begin, end = self._begin_end(module) - # if not need_content: - # return hdf_utils.SectionContent(begin, '', end) - # vendor_converter = hdf_utils.WordsConverter(self.vendor) - # module_converter = hdf_utils.WordsConverter(module) - # data_model = { - # 'module_upper_case': module_converter.upper_case(), - # 'module_lower_case': module_converter.lower_case(), - # 'vendor_lower_case': vendor_converter.lower_case(), - # 'drivers_path': HdfToolSettings().get_drivers_path_adapter() - # } - # template_str = hdf_utils.get_template('hdf_vendor_mk_module.template') - # module_item = Template(template_str).safe_substitute(data_model) - # return hdf_utils.SectionContent(begin, module_item, end) - def add_module(self, data_model): - self.contents.append(Template(self.template_str).safe_substitute(data_model)) + self.contents.append(Template(self.template_str) + .safe_substitute(data_model)) hdf_utils.write_file_lines(self.file_path, self.contents) return self.file_path def delete_module(self, module): - # module_content = self._create_module(module, False) module_converter = hdf_utils.WordsConverter(module) data_model = { 'module_upper_case': module_converter.upper_case(), 'module_lower_case': module_converter.lower_case(), } - delete_template = Template(self.template_str).safe_substitute(data_model) + delete_template = Template( + self.template_str).safe_substitute(data_model) if delete_template in self.contents: self.contents.remove(delete_template) - hdf_utils.write_file_lines(content=self.contents, file_path=self.file_path) - """ - module_converter = hdf_utils.WordsConverter(module) - data_model = { - 'module_upper_case': module_converter.upper_case(), - 'module_lower_case': module_converter.lower_case(), - 'vendor_lower_case': vendor_converter.lower_case(), - 'drivers_path': HdfToolSettings().get_drivers_path_adapter() - } - template_str = hdf_utils.get_template('hdf_vendor_mk_module.template') - """ - # old_range = hdf_utils.find_section(self.contents, module_content) - # if not old_range: - # return - # hdf_utils.delete_and_save(self.contents, self.file_path, old_range) + hdf_utils.write_file_lines( + content=self.contents, file_path=self.file_path) def rename_vendor(self): pattern = r'vendor/([a-zA-Z0-9_\-]+)/' diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_mk_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_mk_file.py index 8a223763a..d36702839 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_mk_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_mk_file.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import re diff --git a/tools/hdf_dev_eco_tool/hdf_tool_daemon_server.py b/tools/hdf_dev_eco_tool/hdf_tool_daemon_server.py index d875808dd..ef8d56eb7 100755 --- a/tools/hdf_dev_eco_tool/hdf_tool_daemon_server.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_daemon_server.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import sys diff --git a/tools/hdf_dev_eco_tool/hdf_tool_exception.py b/tools/hdf_dev_eco_tool/hdf_tool_exception.py index 0bcddf49e..c52b5c233 100755 --- a/tools/hdf_dev_eco_tool/hdf_tool_exception.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_exception.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. from command_line.hdf_command_error_code import CommandErrorCode diff --git a/tools/hdf_dev_eco_tool/hdf_tool_settings.py b/tools/hdf_dev_eco_tool/hdf_tool_settings.py index c02c5103d..d1f72412a 100755 --- a/tools/hdf_dev_eco_tool/hdf_tool_settings.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_settings.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import os import json diff --git a/tools/hdf_dev_eco_tool/hdf_tool_version.py b/tools/hdf_dev_eco_tool/hdf_tool_version.py index c4e8a642f..0597ce4a4 100755 --- a/tools/hdf_dev_eco_tool/hdf_tool_version.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_version.py @@ -1,33 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. HDF_TOOL_VERSION = '1.0.0' diff --git a/tools/hdf_dev_eco_tool/hdf_utils.py b/tools/hdf_dev_eco_tool/hdf_utils.py index 6e48dc16b..b7efd6473 100755 --- a/tools/hdf_dev_eco_tool/hdf_utils.py +++ b/tools/hdf_dev_eco_tool/hdf_utils.py @@ -1,33 +1,37 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + + import json import os import hashlib @@ -202,9 +206,6 @@ def write_file_lines(file_path, content, code_type="utf-8"): def get_framework_lite_dir(root): - """ - return os.path.join(root, 'drivers', 'hdf', 'lite') - """ return os.path.join(root, 'drivers', 'adapter', 'khdf', 'liteos') @@ -227,7 +228,6 @@ def get_vendor_hdf_dir_adapter(root, kernel='liteos'): def get_vendor_lite_mk_path(root): - # return os.path.join(get_vendor_hdf_dir(root, vendor), 'hdf_vendor.mk') return os.path.join(get_vendor_hdf_dir_adapter(root), 'hdf_lite.mk') @@ -236,12 +236,7 @@ def get_vendor_makefile_path(root, kernel): def get_dot_configs_path(root, vendor, board): - # relative_path = HdfToolSettings().get_dot_configs(board) - # return get_vendor_hdf_dir_adapter(root, relative_path) - path = os.path.join(root, "vendor", vendor, board, 'kernel_configs') - # return ([os.path.join(path, i) for i in os.listdir(path)] + - # [os.path.join(root, path) for path in relative_path]) return [os.path.join(path, i) for i in os.listdir(path)] @@ -258,7 +253,6 @@ def get_drv_dir(root, vendor, module, driver): def get_drv_src_dir(root, vendor, module): - # return os.path.join(get_drv_dir(root, vendor, module, driver), 'src') return get_drv_root_dir(root, vendor, module) @@ -327,7 +321,6 @@ def is_commented_line(line, comment_start): def get_vendor_gn_path(root): - # return os.path.join(get_vendor_hdf_dir(root, vendor), 'hdf_vendor.mk') return os.path.join(get_vendor_hdf_dir_adapter(root), 'BUILD.gn') @@ -337,9 +330,9 @@ def get_template_file_path(root, kernel='liteos'): return os.path.join(root, relative_path2, template_relative_path) -# "hdf_config", "device_info", "device_info.hcs" def get_hcs_file_path(root, vendor, board): - return os.path.join(root, "vendor", vendor, board, "hdf_config", "device_info", "device_info.hcs") + return os.path.join(root, "vendor", vendor, board, + "hdf_config", "device_info", "device_info.hcs") def template_filename_filtrate(dir_path, kernal): @@ -351,16 +344,16 @@ def template_filename_filtrate(dir_path, kernal): def get_create_model_info(root, create_data): - json_type_data = json.loads(create_data) + data = json.loads(create_data) out_model_list = [] - if not json_type_data: + if not data: return [] - file_key_list = list(list(json_type_data.items())[0][-1].keys())[:-1] - for k, v in json_type_data.items(): + file_key_list = list(list(data.items())[0][-1].keys())[:-1] + for k, _ in data.items(): model_file_path = {} for key in file_key_list: if key.split("_")[-1] == "path": - path_dict = json_type_data[k][key] + path_dict = data[k][key] if isinstance(path_dict, dict): for k_filename, file_path in path_dict.items(): if not os.path.exists(os.path.join(root, file_path)): diff --git a/tools/hdf_dev_eco_tool/main.py b/tools/hdf_dev_eco_tool/main.py index 339c1cff9..a9aa14688 100755 --- a/tools/hdf_dev_eco_tool/main.py +++ b/tools/hdf_dev_eco_tool/main.py @@ -1,38 +1,38 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. # -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: # -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with th -# e distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. import sys import argparse -import hdf_utils from command_line.hdf_tool_commands import HdfToolCommands from hdf_tool_daemon_server import HdfToolDaemonServer -- Gitee