Skip to content

Commit

Permalink
Test file naming conventions in build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdurdin committed Sep 14, 2017
1 parent 20f78f4 commit b0f534b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 63 deletions.
58 changes: 6 additions & 52 deletions build.sh
Expand Up @@ -11,10 +11,11 @@ function display_usage {
# TODO: Test on macOS as well.
# TODO: Copy the final keyboard_info.json to resources/

KEYBOARDROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KEYBOARDINFO_SCHEMA_JSON="$KEYBOARDROOT/tools/keyboard_info.source.json"
KEYBOARDINFO_SCHEMA_DIST_JSON="$KEYBOARDROOT/tools/keyboard_info.distribution.json"
KMCOMP="$KEYBOARDROOT/tools/kmcomp.exe"
export KEYBOARDROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export KEYBOARDINFO_SCHEMA_JSON="$KEYBOARDROOT/tools/keyboard_info.source.json"
export KEYBOARDINFO_SCHEMA_DIST_JSON="$KEYBOARDROOT/tools/keyboard_info.distribution.json"
export KMCOMP="$KEYBOARDROOT/tools/kmcomp.exe"

# KMCOMP="/c/Projects/keyman/open/windows/src/developer/kmcomp/kmcomp.exe"

# Master is https://api.keyman.com/schemas/keyboard_info.json
Expand All @@ -30,54 +31,7 @@ KMCOMP="$KEYBOARDROOT/tools/kmcomp.exe"
# Default is validate keyboard_info, build keyboards, don't codesign
#

DO_VALIDATE=true
DO_BUILD=true
DO_CODESIGN=false
TARGET=
PROJECT_TARGET=
FLAG_SILENT=
FLAG_DEBUG=
FLAG_CLEAN=
FLAG_TARGET=
START=
# TODO: implement silent, debug, clean

# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-validate)
DO_BUILD=false
;;
-codesign)
DO_CODESIGN=true
;;
-start)
shift
START=$1
;;
-s)
FLAG_SILENT=-s
;;
-d)
FLAG_DEBUG=-d
;;
-c)
FLAG_CLEAN=-c
;;
-h|-?)
display_usage
;;
-t)
shift
FLAG_TARGET=-t
PROJECT_TARGET=$1
;;
*)
TARGET=$1
esac
shift # past argument
done
parse_args $@

#
# Check build environment
Expand Down
18 changes: 18 additions & 0 deletions docs/custom-build-script.md
@@ -0,0 +1,18 @@

The following example shows how to create a minimal build script for a keyboard.
If you don't need a custom build step, don't include a build script in the keyboard.

````bash
#!/bin/bash
echo A custom build.sh script for a release/ keyboard

. ../../../resources/util.sh

parse_args $@

local kpjs=(*.kpj)
local kpj=${kpjs[0]}

echo "$KMCOMP" -nologo $FLAG_SILENT $FLAG_CLEAN $FLAG_DEBUG "$kpj" $FLAG_TARGET "$PROJECT_TARGET" || die "Could not compile keyboard"
"$KMCOMP" -nologo $FLAG_SILENT $FLAG_CLEAN $FLAG_DEBUG "$kpj" $FLAG_TARGET "$PROJECT_TARGET" || die "Could not compile keyboard"
````
17 changes: 12 additions & 5 deletions resources/compile.sh
Expand Up @@ -10,7 +10,7 @@ function build_keyboards {
# build based on the folder name and location.

# excluded folders are: shared, packages and template

local group=$1
local excluded_folders=" shared packages template "

Expand Down Expand Up @@ -129,7 +129,7 @@ function build_keyboard {
if [ -f build.sh ]; then
# We call this build.sh and assume it generates the
# right stuff
. ./build.sh || die "Failed to build keyboard $base_keyboard"
. ./build.sh $FLAG_SILENT $FLAG_CLEAN $FLAG_DEBUG "$kpj" $FLAG_TARGET "$PROJECT_TARGET" || die "Custom build script failed with an error"
else
# We will use the standard build based on the group
if [[ $group == release ]]; then
Expand Down Expand Up @@ -158,8 +158,8 @@ function build_keyboard {
if [ -n "$keyboard_info_jsFilename" ]; then test -f "build/$keyboard_info_jsFilename" || die "Could not find output file build/$keyboard_info_jsFilename"; fi
if [ -n "$keyboard_info_documentationFilename" ]; then test -f "build/$keyboard_info_documentationFilename" || die "Could not find output file build/$keyboard_info_documentationFilename"; fi

merge_keyboard_info "$base_keyboard.keyboard_info" || die "Failed to merge keyboard_info for $base_keyboard"

merge_keyboard_info "$base_keyboard.keyboard_info" $group || die "Failed to merge keyboard_info for $base_keyboard"
#
# Back to root of repo
#
Expand Down Expand Up @@ -213,9 +213,16 @@ function build_release_keyboard {
echo "Building keyboard $1"

local kpj="$base_keyboard.kpj"

# Clean build folder

if [[ -d build ]]; then
rm -rf build/ || die
fi
mkdir build || die "Failed to create build folder for $keyboard"

"$KMCOMP" -nologo $FLAG_SILENT $FLAG_CLEAN $FLAG_DEBUG "$kpj" $FLAG_TARGET "$PROJECT_TARGET" || die "Could not compile keyboard"

return 0
}

10 changes: 8 additions & 2 deletions resources/merge.sh
Expand Up @@ -7,6 +7,7 @@

function merge_keyboard_info {
local keyboard_info=$1
local group=$2

echo "Merging $keyboard_info"

Expand All @@ -20,7 +21,7 @@ function merge_keyboard_info {
#

#
# For release/ folder, we can deduce packageFilename and jsFilename
# We can try and deduce packageFilename and jsFilename
#

if [ ! -n "$keyboard_info_packageFilename" ]; then
Expand Down Expand Up @@ -50,6 +51,7 @@ function merge_keyboard_info {
local pInKmpM=
local pInJs=
local pInJsM=
local pValidateId=

if [ -f build/"$keyboard_info_packageFilename" ]; then
pInKmp=build\\"$keyboard_info_packageFilename"
Expand All @@ -61,7 +63,11 @@ function merge_keyboard_info {
pInJsM=-m
fi

"$KMCOMP" -s $pInKmpM "$pInKmp" $pInJsM "$pInJs" "$pOut" || die "Failed to merge keyboard_info for $1"
if [[ $group == release ]]; then
pValidateId=-m-validate-id
fi

"$KMCOMP" $pValidateId -s $pInKmpM "$pInKmp" $pInJsM "$pInJs" "$pOut" || die "Failed to merge keyboard_info for $1"

return 0
}
50 changes: 50 additions & 0 deletions resources/util.sh
Expand Up @@ -41,3 +41,53 @@ function die {
echo "${t_red}Aborting with error $rc${t_end}"
exit $rc
}

function parse_args {
DO_VALIDATE=true
DO_BUILD=true
DO_CODESIGN=false
TARGET=
PROJECT_TARGET=
FLAG_SILENT=
FLAG_DEBUG=
FLAG_CLEAN=
FLAG_TARGET=
START=

# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-validate)
DO_BUILD=false
;;
-codesign)
DO_CODESIGN=true
;;
-start)
shift
START=$1
;;
-s)
FLAG_SILENT=-s
;;
-d)
FLAG_DEBUG=-d
;;
-c)
FLAG_CLEAN=-c
;;
-h|-?)
display_usage
;;
-t)
shift
FLAG_TARGET=-t
PROJECT_TARGET=$1
;;
*)
TARGET=$1
esac
shift # past argument
done
}
2 changes: 1 addition & 1 deletion resources/validate.sh
Expand Up @@ -34,4 +34,4 @@ $folderlist"
fi

return 0
}
}
8 changes: 5 additions & 3 deletions tools/keyboard_info.source.json
Expand Up @@ -27,9 +27,11 @@
"minKeymanDesktopVersion": { "type": "string", "pattern": "^\\d+\\.0$" },
"platformSupport": { "$ref": "#/definitions/KeyboardPlatformInfo" },
"legacyId": { "type": "number" },
"related": { "type": "array", "items": {
"$ref": "#/definitions/KeyboardRelatedInfo"
}}
"related": { "type": "object", "patternProperties": {
".": { "$ref": "#/definitions/KeyboardRelatedInfo" }
},
"additionalProperties": false
}
},
"required": [
"license", "languages"
Expand Down
Binary file modified tools/kmcomp.exe
Binary file not shown.

0 comments on commit b0f534b

Please sign in to comment.