1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2022 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import shutil 18import platform 19import argparse 20import subprocess 21import sys 22 23def run_command(in_cmd): 24 print(" ".join(in_cmd)) 25 proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE, 26 stderr=subprocess.PIPE, 27 universal_newlines=True, 28 shell=False) 29 stdout, stderr = proc.communicate() 30 if stdout != "": 31 raise Exception(stdout) 32 33if __name__ == '__main__': 34 PARSER_INST = argparse.ArgumentParser() 35 PARSER_INST.add_argument('--dst-file', 36 help='the converted target file') 37 PARSER_INST.add_argument('--module-path', 38 help='the module path') 39 PARSER_INST.add_argument('--out-file', 40 help='js output file') 41 PARSER_INST.add_argument('--out-filePath', 42 help='js output filePath') 43 PARSER_INST.add_argument('--relative-path', 44 help='the code root path relative the root_build_dir') 45 INPUT_ARGUMENTS = PARSER_INST.parse_args() 46 47 BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), INPUT_ARGUMENTS.relative_path)) 48 os.chdir(("%s" + INPUT_ARGUMENTS.module_path) % BUILD_PATH) 49 os_name = sys.platform 50 51 NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/current/bin/node' 52 if not os.path.exists(NODE_PATH): 53 raise Exception('error:NO such file or directory') 54 TSC_PATH = '../../../../third_party/typescript/bin/tsc' 55 CMD_INST = [NODE_PATH, TSC_PATH, "--outDir", INPUT_ARGUMENTS.out_filePath] 56 run_command(CMD_INST) 57 if not os.path.exists(INPUT_ARGUMENTS.out_file): 58 raise Exception('error:NO such file or directory') 59 CMD_INST = shutil.copy(INPUT_ARGUMENTS.out_file, INPUT_ARGUMENTS.dst_file) 60 61 CMD_INST = shutil.rmtree(INPUT_ARGUMENTS.out_filePath) 62 exit(0) 63