1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2023 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import shutil 21 22from containers.arg import Arg 23from resolver.interface.args_resolver_interface import ArgsResolverInterface 24from modules.interface.clean_module_interface import CleanModuleInterface 25from resources.global_var import CURRENT_OHOS_ROOT, DEFAULT_CCACHE_DIR 26from resources.config import Config 27from util.log_util import LogUtil 28 29 30class CleanArgsResolver(ArgsResolverInterface): 31 32 def __init__(self, args_dict: dict): 33 super().__init__(args_dict) 34 35 @staticmethod 36 def resolve_clean_args(target_arg: Arg, clean_module: CleanModuleInterface): 37 if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 38 LogUtil.hb_info( 39 'Clean all args that generated by last compilation') 40 Arg.clean_args_file() 41 42 @staticmethod 43 def resolve_clean_out_product(target_arg: Arg, clean_module: CleanModuleInterface): 44 if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 45 config = Config() 46 if config.out_path is not None and config.out_path != '' \ 47 and config.out_path.startswith(CURRENT_OHOS_ROOT) and os.path.exists(config.out_path): 48 LogUtil.hb_info( 49 'Clean {} directory that generated by last compilation'.format(config.out_path)) 50 shutil.rmtree(config.out_path) 51 52 @staticmethod 53 def resolve_clean_ccache(target_arg: Arg, clean_module: CleanModuleInterface): 54 if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 55 if os.path.exists(DEFAULT_CCACHE_DIR): 56 LogUtil.hb_info( 57 'Clean ccache "{}" directory'.format(DEFAULT_CCACHE_DIR)) 58 shutil.rmtree(DEFAULT_CCACHE_DIR) 59 60 @staticmethod 61 def resolve_clean_all(target_arg: Arg, clean_module: CleanModuleInterface): 62 if target_arg.arg_value: 63 CleanArgsResolver.resolve_clean_out_product( 64 target_arg, clean_module) 65 CleanArgsResolver.resolve_clean_ccache(target_arg, clean_module) 66