2017-03-18 16:19:52 +01:00
|
|
|
# Single example build and deploy script
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import shutil
|
|
|
|
|
import glob
|
2017-06-15 10:39:59 +02:00
|
|
|
import json
|
2017-03-18 16:19:52 +01:00
|
|
|
|
|
|
|
|
# Android SDK version used
|
|
|
|
|
SDK_VERSION = "android-23"
|
|
|
|
|
|
|
|
|
|
PROJECT_FOLDER = ""
|
|
|
|
|
|
2017-08-20 20:32:40 -07:00
|
|
|
# Check if python 3, python 2 not supported
|
|
|
|
|
if sys.version_info <= (3, 0):
|
|
|
|
|
print("Sorry, requires Python 3.x, not Python 2.x")
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-03-18 16:19:52 +01:00
|
|
|
# Name/folder of the project to build
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
PROJECT_FOLDER = sys.argv[1]
|
|
|
|
|
if not os.path.exists(PROJECT_FOLDER):
|
|
|
|
|
print("Please specify a valid project folder to build!")
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Definitions (apk name, folders, etc.) will be taken from a json definition
|
|
|
|
|
if not os.path.isfile(os.path.join(PROJECT_FOLDER, "example.json")):
|
|
|
|
|
print("Could not find json definition for example %s" % PROJECT_FOLDER)
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-03-18 16:19:52 +01:00
|
|
|
# Check if a build file is present, if not create one using the android SDK version specified
|
|
|
|
|
if not os.path.isfile(os.path.join(PROJECT_FOLDER, "build.xml")):
|
|
|
|
|
print("Build.xml not present, generating with %s " % SDK_VERSION)
|
2017-06-15 10:39:59 +02:00
|
|
|
ANDROID_CMD = "android"
|
|
|
|
|
if os.name == 'nt':
|
|
|
|
|
ANDROID_CMD += ".bat"
|
Fix Android install script issue:
1. FileNotFoundError:
``` bash
Traceback (most recent call last):
File "install-all.py", line 11, in <module>
if subprocess.call("python build-all.py -deploy %s" % BUILD_ARGUMENTS) != 0:
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'python build-all.py -deploy '
```
2. KeyError:
``` bash
Traceback (most recent call last):
File "build.py", line 46, in <module>
if "additional" in EXAMPLE_JSON["assets"]:
KeyError: 'assets'
```
2017-06-26 14:04:31 +08:00
|
|
|
if subprocess.call(("%s update project -p ./%s -t %s" % (ANDROID_CMD, PROJECT_FOLDER, SDK_VERSION)).split(' ')) != 0:
|
2017-03-18 16:19:52 +01:00
|
|
|
print("Error: Project update failed!")
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Load example definition from json file
|
|
|
|
|
with open(os.path.join(PROJECT_FOLDER, "example.json")) as json_file:
|
|
|
|
|
EXAMPLE_JSON = json.load(json_file)
|
|
|
|
|
|
|
|
|
|
APK_NAME = EXAMPLE_JSON["apkname"]
|
|
|
|
|
SHADER_DIR = EXAMPLE_JSON["directories"]["shaders"]
|
2017-03-18 16:19:52 +01:00
|
|
|
|
2017-06-16 21:21:55 +02:00
|
|
|
# Additional
|
|
|
|
|
ADDITIONAL_DIRS = []
|
|
|
|
|
ADDITIONAL_FILES = []
|
Fix Android install script issue:
1. FileNotFoundError:
``` bash
Traceback (most recent call last):
File "install-all.py", line 11, in <module>
if subprocess.call("python build-all.py -deploy %s" % BUILD_ARGUMENTS) != 0:
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/Users/piasy/anaconda3/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'python build-all.py -deploy '
```
2. KeyError:
``` bash
Traceback (most recent call last):
File "build.py", line 46, in <module>
if "additional" in EXAMPLE_JSON["assets"]:
KeyError: 'assets'
```
2017-06-26 14:04:31 +08:00
|
|
|
if "assets" in EXAMPLE_JSON and "additional" in EXAMPLE_JSON["assets"]:
|
2017-06-16 21:21:55 +02:00
|
|
|
ADDITIONAL = EXAMPLE_JSON["assets"]["additional"]
|
|
|
|
|
if "directories" in ADDITIONAL:
|
|
|
|
|
ADDITIONAL_DIRS = ADDITIONAL["directories"]
|
|
|
|
|
if "files" in ADDITIONAL:
|
|
|
|
|
ADDITIONAL_FILES = ADDITIONAL["files"]
|
|
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Get assets to be copied
|
|
|
|
|
ASSETS_MODELS = []
|
|
|
|
|
ASSETS_TEXTURES = []
|
|
|
|
|
if "assets" in EXAMPLE_JSON:
|
|
|
|
|
ASSETS = EXAMPLE_JSON["assets"]
|
|
|
|
|
if "models" in ASSETS:
|
|
|
|
|
ASSETS_MODELS = EXAMPLE_JSON["assets"]["models"]
|
|
|
|
|
if "textures" in ASSETS:
|
|
|
|
|
ASSETS_TEXTURES = EXAMPLE_JSON["assets"]["textures"]
|
2017-03-18 16:19:52 +01:00
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Enable validation
|
|
|
|
|
VALIDATION = False
|
|
|
|
|
BUILD_ARGS = ""
|
|
|
|
|
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
|
if arg == "-validation":
|
|
|
|
|
VALIDATION = True
|
|
|
|
|
# Use a define to force validation in code
|
|
|
|
|
BUILD_ARGS = "APP_CFLAGS=-D_VALIDATION"
|
|
|
|
|
break
|
|
|
|
|
|
2017-08-20 20:03:46 -07:00
|
|
|
# Verify submodules are loaded in external folder
|
|
|
|
|
if not os.listdir("../external/glm/") or not os.listdir("../external/gli/"):
|
|
|
|
|
print("External submodules not loaded. Clone them using:")
|
|
|
|
|
print("\tgit submodule init\n\tgit submodule update")
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Build
|
2017-03-18 16:19:52 +01:00
|
|
|
os.chdir(PROJECT_FOLDER)
|
2017-06-15 10:39:59 +02:00
|
|
|
|
|
|
|
|
if subprocess.call("ndk-build %s" %BUILD_ARGS, shell=True) == 0:
|
|
|
|
|
print("Build successful")
|
|
|
|
|
|
|
|
|
|
if VALIDATION:
|
|
|
|
|
# Copy validation layers
|
|
|
|
|
# todo: Currently only arm v7
|
|
|
|
|
print("Validation enabled, copying validation layers...")
|
|
|
|
|
os.makedirs("./libs/armeabi-v7a", exist_ok=True)
|
|
|
|
|
for file in glob.glob("../layers/armeabi-v7a/*.so"):
|
|
|
|
|
print("\t" + file)
|
|
|
|
|
shutil.copy(file, "./libs/armeabi-v7a")
|
|
|
|
|
|
|
|
|
|
# Create folders
|
|
|
|
|
os.makedirs("./assets/shaders/base", exist_ok=True)
|
|
|
|
|
os.makedirs("./assets/shaders/%s" % SHADER_DIR, exist_ok=True)
|
|
|
|
|
os.makedirs("./assets/models", exist_ok=True)
|
|
|
|
|
os.makedirs("./assets/textures", exist_ok=True)
|
2017-06-16 21:21:55 +02:00
|
|
|
for directory in ADDITIONAL_DIRS:
|
|
|
|
|
os.makedirs("./assets/%s" % directory, exist_ok=True)
|
|
|
|
|
os.makedirs("./res/drawable", exist_ok=True)
|
2017-06-15 10:39:59 +02:00
|
|
|
|
2017-06-16 21:21:55 +02:00
|
|
|
for filename in glob.glob("../../data/shaders/base/*.spv"):
|
|
|
|
|
shutil.copy(filename, "./assets/shaders/base")
|
|
|
|
|
for filename in glob.glob("../../data/shaders/%s/*.spv" %SHADER_DIR):
|
|
|
|
|
shutil.copy(filename, "./assets/shaders/%s" % SHADER_DIR)
|
|
|
|
|
for filename in ASSETS_MODELS:
|
|
|
|
|
shutil.copy("../../data/models/%s" % filename, "./assets/models")
|
|
|
|
|
for filename in ASSETS_TEXTURES:
|
|
|
|
|
shutil.copy("../../data/textures/%s" % filename, "./assets/textures")
|
|
|
|
|
for filename in ADDITIONAL_FILES:
|
2017-06-17 11:29:30 +02:00
|
|
|
if "*." in filename:
|
2017-06-17 10:28:29 +02:00
|
|
|
for fname in glob.glob("../../data/%s" % filename):
|
|
|
|
|
locfname = fname.replace("../../data/", "")
|
|
|
|
|
shutil.copy(fname, "./assets/%s" % locfname)
|
|
|
|
|
else:
|
|
|
|
|
shutil.copy("../../data/%s" % filename, "./assets/%s" % filename)
|
2017-06-15 10:39:59 +02:00
|
|
|
|
|
|
|
|
shutil.copy("../../android/images/icon.png", "./res/drawable")
|
|
|
|
|
|
|
|
|
|
if subprocess.call("ant debug -Dout.final.file=%s.apk" % APK_NAME, shell=True) == 0:
|
|
|
|
|
# Deploy to device
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
|
if arg == "-deploy":
|
|
|
|
|
if subprocess.call("adb install -r %s.apk" % APK_NAME, shell=True) != 0:
|
|
|
|
|
print("Could not deploy to device!")
|
|
|
|
|
else:
|
|
|
|
|
print("Error during build process!")
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
else:
|
|
|
|
|
print("Error building project!")
|
2017-03-18 16:19:52 +01:00
|
|
|
sys.exit(-1)
|
|
|
|
|
|
2017-06-15 10:39:59 +02:00
|
|
|
# Copy apk to bin folder
|
2017-03-18 16:19:52 +01:00
|
|
|
os.makedirs("../bin", exist_ok=True)
|
2017-06-15 10:39:59 +02:00
|
|
|
shutil.move('%s.apk' % APK_NAME, "../bin/%s.apk" % APK_NAME)
|