• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2022-2023 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('--checkOutput', required=True)
34    parser.add_argument('--outpath', required=True)
35    parser.add_argument('--toolchain', required=True)
36    parser.add_argument('--compileTarget', required=True)
37    args = parser.parse_args()
38    print(args.haptobinOutput)
39    print(args.unpackOutput)
40    print(args.packOutput)
41    print(args.checkOutput)
42    print(args.outpath)
43    print(args.compileTarget)
44    root_dir = os.path.dirname(os.path.realpath(__file__))
45    toolchain = args.toolchain
46    tool_list = toolchain.split(':')
47    toolchain = tool_list[-1]
48    toolchain += "_" + args.compileTarget
49    time_out = 5000
50
51    # compile haptobin_tool.jar
52    hap_to_bin_shell_path = os.path.join(root_dir, "haptobin.sh")
53    command_haptobin = ['bash', hap_to_bin_shell_path, root_dir, args.haptobinOutput, args.outpath, toolchain]
54    child_haptobin = subprocess.Popen(command_haptobin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55    haptobin_out, haptobin_err = child_haptobin.communicate(timeout=time_out)
56    if child_haptobin.returncode != 0:
57        print(haptobin_out.decode('utf-8'))
58        print(haptobin_err.decode('utf-8'))
59        raise Exception("compile haptobin java class failed!")
60
61    # compile app_unpacking_tool.jar
62    version = subprocess.check_output(['javac', '-version'], stderr=subprocess.STDOUT)
63    version = version.decode('utf-8')
64    array = re.findall(r'\d+', version)
65    compatible_version = 8
66    big_version = ''
67    if int(array[0]) > compatible_version:
68        big_version = 'true'
69    else:
70        big_version = 'false'
71
72    unpack_tool_shell_path = os.path.join(root_dir, "unpackingTool.sh")
73    command_unpack = ['bash', unpack_tool_shell_path, root_dir, args.unpackOutput, args.outpath, big_version, toolchain]
74    child_unpack = subprocess.Popen(command_unpack, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
75    unpack_out, unpack_err = child_unpack.communicate(timeout=time_out)
76    if child_unpack.returncode != 0:
77        print(unpack_out.decode('utf-8'))
78        print(unpack_err.decode('utf-8'))
79        raise Exception("compile unapcking tool java class failed!")
80
81    #compile app_packing_tool.jar
82    pack_tool_shell_path = os.path.join(root_dir, "packingTool.sh")
83    command_pack = ['bash', pack_tool_shell_path, root_dir, args.packOutput, args.outpath, toolchain]
84    child_pack = subprocess.Popen(command_pack, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
85    pack_out, pack_err = child_pack.communicate(timeout=time_out)
86    if child_pack.returncode != 0:
87        print(pack_out.decode('utf-8'))
88        print(pack_err.decode('utf-8'))
89        raise Exception("compile packing tool java class failed!")
90
91    #compile app_check_tool.jar
92    check_tool_shell_path = os.path.join(root_dir, "checkTool.sh")
93    command_check = ['bash', check_tool_shell_path, root_dir, args.checkOutput, args.outpath, toolchain]
94    child_check = subprocess.Popen(command_check, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
95    check_out, check_err = child_check.communicate(timeout=time_out)
96    if child_check.returncode != 0:
97        print(check_out.decode('utf-8'))
98        print(check_err.decode('utf-8'))
99        raise Exception("compile check tool java class failed!")
100
101if __name__ == '__main__':
102    sys.exit(main())
103