15f9996aaSopenharmony_ci#!/usr/bin/env python3 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci 45f9996aaSopenharmony_ci# 55f9996aaSopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd. 65f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 75f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 85f9996aaSopenharmony_ci# You may obtain a copy of the License at 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 115f9996aaSopenharmony_ci# 125f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 135f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 145f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 155f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 165f9996aaSopenharmony_ci# limitations under the License. 175f9996aaSopenharmony_ci# 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_ciimport os 205f9996aaSopenharmony_ciimport shutil 215f9996aaSopenharmony_ci 225f9996aaSopenharmony_cifrom containers.arg import Arg 235f9996aaSopenharmony_cifrom resolver.interface.args_resolver_interface import ArgsResolverInterface 245f9996aaSopenharmony_cifrom modules.interface.clean_module_interface import CleanModuleInterface 255f9996aaSopenharmony_cifrom resources.global_var import CURRENT_OHOS_ROOT, DEFAULT_CCACHE_DIR 265f9996aaSopenharmony_cifrom resources.config import Config 275f9996aaSopenharmony_cifrom util.log_util import LogUtil 285f9996aaSopenharmony_ci 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ciclass CleanArgsResolver(ArgsResolverInterface): 315f9996aaSopenharmony_ci 325f9996aaSopenharmony_ci def __init__(self, args_dict: dict): 335f9996aaSopenharmony_ci super().__init__(args_dict) 345f9996aaSopenharmony_ci 355f9996aaSopenharmony_ci @staticmethod 365f9996aaSopenharmony_ci def resolve_clean_args(target_arg: Arg, clean_module: CleanModuleInterface): 375f9996aaSopenharmony_ci if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 385f9996aaSopenharmony_ci LogUtil.hb_info( 395f9996aaSopenharmony_ci 'Clean all args that generated by last compilation') 405f9996aaSopenharmony_ci Arg.clean_args_file() 415f9996aaSopenharmony_ci 425f9996aaSopenharmony_ci @staticmethod 435f9996aaSopenharmony_ci def resolve_clean_out_product(target_arg: Arg, clean_module: CleanModuleInterface): 445f9996aaSopenharmony_ci if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 455f9996aaSopenharmony_ci config = Config() 465f9996aaSopenharmony_ci if config.out_path is not None and config.out_path != '' \ 475f9996aaSopenharmony_ci and config.out_path.startswith(CURRENT_OHOS_ROOT) and os.path.exists(config.out_path): 485f9996aaSopenharmony_ci LogUtil.hb_info( 495f9996aaSopenharmony_ci 'Clean {} directory that generated by last compilation'.format(config.out_path)) 505f9996aaSopenharmony_ci shutil.rmtree(config.out_path) 515f9996aaSopenharmony_ci 525f9996aaSopenharmony_ci @staticmethod 535f9996aaSopenharmony_ci def resolve_clean_ccache(target_arg: Arg, clean_module: CleanModuleInterface): 545f9996aaSopenharmony_ci if target_arg.arg_value or clean_module.args_dict['clean_all'].arg_value: 555f9996aaSopenharmony_ci if os.path.exists(DEFAULT_CCACHE_DIR): 565f9996aaSopenharmony_ci LogUtil.hb_info( 575f9996aaSopenharmony_ci 'Clean ccache "{}" directory'.format(DEFAULT_CCACHE_DIR)) 585f9996aaSopenharmony_ci shutil.rmtree(DEFAULT_CCACHE_DIR) 595f9996aaSopenharmony_ci 605f9996aaSopenharmony_ci @staticmethod 615f9996aaSopenharmony_ci def resolve_clean_all(target_arg: Arg, clean_module: CleanModuleInterface): 625f9996aaSopenharmony_ci if target_arg.arg_value: 635f9996aaSopenharmony_ci CleanArgsResolver.resolve_clean_out_product( 645f9996aaSopenharmony_ci target_arg, clean_module) 655f9996aaSopenharmony_ci CleanArgsResolver.resolve_clean_ccache(target_arg, clean_module) 66