blob: 42137767f8d5bb728069865161dbf8d9bdbde38b [file] [log] [blame]
#!/usr/bin/python3
#
# 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')
parser.add_argument('--no-daemon', default=False, action='store_true', help='disable gradle daemon')
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):
m = re.match('target_cpu *= *"(.*)"', line.strip())
if m:
target_cpu = m.group(1)
# Copy the resources in the assets directory
clean_dir_cmd = ['rm', '-rf', 'apps/' + args.app_name + '/src/main/assets/resources/']
cp_cmd = ['cp', '-r', '../../resources/', 'apps/' + args.app_name + '/src/main/assets/']
try:
subprocess.check_call(clean_dir_cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
subprocess.check_call(cp_cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
except subprocess.CalledProcessError as error:
print("Copying resources to the assets directory failed, skipping the copy:")
print(error)
clean_dir_cmd = ['rm', '-rf', 'apps/' + args.app_name + '/src/main/assets/skps/']
cp_cmd = ['cp', '-r', '../../skps/', 'apps/' + args.app_name + '/src/main/assets/']
try:
subprocess.check_call(clean_dir_cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
subprocess.check_call(cp_cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
except subprocess.CalledProcessError as error:
print("Copying skps to the assets directory failed, skipping the copy:")
print(error)
# build the apk using gradle
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']
try:
subprocess.check_call(cmd, cwd=os.path.join(os.path.dirname(__file__), ".."))
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",
target_cpu, android_buildtype,
args.app_name + "-" + target_cpu + "-" + android_buildtype + ".apk")
apk_dst = os.path.join(args.output_dir, args.app_name + ".apk")
shutil.copyfile(apk_src, apk_dst)