-
-
Notifications
You must be signed in to change notification settings - Fork 43
chore: Attempt to cache source from downloads.keyman if external source missing #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
darcywong00
merged 3 commits into
keymanapp:master
from
darcywong00:chore/warn-external-source-missing
Feb 4, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| # This file corresponds very closely to external.inc.sh in keymanapp/keyboards | ||
| #---------------------------------------------------------------------------------------- | ||
|
|
||
| . "./tools/jq.inc.sh" | ||
|
|
||
| retrieve_external_model() { | ||
| # Assume we are starting in the correct folder | ||
| [ -f external_source ] || die "No external_source file found" | ||
|
|
@@ -108,8 +110,44 @@ retrieve_external_binary_model() { | |
| [[ $filename =~ ^/ ]] && die "path cannot start with /" | ||
| local path= | ||
| [[ ! $filename =~ .model_info$ ]] && path=source/ | ||
| curl -s -L "$url" --output "$path$filename" --create-dirs || die "Unable to download $filename" | ||
| curl -s -L "$url" --output "$path$filename" --create-dirs || retrieve_cached_model "$path" "$filename" && continue | ||
| echo "$sha256 $path$filename" | sha256sum -c --quiet || die "Invalid checksum for $filename" | ||
| done < external_source | ||
| } | ||
|
|
||
| # | ||
| # Download cached file from downloads.keyman when external source is missing | ||
| # | ||
| retrieve_cached_model() { | ||
| local path="$1" | ||
| local filename="$2" | ||
| builder_warn "Unable to download $filename so getting cached file from downloads.keyman.com" | ||
|
|
||
| local extension="${filename##*.}" | ||
| local model_id="${filename%.model*}" | ||
|
|
||
| local query="https://api.keyman.com/model/?q=${model_id}" | ||
| case "$extension" in | ||
| js) | ||
| local js_filename=`curl "$query" | $JQ -r '.[].jsFilename'` | ||
| curl -s -L "$js_filename" --output "$path$filename" --create-dirs || die "Unable to download $js_filename" | ||
| ;; | ||
| kmp) | ||
| local kmp_filename=`curl "$query" | $JQ -r '.[].packageFilename'` | ||
| curl -s -L "$kmp_filename" --output "$path$filename" --create-dirs || die "Unable to download $kmp_filename" | ||
|
|
||
| # Also handle model_info since we need to query the latest version | ||
| # .model_info is downloaded up a level | ||
| local version=`curl "$query" | $JQ -r '.[].version'` | ||
| local model_info_filename="https://downloads.keyman.com/models/${model_id}/${version}/${model_id}.model_info" | ||
| curl -s -L "$model_info_filename" --output "$model_id.model_info" --create-dirs || die "Unable to download $model_info_filename" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be under the model_info) section, I don't see any benefit to it being under kmp) |
||
| ;; | ||
| model_info) | ||
| # Skip - handled above | ||
| echo "$filename handled elsewhere" | ||
| ;; | ||
| *) | ||
| die "$path $filename had unexpected extension (expecting js, kmp, or model_info)" | ||
| ;; | ||
| esac | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Setup JQ environment variable according to the user's system | ||
| # | ||
| # Windows: ./jq-win64.exe | ||
| # Linux/macOS: jq | ||
| # | ||
|
|
||
| ## START STANDARD BUILD SCRIPT INCLUDE | ||
| # adjust relative paths as necessary | ||
| JQ_THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" | ||
| # . "${THIS_SCRIPT%/*}/build-utils.sh" | ||
| ## END STANDARD BUILD SCRIPT INCLUDE | ||
|
|
||
| case "${OSTYPE}" in | ||
| "cygwin") | ||
| JQ=$(dirname "$JQ_THIS_SCRIPT")/jq-win64.exe | ||
| ;; | ||
| "msys") | ||
| JQ=$(dirname "$JQ_THIS_SCRIPT")/jq-win64.exe | ||
| ;; | ||
| *) | ||
| JQ=jq | ||
| ;; | ||
| esac | ||
|
|
||
| readonly JQ | ||
|
|
||
| # JQ with inplace file replacement | ||
| function jqi() { | ||
| cat <<< "$($JQ -c "$1" < "$2")" > "$2" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't continue if
retrieve_cached_modelfails; we still also need to verify the checksum of the cached model.