Convert build scripts to Python #31

Merged
MartinFouilleul merged 24 commits from build-python into main 2023-08-08 09:38:44 +00:00
4 changed files with 73 additions and 63 deletions
Showing only changes of commit bbe34a3b58 - Show all commits

View File

@ -30,4 +30,4 @@ wasmFlags="--target=wasm32 \
$CLANG $wasmFlags -o ./module.wasm ../../sdk/orca.c ../../cstdlib/src/*.c src/main.c
python3 ../../scripts/mkapp.py --orca-dir ../.. --name Pong --icon icon.png --resource-dir data module.wasm
../../scripts/orca.py bundle --orca-dir ../.. --name Pong --icon icon.png --resource-dir data module.wasm

View File

@ -6,19 +6,53 @@ import shutil
import subprocess
from argparse import ArgumentParser
from log import *
def attach_bundle_commands(subparsers):
mkapp_cmd = subparsers.add_parser("bundle", help="Package a WebAssembly module into a standalone Orca application.")
init_parser(mkapp_cmd)
def init_parser(parser):
parser.add_argument("-d", "--resource", action="append", dest="resource_files", help="copy a file to the app's resource directory")
parser.add_argument("-D", "--resource-dir", action="append", dest="resource_dirs", help="copy a directory to the app's resource directory")
parser.add_argument("-i", "--icon", help="an image file to use as the application's icon")
parser.add_argument("-C", "--out-dir", default=os.getcwd(), help="where to place the final application bundle (defaults to the current directory)")
parser.add_argument("-n", "--name", default="out", help="the app's name")
parser.add_argument("-O", "--orca-dir", default=".")
parser.add_argument("--version", default="0.0.0", help="a version number to embed in the application bundle")
parser.add_argument("module", help="a .wasm file containing the application's wasm module")
parser.set_defaults(func=shellish(make_app))
def make_app(args):
#-----------------------------------------------------------
# Dispatch to platform-specific function
#-----------------------------------------------------------
platformName = platform.system()
if platformName == 'Darwin':
macos_make_app(args)
elif platformName == 'Windows':
windows_make_app(args)
else:
log_error("Platform '" + platformName + "' is not supported for now...")
exit(1)
def macos_make_app(args):
#-----------------------------------------------------------
#NOTE: make bundle directory structure
#-----------------------------------------------------------
app_name = args.name
bundle_name = app_name + '.app'
bundle_path = args.out_dir + '/' + bundle_name
contents_dir = bundle_path + '/Contents'
exe_dir = contents_dir + '/MacOS'
res_dir = contents_dir + '/resources'
guest_dir = contents_dir + '/app'
wasm_dir = guest_dir + '/wasm'
data_dir = guest_dir + '/data'
bundle_path = os.path.join(args.out_dir, bundle_name)
contents_dir = os.path.join(bundle_path, 'Contents')
exe_dir = os.path.join(contents_dir, 'MacOS')
res_dir = os.path.join(contents_dir, 'resources')
guest_dir = os.path.join(contents_dir, 'app')
wasm_dir = os.path.join(guest_dir, 'wasm')
data_dir = os.path.join(guest_dir, 'data')
if os.path.exists(bundle_path):
shutil.rmtree(bundle_path)
@ -33,11 +67,11 @@ def macos_make_app(args):
#-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries
#-----------------------------------------------------------
orca_exe = args.orca_dir + '/build/bin/orca'
milepost_lib = args.orca_dir + '/build/bin/libmilepost.dylib'
gles_lib = args.orca_dir + '/build/bin/libGLESv2.dylib'
egl_lib = args.orca_dir + '/build/bin/libEGL.dylib'
renderer_lib = args.orca_dir + '/build/bin/mtl_renderer.metallib'
orca_exe = os.path.join(args.orca_dir, 'build/bin/orca')
milepost_lib = os.path.join(args.orca_dir, 'build/bin/libmilepost.dylib')
gles_lib = os.path.join(args.orca_dir, 'build/bin/libGLESv2.dylib')
egl_lib = os.path.join(args.orca_dir, 'build/bin/libEGL.dylib')
renderer_lib = os.path.join(args.orca_dir, 'build/bin/mtl_renderer.metallib')
shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir)
@ -48,18 +82,18 @@ def macos_make_app(args):
#-----------------------------------------------------------
#NOTE: copy wasm module and data
#-----------------------------------------------------------
shutil.copy(args.module, wasm_dir + '/module.wasm')
shutil.copy(args.module, os.path.join(wasm_dir, 'module.wasm'))
if args.resource_files != None:
for resource in args.resource_files:
shutil.copytree(resource, data_dir + '/' + os.path.basename(resource), dirs_exist_ok=True)
shutil.copytree(resource, os.path.join(data_dir, os.path.basename(resource)), dirs_exist_ok=True)
if args.resource_dirs != None:
for resource_dir in args.resource_dirs:
for resource in os.listdir(resource_dir):
src = resource_dir + '/' + resource
src = os.path.join(resource_dir, resource)
if os.path.isdir(src):
shutil.copytree(src, data_dir + '/' + os.path.basename(resource), dirs_exist_ok=True)
shutil.copytree(src, os.path.join(data_dir, os.path.basename(resource)), dirs_exist_ok=True)
else:
shutil.copy(src, data_dir)
@ -67,15 +101,15 @@ def macos_make_app(args):
#NOTE: copy runtime resources
#-----------------------------------------------------------
# default fonts
shutil.copy(args.orca_dir + '/resources/OpenSansLatinSubset.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Bold.ttf', res_dir)
shutil.copy(args.orca_dir + '/resources/Menlo Italics.ttf', res_dir)
shutil.copy(os.path.join(args.orca_dir, 'resources/OpenSansLatinSubset.ttf'), res_dir)
shutil.copy(os.path.join(args.orca_dir, 'resources/Menlo.ttf'), res_dir)
shutil.copy(os.path.join(args.orca_dir, 'resources/Menlo Bold.ttf'), res_dir)
shutil.copy(os.path.join(args.orca_dir, 'resources/Menlo Italics.ttf'), res_dir)
#-----------------------------------------------------------
#NOTE make icon
#-----------------------------------------------------------
src_image=args.icon
src_image = args.icon
#if src_image == None:
# src_image = orca_dir + '/resources/default_app_icon.png'
@ -104,7 +138,7 @@ def macos_make_app(args):
size = size*2
subprocess.run(['iconutil', '-c', 'icns', '-o', res_dir + '/icon.icns', iconset])
subprocess.run(['iconutil', '-c', 'icns', '-o', os.path.join(res_dir, 'icon.icns'), iconset])
shutil.rmtree(iconset)
#-----------------------------------------------------------
@ -114,7 +148,7 @@ def macos_make_app(args):
bundle_sig = "????"
icon_file = ''
plist_contents = """
plist_contents = f"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@ -139,7 +173,7 @@ def macos_make_app(args):
<string>True</string>
</dict>
</plist>
""".format(app_name=app_name, version=version, bundle_sig=bundle_sig, icon_file=icon_file)
"""
plist_file = open(contents_dir + '/Info.plist', 'w')
print(plist_contents, file=plist_file)
@ -214,37 +248,8 @@ def windows_make_app(args):
#-----------------------------------------------------------
#TODO
#---------------------------------------------------------------------------------------------
# NOTE: get args
#
# mkapp.py [options] module
#
# -n, --name the name of the app
# -r, --res-file copies a file to the app bundle's resource directory
# -R, --res-dir copies the contents of a directory to the bundle's resource directory
# -i, --icon icon file
# -D, --out-dir output directory
#----------------------------------------------------------------------------------------------
if __name__ == "__main__":
parser = ArgumentParser(prog='mkapp')
init_parser(parser)
parser = ArgumentParser(prog='mkapp')
parser.add_argument("-d", "--resource", action='append', dest='resource_files')
parser.add_argument("-D", "--resource-dir", action='append', dest='resource_dirs')
parser.add_argument("-i", "--icon")
parser.add_argument("-C", "--out-dir", default=os.getcwd())
parser.add_argument("-n", "--name", default='out')
parser.add_argument("-O", "--orca-dir", default='.')
parser.add_argument("--version", default='0.0.0')
parser.add_argument("module")
args = parser.parse_args()
#----------------------------------------------------------------------------------------------
# Dispatch to platform-specific function
#----------------------------------------------------------------------------------------------
platformName = platform.system()
if platformName == 'Darwin':
macos_make_app(args)
elif platformName == 'Windows':
windows_make_app(args)
else:
print("Platform '" + platformName + "' is not supported for now...")
args = parser.parse_args()

View File

@ -2,12 +2,14 @@
import argparse
from build_runtime import attach_build_runtime
from bundle import attach_bundle_commands
from runtime import attach_runtime_commands
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True, title='commands')
attach_build_runtime(subparsers)
attach_bundle_commands(subparsers)
attach_runtime_commands(subparsers)
args = parser.parse_args()
args.func(args)

View File

@ -18,12 +18,15 @@ from utils import pushd, removeall
ANGLE_VERSION = "2023-07-05"
def attach_build_runtime(subparsers):
build_cmd = subparsers.add_parser("build-runtime", help="TODO")
def attach_runtime_commands(subparsers):
runtime_cmd = subparsers.add_parser("runtime", help="Commands for building the Orca runtime")
runtime_sub = runtime_cmd.add_subparsers(required=True, title='commands')
build_cmd = runtime_sub.add_parser("build", help="Build the Orca runtime from source.")
build_cmd.add_argument("--release", action="store_true", help="compile Orca in release mode (default is debug)")
build_cmd.set_defaults(func=shellish(build_runtime))
clean_cmd = subparsers.add_parser("clean", help="Delete all build artifacts and start fresh")
clean_cmd = runtime_sub.add_parser("clean", help="Delete all build artifacts and start fresh.")
clean_cmd.set_defaults(func=shellish(clean))