2017-01-06 16:41:56 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright 2017 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='builds skia android apps')
|
|
|
|
parser.add_argument('-C', '--output_dir', help='ninja out dir')
|
2018-02-20 16:31:25 +00:00
|
|
|
parser.add_argument('--no-daemon', default=False, action='store_true', help='disable gradle daemon')
|
2017-01-06 16:41:56 +00:00
|
|
|
parser.add_argument('app_name')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
target_cpu = "arm64"
|
|
|
|
android_buildtype = "debug"
|
|
|
|
|
|
|
|
if args.output_dir == None:
|
|
|
|
sys.exit("unknown out directory")
|
|
|
|
|
|
|
|
args_gn_path = os.path.join(args.output_dir, "args.gn")
|
|
|
|
if os.path.exists(args_gn_path):
|
|
|
|
for line in open(args_gn_path):
|
2018-01-30 16:35:47 +00:00
|
|
|
m = re.match('target_cpu *= *"(.*)"', line.strip())
|
2017-01-06 16:41:56 +00:00
|
|
|
if m:
|
|
|
|
target_cpu = m.group(1)
|
|
|
|
|
|
|
|
# build the apk using gradle
|
2018-02-20 16:31:25 +00:00
|
|
|
cmd = ['./apps/gradlew',
|
|
|
|
':' + args.app_name + ':assemble' + target_cpu + android_buildtype,
|
|
|
|
'-papps/' + args.app_name,
|
|
|
|
'-P' + target_cpu + '.out.dir=' + os.path.abspath(args.output_dir)]
|
|
|
|
if not args.no_daemon:
|
|
|
|
cmd += ['--daemon']
|
2017-01-06 16:41:56 +00:00
|
|
|
try:
|
2018-02-20 16:31:25 +00:00
|
|
|
subprocess.check_call(cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
|
2017-01-06 16:41:56 +00:00
|
|
|
except subprocess.CalledProcessError as error:
|
|
|
|
print error
|
|
|
|
sys.exit("gradle build failed")
|
|
|
|
|
|
|
|
# copy apk back into the main out directory
|
|
|
|
current_dir = os.path.dirname(__file__)
|
|
|
|
apk_src = os.path.join(current_dir, "..", "apps", args.app_name, "build", "outputs", "apk",
|
2018-02-07 19:56:29 +00:00
|
|
|
args.app_name + "-" + target_cpu + "-" + android_buildtype + ".apk")
|
2017-01-06 16:41:56 +00:00
|
|
|
apk_dst = os.path.join(args.output_dir, args.app_name + ".apk")
|
|
|
|
shutil.copyfile(apk_src, apk_dst)
|