Merge pull request #7342 from keymanapp/chore/epic-ldml/merge-master-to-feature-ldml

chore: merge master into feature-ldml 🙀
This commit is contained in:
Marc Durdin 2022-09-24 10:12:00 +10:00 committed by GitHub
commit 0502d6ccbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 5310 additions and 4857 deletions

View file

@ -1,5 +1,25 @@
# Keyman Version History
## 16.0.68 alpha 2022-09-20
* chore(web): update `got` dependency for regression tests (#7315)
* chore(developer): update multer dependency for server (#7314)
* chore(developer): update node-windows-trayicon to update node-gyp to 9.1.0 (#7321)
## 16.0.67 alpha 2022-09-19
* fix(common/models): blocks full-text "corrections" (#7241)
* change(web): better fat-finger key weighting (#7242)
* fix(web): fixes unintended auto-acceptance of suggestion after reverting (#7305)
* feat(common/models): wordbreaker customization (#7279)
* fix(common/models): fixes reference dropped by git merge (#7313)
* test(android): Add final keyboard to test K_ENTER rule (#7303)
* chore(common): Update to Unicode 15.0 (#7302)
* chore(common): update auto labeler configuration (#7316)
* chore(common): make scripts executable and add pre-commit test (#7317)
* chore(deps): bump nanoid and mocha (#7307)
* chore(common): remove unused ncc dependency (#7318)
## 16.0.66 alpha 2022-09-17
* chore: improve auto labeling (#7288)

View file

@ -1 +1 @@
16.0.67
16.0.69

View file

@ -321,8 +321,10 @@ public final class KeyboardPickerActivity extends BaseActivity {
}
private static void setSelection(int position) {
listView.setItemChecked(position, true);
listView.setSelection(position);
if (listView != null) {
listView.setItemChecked(position, true);
listView.setSelection(position);
}
selectedIndex = position;
}

View file

@ -46,7 +46,7 @@
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.4",
"chai": "^4.3.4",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"typescript": "^4.5.4"
},
"dependencies": {

View file

@ -43,7 +43,7 @@
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"chai": "^4.3.4",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.5.4"
},

View file

@ -37,7 +37,7 @@
"karma-mocha-reporter": "^2.2.5",
"karma-safari-launcher": "^1.0.0",
"karma-teamcity-reporter": "^1.1.0",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"sinon": "^7.1.1",
"ts-node": "^9.1.1",

View file

@ -25,18 +25,18 @@ builder_parse "$@"
# TODO: build if out-of-date if test is specified
# TODO: configure if npm has not been run, and build is specified
if builder_has_action clean; then
if builder_start_action clean; then
npm run clean
builder_report success clean
builder_finish_action success clean
fi
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success clean
builder_finish_action success clean
fi
if builder_has_action build; then
if builder_start_action build; then
npm run build
builder_report success build
builder_finish_action success build
fi

View file

@ -8,7 +8,7 @@
],
"license": "MIT",
"dependencies": {
"commander": "^3.0.0"
"commander": "^5.1.0"
},
"main": "build/index.js",
"bin": {
@ -21,5 +21,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/keymanapp/keyman.git"
},
"devDependencies": {
"@types/node": "^18.7.18"
}
}

View file

@ -21,7 +21,7 @@
"@keymanapp/resources-gosh": "*",
"@types/node": "^11.9.4",
"chai": "^4.3.4",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.5.4"

View file

@ -31,7 +31,7 @@ display_usage ( ) {
FLAGS=
CI_REPORTING=0
FETCH_DEPS=true
CHAINING_FLAGS=-skip-package-install
CHAINING_FLAGS=
# Parse args
while [[ $# -gt 0 ]] ; do
@ -43,7 +43,7 @@ while [[ $# -gt 0 ]] ; do
;;
-CI)
CI_REPORTING=1
CHAINING_FLAGS="$CHAINING_FLAGS -CI"
CHAINING_FLAGS="$CHAINING_FLAGS --ci"
;;
-skip-package-install|-S)
FETCH_DEPS=false
@ -79,7 +79,7 @@ fi
# First, run tests on the keyboard processor.
pushd "$KEYMAN_ROOT/common/web/keyboard-processor"
./test.sh $CHAINING_FLAGS || fail "Tests failed by dependencies; aborting integration tests."
./build.sh test $CHAINING_FLAGS || fail "Tests failed by dependencies; aborting integration tests."
popd
# Build the leaf-style, bundled version of input-processor for use in testing.

View file

@ -9,7 +9,7 @@ The Keyboard Processor module is an internal component of KeymanWeb, seen within
* Builds will call `npm install` to automatically install further necessary build dependencies.
* Linux users can run the following to update to LTS version of nodejs
```
sudo apt-get install python-software-properties
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
@ -18,4 +18,4 @@ sudo apt-get install nodejs
**********************************************************************
The build script may be found at src/build.sh.
The main build script may be found in this folder at ./build.sh.

View file

@ -0,0 +1,81 @@
#!/usr/bin/env bash
#
# Compile KeymanWeb's 'keyboard-processor' module, one of the components of Web's 'core' module.
#
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$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 ################################
# Ensures color var use in `builder_describe`'s argument respects the specified
# --color/--no-color option.
builder_check_color "$@"
builder_describe \
"Compiles the web-oriented utility function module." \
configure \
clean \
build \
test \
"--ci For use with action ${BUILDER_TERM_START}test${BUILDER_TERM_END} - emits CI-friendly test reports"
builder_parse "$@"
# START - Script parameter configuration
REPORT_STYLE=local # Default setting.
if builder_has_option --ci; then
REPORT_STYLE=ci
echo "Replacing user-friendly test reports with CI-friendly versions."
fi
# END - Script parameter configuration
if builder_start_action configure; then
verify_npm_setup
"$KEYMAN_ROOT/common/web/keyman-version/build.sh"
builder_finish_action success configure
fi
if builder_start_action clean; then
npm run clean
builder_finish_action success clean
fi
if builder_start_action build; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/tsconfig.json"
builder_finish_action success build
fi
if builder_start_action test; then
# Build test dependency
pushd "$KEYMAN_ROOT/common/web/recorder"
./build.sh
popd
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/tsconfig.bundled.json"
echo_heading "Running Keyboard Processor test suite"
FLAGS=
if [ $REPORT_STYLE == ci ]; then
FLAGS="$FLAGS --reporter mocha-teamcity-reporter"
fi
npm run mocha -- --recursive $FLAGS ./tests/cases/
builder_finish_action success test
fi

View file

@ -19,13 +19,14 @@
"devDependencies": {
"@keymanapp/resources-gosh": "*",
"chai": "^4.3.4",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.5.4"
},
"scripts": {
"tsc": "tsc",
"clean": "tsc -b --clean src/tsconfig.json && tsc -b --clean src/tsconfig.bundled.json",
"test": "gosh ./test.sh",
"mocha": "mocha"
},

View file

@ -1,53 +0,0 @@
#!/usr/bin/env bash
#
# Compile KeymanWeb's 'keyboard-processor' module, one of the components of Web's 'core' module.
#
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../../../../resources/build/build-utils.sh"
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
## END STANDARD BUILD SCRIPT INCLUDE
# This script runs from its own folder
cd "$(dirname "$THIS_SCRIPT")"
display_usage ( ) {
echo "build.sh [-skip-package-install | -S] [-test]"
echo
echo " -skip-package-install (or -S) skips the `npm install` dependency check."
echo " Intended for use when this script is called by another build script."
echo ""
echo " If more than one target is specified, the last one will take precedence."
exit 1
}
# Establish default build parameters
set_default_vars ( ) {
FETCH_DEPS=true
# We need to build keyman-version with a script for now
"$KEYMAN_ROOT/common/web/keyman-version/build.sh" || fail "Could not build keyman-version"
}
set_default_vars
# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-skip-package-install|-S)
set_default_vars
FETCH_DEPS=false
;;
esac
shift # past argument
done
if [ $FETCH_DEPS = true ]; then
verify_npm_setup
fi
# Compile web's `keyboard-processor` module.
npm run tsc -- -b src/tsconfig.json || fail "Failed to compile the web/keyboard-processor module."

View file

@ -1,75 +0,0 @@
#!/usr/bin/env bash
set -eu
# Include useful testing resource functions
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
# We should work within the script's directory, not the one we were called in.
cd "$THIS_SCRIPT_PATH"
# A simple utility script to facilitate unit-testing for the LM Layer.
# It's rigged to be callable by NPM to facilitate testing during development when in other folders.
display_usage ( ) {
echo "test.sh [-skip-package-install] [-CI] [ -? | -h | -help]"
echo " -CI to perform continuous-integration friendly tests and reporting formatted for TeamCity"
echo " -? | -h | -help to display this help information"
echo " -skip-package-install to bypass refreshing dependencies. Useful when called by scripts that pre-fetch"
echo ""
exit 0
}
# Defaults
FLAGS=
CI_REPORTING=0
FETCH_DEPS=true
# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-skip-package-install|-S)
FETCH_DEPS=false
;;
-h|-help|-\?)
display_usage
exit
;;
-CI)
CI_REPORTING=1
;;
esac
shift # past argument
done
if [ $FETCH_DEPS = true ]; then
verify_npm_setup
fi
test-headless ( ) {
if (( CI_REPORTING )); then
FLAGS="$FLAGS --reporter mocha-teamcity-reporter"
fi
npm run mocha -- --recursive $FLAGS ./tests/cases/
}
# Build test dependency
pushd "$KEYMAN_ROOT/common/web/recorder/src"
./build.sh -skip-package-install || fail "recorder-core compilation failed."
popd
# Compile web's `keyboard-processor` module."
npm run tsc -- -b src/tsconfig.bundled.json || fail "Failed to compile the testing version of the core/web/keyboard-processor module."
# Run headless (browserless) tests.
echo_heading "Running Keyboard Processor test suite"
test-headless || fail "Keyboard Processor tests failed!"

View file

@ -25,18 +25,18 @@ builder_parse "$@"
# TODO: build if out-of-date if test is specified
# TODO: configure if npm has not been run, and build is specified
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
if builder_has_action clean; then
if builder_start_action clean; then
npm run clean
rm -f ./version.inc.ts
builder_report success clean
builder_finish_action success clean
fi
if builder_has_action build; then
if builder_start_action build; then
# Generate keyman-version.mts
echo "
// Generated by common/web/keyman-version/build.sh
@ -74,6 +74,6 @@ if builder_has_action build; then
" > ./version.inc.ts
# Build
npm run build -- $builder_verbose || die "Could not build worker."
builder_report success build
npm run build -- $builder_verbose
builder_finish_action success build
fi

View file

@ -83,9 +83,9 @@ builder_parse "$@"
# TODO: build if out-of-date if test is specified
# TODO: configure if npm has not been run, and build is specified
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
# We always need to clean first because the wrapping function
@ -95,12 +95,12 @@ fi
# of typescript, we need to avoid this!
# TODO: we should try and rework this to avoid the need to manually wrap
if builder_has_action clean || builder_has_action build >/dev/null; then
if builder_start_action clean || builder_has_action build; then
npm run clean
builder_report success clean
builder_finish_action success clean
fi
if builder_has_action build; then
if builder_start_action build; then
# Ensure keyman-version is properly build (requires build script)
"$KEYMAN_ROOT/common/web/keyman-version/build.sh" || fail "Could not build keyman-version"
@ -115,10 +115,10 @@ if builder_has_action build; then
wrap-worker-code LMLayerWorkerCode "${WORKER_OUTPUT}/intermediate.js" > "${WORKER_OUTPUT_FILENAME}" || die
cp "${WORKER_OUTPUT_FILENAME}" "${WORKER_TEST_BUNDLE_TARGET_FILENAME}" || die
builder_report success build
builder_finish_action success build
fi
if builder_has_action test; then
if builder_start_action test; then
npm test || fail "Tests failed"
builder_report success test
builder_finish_action success test
fi

View file

@ -29,7 +29,7 @@
"karma-mocha-reporter": "^2.2.5",
"karma-safari-launcher": "^1.0.0",
"karma-teamcity-reporter": "^1.1.0",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"sinon": "^7.1.1",
"ts-node": "^9.1.1",

78
common/web/recorder/build.sh Executable file
View file

@ -0,0 +1,78 @@
#!/usr/bin/env bash
#
# Compiles development-related KeymanWeb resources for use with developing/running tests.
# - the Recorder module (for engine tests)
# - the DOM module (for touch-alias and element-interface tests)
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
################################ Main script ################################
builder_describe \
"Compiles the web-oriented utility function module." \
configure \
clean \
build \
":module Builds recorder-core module" \
":proctor Builds headless-testing, node-oriented 'proctor' component"
builder_parse "$@"
# START - Script parameter configuration
REPORT_STYLE="local" # Default setting.
if builder_has_option --ci; then
REPORT_STYLE="ci"
echo "Replacing user-friendly test reports with CI-friendly versions."
fi
# END - Script parameter configuration
function do_configure() {
verify_npm_setup
"$KEYMAN_ROOT/common/web/keyman-version/build.sh"
}
if builder_start_action configure :module; then
do_configure
builder_finish_action success configure :module
fi
if builder_start_action configure :proctor; then
if builder_has_action configure :module; then
echo "Configuration already completed in configure:module; skipping."
else
do_configure
fi
builder_finish_action success configure :proctor
fi
if builder_start_action clean :module; then
npm run tsc -- -b --clean "$THIS_SCRIPT_PATH/src/tsconfig.json"
builder_finish_action success clean :module
fi
if builder_start_action clean :proctor; then
npm run tsc -- -b --clean "$THIS_SCRIPT_PATH/src/nodeProctor.tsconfig.json"
builder_finish_action success clean :proctor
fi
if builder_start_action build :module; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/tsconfig.json"
builder_finish_action success build :module
fi
if builder_start_action build :proctor; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/nodeProctor.tsconfig.json"
builder_finish_action success build :proctor
fi

View file

@ -3,7 +3,8 @@
"description": "Core classes used to develop KeymanWeb test cases based on keystrokes",
"main": "index.js",
"scripts": {
"tsc": "tsc"
"tsc": "tsc",
"clean": "tsc -b --clean src/tsconfig.json && tsc -b --clean src/nodeProctor.tsconfig.json"
},
"repository": {
"type": "git",

View file

@ -1,60 +0,0 @@
#!/usr/bin/env bash
#
# Compiles development-related KeymanWeb resources for use with developing/running tests.
# - the Recorder module (for engine tests)
# - the DOM module (for touch-alias and element-interface tests)
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../../../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
display_usage ( ) {
echo "build.sh [-skip-package-install]"
echo
echo " -skip-package-install skips the `npm install` dependency check."
echo " (or -S) Intended for use when this script is called by another build script."
echo ""
echo " If more than one target is specified, the last one will take precedence."
exit 1
}
# Establish default build parameters
set_default_vars ( ) {
FETCH_DEPS=true
}
set_default_vars
# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-skip-package-install|-S)
set_default_vars
FETCH_DEPS=false
;;
esac
shift # past argument
done
if [ $FETCH_DEPS = true ]; then
verify_npm_setup
# We need to build keyman-version and lm-worker with a script for now
"$KEYMAN_ROOT/common/web/keyman-version/build.sh" || fail "Could not build keyman-version"
fi
npm run tsc -- --build "$THIS_SCRIPT_PATH/tsconfig.json"
if [ $? -ne 0 ]; then
fail "KeymanWeb recorder-core compilation failed."
fi
npm run tsc -- --build "$THIS_SCRIPT_PATH/nodeProctor.tsconfig.json"
if [ $? -ne 0 ]; then
fail "Node-based unit-test Proctor compilation failed."
fi

View file

@ -11,41 +11,28 @@ THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BA
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
display_usage ( ) {
echo "build.sh [-skip-package-install]"
echo
echo " -skip-package-install skips the \`npm install\` dependency check."
echo " (or -S) Intended for use when this script is called by another build script."
echo ""
echo " If more than one target is specified, the last one will take precedence."
exit 1
}
################################ Main script ################################
# Establish default build parameters
set_default_vars ( ) {
FETCH_DEPS=true
# We need to build keyman-version and lm-worker with a script for now
"$KEYMAN_ROOT/common/web/keyman-version/build.sh" || fail "Could not build keyman-version"
}
builder_describe \
"Compiles the web-oriented utility function module." \
configure clean build
set_default_vars
builder_parse "$@"
# Parse args
while [[ $# -gt 0 ]] ; do
key="$1"
case $key in
-skip-package-install|-S)
FETCH_DEPS=false
;;
esac
shift # past argument
done
if builder_start_action configure; then
verify_npm_setup
if [ "$FETCH_DEPS" = true ]; then
verify_npm_setup
"$KEYMAN_ROOT/common/web/keyman-version/build.sh"
builder_finish_action success configure
fi
npm run tsc -- --build "$THIS_SCRIPT_PATH/tsconfig.json"
if [ $? -ne 0 ]; then
fail "Utility-function package compilation failed."
if builder_start_action clean; then
npm run clean
builder_finish_action success clean
fi
if builder_start_action build; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/tsconfig.json"
builder_finish_action success build
fi

View file

@ -5,6 +5,7 @@
"types": "./build/index.d.ts",
"scripts": {
"build": "gosh ./build.sh",
"clean": "tsc -b --clean",
"tsc": "tsc"
},
"repository": {

View file

@ -7,10 +7,10 @@
do_clean() {
# clean: note build/<target> will be left, but build/<target>/<configuration> should be gone
local target=$1
builder_has_action clean:$target || return 0
builder_start_action clean:$target || return 0
rm -rf "$MESON_PATH"
builder_report success clean:$target
builder_finish_action success clean:$target
}
# ----------------------------------------------------------------------------
@ -19,7 +19,7 @@ do_clean() {
do_configure() {
local target=$1
builder_has_action configure:$target || return 0
builder_start_action configure:$target || return 0
local STANDARD_MESON_ARGS=
@ -42,6 +42,7 @@ do_configure() {
meson setup "$MESON_PATH" --werror --buildtype $CONFIGURATION $STANDARD_MESON_ARGS "${builder_extra_params[@]}"
popd > /dev/null
fi
builder_finish_action success configure:$target
}
has_configured_dependencies=false
@ -74,7 +75,7 @@ do_configure_dependencies() {
do_build() {
local target=$1
builder_has_action build:$target || return 0
builder_start_action build:$target || return 0
echo_heading "======= Building $target ======="
@ -90,6 +91,7 @@ do_build() {
ninja
popd > /dev/null
fi
builder_finish_action success build:$target
}
# ----------------------------------------------------------------------------
@ -98,7 +100,7 @@ do_build() {
do_test() {
local target=$1
builder_has_action test:$target || return 0
builder_start_action test:$target || return 0
echo_heading "======= Testing $target ======="
@ -109,6 +111,7 @@ do_test() {
meson test "${builder_extra_params[@]}"
popd > /dev/null
fi
builder_finish_action success test:$target
}
# ----------------------------------------------------------------------------
@ -126,13 +129,11 @@ do_uninstall() {
do_command() {
local command=$1
local target=$2
builder_has_action $command:$target || return 0
echo_heading "======= Installing $target ======="
builder_start_action $command:$target || return 0
pushd "$MESON_PATH" > /dev/null
ninja $command
popd > /dev/null
builder_finish_action success $command:$target
}
# ----------------------------------------------------------------------------

View file

@ -28,23 +28,23 @@ builder_parse "$@"
# TODO: configure if npm has not been run, and build is specified
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ../../include/ldml/build/
# Not removing ${KBP_LDML_H_FILE} as it is checked in
builder_report success clean
builder_finish_action success clean
fi
if builder_has_action build; then
if builder_start_action build; then
# Generate index.ts
npx tsc -b ../../include/ldml/tsconfig.build.json
builder_report success build
builder_finish_action success build
fi
if builder_has_action run; then
if builder_start_action run; then
node ../../include/ldml/ldml-const-builder/ldml-const-builder.js > ${KBP_LDML_H_FILE}
echo "Updated ${KBP_LDML_H_FILE}"
builder_report success run
builder_finish_action success run
fi

View file

@ -29,9 +29,9 @@ builder_parse "$@"
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_report success clean
builder_finish_action success clean
else
# We need the schema file at runtime and bundled, so always copy it for all actions except `clean`
mkdir -p "$THIS_SCRIPT_PATH/build/src/"
@ -40,21 +40,21 @@ fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build; then
if builder_start_action build; then
npm run build
builder_report success build
builder_finish_action success build
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build-fixtures; then
if builder_start_action build-fixtures; then
# Build basic.kmx and emit its checksum
mkdir -p ./build/test/fixtures
node . ./test/fixtures/basic.xml --no-compiler-version --debug --out-file ./build/test/fixtures/basic-xml.kmx
@ -64,20 +64,20 @@ if builder_has_action build-fixtures; then
# Generate a binary file from basic.txt for comparison purposes
node ../../../common/tools/hextobin/build/hextobin.js ./test/fixtures/basic.txt ./build/test/fixtures/basic-txt.kmx
builder_report success build-fixtures
builder_finish_action success build-fixtures
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action test; then
if builder_start_action test; then
npm test
builder_report success test
builder_finish_action success test
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action publish; then
if builder_start_action publish; then
. "$KEYMAN_ROOT/resources/build/npm-publish.inc.sh"
npm_publish
builder_report success publish
builder_finish_action success publish
fi

View file

@ -32,6 +32,7 @@
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7",
"@types/node": "^10.14.6",
"@types/semver": "^7.3.12",
"@types/xml2js": "^0.4.5",
"c8": "^7.12.0",
"chai": "^4.3.4",

View file

@ -27,7 +27,7 @@ export class MetaCompiler extends SectionCompiler {
this.callbacks.reportMessage(CompilerMessages.Error_InvalidVersion({ version: versionNumber }));
return false;
}
if(!semver.parse(versionNumber, {loose: false, includePrerelease: true})) {
if(!semver.parse(versionNumber, {loose: false})) {
this.callbacks.reportMessage(CompilerMessages.Error_InvalidVersion({ version: versionNumber }));
return false;
}

View file

@ -75,7 +75,15 @@ export default class LDMLKeyboardXMLSourceFileReader {
let parser = new xml2js.Parser({
explicitArray: false,
mergeAttrs: true,
emptyTag: {}
emptyTag: {} as any
// Why "as any"? xml2js is broken:
// https://github.com/Leonidas-from-XIV/node-xml2js/issues/648 means
// that an old version of `emptyTag` is used which doesn't support
// functions, but DefinitelyTyped is requiring use of function or a
// string. See also notes at
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59259#issuecomment-1254405470
// An alternative fix would be to pull xml2js directly from github
// rather than using the version tagged on npmjs.com.
});
parser.parseString(file, (e: unknown, r: unknown) => { a = r as LDMLKeyboardXMLSourceFile });
return a;

View file

@ -28,36 +28,36 @@ builder_parse "$@"
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_report success clean
builder_finish_action success clean
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build; then
if builder_start_action build; then
npm run build
builder_report success build
builder_finish_action success build
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action test; then
if builder_start_action test; then
#npm test - no tests as yet
builder_report success test
builder_finish_action success test
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action publish; then
if builder_start_action publish; then
. "$KEYMAN_ROOT/resources/build/npm-publish.inc.sh"
npm_publish
builder_report success publish
builder_finish_action success publish
fi

View file

@ -28,40 +28,40 @@ builder_parse "$@"
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_report success clean
builder_finish_action success clean
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build; then
if builder_start_action build; then
# Note: build-cjs only emits lexical-model-compiler.cjs at this time, as that
# is the only file required by other non-ES modules
# (common/web/input-processor tests)
mkdir -p build/cjs-src
npm run build
builder_report success build
builder_finish_action success build
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action test; then
if builder_start_action test; then
npm test
builder_report success test
builder_finish_action success test
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action publish; then
if builder_start_action publish; then
. "$KEYMAN_ROOT/resources/build/npm-publish.inc.sh"
npm_publish
builder_report success publish
builder_finish_action success publish
fi

View file

@ -28,36 +28,36 @@ builder_parse "$@"
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_report success clean
builder_finish_action success clean
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build; then
if builder_start_action build; then
npm run build
builder_report success build
builder_finish_action success build
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action test; then
if builder_start_action test; then
npm test
builder_report success test
builder_finish_action success test
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action publish; then
if builder_start_action publish; then
. "$KEYMAN_ROOT/resources/build/npm-publish.inc.sh"
npm_publish
builder_report success publish
builder_finish_action success publish
fi

View file

@ -30,9 +30,9 @@ builder_parse "$@"
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action clean; then
if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_report success clean
builder_finish_action success clean
else
# We need the schema file at runtime and bundled, so always copy it for all actions except `clean`
mkdir -p "$THIS_SCRIPT_PATH/build/src/"
@ -42,30 +42,30 @@ fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action build; then
if builder_start_action build; then
npm run build
builder_report success build
builder_finish_action success build
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action test; then
if builder_start_action test; then
# npm test -- no tests as yet
builder_report success test
builder_finish_action success test
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action bundle; then
if builder_start_action bundle; then
if ! builder_has_option --build-path; then
builder_report "Parameter --build-path is required" bundle
builder_finish_action "Parameter --build-path is required" bundle
exit 64
fi
@ -73,13 +73,13 @@ if builder_has_action bundle; then
npm run bundle
cp build/cjs-src/* "$BUILD_PATH"
builder_report success bundle
builder_finish_action success bundle
fi
#-------------------------------------------------------------------------------------------------------------------
if builder_has_action publish; then
if builder_start_action publish; then
. "$KEYMAN_ROOT/resources/build/npm-publish.inc.sh"
npm_publish
builder_report success publish
builder_finish_action success publish
fi

View file

@ -14,14 +14,14 @@
"@sentry/node": "^6.16.1",
"chalk": "^4.1.2",
"express": "^4.17.2",
"multer": "^1.4.4",
"multer": "^1.4.5-lts.1",
"ngrok": "^4.2.2",
"open": "^8.4.0",
"ws": "^8.3.0"
},
"optionalDependencies": {
"hetrodo-node-hide-console-window-napi": "keymanapp/hetrodo-node-hide-console-window-napi#keyman-15.0",
"node-windows-trayicon": "keymanapp/node-windows-trayicon#keyman-15.0"
"node-windows-trayicon": "keymanapp/node-windows-trayicon#keyman-16.0"
},
"devDependencies": {
"@keymanapp/resources-gosh": "*",
@ -34,10 +34,10 @@
"@types/ws": "^8.2.2",
"chai": "^4.3.4",
"copyfiles": "^2.4.1",
"mocha": "^9.1.4",
"mocha": "^10.0.0",
"ts-node": "^10.4.0",
"tsc-watch": "^4.5.0",
"typescript": "^4.5.4"
"typescript": "~4.5.4"
},
"mocha": {
"require": "ts-node/register",

8329
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
"private": true,
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.5.4"

View file

@ -12,6 +12,10 @@ including this file...
## Various tools
### build-utils.sh
See [build-utils.md](build-utils.md)
### vswhere
vswhere.exe is used by Keyman Core to select a Visual Studio version on Windows.

View file

@ -0,0 +1,587 @@
# Using the build-utils.sh builder functions
The Keyman repository is standardising on bash scripts for builds. These may
call project-specific builders, such as `tsc` for Typescript projects, `meson`
for our cross-platform C++ projects, `xcodebuild` on macOS and iOS projects,
`gradle` for Android, `nmake` in our Windows builds, or worse, but each project
should also have a `build.sh` script in its root.
We have standardised on parameters and structure for `build.sh` scripts. The
objectives are:
1. to be consistent in use of script parameters across all platforms and
projects
2. to be self-documenting in usage (`--help` should always tell you all you need
to know)
3. for the scripts to be easily readable, coherent, and straightforward for
anyone involved in the project to maintain.
* [Jump to API definitions](#builder-api-functions-and-variables)
---
# Anatomy of a build script
A build script is made up of three sections:
* [Prologue](#build-script-prologue)
* [Definition](#defining-build-script-parameters)
* [Processing actions](#build-script-actions)
# Build script prologue
A build script should always start with the following prologue:
```bash
#!/usr/bin/env bash
#
# <short description of the script purpose>
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/<relative-path-to-repo-root>/resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
# any other includes, such as jq.inc.sh
################################ Main script ################################
```
This prologue ensures that we have a consistent environment. Explaining each section:
## Shebang
```bash
#!/usr/bin/env bash
```
We use the `/usr/bin/env` prefix to ensure that we get the right version of bash
on macOS (installed via homebrew, rather than the obsolete system-provided one).
This also works fine on Linux, git bash on Windows, and WSL.
## Bash options (`set -eu`)
We use `set -eu` throughout:
* `-e` to exit on any statement failure
* `-u` to abort on unset variable use (usually coming from typos)
## Standard build script include
```bash
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/<relative-path-to-repo-root>/resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
```
This somewhat unwieldy incantation handles all our build environments, with
`greadlink` necessary on macOS (again installed with homebrew) due to the
included macOS `readlink` struggling with canonicalization of symbolic links.
The intent is to get a good solid consistent path for the script so that we can
safely include the build script, no matter what `pwd` is when the script is run.
The only modification permissible in this block is the
`<relative-path-to-repo-root>` text which will be a series of `../` paths taking
us to the repository root from the location of the script itself.
Inclusion of other scripts should be kept outside this standard build script
include section, as we may programatically update (a.ka. global
search-and-replace) this section in the future as required.
## Any other includes
Once `build-utils.sh` has been included, the variable `$KEYMAN_ROOT` will be
available, so other include scripts should be sourced accordingly, for example:
```bash
. "$KEYMAN_ROOT/resources/build/jq.inc.sh"
```
## Split
The comment line splitting the prologue from the body of the script is optional,
but makes the script easy to scan!
```bash
################################ Main script ################################
```
# Defining build script parameters
The build script should use the `builder` functions and variables to process its
command line and control its run.
Build scripts can define **targets**, **actions**, and **options**, which are
parameters passed in to the script when it is run by a user or called by
another script:
* **targets**: these are the expected outputs of the build script. A target is
prefixed with a `:`, for example `:app`. If no target is defined for a script,
then the default target `:project` is used.
* **actions**: these are the various actions that a build script can take, such
as `clean`, or `build`. If no action is passed in to on a given script
invocation, then the default action is `build` (unless the script defines an
alternative default).
* **options**: these are possible additional options that can be passed to the
script to modify the behavior of the script. All options should be prefixed
with `--`, such as `--debug`, and a shorthand single letter form may also be
optionally provided, such as `-d`.
Note that when we call scripts from other scripts, particularly in CI, we
should always use the longhand form; the shorthand form is for convenience on
the command line only.
Be judicious in use of options; a common one will be `--debug` to do a debug
build, but overuse of options will make scripts hard to use.
Options can be used to provide additional data, by including `=<varname>` in
their definition. Otherwise, they are treated as a boolean.
The first step in your script is to describe the available parameters, using
[`builder_describe`], for example:
```bash
builder_describe \
"Tests the build-utils.sh builder functions. This is merely an example." \
clean \
build \
test \
"install Installs something on the local system" \
:app \
":engine The internal engine for the app" \
"--power,-p Use powerful mode" \
"--zoom,-z Use zoom mode" \
"--feature=FOO Enable feature foo"
```
After describing the available parameters, you need to pass the command line
parameters in for parsing and validation:
```bash
builder_parse "$@"
```
If any parameters are invalid, the script will be terminated by
[`builder_parse`](#builderparse-function) with an error and will print the
script usage help using [`builder_display_usage`](#builderdisplayusage-function).
# Build script actions
Then, check each of the potential actions, in the order that they should be run,
for example:
```bash
if builder_start_action configure; then
verify_npm_setup
builder_finish_action success configure
fi
if builder_start_action clean; then
npm run clean
rm -f ./version.inc.ts
builder_finish_action success clean
fi
if builder_start_action build; then
npm run build -- $builder_verbose
builder_finish_action success build
fi
```
Each step is run separately, is started with [`builder_start_action`], and
finishes with [`builder_finish_action`]. If a build step is complex, it may be
worthwhile splitting it into a separate function or even a separate script
include.
Use the longer form of `if ...; then` rather than the shorter `[ ... ] && `
pattern, for consistency and readability.
# Standard builder parameters
The following parameters are pre-defined and should not be overridden:
* `--help`, `-h`: displays help on using this script
* `--color`: forces on ANSI color output for the script
* `--no-color`: forces off ANSI color output for the script
* `--verbose`, `-v`: verbose mode, sets the [`$builder_verbose`] variable
# Builder API functions and variables
## `builder_check_color` function
If you wish to provide [formatting variables] in your [`builder_describe`] call, you
will need to use `builder_check_color` first. This function takes the same
parameters as [`builder_parse`].
### Usage
```bash
builder_check_color "$@"
builder_describe "sample" \
"--ci For use with action ${BUILDER_TERM_START}test${BUILDER_TERM_END} - emits CI-friendly test reports"
```
## `builder_describe` function
Describes a build script, defines available parameters and their meanings. Use
together with `builder_parse` to process input parameters.
### Usage
```bash
builder_describe description param_desc...
```
### Parameters
* `description`: A short description of what the script does
* `param_desc`: Space separated name and description of parameter.
### Description
The `param_desc` parameter has two components: first, the parameter definition,
and second, an optional description for the parameter. The parameter definition
must not include any spaces, and the description, if included, must be preceded
by at least one space. This means that the parameters should be surrounded by
quote marks so that they are treated as a single parameter, for example:
```bash
builder_describe "Sample script" \
":app the app" \
configure \
build \
test \
"--print-errors,-p Print errors"
```
Or, a shorthand version for a simple script:
```bash
builder_describe "Build version module" clean configure build test
```
Each `param_desc` parameter defines a **target**, **action**, or **option**. All
parameters passed on the command line in a call to the script (prior to `--`,
see [`$builder_extra_params`] variable) must match one of the parameters defined
here.
**Targets** are defined by including a `:` prefix, for example:
```bash
builder_describe "Sample script" :engine ":proxy the proxy module"
```
There are several predefined targets. These will not be available to users of
your script unless you include them in the `builder_describe` call, but when
used, they have default descriptions, which can be used instead of adding your
own in the call:
* `:project`: `"this project"`
* `:app`: `"main app"`
* `:engine`: `"engine module"`
* `:module`: `"this module"`
* `:tools`: `"build tools for this project"`
**Actions** are defined as single words, for example:
```bash
builder_describe "Sample script build "install installs app on local system"
```
There are several predefined actions. Again, these will not be available to
users unless you include them in the call, but they do have default
descriptions:
* `clean`: `"remove build/ folder and build artifacts"`
* `configure`: `"install dependencies, e.g. npm"`
* `build`: `"build target(s)"`
* `test`: `"run automated tests"`
The default action will be `build`, unless overridden by using the `+` suffix on
a definition:
```bash
builder_describe "Testing script" clean test+
```
**Options** are defined by including a `--` prefix, for example:
```bash
builder_describe "Sample script" \
--debug,-d \
"--out-path,-o=OUT_PATH Specify output path"
```
A shorthand form may optionally be provided by appending `,-x` to the parameter
definition, where `x` is a one letter shorthand form. Currently, shorthand forms
may not be combined when invoking the script -- each must be passed separately.
Ensure that you do not include a space after the comma.
By default, an option will be treated as a boolean. It can be tested with
[`builder_has_option`]. If you need to pass additional data, then the
`=<variable>` format specifies an environment variable where the additional data
will be stored. When using this format, it is good to use [`builder_has_option`]
to test for the presence of the parameter before attempting to use the variable.
**Note:** although the definition uses `=` to define the variable, when invoking
script, the value should be passed in as a separate parameter.
There is one option with a predefined description: `--debug`. When including
this, you should use `--debug,-d` to enable the shorthand form.
Note that you should not include any of the [standard builder parameters] here.
## `builder_display_usage` function
Prints the help for the script, constructed from the [`builder_describe`]
parameters, so must be called after `builder_describe`.
### Usage
```bash
builder_describe "sample" clean build test
builder_display_usage
```
## `$builder_extra_params` variable
If a build script needs to be able to pass arbitrary additional parameters onto
another tool, for example, to a test runner, then the `--` parameter can be
used, for example:
```bash
./build.sh test -- test-window-color --verbose
```
These two additional parameters will be available in the `$builder_extra_params`
array variable, which can then be used in a call to the tool, using the `${var[@]}`
array expansion format:
```bash
npm test -- "${builder_extra_params[@]}"
```
## `builder_finish_action` function
Finishes an action sequence. Should always be paired with [`builder_start_action`].
### Usage
```bash
if builder_start_action action:target; then
# ... do the action
if something_failed; then
builder_finish_action "yeah, something failed" action:target
exit 1
fi
builder_finish_action success action:target
fi
```
### Parameters
* **result**: Result or message -- `success`, `failure`, or a more detailed
failure message
* **action**: Action to test
* **:target**: Target to test
These last two parameters can optionally be space separated.
### Description
In normal circumstances, `builder_finish_action` will then print a corresponding
message:
```
## [common/web/keyman-version] action:target completed successfully
```
When errors arise, a failure message will be printed, and the script will abort
with a non-zero exit code:
```
## [common/web/keyman-version] action:target failed with message: yeah, something failed
```
## `builder_has_action` function
This is similar to [`builder_start_action`], testing whether the script
invocation included a specific action, but does not start the action, and thus
does not print any messages to the console.
### Usage
```bash
if builder_has_action action:target; then
# ...
fi
```
See [`builder_start_action`] for more details.
## `builder_has_option` function
Tests if an option has been passed in the script invocation. The option must be
defined in [`builder_describe`].
### Usage
```bash
if builder_has_option --option; then
# ...
fi
```
### Parameters
* **--option**: The option to test. Must be the longhand form, and must be
prefixed with `--`.
### Description
When testing for presence of options that take additional data, the additional
data variable will only be set if the option is passed in the script invocation.
So `builder_has_option` is a clean way to test for the presence of the option in
this case too:
```bash
builder_describe "Sample" "--path=OUT_PATH"
builder_parse "$@"
if builder_has_option --path; then
echo "The output path is $OUT_PATH"
fi
```
## `builder_parse` function
Initializes a build.sh script, parses command line. Will abort the script if
invalid parameters are passed in. Use together with [`builder_describe`], which
sets up the possible command line parameters.
### Usage
```bash
builder_parse "$@"
```
### Description
Generally, you will always pass `"$@"` as the parameter for this call, to pass
all the command line parameters from the script invocation, with automatically
correct quoting and escaping.
## `builder_start_action` function
Starts an action and prints a message to the console, if the user has provided
the action in the script invocation.
### Usage
```bash
if builder_start_action action:target; then
# ... do the action
fi
if builder_start_action action :target; then
# ... do the action
fi
if builder_start_action action; then
# ... do the action for default target (:project)
fi
```
### Parameters
* **action** Action to test
* **:target** Target to test
These two parameters can optionally be space separated.
### Description
`builder_start_action` will only return `0` if the user passes that action as a
parameter when invoking the script. If the user has passed that action in, or
the action is the default (when no actions are provided), then the function will
also print a log message indicating that the action has started, for example:
```
## [common/web/keyman-version] build:project starting...
```
## `builder_use_color` function
This will normally be managed internally by build-utils, but can be manually
overridden with:
```bash
builder_use_color true
# or
builder_use_color false
```
## `$builder_verbose` variable
This standard variable will be set to `"--verbose"`, if the `--verbose` or `-v`
parameter is passed on the command line, and otherwise will be set to `""`.
### Usage
For example, can be used to pass `--verbose` to another app:
```bash
npm test -- $builder_verbose
# Can also be used like a standard option:
if builder_has_option --verbose; then
# ...
fi
```
## Formatting variables
These helper variables define ANSI color escapes when running in color mode, and
resolve either to empty string (for `$COLOR_*`), or equivalent plain-text forms
(for `$BUILDER_TERM_*`) when running without color:
* `$BUILDER_TERM_START`: Use blue to start definition of a term for builder
documentation (or `<` in plain-text)
* `$BUILDER_TERM_END`: Return to standard color to finish definition of a term
for builder documentation (or `>` in plain-text)
* `$COLOR_RED`: Red (error)
* `$COLOR_GREEN`: Green (success)
* `$COLOR_BLUE`: Blue (heading / informational)
* `$COLOR_YELLOW`: Yellow (warning)
* `$COLOR_RESET`: Back to default (light grey/white)
* `$HEADING_SETMARK`: Add a setmark, e.g. with VSCode
<https://code.visualstudio.com/updates/v1_69#_setmark-sequence-support>
[standard builder parameters]: #standard-builder-parameters
[`builder_check_color`]: #buildercheckcolor-function
[`builder_describe`]: #builderdescribe-function
[`builder_display_usage`]: #builderdisplayusage-function
[`$builder_extra_params`]: #builderextraparams-variable
[`builder_finish_action`]: #builderfinishaction-function
[`builder_has_action`]: #builderhasaction-function
[`builder_has_option`]: #builderhasoption-function
[`builder_parse`]: #builderparse-function
[`builder_start_action`]: #builderstartaction-function
[`builder_use_color`]: #builderusecolor-function
[`$builder_verbose`]: #builderverbose-variable
[formatting variables]: #formatting-variables

View file

@ -32,14 +32,6 @@
#
SHLVL=0
# Setup variable for calling script's path and name
if [ ! -z ${THIS_SCRIPT+x} ]; then
THIS_SCRIPT_PATH="$(dirname "$THIS_SCRIPT")"
readonly THIS_SCRIPT_PATH
THIS_SCRIPT_NAME="$(basename "$THIS_SCRIPT")"
readonly THIS_SCRIPT_NAME
fi
function die () {
# TODO: consolidate this with fail() from shellHelperFunctions.sh
echo
@ -57,6 +49,24 @@ function findRepositoryRoot() {
readonly KEYMAN_ROOT
}
# Used to build script-related build variables useful for referencing the calling script
# and for prefixing builder_finish_action outputs in order to more clearly identify the calling
# script.
#
# Assumes that `findRepositoryRoot` has already been called, a condition met later on
# within this script.
function _builder_setBuildScriptIdentifiers() {
if [ ! -z ${THIS_SCRIPT+x} ]; then
THIS_SCRIPT_PATH="$(dirname "$THIS_SCRIPT")"
readonly THIS_SCRIPT_PATH
THIS_SCRIPT_NAME="$(basename "$THIS_SCRIPT")"
readonly THIS_SCRIPT_NAME
# Leaves only the part of the path based upon KEYMAN_ROOT.
THIS_SCRIPT_IDENTIFIER=${THIS_SCRIPT_PATH#"$KEYMAN_ROOT/"}
readonly THIS_SCRIPT_IDENTIFIER
fi
}
function findVersion() {
local VERSION_MD="$KEYMAN_ROOT/VERSION.md"
VERSION=`cat $VERSION_MD | tr -d "[:space:]"`
@ -181,6 +191,7 @@ function findShouldSentryRelease() {
}
findRepositoryRoot
_builder_setBuildScriptIdentifiers
findTier
findVersion
# printVersionUtilsDebug
@ -296,6 +307,11 @@ builder_use_color() {
COLOR_RESET=$(tput sgr0)
# e.g. VSCode https://code.visualstudio.com/updates/v1_69#_setmark-sequence-support
HEADING_SETMARK='\x1b]1337;SetMark\x07'
# Used by `builder_display_usage` when marking special terms (actions, targets, options)
# in the plain-text description area.
BUILDER_TERM_START="$COLOR_BLUE"
BUILDER_TERM_END="$COLOR_RESET"
else
COLOR_RED=
COLOR_GREEN=
@ -307,6 +323,8 @@ builder_use_color() {
COLOR_GREY=
COLOR_RESET=
HEADING_SETMARK=
BUILDER_TERM_START="<"
BUILDER_TERM_END=">"
fi
}
@ -354,8 +372,54 @@ _builder_item_is_target() {
return 0
}
function _builder_warn_if_incomplete() {
if [ -n "${_builder_current_action}" ]; then
local scope="[$THIS_SCRIPT_IDENTIFIER] "
echo "${COLOR_YELLOW}## ${scope}Warning - $_builder_current_action never reported success or failure${COLOR_RESET}"
# exit 1 # If we wanted this scenario to result in a forced build-script fail.
fi
# Since we've already warned about this once, we'll clear the variable to prevent repetitions.
_builder_current_action=
}
# Used by a `trap` statement later to facilitate auto-reporting failures on error detection
# without obscuring failure exit/error codes.
_builder_failure_trap() {
local trappedExitCode=$?
local action target
# Since 'exit' is also trapped, we can also handle end-of-script incomplete actions.
if [[ $trappedExitCode == 0 ]]; then
# While there weren't errors, were there any actions that never reported success or failure?
_builder_warn_if_incomplete
return
fi
# If we've reached this point, we're here because an error occurred.
# Iterate across currently-active actions and report their failures.
if [ -n "${_builder_current_action}" ]; then
action="${_builder_current_action}"
if [[ $action =~ : ]]; then
IFS=: read -r action target <<< $action
target=:$target
else
target=:project
fi
builder_finish_action failure $action $target
fi
}
#
# Returns 0 if the user has asked to perform action on target on the command line
# Builds the standardized `action:target` string for the specified action-target
# pairing and also returns 0 if the user has asked to perform it on the command
# line. Otherwise, returns 0 and sets an empty string in place of the matched
# pair.
#
# The string will be set as `_builder_matched_action`, which is for
# build-utils.sh internal use, used by `builder_start_action`.
#
# Usage:
# if build_has_action action[:target]; then ...; fi
@ -363,9 +427,7 @@ _builder_item_is_target() {
# 1: action name of action
# 2: :target name of target, :-prefixed, as part of first param or space separated ok
# Example:
# if build_has_action build :app; then
# if build_has_action build:app; then
#
# if builder_has_action build :app; then # or build:app, that's fine too.
builder_has_action() {
local action="$1" target
@ -379,10 +441,41 @@ builder_has_action() {
fi
if _builder_item_in_array "$action$target" "${_builder_chosen_action_targets[@]}"; then
echo "${COLOR_BLUE}## $action$target starting...${COLOR_RESET}"
# To avoid WET re-processing of the $action$target string set
_builder_matched_action="$action$target"
return 0
else
_builder_matched_action=
return 1
fi
}
#
# Returns 0 if the user has asked to perform action on target on the command line, and
# then starts the action. Should be paired with builder_finish_action
#
# Usage:
# if builder_start_action action[:target]; then ...; fi
# Parameters:
# 1: action name of action
# 2: :target name of target, :-prefixed, as part of first param or space separated ok
# Example:
# if builder_start_action build :app; then
# if builder_start_action build:app; then
#
builder_start_action() {
local scope="[$THIS_SCRIPT_IDENTIFIER] "
if builder_has_action $@; then
echo "${COLOR_BLUE}## $scope$_builder_matched_action starting...${COLOR_RESET}"
if [ -n "${_builder_current_action}" ]; then
_builder_warn_if_incomplete
fi
_builder_current_action="$_builder_matched_action"
return 0
else
return 1
fi
return 1
}
#
@ -414,9 +507,8 @@ _builder_trim() {
}
#
# Describes a build script, defines available parameters
# and their meanings. Use together with builder_parse
# to process input parameters
# Describes a build script, defines available parameters and their meanings. Use
# together with `builder_parse` to process input parameters.
#
# Usage:
# builder_describe description param_desc...
@ -552,6 +644,32 @@ _builder_parameter_error() {
}
# Pre-initializes the color setting based on the options specified to a
# a build.sh script, parsing the command line to do so. This is only
# needed if said script wishes to use this script's defined colors while
# respecting the options provided by the script's caller.
#
# Usage:
# builder_check_color "$@"
# Parameters
# 1: $@ all command-line arguments (as with builder_parse)
builder_check_color() {
# Process command-line arguments
while [[ $# -gt 0 ]] ; do
local key="$1"
case "$key" in
--color)
builder_use_color true
;;
--no-color)
builder_use_color false
;;
esac
shift # past the processed argument
done
}
# Initializes a build.sh script, parses command line. Will abort the script if
# invalid parameters are passed in. Use together with builder_describe which
# sets up the possible command line parameters
@ -565,6 +683,7 @@ builder_parse() {
builder_extra_params=()
_builder_chosen_action_targets=()
_builder_chosen_options=()
_builder_current_action=
# Process command-line arguments
while [[ $# -gt 0 ]] ; do
@ -672,6 +791,15 @@ builder_parse() {
echo "* $e"
done
fi
# Now that we've successfully parsed options adhering to the _builder spec, we may activate our
# action_failure and action_hanging traps. (We don't want them active on scripts not yet using
# said script.)
#
# Note: if an error occurs within a script's function in a `set -e` script, it becomes an exit
# instead for the function's caller. So, we need both `err` and `exit` here.
# See https://medium.com/@dirk.avery/the-bash-trap-trap-ce6083f36700.
trap _builder_failure_trap err exit
}
_builder_pad() {
@ -741,8 +869,10 @@ builder_display_usage() {
_builder_pad $width " --color" "Force colorized output"
_builder_pad $width " --no-color" "Never use colorized output"
_builder_pad $width " --help, -h" "Show this help"
local c1="${COLOR_BLUE:=<}"
local c0="${COLOR_RESET:=>}"
# Defined in `builder_use_color`; this assumes that said func has been called.
local c1=$BUILDER_TERM_START
local c0=$BUILDER_TERM_END
echo
echo "* Specify ${c1}action:target${c0} to run a specific ${c1}action${c0} against a specific ${c1}:target${c0}."
echo "* If ${c1}action${c0} is specified without a ${c1}target${c0} suffix, it will be applied to all ${c1}:target${c0}s."
@ -751,7 +881,7 @@ builder_display_usage() {
echo
}
builder_report() {
builder_finish_action() {
local result="$1"
local action="$2" target
@ -764,10 +894,21 @@ builder_report() {
target="$3"
fi
if [[ $result == success ]]; then
echo "${COLOR_GREEN}## $action$target completed successfully${COLOR_RESET}"
local scope="[$THIS_SCRIPT_IDENTIFIER] "
if [[ "$action$target" == "${_builder_current_action}" ]]; then
if [[ $result == success ]]; then
echo "${COLOR_GREEN}## $scope$action$target completed successfully${COLOR_RESET}"
elif [[ $result == failure ]]; then
echo "${COLOR_RED}## $scope$action$target failed${COLOR_RESET}"
else
echo "${COLOR_RED}## $scope$action$target failed with message: $result${COLOR_RESET}"
fi
# Remove $action$target from the array; it is no longer a current action
_builder_current_action=
else
echo "${COLOR_RED}## $action$target failed. Result: $result${COLOR_RESET}"
echo "${COLOR_YELLOW}## Warning: reporting result of $action$target but the action was never started!${COLOR_RESET}"
fi
}

View file

@ -18,9 +18,9 @@ if [[ "${_builder_chosen_action_targets[@]}" != "build:project" ]]; then
fail " Test: builder_parse, shorthand form 'build' should give us 'build:project"
fi
if builder_has_action build; then
if builder_start_action build; then
echo "building project"
builder_report success build
builder_finish_action success build
else
fail "FAIL: should have matched action build for :project"
fi
@ -54,35 +54,35 @@ if [[ $_builder_default_action != "default" ]]; then
fi
# Shorthand form where we don't have a :target (default is ":project")
if builder_has_action build; then
if builder_start_action build; then
echo "building project"
builder_report success build
builder_finish_action success build
else
fail "FAIL: should have matched action build for :project"
fi
if builder_has_action clean :app; then
if builder_start_action clean :app; then
echo "Cleaning <clean :app>"
builder_report success clean :app
builder_finish_action success clean :app
else
fail "FAIL: should have matched action clean for :app"
fi
if builder_has_action clean:app; then
if builder_start_action clean:app; then
echo "Cleaning <clean:app>"
builder_report success clean:app
builder_finish_action success clean:app
else
fail "FAIL: should have matched action clean for :app"
fi
if builder_has_action build :app; then
if builder_start_action build :app; then
echo "Building app"
builder_report success build :app
builder_finish_action success build :app
else
fail "FAIL: should have matched action build for :app"
fi
if builder_has_action build :module; then
if builder_start_action build :module; then
fail "FAIL: should not have matched action build for :module"
fi
@ -159,7 +159,18 @@ if [[ ${builder_extra_params[2]} != "three four five" ]]; then
fail "FAIL: -- extra parameter 'three four five' not found"
fi
# Run tests based in separate scripts to facilitate their operation
# Due to the nature of the build-utils-traps tests, only one may be
# specified at a time; each ends with an `exit`.
echo "Running separate tests"
$THIS_SCRIPT_PATH/tests/build-utils-traps.test.sh error
$THIS_SCRIPT_PATH/tests/build-utils-traps.test.sh error-in-function
$THIS_SCRIPT_PATH/tests/build-utils-traps.test.sh incomplete
echo "Fin"
# Finally, run with --help so we can see what it looks like
# Note: calls `exit`, so no further tests may be defined.
echo "${COLOR_BLUE}## Testing --help${COLOR_RESET}"

View file

@ -0,0 +1,175 @@
#!/usr/bin/env bash
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../build-utils.sh"
# END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
##############
CHECK="${COLOR_GREEN}${COLOR_RESET}" # ✔
CROSS="${COLOR_RED}${COLOR_RESET}" # ❌
builder_describe \
"Provides actions useful for build-utils.sh trap-functionality unit testing.\nOnly one action may be set at a time." \
"error" \
"error-in-function" \
"incomplete"
builder_parse "$@"
###
HR="------------------------------------------------"
active_test=
error-test-matcher() {
ERR_CODE=$?
ALL_PASS=true
echo "$HR"
if [[ $ERR_CODE != 0 ]]; then
printf "${CHECK} Error reported to calling script\n"
else
printf "${CROSS} Error not reported to calling script\n"
ALL_PASS=false
fi
# output_logs will be accessible here. The report makes the most intuitive sense
# when presented here.
# Verify output logs have the expected output message.
if [[ "${output_logs:-}" =~ "raise-build-error:project failed" ]]; then
printf "${CHECK} Expected build-failure report was emitted\n"
else
printf "${CROSS} Expected build-failure report was not emitted\n"
ALL_PASS=false
fi
# Let's not re-trap ourselves from the trap!
trap - err exit
if [[ $ALL_PASS == true ]]; then
builder_finish_action success $active_test
exit 0
else
builder_finish_action failure $active_test
exit 1
fi
}
# Note: if this test is run, no other ones after it may execute!
if builder_start_action error; then
# clear base traps
trap - err
trap - exit
active_test=error
echo "$HR"
# The `|| true` disables any trap shenanigans.
# Needed to capture the log messages.
output_logs=`$THIS_SCRIPT_PATH/trap-test-builds.sh raise-build-error` || true
trap error-test-matcher err exit
# Relies on the `trap` - no further commands outside the handler will be processed.
# Also emits the log messages (but we can't capture them here)
$THIS_SCRIPT_PATH/trap-test-builds.sh raise-build-error
# In case the expected error isn't emitted. Will emit the report-failure.
error-test-matcher
fi
function-with-error() {
$THIS_SCRIPT_PATH/trap-test-builds.sh raise-build-error
}
# Note: if this test is run, no other ones after it may execute!
if builder_start_action error-in-function; then
# clear base traps
trap - err
trap - exit
active_test=error-in-function
echo "$HR"
# The `|| true` disables any trap shenanigans.
# Needed to capture the log messages.
output_logs=`function-with-error` || true
trap error-test-matcher err exit
# Relies on the `trap` - no further commands outside the handler will be processed.
# Also emits the log messages (but we can't capture them here)
function-with-error
# In case the expected error isn't emitted. Will emit the report-failure.
error-test-matcher
fi
########
warning-test-matcher() {
ERR_CODE=$?
ALL_PASS=true
echo "$HR"
if [[ $ERR_CODE == 0 ]]; then
printf "${CHECK} Error not reported to calling script\n"
else
printf "${CROSS} Error reported to calling script\n"
ALL_PASS=false
fi
# output_logs will be accessible here. The report makes the most intuitive sense
# when presented here.
# Verify output logs have the expected output message.
if [[ "${output_logs:-}" =~ "unreported-action:project never reported" ]]; then
printf "${CHECK} Expected warning report was emitted\n"
else
printf "${CROSS} Expected warning report was not emitted\n"
ALL_PASS=false
fi
# Let's not re-trap ourselves from the trap!
trap - err exit
if [[ $ALL_PASS == true ]]; then
builder_finish_action success incomplete
exit 0
else
builder_finish_action failure incomplete
exit 1
fi
}
if builder_start_action incomplete; then
# clear base traps
trap - err
trap - exit
echo "$HR"
# The `|| true` disables any trap shenanigans.
output_logs=`$THIS_SCRIPT_PATH/trap-test-builds.sh unreported-action` || true
trap warning-test-matcher err
# Relies on the `trap` - no further commands outside the handler will be processed.
$THIS_SCRIPT_PATH/trap-test-builds.sh unreported-action
warning-test-matcher
fi

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -eu
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
. "$(dirname "$THIS_SCRIPT")/../build-utils.sh"
# END STANDARD BUILD SCRIPT INCLUDE
builder_describe \
"Error-generating delegate script" \
"raise-build-error+" \
"unreported-action"
builder_parse "$@"
if builder_start_action raise-build-error; then
echo "Emulating build script error => failure report"
exit 1
fi
if builder_start_action unreported-action; then
echo "Leaving action 'success' unreported; should trigger trap message"
fi

View file

@ -9,7 +9,6 @@
"devDependencies": {
"@types/node": "^13.7.0",
"@types/semver": "^7.1.0",
"@zeit/ncc": "^0.21.0",
"semver": "^7.1.2",
"ts-node": "^8.6.2"
},
@ -17,20 +16,16 @@
"node": "16"
},
"files": [
"dist",
"src"
],
"license": "MIT",
"main": "dist/index.js",
"main": "lib/index.js",
"name": "@keymanapp/auto-history-action",
"private": true,
"scripts": {
"build": "npm run clean:dist; npm run build:dist",
"build:dist": "ncc build src/index.ts --minify --source-map --v8-cache",
"build:ts": "tsc --project tsconfig.production.json",
"build:ts:watch": "tsc --project tsconfig.production.json --watch",
"clean": "run-p clean:*",
"clean:dist": "rm -rf dist",
"clean:lib": "rm -rf lib",
"types": "tsc --noEmit"
}

View file

@ -21,12 +21,12 @@ builder_describe \
"build (default) builds bulk_renderer to ../release/renderer/"
builder_parse "$@"
if builder_has_action configure; then
if builder_start_action configure; then
verify_npm_setup
builder_report success configure
builder_finish_action success configure
fi
if builder_has_action build; then
if builder_start_action build; then
tsc --build "$THIS_SCRIPT_PATH/tsconfig.json" $builder_verbose
builder_report success build
builder_finish_action success build
fi

View file

@ -36,7 +36,7 @@
"karma-mocha-reporter": "^2.2.5",
"karma-safari-launcher": "^1.0.0",
"karma-teamcity-reporter": "^1.1.0",
"mocha": "^8.4.0",
"mocha": "^10.0.0",
"modernizr": "^3.11.7",
"ts-node": "^9.1.1",
"typescript": "^4.5.4"

View file

@ -1,6 +1,6 @@
# Regression Tests
This folder contains tools to run automated regression tests on Keyman Engine for Web
This folder contains tools to run automated regression tests on Keyman Engine for Web
and Keyman Developer. The intent is to validate changes to the compiler and the engine
against the set of available keyboards in the Keyman keyboards repository from
https://github.com/keymanapp/keyboards.
@ -10,7 +10,7 @@ the `kmanalyze` program which is not yet available outside the keyman source rep
is the only Windows dependency (the `kmcomp` compiler is also used, but this runs under
WINE and is available in binary form outside the source repo).
The test suite runs in Node.js and launches Chrome for the tests. In the future, the
The test suite runs in Node.js and launches Chrome for the tests. In the future, the
tests may be able to be run in native Node.js.
## Configuration
@ -35,7 +35,7 @@ the keyman repository, for example:
- regression-tests
Keyman Engine for Web, Keyman Developer (kmcomp, kmcmpdll, kmanalyze) must be built
prior to running the tests. (If not testing source versions, only kmanalyze is
prior to running the tests. (If not testing source versions, only kmanalyze is
required). See the build documentation for each project for details; summary below:
To build KeymanWeb (bash):
@ -45,12 +45,12 @@ To build KeymanWeb (bash):
To build just the Keyman Developer tools required from the Windows source (cmd):
cd windows\src
make -DNOUI ext global buildtools developer
cd developer\src
nmake
### Known Failures
As there are some known failures, these are listed in `src/known-failures.js`.
As there are some known failures, these are listed in `src/known-failures.js`.
As the bugs that impact these keyboards are addressed, they should be progressively
removed from the file. Keyboards listed in this file will still be tested and
report errors, but they will not fail the test suite overall.
@ -62,7 +62,7 @@ tests that run with node + Karma + Mocha + Chai.
### Manual Tests
`node interactive.js` will start a web server listening on http://localhost:1337/.
`node interactive.js` will start a web server listening on http://localhost:1337/.
Navigating to this address will allow you to load and test a given keyboard from the
keyboards repository. This assumes that the keyboards are already available and that
the .tests have already been built.
@ -72,7 +72,7 @@ tools than for intensive testing.
### Automated Tests
`node test.js` runs the entire test suite. There are a number of command line
`node test.js` runs the entire test suite. There are a number of command line
parameters available:
$ node test.js -h
@ -89,15 +89,15 @@ parameters available:
-l, --log-all-failures Log all test failures to console, not just the first failure for each keyboard
-h, --help output usage information
When the entire test suite is run, the regression test compares the latest version of
When the entire test suite is run, the regression test compares the latest version of
the compiler from the source repository, together with the latest version of Keyman
Engine for Web from the source repository, against the latest stable releases of
Engine for Web from the source repository, against the latest stable releases of
each, downloaded from https://downloads.keyman.com/
These two versions are referenced as `source` and `stable` respectively. You can
also specify exact stable, beta or alpha versions for download by specifying a
version number in the `-c` and `-e` parameters. You can test as many versions as
you like at a time, but beware: the number of permutations tested increases as
you like at a time, but beware: the number of permutations tested increases as
the square of tested versions.
The continuous integration configuration currently uses `node test.js -l`.
@ -126,14 +126,14 @@ The test builder generates a `tests-generated.js` file for running Karma and the
## Background
`kmanalyze` generates a .tests file for a given keyboard, from analysis of a
corresponding .kmx file (a future update will use the intermediate in-memory
corresponding .kmx file (a future update will use the intermediate in-memory
.kmx file used by the compiler to ensure we access only the web rules). It
does not currently support deadkeys, recursive groups, or web-specific rules
(lines prefixed with `$keymanweb:`). Nor does it support keyboard or system
options. It will generate a single test for each store referenced in an `any`
statement, rather than a test for each character in the store.
.tests files and .results files are stored in a `tests/` folder for each
.tests files and .results files are stored in a `tests/` folder for each
keyboard in the repository.
The test suite runs tests against the physical keyboard ruleset for keyboards.

View file

@ -13,7 +13,7 @@
"commander": "^2.19.0",
"express": "^4.16.4",
"fs-extra": "^7.0.1",
"got": "^9.6.0",
"got": "^11.8.5",
"jasmine-core": "^3.3.0",
"karma": "^6.3.16",
"karma-chai": "^0.1.0",

View file

@ -1,6 +1,6 @@
// test-runner
const KEYBOARDS_RELATIVE_PATH = "/keyboards/";
const KEYBOARDS_RELATIVE_PATH = "/keyboards/";
const TEST_BATCH_SIZE = 100; // or Infinity
var receiver;
@ -17,7 +17,7 @@ var windowLoad = new Promise(function(resolve, reject) {
receiver = document.getElementById('receiver');
if(!receiver) {
// When running tests, we dynamically create the receiver
receiver = document.createElement('input');
receiver = document.createElement('input');
document.body.appendChild(receiver);
let d0 = document.createElement('div');
d0.id = 'progressWindow';
@ -51,15 +51,15 @@ function chunk(arr, chunkSize) {
}
var testRunner = {
modCodes: keyman.osk.modifierCodes,
keyCodes: keyman.osk.keyCodes,
modCodes: com.keyman.text.Codes.modifierCodes,
keyCodes: com.keyman.text.Codes.keyCodes,
keyboards: {},
max: 0,
/**
* Loads a .tests file for the given keyboard, and the corresponding keyboard. Both the
* Loads a .tests file for the given keyboard, and the corresponding keyboard. Both the
* keyboard and the tests file are injected via script into the document.
*
*
* @param {string} locator a string in the form of shortname/id, e.g. k/kayan, sil/sil_ipa
* @returns {Promise} A promise fulfilled when the keyboard and the tests file are ready
*/
@ -102,7 +102,7 @@ var testRunner = {
/**
* Load a tests file and a keyboard from the keyboards repository
* @param {string} locator
* @param {string} locator
*/
loadTests: function(locator) {
console.log('Loading tests + keyboard for '+locator);
@ -130,7 +130,7 @@ var testRunner = {
};
// The KeymanWeb global will always exist, even when we otherwise change API.
KeymanWeb.registerStub(stub);
let k = testRunner.keyboards[id];
let k = testRunner.keyboards[id];
keyman.setKeyboardForControl(receiver, id, k.keyboard.languages[0].id);
document.body.focus();
receiver.focus();
@ -185,7 +185,7 @@ var testRunner = {
};
http.open('POST', '/save-results');
http.setRequestHeader('Content-Type', 'application/json');
http.send(JSON.stringify(json));
http.send(JSON.stringify(json));
});
},
@ -203,7 +203,7 @@ var testRunner = {
/**
* Called by a .tests file to register a set of input tests
* @param {object} data
* @param {object} data
*/
register: function(data) {
let keys = Object.keys(data.inputTests);
@ -240,7 +240,7 @@ var testRunner = {
runTests: function(keyboardId) {
return new Promise(function(resolve, reject) {
this.keyboards[keyboardId].results = {};
console.log('-- Running '+this.keyboards[keyboardId].inputTests.length+' tests for '+keyboardId+'.');
var chunkSize = TEST_BATCH_SIZE;
@ -291,7 +291,7 @@ var testRunner = {
e.LisVirtualKeyCode = true;
e.LisVirtualKey = true;
e.vkCode = test.key;
// Keyman 14 changes the processKeystroke interface
e.device = keyman.util.device.coreSpec;
if(keyman.core) {
@ -319,7 +319,7 @@ var testRunner = {
initProgress: function(max) {
this.max = max;
this.progressPosition = document.getElementById('progressPosition');
if(this.progressPosition) this.progressPosition.style.width = '0px';
if(this.progressPosition) this.progressPosition.style.width = '0px';
},
/**
@ -327,7 +327,7 @@ var testRunner = {
* @param {number} len Current position of progress bar
*/
updateProgress: function(len) {
if(this.progressPosition) this.progressPosition.style.width = Math.round(len / this.max * 100).toString() + '%';
if(this.progressPosition) this.progressPosition.style.width = Math.round(len / this.max * 100).toString() + '%';
}
};

View file

@ -24,7 +24,7 @@ program
.version('0.1')
.option('-c, --compiler-versions [versions]', 'Specify compiler version(s) to test. Can specify "stable", "source" or a specific version number.', list, ['stable','source'])
.option('-e, --engine-versions [versions]', 'Specify KeymanWeb engine version(s) to test. Can specify "stable", "source" or a specific version number.', list, ['stable','source'])
.option('-k, --keyboards [keyboards]', 'Builds and tests specific keyboard source files. If -k is not specified, then test all keyboards in the keyboards repository.', list, [])
.option('-k, --keyboards [keyboards]', 'Builds and tests specific keyboard source files (e.g. k/khmer_angkor). If -k is not specified, then test all keyboards in the keyboards repository.', list, [])
.option('-f, --fail-fast', "Don't attempt to continue tests after the first keyboard test fails")
.option('-d, --debug', "Build keyboard with debug symbols")
.option('--deep', "Compare all version combinations against base version, instead of just one; only valid when comparing 1 version of each against base")
@ -57,8 +57,8 @@ const bash = process.platform == 'win32'
//TODO: support testing standalone keyboards that are not in the repo
const compilerDestPath = path.join(config.KEYBOARDS_ROOT, 'tools');
const kmcompDestPath = path.join(compilerDestPath, 'kmcomp.exe');
const kmcmpdllDestPath = path.join(compilerDestPath, 'kmcmpdll.dll');
const kmcompDestPath = path.join(compilerDestPath, 'kmcomp', 'kmcomp.exe');
const kmcmpdllDestPath = path.join(compilerDestPath, 'kmcomp', 'kmcmpdll.dll');
let testedCompilerVersions = [], testedEngineVersions = [], firstCompile = true;
@ -75,7 +75,7 @@ process.on('unhandledRejection', (reason, p) => {
});
/**
*
*
* @param items An array of items.
* @param fn A function that accepts an item from the array and returns a promise.
* @returns {Promise}
@ -95,7 +95,7 @@ function fail(msg, code) {
if(program.failFast) process.exit();
}
//
//
// Clean the keyboards repo -- unless we are skipping analysis
// This removes the build/ and tests/ folders
//
@ -107,27 +107,31 @@ if(!program.skipAnalysis) {
let cleanKeyboard = function(keyboard) {
keyboard = keyboard ? config.KEYBOARDS_GROUP+'/'+keyboard : config.KEYBOARDS_GROUP;
return util.runProcess(
`${bash.command}`,
[].concat(bash.params, ['build.sh', '-c', keyboard]),
`${bash.command}`,
[].concat(bash.params, ['build.sh', '-c', keyboard]),
{ cwd: config.KEYBOARDS_ROOT });
};
cleanKeyboards = (program.keyboards.length)
cleanKeyboards = (program.keyboards.length)
? forEachPromise(program.keyboards, cleanKeyboard)
: cleanKeyboard('');
}
}
cleanKeyboards.then(() => {
fs.renameSync(kmcompDestPath, kmcompDestPath + '.bak');
fs.renameSync(kmcmpdllDestPath, kmcmpdllDestPath + '.bak');
process.on('exit', () => {
console.log('Restoring original compiler files');
fs.renameSync(kmcompDestPath + '.bak', kmcompDestPath);
fs.renameSync(kmcmpdllDestPath + '.bak', kmcmpdllDestPath);
if(fs.existsSync(kmcompDestPath + '.bak')) {
fs.renameSync(kmcompDestPath + '.bak', kmcompDestPath);
}
if(fs.existsSync(kmcmpdllDestPath + '.bak')) {
fs.renameSync(kmcmpdllDestPath + '.bak', kmcmpdllDestPath);
}
});
}).then(() => forEachPromise(program.compilerVersions, version => {
//
//
// Compile phase - get the compiler
//
@ -141,17 +145,18 @@ cleanKeyboards.then(() => {
console.error('Source build of compiler is only available on Windows.');
reject();
}
fs.copyFileSync(path.join(config.KEYMAN_REPO_BASE_RELATIVE_PATH, 'windows', 'bin', 'developer', 'kmcomp.exe'), kmcompDestPath);
fs.copyFileSync(path.join(config.KEYMAN_REPO_BASE_RELATIVE_PATH, 'windows', 'bin', 'developer', 'kmcmpdll.dll'), kmcmpdllDestPath);
fs.copyFileSync(path.join(config.KEYMAN_REPO_BASE_RELATIVE_PATH, 'developer', 'bin', 'kmcomp.exe'), kmcompDestPath);
fs.copyFileSync(path.join(config.KEYMAN_REPO_BASE_RELATIVE_PATH, 'developer', 'bin', 'kmcmpdll.dll'), kmcmpdllDestPath);
resolve();
});
break;
case 'stable':
getCompiler = got('https://downloads.keyman.com/api/version/developer/2.0', { json: true })
getCompiler = got('https://downloads.keyman.com/api/version/developer/2.0')
.json()
.then(response => {
compilerVersion = response.body.developer.stable.version;
compilerVersion = response.developer.stable.version;
console.log('Downloading compiler version '+compilerVersion);
return got(`https://downloads.keyman.com/developer/stable/${compilerVersion}/kmcomp-${compilerVersion}.zip`, { encoding: null });
return got(`https://downloads.keyman.com/developer/stable/${compilerVersion}/kmcomp-${compilerVersion}.zip`, { responseType: 'buffer' });
})
.then(response => {
console.log('Unzipping compiler');
@ -163,7 +168,7 @@ cleanKeyboards.then(() => {
default:
console.log('Downloading specified compiler version '+version);
compilerVersion = version;
getCompiler = got(`https://downloads.keyman.com/developer/stable/${version}/kmcomp-${version}.zip`, { encoding: null })
getCompiler = got(`https://downloads.keyman.com/developer/stable/${version}/kmcomp-${version}.zip`, { responseType: 'buffer' })
.then(response => {
console.log('Unzipping compiler');
let zip = new AdmZip(response.body);
@ -190,11 +195,11 @@ cleanKeyboards.then(() => {
console.log('building keyboard '+keyboard);
return util.runProcess(
`${bash.command}`,
[].concat(bash.params, ['build.sh'], program.debug?['-d']:[], [/*TODO: waiting on keyboards repo support for this param: '-T', 'kmn',*/ keyboard]),
`${bash.command}`,
[].concat(bash.params, ['build.sh'], program.debug?['-d']:[], [/*TODO: waiting on keyboards repo support for this param: '-T', 'kmn',*/ keyboard]),
{ cwd: config.KEYBOARDS_ROOT });
};
return (program.keyboards.length) ? forEachPromise(program.keyboards, buildKeyboard) : buildKeyboard('');
});
@ -208,7 +213,7 @@ cleanKeyboards.then(() => {
firstCompile = false;
let analyzeKeyboard = function(keyboard) {
const locator = keyboard.shortname+'/'+keyboard.id;
const kmx = path.join(config.KEYBOARDS_ROOT, config.KEYBOARDS_GROUP, locator, 'build', keyboard.id+'.kmx');
const testsPath = path.join(config.KEYBOARDS_ROOT, config.KEYBOARDS_GROUP, locator, 'tests');
const tests = path.join(testsPath, keyboard.id+'.tests');
@ -225,11 +230,11 @@ cleanKeyboards.then(() => {
console.log(`Building test cases for ${locator}`);
// TODO: Find kmanalyze outside the repo. This forces Windows-dependence right now
return util.runProcess('../../../windows/bin/developer/kmanalyze.exe', [kmx, tests], {}, true);
return util.runProcess('../../../developer/bin/kmanalyze.exe', [kmx, tests], {}, true);
};
let keyboards = program.keyboards.length
? program.keyboards.map((locator) => util.parseLocator(locator))
let keyboards = program.keyboards.length
? program.keyboards.map((locator) => util.parseLocator(locator))
: util.getKeyboardFolders(KEYBOARDS_ROOT, false);
return forEachPromise(keyboards, analyzeKeyboard);
}
@ -267,11 +272,12 @@ cleanKeyboards.then(() => {
});
break;
case 'stable':
getEngine = got('https://downloads.keyman.com/api/version/web/2.0', { json: true })
getEngine = got('https://downloads.keyman.com/api/version/web/2.0')
.json()
.then(response => {
engineVersion = response.body.web.stable.version;
engineVersion = response.web.stable.version;
console.log('Downloading engine version '+engineVersion);
return got(`https://downloads.keyman.com/web/stable/${engineVersion}/keymanweb-${engineVersion}.zip`, { encoding: null });
return got(`https://downloads.keyman.com/web/stable/${engineVersion}/keymanweb-${engineVersion}.zip`, { responseType: 'buffer' });
})
.then(response => {
console.log('Unzipping engine');
@ -283,7 +289,7 @@ cleanKeyboards.then(() => {
default:
console.log('Downloading specified engine version '+version0);
engineVersion = version0;
getEngine = got(`https://downloads.keyman.com/web/stable/${version0}/keymanweb-${version0}.zip`, { encoding: null })
getEngine = got(`https://downloads.keyman.com/web/stable/${version0}/keymanweb-${version0}.zip`, { responseType: 'buffer' })
.then(response => {
console.log('Unzipping engine');
// Assuming engine files we want are at unminified/ in the zip
@ -292,8 +298,8 @@ cleanKeyboards.then(() => {
});
}
return getEngine.then(() => {
console.log('Testing compiler version '+compilerVersion+', engine version '+engineVersion);
return getEngine.then(() => {
console.log('Testing compiler version '+compilerVersion+', engine version '+engineVersion);
if(testedEngineVersions.indexOf(engineVersion) < 0) {
testedEngineVersions.push(engineVersion);
@ -302,9 +308,9 @@ cleanKeyboards.then(() => {
return util.runProcess(
`node`,
[].concat(
['test-builder.js',
'--compiler-version', compilerVersion,
'--engine-version', engineVersion],
['test-builder.js',
'--compiler-version', compilerVersion,
'--engine-version', engineVersion],
program.keyboards.length ? ['--keyboards', program.keyboards.join(',')] : []
)
);
@ -330,8 +336,8 @@ cleanKeyboards.then(() => {
// Validate each of the test files against the first tested compiler+engine version
let localFailCount = 0;
const localFail = knownFailures.hasOwnProperty([keyboard.id]) ?
(msg) => { if(++localFailCount == 1) console.warn(`WARN: Not failing test because ${keyboard.id} is in known-failures.`); console.warn(`WARN: ${msg}`); } :
const localFail = knownFailures.hasOwnProperty([keyboard.id]) ?
(msg) => { if(++localFailCount == 1) console.warn(`WARN: Not failing test because ${keyboard.id} is in known-failures.`); console.warn(`WARN: ${msg}`); } :
fail;
try {
@ -370,8 +376,8 @@ cleanKeyboards.then(() => {
for(let k in baseResultJSON) {
if(resultJSON[k] !== baseResultJSON[k]) {
if(++errors == 1 || program.logAllFailures) {
let
ix = k.toString(),
let
ix = k.toString(),
whitespace = ' '.repeat(prefix.length + ix.length + 6),
input = `${testsJSON.inputTests[k].context ? `"${testsJSON.inputTests[k].context}" ` : ""}+ ${keyname(testsJSON.inputTests[k].modifier, testsJSON.inputTests[k].key)}`;
console.error(`${prefix}[${ix}]: expected: ${input} > "${baseResultJSON[k]}"`);

View file

@ -28,8 +28,8 @@ readonly ENGINE_TEST_OUTPUT
# (Facilitates automated setup for build agents.)
PATH="../../node_modules/.bin:$PATH"
pushd "$KEYMAN_ROOT/common/web/recorder/src"
./build.sh -skip-package-install || fail "recorder-core compilation failed."
pushd "$KEYMAN_ROOT/common/web/recorder"
./build.sh || fail "recorder-core compilation failed."
popd
compiler="npm run tsc --"