diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/README.md | 14 | ||||
| -rw-r--r-- | android/scripts/ci-android-xml.sh | 38 | ||||
| -rwxr-xr-x | android/scripts/tidy.sh | 56 |
3 files changed, 68 insertions, 40 deletions
diff --git a/android/README.md b/android/README.md index 92c1832f74..57e428eaa7 100644 --- a/android/README.md +++ b/android/README.md @@ -40,8 +40,18 @@ Also, see the [`ktfmt` gradle plugin documentation](https://github.com/cortinico how to use it as a gradle task. ### XML formatting -`tidy` is used for XML resource formatting. `tidy` is a separate tool which has to be installed -unless the container image (which includes `tidy`) is used. +In order to format XML files, the script `scripts/tidy.sh` is used. As the script name implies, it's basically a helper script to run the tool called `tidy`. It needs to be installed unless the +container image is used. + +Command to format: +``` +scripts/tidy.sh format +``` + +Command to format and check for any changes: +``` +scripts/tidy.sh formatAndCheckDiff +``` ### Android Gradle Plugin lint tool diff --git a/android/scripts/ci-android-xml.sh b/android/scripts/ci-android-xml.sh deleted file mode 100644 index 0fd552b3a6..0000000000 --- a/android/scripts/ci-android-xml.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -# CI/Developer script to format -# Relies on Tidy - https://github.com/htacg/tidy-html5 - -# Autoformats Android XML files -function tidy-up-android-xml { - tidy -xml \ - -m \ - -i \ - -w 100 \ - -utf8 \ - --quiet yes \ - --indent-attributes yes \ - --indent-spaces 4 \ - --literal-attributes yes \ - android/app/src/main/AndroidManifest.xml \ - android/app/src/main/res/anim*/*.xml \ - android/app/src/main/res/drawable*/*.xml \ - android/app/src/main/res/layout*/*.xml \ - android/app/src/main/res/values/*.xml - - # FIXME - when tidy learns to not leave whitespace around, remove the line below - https://github.com/htacg/tidy-html5/issues/864 - find android/app/src/main/ -name '*.xml' -exec sed -i -e 's/[ \t]*$//' '{}' ';' -} - -# Autoformats Android XML files and returns 0 if no files were actually changed, or 1 if files were changed -function tidy-verify-xml { - tidy-up-android-xml - - if git diff --exit-code -- android/app/src/main/AndroidManifest.xml android/app/src/main/res; then - echo "Android XML files are correctly formatted" - return 0 - else - echo "android/app/src/main contains files that were changed, XML is not formatted properly" - return 1 - fi -} diff --git a/android/scripts/tidy.sh b/android/scripts/tidy.sh new file mode 100755 index 0000000000..8e0546046b --- /dev/null +++ b/android/scripts/tidy.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# CI/Developer script to format +# Relies on Tidy - https://github.com/htacg/tidy-html5 + +set -eu + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPT_DIR" + +function main { + case ${1:-""} in + format) format;; + formatAndCheckDiff) format && checkDiff;; + "") + echo "Available subcommands: format, formatAndCheckDiff" + ;; + *) + echo "Unknown parameter: $1" + exit 1 + ;; + esac +} + +# Autoformats Android XML files +function format { + tidy -xml \ + -m \ + -i \ + -w 100 \ + -utf8 \ + --quiet yes \ + --indent-attributes yes \ + --indent-spaces 4 \ + --literal-attributes yes \ + ../app/src/main/AndroidManifest.xml \ + ../app/src/main/res/anim*/*.xml \ + ../app/src/main/res/drawable*/*.xml \ + ../app/src/main/res/layout*/*.xml \ + ../app/src/main/res/values/*.xml + + # FIXME - when tidy learns to not leave whitespace around, remove the line below - https://github.com/htacg/tidy-html5/issues/864 + find ../app/src/main/ -name '*.xml' -exec sed -i -e 's/[ \t]*$//' '{}' ';' +} + +function checkDiff { + if git diff --exit-code -- ../app/src/main/AndroidManifest.xml ../app/src/main/res; then + echo "Android XML files are correctly formatted" + return 0 + else + echo "Android XML files are NOT correctly formatted" + return 1 + fi +} + +main "$@" |
