1 #!/usr/bin/python 2 # 3 # Copyright 2017 Google Inc. 4 # 5 # Use of this source code is governed by a BSD-style license that can be 6 # found in the LICENSE file. 7 8 import argparse 9 import os 10 import re 11 import shutil 12 import subprocess 13 import sys 14 15 parser = argparse.ArgumentParser(description='builds skia android apps') 16 parser.add_argument('-C', '--output_dir', help='ninja out dir') 17 parser.add_argument('app_name') 18 19 args = parser.parse_args() 20 21 target_cpu = "arm64" 22 android_variant = "" 23 android_buildtype = "debug" 24 25 if args.output_dir == None: 26 sys.exit("unknown out directory") 27 28 args_gn_path = os.path.join(args.output_dir, "args.gn") 29 if os.path.exists(args_gn_path): 30 for line in open(args_gn_path): 31 m = re.match('target_cpu ?= ?"(.*)"', line.strip()) 32 if m: 33 target_cpu = m.group(1) 34 35 if target_cpu == "arm": 36 android_variant = "arm" 37 elif target_cpu == "arm64": 38 android_variant = "arm64" 39 elif target_cpu == "x86": 40 android_variant = "x86" 41 elif target_cpu == "x64": 42 android_variant = "x86_64" 43 elif target_cpu == "mipsel": 44 android_variant = "mips" 45 elif target_cpu == "mips64el": 46 android_variant = "mips64" 47 else: 48 sys.exit("unknown target_cpu") 49 50 # build the apk using gradle 51 try: 52 subprocess.check_call(['./apps/gradlew', 53 ':viewer:assemble' + android_variant + android_buildtype, 54 '-papps/' + args.app_name, 55 '-P' + target_cpu + '.out.dir=' + args.output_dir, 56 '--daemon'], cwd=os.path.join(os.path.dirname(__file__), "..")) 57 except subprocess.CalledProcessError as error: 58 print error 59 sys.exit("gradle build failed") 60 61 # copy apk back into the main out directory 62 current_dir = os.path.dirname(__file__) 63 apk_src = os.path.join(current_dir, "..", "apps", args.app_name, "build", "outputs", "apk", 64 args.app_name + "-" + android_variant + "-" + android_buildtype + ".apk") 65 apk_dst = os.path.join(args.output_dir, args.app_name + ".apk") 66 shutil.copyfile(apk_src, apk_dst) 67