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""" 16Archives a set of files. 17""" 18 19 20import os 21import sys 22import argparse 23import subprocess 24import re 25 26 27def main(): 28 parser = argparse.ArgumentParser() 29 parser.add_argument('--haptobin', required=True) 30 parser.add_argument('--haptobinOutput', required=True) 31 parser.add_argument('--unpackOutput', required=True) 32 parser.add_argument('--packOutput', required=True) 33 parser.add_argument('--outpath', required=True) 34 parser.add_argument('--toolchain', required=True) 35 parser.add_argument('--compileTarget', required=True) 36 args = parser.parse_args() 37 print(args.haptobinOutput) 38 print(args.unpackOutput) 39 print(args.packOutput) 40 print(args.outpath) 41 print(args.compileTarget) 42 root_dir = os.path.dirname(os.path.realpath(__file__)) 43 toolchain = args.toolchain 44 tool_list = toolchain.split(':') 45 toolchain = tool_list[-1] 46 toolchain += "_" + args.compileTarget 47 time_out = 5000 48 49 # compile haptobin_tool.jar 50 hap_to_bin_shell_path = os.path.join(root_dir, "haptobin.sh") 51 command_haptobin = ['bash', hap_to_bin_shell_path, root_dir, args.haptobinOutput, args.outpath, toolchain] 52 child_haptobin = subprocess.Popen(command_haptobin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 53 haptobin_out, haptobin_err = child_haptobin.communicate(timeout=time_out) 54 if child_haptobin.returncode != 0: 55 print(haptobin_out.decode('utf-8')) 56 print(haptobin_err.decode('utf-8')) 57 raise Exception("compile haptobin java class failed!") 58 59 # compile app_unpacking_tool.jar 60 version = subprocess.check_output(['javac', '-version'], stderr=subprocess.STDOUT) 61 version = version.decode('utf-8') 62 array = re.findall(r'\d+', version) 63 compatible_version = 8 64 big_version = '' 65 if int(array[0]) > compatible_version: 66 big_version = 'true' 67 else: 68 big_version = 'false' 69 70 unpack_tool_shell_path = os.path.join(root_dir, "unpackingTool.sh") 71 command_unpack = ['bash', unpack_tool_shell_path, root_dir, args.unpackOutput, args.outpath, big_version, toolchain] 72 child_unpack = subprocess.Popen(command_unpack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 73 unpack_out, unpack_err = child_unpack.communicate(timeout=time_out) 74 if child_unpack.returncode != 0: 75 print(unpack_out.decode('utf-8')) 76 print(unpack_err.decode('utf-8')) 77 raise Exception("compile unapcking tool java class failed!") 78 79 #compile app_packing_tool.jar 80 pack_tool_shell_path = os.path.join(root_dir, "packingTool.sh") 81 command_pack = ['bash', pack_tool_shell_path, root_dir, args.packOutput, args.outpath, toolchain] 82 child_pack = subprocess.Popen(command_pack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 83 pack_out, pack_err = child_pack.communicate(timeout=time_out) 84 if child_pack.returncode != 0: 85 print(pack_out.decode('utf-8')) 86 print(pack_err.decode('utf-8')) 87 raise Exception("compile packing tool java class failed!") 88 89if __name__ == '__main__': 90 sys.exit(main()) 91