diff --git a/android/.build-builder b/android/.build-builder new file mode 100644 index 0000000000..3769f7152b --- /dev/null +++ b/android/.build-builder @@ -0,0 +1,4 @@ +The presence of this file tells CI to use the new builder_ style parameters for build.sh + +Once all branches for 16.0+ are updated to merge #7407, then we +can remove this file and the corresponding bash test branches in CI. diff --git a/android/KMAPro/build.sh b/android/KMAPro/build.sh index 8c233c1e66..46a4676e2f 100755 --- a/android/KMAPro/build.sh +++ b/android/KMAPro/build.sh @@ -1,13 +1,8 @@ #!/usr/bin/env bash -# Build KMAPro +# Build Keyman for Android app (KMAPro) -# Set sensible script defaults: -# set -e: Terminate script if a command returns an error -set -e -# set -u: Terminate script if an unset variable is used -set -u -# set -x: Debugging use, print each statement # set -x +set -eu ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary @@ -19,23 +14,51 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" . "$KEYMAN_ROOT/resources/build/build-help.inc.sh" . "$KEYMAN_ROOT/resources/build/build-download-resources.sh" -echo Build KMAPro +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" -# -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 +# ################################ Main script ################################ -display_usage ( ) { - echo "build.sh [-no-daemon] [-debug] [-download-resources]" - echo - echo "Build Keyman for Android" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -upload-sentry Uploads debug symbols, etc, to Sentry" - echo " -debug Compile only Debug variant" - echo " -download-resources Download sil_euro_latin.kmp and nrc.en.mtnt.model.kmp from downloads.keyman.com" - exit 1 -} +# Definition of global compile constants + +CONFIG="release" +BUILD_FLAGS="build -x lint -x test" # Gradle build w/o test +TEST_FLAGS="-x assembleRelease lintRelease testRelease" # Gradle test w/o build +DAEMON_FLAG= + +builder_describe "Builds Keyman for Android app." \ + "@/android/KMEA" \ + "clean" \ + "configure" \ + "build" \ + "test Runs lint and unit tests." \ + "--ci Don't start the Gradle daemon. For CI" \ + "--upload-sentry Upload to sentry" + +# parse before describe_outputs to check debug flags +builder_parse "$@" + +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + BUILD_FLAGS="assembleDebug -x lint -x test" + TEST_FLAGS="-x assembleDebug lintDebug testDebug" +fi + +builder_describe_outputs \ + configure /android/KMAPro/kMAPro/libs/keyman-engine.aar \ + build /android/KMAPro/kMAPro/build/outputs/apk/$CONFIG/keyman-${VERSION}.apk + +#### Build + + +# Parse args + +if builder_has_option --ci; then + DAEMON_FLAG=--no-daemon +fi + +#### Build action definitions #### function makeLocalSentryRelease() { echo "Making a Sentry release for tag $VERSION_GIT_TAG" @@ -46,97 +69,50 @@ function makeLocalSentryRelease() { sentry-cli releases finalize "$VERSION_GIT_TAG" } -NO_DAEMON=false -ONLY_DEBUG=false -DO_KEYBOARDS_DOWNLOAD=false -DO_MODELS_DOWNLOAD=false -DO_SENTRY_LOCAL_UPLOAD=false -# Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-daemon) - NO_DAEMON=true - ;; - -upload-sentry) - # Overrides default set by build-utils.sh - UPLOAD_SENTRY=true - ;; - -debug) - ONLY_DEBUG=true - ;; - -download-resources) - DO_KEYBOARDS_DOWNLOAD=true - DO_MODELS_DOWNLOAD=true - ;; - -h|-\?) - display_usage - ;; - esac - shift # past argument -done +#### Build action definitions #### -KEYBOARD_PACKAGE_ID="sil_euro_latin" -KEYBOARDS_TARGET="$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/assets/${KEYBOARD_PACKAGE_ID}.kmp" -MODEL_PACKAGE_ID="nrc.en.mtnt" -MODELS_TARGET="$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/assets/${MODEL_PACKAGE_ID}.model.kmp" - -# Verify default keyboard and dictionary exist -if [[ ! -f "$KEYBOARDS_TARGET" ]]; then - echo "$KEYBOARDS_TARGET doesn't exist. Will download the latest version" - DO_KEYBOARDS_DOWNLOAD=true +# Check about cleaning artifact paths +if builder_start_action clean; then + rm -rf "$KEYMAN_ROOT/android/KMAPro/kMAPro/build/outputs" + builder_finish_action success clean fi -if [[ ! -f "$MODELS_TARGET" ]]; then - echo "$MODELS_TARGET doesn't exist. Will download the latest version" - DO_MODELS_DOWNLOAD=true -fi +if builder_start_action configure; then -# Local development optimization to upload local symbols to Sentry -if [[ $VERSION_ENVIRONMENT == "local" && $ONLY_DEBUG == true && $UPLOAD_SENTRY == true ]]; then - DO_SENTRY_LOCAL_UPLOAD=true -fi + # Copy Keyman Engine for Android + cp "$KEYMAN_ROOT/android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar" "$KEYMAN_ROOT/android/KMAPro/kMAPro/libs/keyman-engine.aar" -echo -echo "NO_DAEMON: $NO_DAEMON" -echo "ONLY_DEBUG: $ONLY_DEBUG" -echo "DO_KEYBOARDS_DOWNLOAD: $DO_KEYBOARDS_DOWNLOAD" -echo "DO_MODELS_DOWNLOAD: $DO_MODELS_DOWNLOAD" -echo "DO_SENTRY_LOCAL_UPLOAD: $DO_SENTRY_LOCAL_UPLOAD" -echo + KEYBOARD_PACKAGE_ID="sil_euro_latin" + KEYBOARDS_TARGET="$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/assets/${KEYBOARD_PACKAGE_ID}.kmp" + MODEL_PACKAGE_ID="nrc.en.mtnt" + MODELS_TARGET="$KEYMAN_ROOT/android/KMAPro/kMAPro/src/main/assets/${MODEL_PACKAGE_ID}.model.kmp" -if [ "$NO_DAEMON" = true ]; then - DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= -fi - -# Convert markdown to html for offline help -echo "Converting markdown to html for offline help" -cd "$KEYMAN_ROOT/android" -build_help_html android KMAPro/kMAPro/src/main/assets/info -cd "$KEYMAN_ROOT/android/KMAPro" - -# Download default keyboard and dictionary -if [ "$DO_KEYBOARDS_DOWNLOAD" = true ]; then downloadKeyboardPackage "$KEYBOARD_PACKAGE_ID" "$KEYBOARDS_TARGET" -fi - -if [ "$DO_MODELS_DOWNLOAD" = true ]; then downloadModelPackage "$MODEL_PACKAGE_ID" "$MODELS_TARGET" + + builder_finish_action success configure fi -if [ "$ONLY_DEBUG" = true ]; then - BUILD_FLAGS="assembleDebug lintDebug" -else - # build = assemble + check; check = test + lint - BUILD_FLAGS=build +if builder_start_action build; then + + # Convert markdown to html for offline help + build_help_html android KMAPro/kMAPro/src/main/assets/info + + echo "BUILD_FLAGS $BUILD_FLAGS" + ./gradlew $DAEMON_FLAG clean $BUILD_FLAGS + + if builder_has_option --upload-sentry; then + makeLocalSentryRelease + fi + + builder_finish_action success build fi -echo "BUILD_FLAGS $BUILD_FLAGS" -./gradlew $DAEMON_FLAG clean $BUILD_FLAGS +if builder_start_action test; then -if [ "$DO_SENTRY_LOCAL_UPLOAD" = true ]; then - makeLocalSentryRelease -fi \ No newline at end of file + echo "TEST_FLAGS $TEST_FLAGS" + ./gradlew $DAEMON_FLAG $TEST_FLAGS + + builder_finish_action success test +fi diff --git a/android/KMAPro/kMAPro/build.gradle b/android/KMAPro/kMAPro/build.gradle index f2d788df2b..df38b2ade8 100644 --- a/android/KMAPro/kMAPro/build.gradle +++ b/android/KMAPro/kMAPro/build.gradle @@ -95,6 +95,11 @@ android { } } variant.resValue "string", "app_name", 'Keyman' + appSuffix; + + // Adjust output name to "keyman-${VERSION_MD}.apk" + variant.outputs.all { + outputFileName = "keyman-" + VERSION_MD + ".apk" + } } lintOptions { disable 'MissingQuantity', 'MissingTranslation' diff --git a/android/KMAPro/kMAPro/src/main/assets/.gitkeep b/android/KMAPro/kMAPro/src/main/assets/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/android/KMEA/app/build.gradle b/android/KMEA/app/build.gradle index 0caa91a70b..4b4da18754 100644 --- a/android/KMEA/app/build.gradle +++ b/android/KMEA/app/build.gradle @@ -25,6 +25,13 @@ android { } } + // Sepcify library filename $CONFIG/keyman-engine.aar + libraryVariants.all { variant -> + variant.outputs.all { + outputFileName = "${variant.buildType.name}/keyman-engine.aar" + } + } + // TODO: Remove ResourceType when SDK > 17 lintOptions { disable 'ImpliedQuantity', 'MissingQuantity', 'MissingTranslation', 'ResourceType' diff --git a/android/KMEA/build.sh b/android/KMEA/build.sh index fdf7bc7eb9..ecfba488bc 100755 --- a/android/KMEA/build.sh +++ b/android/KMEA/build.sh @@ -1,18 +1,9 @@ #!/usr/bin/env bash -# Build Keyman Engine Android using Keyman Web artifacts +# Build Keyman Engine for Android using Keyman Web artifacts # -# Abbreviations: -# KMA - Keyman Android -# KMEA - Keyman Engine Android -# KMW - Keyman Web -# Set sensible script defaults: -# set -e: Terminate script if a command returns an error -set -e -# set -u: Terminate script if an unset variable is used -set -u -# set -x: Debugging use, print each statement -# set -x +#set -x +set -eu ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary @@ -20,172 +11,104 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" . "${THIS_SCRIPT%/*}/../../resources/build/build-utils.sh" ## END STANDARD BUILD SCRIPT INCLUDE -display_usage ( ) { - echo "build.sh [-no-kmw-build] | [-no-kmw] [-no-daemon] | [-no-test] | [-upload-sentry] | [-debug]" - echo - echo "Build Keyman Engine Android (KMEA) using Keyman Web (KMW) artifacts" - echo " -no-kmw-build Don't build KMW. Just copy existing artifacts" - echo " -no-kmw Don't build KMW. Don't copy artifacts" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -no-test Don't run the unit-test suite. Use for development builds" - echo " to facilitate manual debugging and testing" - echo " -upload-sentry Uploads debug symbols, etc, to Sentry" - echo " -debug Local debug build; use for development builds" - exit 1 -} +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" -echo Build KMEA +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" -# -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 +# ################################ Main script ################################ -# Path definitions +# Definition of global compile constants -KMA_ROOT="$KEYMAN_ROOT/android" -KMW_ROOT="$KEYMAN_ROOT/web" -KMEA_ASSETS="$KMA_ROOT/KMEA/app/src/main/assets" +KEYMAN_ANDROID_ROOT="$KEYMAN_ROOT/android" +KEYMAN_WEB_ROOT="$KEYMAN_ROOT/web" +ENGINE_ASSETS="$KEYMAN_ANDROID_ROOT/KMEA/app/src/main/assets" +CONFIG="release" +BUILD_FLAGS="aR -x lint -x test" # Gradle build w/o test +TEST_FLAGS="-x aR lintRelease testRelease" # Gradle test w/o build +JUNIT_RESULTS="##teamcity[importData type='junit' path='keyman\android\KMEA\app\build\test-results\testReleaseUnitTest\']" -# Default is building KMW and copying artifacts -DO_BUILD=true -DO_COPY=true -DO_TEST=true -NO_DAEMON=false -DEBUG_BUILD=false -KMWFLAGS="build:embed" -KMW_CONFIG=release +builder_describe "Builds Keyman Engine for Android." \ + "@/web" \ + "clean" \ + "configure" \ + "build" \ + "test Runs lint and unit tests." \ + ":engine Builds Engine" \ + "--ci Don't start the Gradle daemon. For CI" -# Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-kmw-build) - DO_BUILD=false - DO_COPY=true - ;; - -no-kmw) - DO_BUILD=false - DO_COPY=false - ;; - -no-daemon) - NO_DAEMON=true - ;; - -upload-sentry) - # Overrides default set by build-utils.sh - UPLOAD_SENTRY=true - ;; - -debug) - DEBUG_BUILD=true - KMWFLAGS="$KMWFLAGS --debug" - KMW_CONFIG=debug - ;; - -h|-\?) - display_usage - ;; - -no-test) - DO_TEST=false - ;; - esac - shift # past argument -done +# parse before describe_outputs to check debug flags +builder_parse "$@" -# Local development optimization - cross-target Sentry uploading when requested -# by developer. As it's not CI, the Web artifacts won't exist otherwise... -# unless the developer manually runs the correct build configuration accordingly. -if [[ $VERSION_ENVIRONMENT == "local" ]] && [[ $UPLOAD_SENTRY == true ]]; then - # TODO: handle the -upload-sentry in its eventual new form - KMWFLAGS="$KMWFLAGS -upload-sentry" +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + BUILD_FLAGS="assembleDebug -x lint -x test" + TEST_FLAGS="-x assembleDebug lintDebug testDebug" + JUNIT_RESULTS="##teamcity[importData type='junit' path='keyman\android\KMEA\app\build\test-results\testDebugUnitTest\']" fi -echo -echo "DO_BUILD: $DO_BUILD" -echo "DO_COPY: $DO_COPY" -echo "DO_TEST: $DO_TEST" -echo "NO_DAEMON: $NO_DAEMON" -echo "DEBUG_BUILD: $DEBUG_BUILD" -echo "KMWFLAGS: $KMWFLAGS" -echo "KMW_CONFIG: $KMW_CONFIG" -echo +builder_describe_outputs \ + build:engine /android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar -if [ "$NO_DAEMON" = true ]; then +#### Build + + +# Parse args + +DAEMON_FLAG= +if builder_has_option --ci; then DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= +fi + +#### Build action definitions #### + +# Check about cleaning artifact paths +if builder_start_action clean:engine; then + rm -rf "$KEYMAN_ROOT/android/KMEA/app/build/outputs" + builder_finish_action success clean:engine +fi + +if builder_start_action configure:engine; then + + # Copy KeymanWeb artifacts + echo "Copying Keyman Web artifacts" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/osk/ajax-loader.gif" "$ENGINE_ASSETS/ajax-loader.gif" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/keyman.js" "$ENGINE_ASSETS/keymanandroid.js" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/keyman.js.map" "$ENGINE_ASSETS/keyman.js.map" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/osk/kmwosk.css" "$ENGINE_ASSETS/kmwosk.css" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/osk/globe-hint.css" "$ENGINE_ASSETS/globe-hint.css" + cp "$KEYMAN_WEB_ROOT/build/app/embed/$CONFIG/osk/keymanweb-osk.ttf" "$ENGINE_ASSETS/keymanweb-osk.ttf" + + cp "$KEYMAN_ROOT/common/web/sentry-manager/build/index.js" "$ENGINE_ASSETS/keyman-sentry.js" + + echo "Copying es6-shim polyfill" + cp "$KEYMAN_ROOT/node_modules/es6-shim/es6-shim.min.js" "$ENGINE_ASSETS/es6-shim.min.js" + + builder_finish_action success configure:engine fi # Destinations that will need the keymanweb artifacts -PLATFORM=`uname -s` -if [ "$DO_BUILD" = true ]; then - echo "Building keyman web engine" +if builder_start_action build:engine; then - "$KMW_ROOT/build.sh" $KMWFLAGS + echo "BUILD_FLAGS $BUILD_FLAGS" + # Build without test + ./gradlew $DAEMON_FLAG clean $BUILD_FLAGS - if [ $? -ne 0 ]; then - builder_die "ERROR: keymanweb build failed. Exiting" - fi -fi -if [ "$DO_COPY" = true ]; then - echo "Copying KMW artifacts" - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/osk/ajax-loader.gif $KMEA_ASSETS/ajax-loader.gif - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/keyman.js $KMEA_ASSETS/keymanandroid.js - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/keyman.js.map $KMEA_ASSETS/keyman.js.map - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/osk/kmwosk.css $KMEA_ASSETS/kmwosk.css - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/osk/globe-hint.css $KMEA_ASSETS/globe-hint.css - cp $KMW_ROOT/build/app/embed/$KMW_CONFIG/osk/keymanweb-osk.ttf $KMEA_ASSETS/keymanweb-osk.ttf - - cp $KEYMAN_ROOT/common/web/sentry-manager/build/index.js $KMEA_ASSETS/keyman-sentry.js - - echo "Copying es6-shim polyfill" - cp $KEYMAN_ROOT/node_modules/es6-shim/es6-shim.min.js $KMEA_ASSETS/es6-shim.min.js - - if [ $? -ne 0 ]; then - builder_die "ERROR: copying artifacts failed" - fi + builder_finish_action success build:engine fi -echo "Gradle Build of KMEA" -cd $KMA_ROOT/KMEA +if builder_start_action test:engine; then -if [ "$DEBUG_BUILD" = true ]; then - BUILD_FLAGS="assembleDebug lintDebug" - TEST_FLAGS="testDebug" - ARTIFACT="app-debug.aar" - if [ "$DO_TEST" = true ]; then + if builder_has_option --ci; then # Report JUnit test results to CI - echo "##teamcity[importData type='junit' path='keyman\android\KMEA\app\build\test-results\testDebugUnitTest\']" + echo "$JUNIT_RESULTS" fi -else - BUILD_FLAGS="aR lint" - TEST_FLAGS="testRelease" - ARTIFACT="app-release.aar" - if [ "$DO_TEST" = true ]; then - # Report JUnit test results to CI - echo "##teamcity[importData type='junit' path='keyman\android\KMEA\app\build\test-results\testReleaseUnitTest\']" - fi -fi -echo "BUILD_FLAGS $BUILD_FLAGS" -./gradlew $DAEMON_FLAG clean $BUILD_FLAGS -if [ $? -ne 0 ]; then - builder_die "ERROR: Build of KMEA failed" -fi -if [ "$DO_TEST" = true ]; then - echo "TEST_FLAGS $TEST_FLAGS" - ./gradlew $DAEMON_FLAG $TEST_FLAGS - if [ $? -ne 0 ]; then - builder_die "ERROR: KMEA test cases failed" - fi -fi + echo "TEST_FLAGS: $TEST_FLAGS" + ./gradlew $DAEMON_FLAG $TEST_FLAGS -echo "Copying Keyman Engine for Android to KMAPro, Sample apps, and Tests" -mv $KMA_ROOT/KMEA/app/build/outputs/aar/$ARTIFACT $KMA_ROOT/KMAPro/kMAPro/libs/keyman-engine.aar -cp $KMA_ROOT/KMAPro/kMAPro/libs/keyman-engine.aar $KMA_ROOT/Samples/KMSample1/app/libs/keyman-engine.aar -cp $KMA_ROOT/KMAPro/kMAPro/libs/keyman-engine.aar $KMA_ROOT/Samples/KMSample2/app/libs/keyman-engine.aar -cp $KMA_ROOT/KMAPro/kMAPro/libs/keyman-engine.aar $KMA_ROOT/Tests/KeyboardHarness/app/libs/keyman-engine.aar -if [ ! -z ${RELEASE_OEM+x} ]; then - cp $KMA_ROOT/KMAPro/kMAPro/libs/keyman-engine.aar $KMA_ROOT/../oem/firstvoices/android/app/libs/keyman-engine.aar + builder_finish_action success test:engine fi -cd ..\ diff --git a/android/README.md b/android/README.md index 067f3667be..a75c769e56 100644 --- a/android/README.md +++ b/android/README.md @@ -21,11 +21,11 @@ Keyman for Android uses [Sentry](https://sentry.io) for crash reporting at a ser ### Compiling From Command Line 1. Launch a command prompt and cd to the directory **keyman/android** -2. Run the top level build script `./build.sh -debug` which will: +2. Run the top level build script `./build.sh configure build --debug` which will: * Compile KMEA (and its KMW dependency) * Download default keyboard and dictionary resources as needed * Compile KMAPro - * Note: to force an update to the latest keyboard and dictionary packages, use the `-download-resources` flag. + * Note: to force an update to the latest keyboard and dictionary packages, use the `--download-resources` flag. 3. The APK will be found in **keyman/android/KMAPro/kMAPro/build/outputs/apk/debug/kMAPro-debug.apk** @@ -75,14 +75,13 @@ There are two included sample projects that can be modified to test a keyboard. **android/Samples/KMSample1** app runs a bare Keyman app for testing a keyboard. **android/Samples/KMSample2** app provides prompts for setting KMSample2 as a system level keyboard. -Both sample apps include a default Tamil keyboard. +Both sample apps include a default Tamil keyboard and sample dictionary. Building these projects follow the same steps as KMAPro: -1. Build KMEA -2. cd to the desired KMSample directory -3. `./build.sh` -4. Open Android Studio to run the app +1. cd to the desired KMSample directory +2. `./build.sh` +3. Open Android Studio to run the app ### Tests: KeyboardHarness @@ -100,8 +99,8 @@ Building these projects follow the same steps as KMAPro: -------------------------------------------------------------- ## How to Build Keyman Engine for Android -1. Open a terminal or Git Bash prompt and go to Keyman Engine for Android project folder (e.g. `cd ~/keyman/android/KMEA/`) -2. Run `./build.sh` +1. Open a terminal or Git Bash prompt and go to the Android project folder (e.g. `cd ~/keyman/android/`) +2. Run `./build.sh --debug` Keyman Engine for Android library (**keyman-engine.aar**) is now ready to be imported in any project. diff --git a/android/Samples/KMSample1/build.sh b/android/Samples/KMSample1/build.sh index 9bb3300c7d..3edcb44e01 100755 --- a/android/Samples/KMSample1/build.sh +++ b/android/Samples/KMSample1/build.sh @@ -1,61 +1,80 @@ #!/usr/bin/env bash -# Build KMSample1 - -set -e -set -u - -display_usage ( ) { - echo "build.sh [-no-daemon] [-debug]" - echo - echo "Build KM Sample 1" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -debug Compile only Debug variant" - exit 1 -} - -echo Build KMSample1 - # -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 +# Samples: KMsample1 + +set -eu +# set -x: Debugging use, print each statement +# set -x + +## START STANDARD BUILD SCRIPT INCLUDE +# adjust relative paths as necessary +THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" +. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh" +## END STANDARD BUILD SCRIPT INCLUDE + +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" + +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" + +################################ Main script ################################ + +# Definition of global compile constants + +CONFIG="release" +SAMPLE_FLAGS="build" + +builder_describe "Build KMSample1 app for Android." \ + "@/android/KMEA" \ + "clean" \ + "configure" \ + "build" \ + ":app KMSample1" \ + "--ci Don't start the Gradle daemon. Use for CI" + +# parse before describe_outputs to check debug flags +builder_parse "$@" + +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + SAMPLE_FLAGS="assembleDebug" +fi + +ARTIFACT="app-$CONFIG.apk" + + +builder_describe_outputs \ + configure /android/Samples/KMSample1/app/libs/keyman-engine.aar \ + build:app /android/Samples/KMSample1/app/build/outputs/apk/$CONFIG/$ARTIFACT + -NO_DAEMON=false -ONLY_DEBUG=false # Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-daemon) - NO_DAEMON=true - ;; - -debug) - ONLY_DEBUG=true - ;; - -h|-\?) - display_usage - ;; - esac - shift # past argument -done -echo -echo "NO_DAEMON: $NO_DAEMON" -echo "ONLY_DEBUG: $ONLY_DEBUG" -echo - -if [ "$NO_DAEMON" = true ]; then - DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= +if builder_has_option --ci; then + SAMPLE_FLAGS="$SAMPLE_FLAGS -no-daemon" fi -if [ "$ONLY_DEBUG" = true ]; then - BUILD_FLAG=assembleDebug -else - BUILD_FLAG=build +#### Build action definitions #### + +# Check about cleaning artifact paths +if builder_start_action clean:app; then + rm -rf "$KEYMAN_ROOT/android/Samples/KMSample1/app/build/outputs" + builder_finish_action success clean:app fi -./gradlew $DAEMON_FLAG clean $BUILD_FLAG +if builder_start_action configure:app; then + # Copy Keyman Engine for Android + cp "$KEYMAN_ROOT/android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar" "$KEYMAN_ROOT/android/Samples/KMSample1/app/libs/keyman-engine.aar" + builder_finish_action success configure:app +fi + +# Building KMSample1 +if builder_start_action build:app; then + ./gradlew clean $SAMPLE_FLAGS + + + builder_finish_action success build:app +fi diff --git a/android/Samples/KMSample2/build.sh b/android/Samples/KMSample2/build.sh index 02b7a56b25..608076ee57 100755 --- a/android/Samples/KMSample2/build.sh +++ b/android/Samples/KMSample2/build.sh @@ -1,61 +1,80 @@ #!/usr/bin/env bash -# Build KMSample2 - -set -e -set -u - -display_usage ( ) { - echo "build.sh [-no-daemon] [-debug]" - echo - echo "Build KM Sample 2" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -debug Compile only Debug variant" - exit 1 -} - -echo Build KMSample2 - # -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 +# Samples: KMSample2 + +set -eu +# set -x: Debugging use, print each statement +# set -x + +## START STANDARD BUILD SCRIPT INCLUDE +# adjust relative paths as necessary +THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" +. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh" +## END STANDARD BUILD SCRIPT INCLUDE + +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" + +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" + +################################ Main script ################################ + +# Definition of global compile constants + +CONFIG="release" +SAMPLE_FLAGS="build" + +builder_describe "Build KMSample2 app for Android." \ + "@/android/KMEA" \ + "clean" \ + "configure" \ + "build" \ + ":app KMSample2" \ + "--ci Don't start the Gradle daemon. Use for CI" + +# parse before describe_outputs to check debug flags +builder_parse "$@" + +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + SAMPLE_FLAGS="assembleDebug" +fi + +ARTIFACT="app-$CONFIG.apk" + + +builder_describe_outputs \ + configure /android/Samples/KMSample2/app/libs/keyman-engine.aar \ + build:app /android/Samples/KMSample2/app/build/outputs/apk/$CONFIG/$ARTIFACT + -NO_DAEMON=false -ONLY_DEBUG=false # Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-daemon) - NO_DAEMON=true - ;; - -debug) - ONLY_DEBUG=true - ;; - -h|-\?) - display_usage - ;; - esac - shift # past argument -done -echo -echo "NO_DAEMON: $NO_DAEMON" -echo "ONLY_DEBUG: $ONLY_DEBUG" -echo - -if [ "$NO_DAEMON" = true ]; then - DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= +if builder_has_option --ci; then + SAMPLE_FLAGS="$SAMPLE_FLAGS -no-daemon" fi -if [ "$ONLY_DEBUG" = true ]; then - BUILD_FLAG=assembleDebug -else - BUILD_FLAG=build +#### Build action definitions #### + +# Check about cleaning artifact paths +if builder_start_action clean:app; then + rm -rf "$KEYMAN_ROOT/android/Samples/KMSample2/app/build/outputs" + builder_finish_action success clean:app fi -./gradlew $DAEMON_FLAG clean $BUILD_FLAG +if builder_start_action configure:app; then + # Copy Keyman Engine for Android + cp "$KEYMAN_ROOT/android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar" "$KEYMAN_ROOT/android/Samples/KMSample2/app/libs/keyman-engine.aar" + builder_finish_action success configure:app +fi + +# Building KMSample2 +if builder_start_action build:app; then + ./gradlew clean $SAMPLE_FLAGS + + + builder_finish_action success build:app +fi diff --git a/android/Tests/KeyboardHarness/build.sh b/android/Tests/KeyboardHarness/build.sh index 331c28aa07..5051b1f8b4 100755 --- a/android/Tests/KeyboardHarness/build.sh +++ b/android/Tests/KeyboardHarness/build.sh @@ -1,60 +1,94 @@ #!/usr/bin/env bash -# Build KeyboardHarness test app +# +# Build Test app: KeyboardHarness +#set -x +set -eu -display_usage ( ) { - echo "build.sh [-no-daemon] [-debug]" - echo - echo "Build KeyboardHarness test app" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -debug Compile only Debug variant" - exit 1 -} +## START STANDARD BUILD SCRIPT INCLUDE +# adjust relative paths as necessary +THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" +. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh" +## END STANDARD BUILD SCRIPT INCLUDE + +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" + +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" + +################################ Main script ################################ + +# Definition of global compile constants +CONFIG="release" +BUILD_FLAGS="aR -x lint -x test" # Gradle build w/o test +TEST_FLAGS="-x aR lintRelease testRelease" # Gradle test w/o build + +builder_describe "Build KeyboardHarness test app for Android." \ + "@/android/KMEA" \ + "clean" \ + "configure" \ + "build" \ + ":app KeyboardHarness" \ + "--ci Don't start the Gradle daemon. Use for CI" + +# parse before describe outputs to check debug flags +builder_parse "$@" + +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + BUILD_FLAGS="assembleDebug -x lint -x test" + TEST_FLAGS="-x assembleDebug lintDebug testDebug" +fi + +ARTIFACT="app-$CONFIG.apk" + +builder_describe_outputs \ + configure /android/Tests/KeyboardHarness/app/libs/keyman-engine.aar \ + build:app /android/Tests/KeyboardHarness/app/build/outputs/apk/$CONFIG/${ARTIFACT} + +#### Build -echo Build KeyboardHarness test app # # Prevents 'clear' on exit of mingw64 bash shell # SHLVL=0 -NO_DAEMON=false -ONLY_DEBUG=false # Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-daemon) - NO_DAEMON=true - ;; - -debug) - ONLY_DEBUG=true - ;; - -h|-\?) - display_usage - ;; - esac - shift # past argument -done -echo -echo "NO_DAEMON: $NO_DAEMON" -echo "ONLY_DEBUG: $ONLY_DEBUG" -echo - -if [ "$NO_DAEMON" = true ]; then - DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= +# Build flags that apply to all targets +if builder_has_option --ci; then + BUILD_FLAGS="$BUILD_FLAGS -no-daemon" + TEST_FLAGS="$TEST_FLAGS -no-daemon" fi -if [ "$ONLY_DEBUG" = true ]; then - BUILD_FLAG=assembleDebug -else - BUILD_FLAG=build +#### Build action definitions #### + +# Check about cleaning artifact paths +if builder_start_action clean:app; then + rm -rf "$KEYMAN_ROOT/android/Tests/KeyboardHarness/app/build/outputs" + builder_finish_action success clean:app fi -echo Build KeyboardHarness -./gradlew $DAEMON_FLAG clean $BUILD_FLAG +if builder_start_action configure:app; then + # Copy Keyman Engine for Android + cp "$KEYMAN_ROOT/android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar" "$KEYMAN_ROOT/android/Tests/KeyboardHarness/app/libs/keyman-engine.aar" + builder_finish_action success configure:app +fi + +# Building KeyboardHarness +if builder_start_action build:app; then + + echo "BUILD_FLAGS: $BUILD_FLAGS" + ./gradlew clean $BUILD_FLAGS + builder_finish_action success build:app +fi + +if builder_start_action test:app; then + echo "TEST_FLAGS $TEST_FLAGS" + + builder_finish_action success test:app +fi diff --git a/android/build.sh b/android/build.sh index b33bc35445..eae19089e5 100755 --- a/android/build.sh +++ b/android/build.sh @@ -1,14 +1,10 @@ #!/usr/bin/env bash -# Build Keyman Engine for Android, Keyman for Android, and FirstVoices Android app -# Use '-clean' flag to clean build artifacts (won't do other build steps) +# +# Build Keyman Engine for Android, Keyman for Android, OEM FirstVoices Android app, +# Samples: KMsample1 and KMSample2, Test - KeyboardHarness -# Set sensible script defaults: -# set -e: Terminate script if a command returns an error -set -e -# set -u: Terminate script if an unset variable is used -#set -u: Not set because of $RELEASE_OEM -# set -x: Debugging use, print each statement -# set -x +#set -x +set -eu ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary @@ -16,70 +12,38 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" . "${THIS_SCRIPT%/*}/../resources/build/build-utils.sh" ## END STANDARD BUILD SCRIPT INCLUDE -# -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" -# Clean build artifacts: keyman-engine.aar libaries, output and upload directories -clean ( ) { - cd "$KEYMAN_ROOT/android" +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" - find . -name "keyman-engine.aar" | while read fname; do - echo "Cleaning $fname" - rm $fname - done - if [ -f "$KEYMAN_ROOT/oem/firstvoices/android/app/libs/keyman-engine.aar" ]; then - echo "Cleaning OEM FirstVoices keyman-engine.aar" - rm "$KEYMAN_ROOT/oem/firstvoices/android/app/libs/keyman-engine.aar" - fi +################################ Main script ################################ - if [ -d "$KEYMAN_ROOT/android/KMAPro/kMAPro/build/outputs" ]; then - echo "Cleaning KMAPro build outputs directory" - rm -rf "$KEYMAN_ROOT/android/KMAPro/kMAPro/build/outputs" - fi +builder_describe \ + "Build Keyman Engine for Android, Keyman for Android, and FirstVoices Android app." \ + clean \ + configure \ + build \ + test \ + "publish Publishes the APKs to the Play Store." \ + --ci+ \ + --upload-sentry+ \ + ":engine=KMEA Keyman Engine for Android" \ + ":app=KMAPro Keyman for Android" \ + ":sample1=Samples/KMSample1 Sample app: KMSample1" \ + ":sample2=Samples/KMSample2 Sample app: KMSample2" \ + ":keyboardharness=Tests/KeyboardHarness Test app: KeyboardHarness" \ + ":fv=../oem/firstvoices/android OEM FirstVoices for Android app" - if [ -d "$KEYMAN_ROOT/android/upload" ]; then - echo "Cleaning upload directory" - rm -rf "$KEYMAN_ROOT/android/upload" - fi -} +builder_parse "$@" -echo Build KMEA and KMAPro: +# This script also responsible for cleaning up /android/upload +builder_run_child_actions clean -# Check about cleaning artifact paths -if [[ "$1" == "-clean" ]] ; then - clean - exit +if builder_start_action clean; then + builder_heading "Cleanup /android/upload" + rm -rf "$KEYMAN_ROOT/android/upload" + builder_finish_action success clean fi -# Building Keyman Engine for Android - -cd "$KEYMAN_ROOT/android/KMEA" -./build.sh "$@" - -if [ $? -ne 0 ]; then - builder_die "ERROR: KMEA/build.sh failed" -fi - -# Building Keyman for Android - -cd "$KEYMAN_ROOT/android/KMAPro" -./build.sh "$@" - -if [ $? -ne 0 ]; then - builder_die "ERROR: KMAPro/build.sh failed" -fi - -cd "$KEYMAN_ROOT/android" - -# Building OEM apps - -if [ ! -z "$RELEASE_OEM" ]; then - pushd "$KEYMAN_ROOT/oem/firstvoices/android" - ./build.sh -download-keyboards -lib-nobuild "$@" - - if [ $? -ne 0 ]; then - builder_die "ERROR: oem/firstvoices/android/build.sh failed" - fi -fi +builder_run_child_actions configure build test publish diff --git a/android/version.gradle b/android/version.gradle index 7aef41058b..ebf68a94e0 100644 --- a/android/version.gradle +++ b/android/version.gradle @@ -35,6 +35,18 @@ def getVersionCode = { -> return 100 } +def getVersionMD = { -> + String env_version = System.getenv("VERSION") + if (env_version != null) { + // If building from script, we have build number in VERSION + println "Using build $env_version from VERSION" + return "$env_version" + } else { + String version_md = file("$rootPath/../VERSION.md").text.trim() + return "$version_md" + } +} + def getVersionName = { -> String env_version = System.getenv("VERSION_WITH_TAG") if (env_version != null) { @@ -78,6 +90,7 @@ def getVersionGitTag = { -> } ext { VERSION_CODE=getVersionCode() + VERSION_MD=getVersionMD() VERSION_NAME=getVersionName() VERSION_ENVIRONMENT=getVersionEnvironment() VERSION_TAG=System.getenv("VERSION_TAG") diff --git a/oem/firstvoices/android/app/build.gradle b/oem/firstvoices/android/app/build.gradle index aba0c1bb43..737d3462c3 100644 --- a/oem/firstvoices/android/app/build.gradle +++ b/oem/firstvoices/android/app/build.gradle @@ -58,6 +58,12 @@ android { productFlavors { } + applicationVariants.all { variant -> + // Adjust output name to "firstvoices-${VERSION_MD}.apk" + variant.outputs.all { + outputFileName = "firstvoices-" + VERSION_MD + ".apk" + } + } lintOptions { disable 'MissingTranslation' lintConfig file("lint.xml") diff --git a/oem/firstvoices/android/build.sh b/oem/firstvoices/android/build.sh index 4951d5f305..e118afa875 100755 --- a/oem/firstvoices/android/build.sh +++ b/oem/firstvoices/android/build.sh @@ -1,12 +1,8 @@ #!/usr/bin/env bash +# Build FirstVoices for Android app -# Set sensible script defaults: -# set -e: Terminate script if a command returns an error -set -e -# set -u: Terminate script if an unset variable is used -set -u -# set -x: Debugging use, print each statement # set -x +set -eu ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary @@ -14,84 +10,95 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" . "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh" ## END STANDARD BUILD SCRIPT INCLUDE +. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" + . "$KEYMAN_ROOT/resources/build/build-download-resources.sh" -display_usage ( ) { - echo "build.sh [-no-daemon] [-debug] [-no-update] [-lib-build|-no-lib-build] [-download-keyboards] [-h|-?]" - echo "Build $TARGET" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -debug Compile only Debug variant" - echo " -no-update Don't copy or build the Keyman Engine library in (assumes already present)" - echo " -lib-build Force rebuild of the Keyman Engine library" - echo " -no-lib-build Only rebuild the Keyman Engine library if it doesn't exist in /android" - echo " -download-resources Download fv_all.kmp from downloads.keyman.com" - echo " (dictionaries will be downloaded within the app)" - echo "" - exit 1 +# This script runs from its own folder +cd "$THIS_SCRIPT_PATH" + +# ################################ Main script ################################ + +# Definition of global compile constants + +CONFIG="release" +BUILD_FLAGS="build -x lint -x test" # Gradle build w/o test +TEST_FLAGS="-x assembleRelease lintRelease testRelease" # Gradle test w/o build +DAEMON_FLAG= + +builder_describe "Builds FirstVoices for Android app." \ + "@/android/KMEA" \ + "clean" \ + "configure" \ + "build" \ + "test Runs lint and tests." \ + "--ci Don't start the Gradle daemon. For CI" \ + "--upload-sentry Upload to sentry" + +# parse before describe_outputs to check debug flags +builder_parse "$@" + +if builder_is_debug_build; then + builder_heading "### Debug config ####" + CONFIG="debug" + BUILD_FLAGS="assembleDebug -x lint -x test" + TEST_FLAGS="-x assembleDebug lintDebug testDebug" +fi + +ARTIFACT="firstvoices-$VERSION.apk" + +builder_describe_outputs \ + configure /oem/firstvoices/android/app/libs/keyman-engine.aar \ + build /oem/firstvoices/android/app/build/outputs/apk/$CONFIG/${ARTIFACT} + +#### Build + +# Parse args + +if builder_has_option --ci; then + DAEMON_FLAG=--no-daemon +fi + +#### Build action definitions #### + +function makeLocalSentryRelease() { + echo "Placeholder for uploading symbols to Sentry" } -export TARGET=FirstVoices -KEYBOARD_PACKAGE_ID="fv_all" -KEYBOARDS_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/${KEYBOARD_PACKAGE_ID}.kmp" -KEYBOARDS_CSV="$KEYMAN_ROOT/oem/firstvoices/keyboards.csv" -KEYBOARDS_CSV_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/keyboards.csv" +#### Build action definitions #### -# This build script assumes that the https://github.com/keymanapp/keyboards repo is in -# the same parent folder as this repo, with the default name 'keyboards' - -PARAM_DEBUG= -PARAM_NO_DAEMON= -PARAM_NO_UPDATE= -PARAM_LIB_BUILD= -PARAM_NO_LIB_BUILD= -DO_KEYBOARDS_DOWNLOAD=false - -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -download-resources) - DO_KEYBOARDS_DOWNLOAD=true - ;; - -h|-\?) - display_usage - ;; - -debug) - PARAM_DEBUG=-debug - ;; - -no-daemon) - PARAM_NO_DAEMON=-no-daemon - ;; - -no-update) - PARAM_NO_UDPATE=-no-update - ;; - -lib-build) - PARAM_LIB_BUILD=-lib-build - ;; - -no-lib-build|-lib-nobuild) - PARAM_NO_LIB_BUILD=-no-lib-build - ;; - esac - shift -done - -# Verify default keyboard package exists -if [[ ! -f "$KEYBOARDS_TARGET" || ! -f "$KEYBOARDS_CSV_TARGET" ]]; then - echo "$KEYBOARDS_TARGET and $KEYBOARDS_CSV_TARGET required. Will download the latest version" - DO_KEYBOARDS_DOWNLOAD=true +# Check about cleaning artifact paths +if builder_start_action clean; then + rm -rf "$KEYMAN_ROOT/oem/firstvoices/android/app/build/outputs" + builder_finish_action success clean fi -if [ ! -z "$PARAM_LIB_BUILD" ] && [ ! -z "$PARAM_NO_LIB_BUILD" ]; then - echo "ERROR: Cannot set both -lib-build and -no-lib-build" - exit 1 -fi +if builder_start_action configure; then + # Copy Keyman Engine for Android + cp "$KEYMAN_ROOT/android/KMEA/app/build/outputs/aar/${CONFIG}/keyman-engine.aar" "$KEYMAN_ROOT/oem/firstvoices/android/app/libs/keyman-engine.aar" + + KEYBOARDS_CSV="$KEYMAN_ROOT/oem/firstvoices/keyboards.csv" + KEYBOARDS_CSV_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/keyboards.csv" + + KEYBOARD_PACKAGE_ID="fv_all" + KEYBOARDS_TARGET="$KEYMAN_ROOT/oem/firstvoices/android/app/src/main/assets/${KEYBOARD_PACKAGE_ID}.kmp" -# Download default keyboard package -if [ "$DO_KEYBOARDS_DOWNLOAD" = true ]; then - echo "Copying keyboards.csv" cp "$KEYBOARDS_CSV" "$KEYBOARDS_CSV_TARGET" - downloadKeyboardPackage "$KEYBOARD_PACKAGE_ID" "$KEYBOARDS_TARGET" + + builder_finish_action success configure fi -# TODO: in the future build_common.sh should probably be shared with all oem products? -./build_common.sh $PARAM_DEBUG $PARAM_NO_DAEMON $PARAM_NO_UPDATE $PARAM_LIB_BUILD $PARAM_NO_LIB_BUILD +if builder_start_action build; then + echo "BUILD_FLAGS: $BUILD_FLAGS" + ./gradlew $DAEMON_FLAG clean $BUILD_FLAGS + + builder_finish_action success build +fi + +if builder_start_action test; then + echo "TEST_FLAGS: $TEST_FLAGS" + ./gradlew $DAEMON_FLAG $TEST_FLAGS + + builder_finish_action success test +fi diff --git a/oem/firstvoices/android/build_common.sh b/oem/firstvoices/android/build_common.sh deleted file mode 100755 index 8b843f9d02..0000000000 --- a/oem/firstvoices/android/build_common.sh +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env bash - -# Set sensible script defaults: -# set -e: Terminate script if a command returns an error -set -e -# set -u: Terminate script if an unset variable is used -set -u -# set -x: Debugging use, print each statement -# set -x - -if [ -z "$TARGET" ]; then - exit 1 -fi - -display_usage ( ) { - echo "build_common.sh [-no-daemon] [-debug] [-no-update] [-lib-build|-no-lib-build]" - echo "Build $TARGET" - echo " -no-daemon Don't start the Gradle daemon. Use for CI" - echo " -debug Compile only Debug variant" - echo " -no-update Don't copy or build the Keyman Engine library in (assumes already present)" - echo " -lib-build Force rebuild of the Keyman Engine library" - echo " -no-lib-build Only rebuild the Keyman Engine library if it doesn't exist in /android" - exit 1 -} - -verify_KMEA ( ) { - KMEA_BUILD_EXISTS=true - [ -f "$KEYMAN_ENGINE_DST" ] || KMEA_BUILD_EXISTS=false -} - -echo Build $TARGET - -# -# Prevents 'clear' on exit of mingw64 bash shell -# -SHLVL=0 - -DO_UPDATE=true -FORCE_KMEA_BUILD=false -ALLOW_KMEA_BUILD=true -NO_DAEMON=false -ONLY_DEBUG=false - -# Parse args -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-daemon) - NO_DAEMON=true - ;; - -debug) - ONLY_DEBUG=true - ;; - # Settings relating to engine build - -no-update) - DO_UPDATE=false - ALLOW_KMEA_BUILD=false - ;; - -lib-build) - FORCE_KMEA_BUILD=true - ;; - -lib-nobuild|-no-lib-build) - ALLOW_KMEA_BUILD=false - ;; - -h|-\?) - display_usage - ;; - esac - shift # past argument -done - -echo -echo "NO_DAEMON: $NO_DAEMON" -echo "ONLY_DEBUG: $ONLY_DEBUG" -echo "DO_UPDATE: $DO_UPDATE" -echo "ALLOW_KMEA_BUILD: $ALLOW_KMEA_BUILD" -echo "FORCE_KMEA_BUILD: $FORCE_KMEA_BUILD" -echo - -# The KMEA build script moves the final .aar from KMEA to KMAPro... -KMEA_BUILD_DIR=../../../android/KMEA/ -KEYMAN_ENGINE_SRC=../../../android/KMAPro/kMAPro/libs/keyman-engine.aar -KEYMAN_ENGINE_DST=app/libs/keyman-engine.aar - -# -# Build Keyman Engine -# - -if [ $DO_UPDATE = true ]; then - # Does a prior build of KMEA exist? - verify_KMEA - - if [ $ALLOW_KMEA_BUILD = true ] && [ $FORCE_KMEA_BUILD = false ] && [ $KMEA_BUILD_EXISTS = false ]; then - echo "Previous Keyman Engine build information is unavailable; rebuilding." - FORCE_KMEA_BUILD=true - fi - - if [ $FORCE_KMEA_BUILD = true ]; then - echo "Building Keyman Engine..." - pushd $KMEA_BUILD_DIR - ./build.sh "$@" - popd - fi - - verify_KMEA - - if ! [ $KMEA_BUILD_EXISTS ]; then - echo "Build failed: Could not build required Keyman Engine resources." - exit 1 - fi - - # Copy Keyman Engine aar to - cp "$KEYMAN_ENGINE_SRC" "$KEYMAN_ENGINE_DST" -fi - - -if [ "$NO_DAEMON" = true ]; then - DAEMON_FLAG=--no-daemon -else - DAEMON_FLAG= -fi - -if [ "$ONLY_DEBUG" = true ]; then - BUILD_FLAG=assembleDebug -else - BUILD_FLAG=build -fi - -./gradlew $DAEMON_FLAG clean $BUILD_FLAG