diff --git a/build.py b/build.py index 6d540926ce26a788efef4bcac5c36834d2568bd9..769e9c3a7bec26040cba468794ff4438adef186c 100755 --- a/build.py +++ b/build.py @@ -22,62 +22,69 @@ import sys import argparse import subprocess import re +import threading + +lock = threading.Lock() def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--haptobin', required=True) - parser.add_argument('--haptobinOutput', required=True) - parser.add_argument('--unpackOutput', required=True) - parser.add_argument('--packOutput', required=True) - parser.add_argument('--outpath', required=True) - args = parser.parse_args() - print(args.haptobinOutput) - print(args.unpackOutput) - print(args.packOutput) - print(args.outpath) - root_dir = os.path.dirname(os.path.realpath(__file__)) - time_out = 5000 + try: + lock.acquire() + parser = argparse.ArgumentParser() + parser.add_argument('--haptobin', required=True) + parser.add_argument('--haptobinOutput', required=True) + parser.add_argument('--unpackOutput', required=True) + parser.add_argument('--packOutput', required=True) + parser.add_argument('--outpath', required=True) + args = parser.parse_args() + print(args.haptobinOutput) + print(args.unpackOutput) + print(args.packOutput) + print(args.outpath) + root_dir = os.path.dirname(os.path.realpath(__file__)) + time_out = 5000 - # compile haptobin_tool.jar - hap_to_bin_shell_path = os.path.join(root_dir, "haptobin.sh") - command_haptobin = ['bash', hap_to_bin_shell_path, root_dir, args.haptobinOutput, args.outpath] - child_haptobin = subprocess.Popen(command_haptobin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - haptobin_out, haptobin_err = child_haptobin.communicate(timeout=time_out) - if child_haptobin.returncode != 0: - print(haptobin_out.decode('utf-8')) - print(haptobin_err.decode('utf-8')) - raise Exception("compile haptobin java class failed!") + # compile haptobin_tool.jar + hap_to_bin_shell_path = os.path.join(root_dir, "haptobin.sh") + command_haptobin = ['bash', hap_to_bin_shell_path, root_dir, args.haptobinOutput, args.outpath] + child_haptobin = subprocess.Popen(command_haptobin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + haptobin_out, haptobin_err = child_haptobin.communicate(timeout=time_out) + if child_haptobin.returncode != 0: + print(haptobin_out.decode('utf-8')) + print(haptobin_err.decode('utf-8')) + raise Exception("compile haptobin java class failed!") - # compile app_unpacking_tool.jar - version = subprocess.check_output(['javac', '-version'], stderr=subprocess.STDOUT) - version = version.decode('utf-8') - array = re.findall(r'\d+', version) - compatible_version = 8 - big_version = '' - if int(array[0]) > compatible_version: - big_version = 'true' - else: - big_version = 'false' - - unpack_tool_shell_path = os.path.join(root_dir, "unpackingTool.sh") - command_unpack = ['bash', unpack_tool_shell_path, root_dir, args.unpackOutput, args.outpath, big_version] - child_unpack = subprocess.Popen(command_unpack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - unpack_out, unpack_err = child_unpack.communicate(timeout=time_out) - if child_unpack.returncode != 0: - print(unpack_out.decode('utf-8')) - print(unpack_err.decode('utf-8')) - raise Exception("compile unapcking tool java class failed!") - - #compile app_packing_tool.jar - pack_tool_shell_path = os.path.join(root_dir, "packingTool.sh") - command_pack = ['bash', pack_tool_shell_path, root_dir, args.packOutput, args.outpath] - child_pack = subprocess.Popen(command_pack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - pack_out, pack_err = child_pack.communicate(timeout=time_out) - if child_pack.returncode != 0: - print(pack_out.decode('utf-8')) - print(pack_err.decode('utf-8')) - raise Exception("compile packing tool java class failed!") + # compile app_unpacking_tool.jar + version = subprocess.check_output(['javac', '-version'], stderr=subprocess.STDOUT) + version = version.decode('utf-8') + array = re.findall(r'\d+', version) + compatible_version = 8 + big_version = '' + if int(array[0]) > compatible_version: + big_version = 'true' + else: + big_version = 'false' + + unpack_tool_shell_path = os.path.join(root_dir, "unpackingTool.sh") + command_unpack = ['bash', unpack_tool_shell_path, root_dir, args.unpackOutput, args.outpath, big_version] + child_unpack = subprocess.Popen(command_unpack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + unpack_out, unpack_err = child_unpack.communicate(timeout=time_out) + if child_unpack.returncode != 0: + print(unpack_out.decode('utf-8')) + print(unpack_err.decode('utf-8')) + raise Exception("compile unapcking tool java class failed!") + + #compile app_packing_tool.jar + pack_tool_shell_path = os.path.join(root_dir, "packingTool.sh") + command_pack = ['bash', pack_tool_shell_path, root_dir, args.packOutput, args.outpath] + child_pack = subprocess.Popen(command_pack, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + pack_out, pack_err = child_pack.communicate(timeout=time_out) + if child_pack.returncode != 0: + print(pack_out.decode('utf-8')) + print(pack_err.decode('utf-8')) + raise Exception("compile packing tool java class failed!") + finally: + lock.release() if __name__ == '__main__': sys.exit(main())