switch toml parsers

This commit is contained in:
j-hc 2024-11-16 16:51:14 +03:00
parent 828160801d
commit 9b696e8fbc
No known key found for this signature in database
GPG Key ID: CDF97F1DBFE904CD
6 changed files with 34 additions and 22 deletions

View File

@ -13,7 +13,7 @@ There exists an example below with all defaults shown and all the keys explicitl
**All keys are optional** (except download urls) and are assigned to their default values if not set explicitly. **All keys are optional** (except download urls) and are assigned to their default values if not set explicitly.
```toml ```toml
parallel-jobs = 1 # amount of cores to use for parallel patching, if not set nproc is used parallel-jobs = 1 # amount of cores to use for parallel patching, if not set $(nproc) is used
compression-level = 9 # module zip compression level compression-level = 9 # module zip compression level
remove-rv-integrations-checks = true # remove checks from the revanced integrations remove-rv-integrations-checks = true # remove checks from the revanced integrations
@ -23,18 +23,29 @@ cli-source = "j-hc/revanced-cli" # where to fetch cli from. default: "j-hc/revan
rv-brand = "ReVanced Extended" # rebrand from 'ReVanced' to something different. default: "ReVanced" rv-brand = "ReVanced Extended" # rebrand from 'ReVanced' to something different. default: "ReVanced"
patches-version = "v2.160.0" # 'latest', 'dev', or a version number. default: "latest" patches-version = "v2.160.0" # 'latest', 'dev', or a version number. default: "latest"
cli-version = "v5.0.0" # 'latest', 'dev', or a version number. default: "latest"
[Some-App] [Some-App]
app-name = "SomeApp" # if set, release name becomes SomeApp instead of Some-App. default is same as table name, which is 'Some-App' here. app-name = "SomeApp" # if set, release name becomes SomeApp instead of Some-App. default is same as table name, which is 'Some-App' here.
enabled = true # whether to build the app. default: true enabled = true # whether to build the app. default: true
patcher-args = "-Okey=value" # optional args to be passed to cli. can be used to set patch options
# optional args to be passed to cli. can be used to set patch options
# multiline strings in the config is supported
patcher-args = """\
-OdarkThemeBackgroundColor=#FF0F0F0F \
-Oanother-option=value \
"""
version = "auto" # 'auto', 'latest', 'beta' or a version number (e.g. '17.40.41'). default: auto version = "auto" # 'auto', 'latest', 'beta' or a version number (e.g. '17.40.41'). default: auto
# 'auto' option gets the latest possible version supported by all the included patches # 'auto' option gets the latest possible version supported by all the included patches
# 'latest' gets the latest stable without checking patches support. 'beta' gets the latest beta/alpha # 'latest' gets the latest stable without checking patches support. 'beta' gets the latest beta/alpha
include-stock = true # includes stock apk in the module. default: true include-stock = true # includes stock apk in the module. default: true
build-mode = "apk" # 'both', 'apk' or 'module'. default: apk build-mode = "apk" # 'both', 'apk' or 'module'. default: apk
excluded-patches = "'Some Patch' 'Some Other Patch'" # whitespace seperated list of patches to exclude. default: "" (empty) # whitespace seperated list of patches to exclude. default: ""
included-patches = "'Patch something'" # whitespace seperated list of patches to include, all default patches are included by default. default: "" (empty) excluded-patches = """\
'Some Patch' \
'Some Other Patch' \
"""
included-patches = "'Some Patch'" # whitespace seperated list of patches to include, all default patches are included by default. default: ""
exclusive-patches = false # exclude all patches by default. default: false exclusive-patches = false # exclude all patches by default. default: false
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app"
uptodown-dlurl = "https://spotify.en.uptodown.com/android" uptodown-dlurl = "https://spotify.en.uptodown.com/android"

BIN
bin/toml/toml-arm Executable file

Binary file not shown.

BIN
bin/toml/toml-arm64 Executable file

Binary file not shown.

BIN
bin/toml/toml-x86_64 Executable file

Binary file not shown.

View File

@ -10,12 +10,13 @@ if [ "${1-}" = "clean" ]; then
fi fi
source utils.sh source utils.sh
get_prebuilts
vtf() { if ! isoneof "${1}" "true" "false"; then abort "ERROR: '${1}' is not a valid option for '${2}': only true or false is allowed"; fi; } vtf() { if ! isoneof "${1}" "true" "false"; then abort "ERROR: '${1}' is not a valid option for '${2}': only true or false is allowed"; fi; }
toml_prep "$(cat 2>/dev/null "${1:-config.toml}")" || abort "could not find config file '${1:-config.toml}'\n\tUsage: $0 <config.toml>"
# -- Main config -- # -- Main config --
main_config_t=$(toml_get_table "") toml_prep "${1:-config.toml}" || abort "could not find config file '${1:-config.toml}'\n\tUsage: $0 <config.toml>"
main_config_t=$(toml_get_table_main)
COMPRESSION_LEVEL=$(toml_get "$main_config_t" compression-level) || COMPRESSION_LEVEL="9" COMPRESSION_LEVEL=$(toml_get "$main_config_t" compression-level) || COMPRESSION_LEVEL="9"
if ! PARALLEL_JOBS=$(toml_get "$main_config_t" parallel-jobs); then if ! PARALLEL_JOBS=$(toml_get "$main_config_t" parallel-jobs); then
if [ "$OS" = Android ]; then PARALLEL_JOBS=1; else PARALLEL_JOBS=$(nproc); fi if [ "$OS" = Android ]; then PARALLEL_JOBS=1; else PARALLEL_JOBS=$(nproc); fi
@ -54,14 +55,13 @@ if [ "$(echo "$TEMP_DIR"/*-rv/changelog.md)" ]; then
: >"$TEMP_DIR"/*-rv/changelog.md || : : >"$TEMP_DIR"/*-rv/changelog.md || :
fi fi
get_prebuilts
declare -A cliriplib declare -A cliriplib
idx=0 idx=0
for table_name in $(toml_get_table_names); do for table_name in $(toml_get_table_names); do
if [ -z "$table_name" ]; then continue; fi if [ -z "$table_name" ]; then continue; fi
t=$(toml_get_table "$table_name") t=$(toml_get_table "$table_name")
enabled=$(toml_get "$t" enabled) && vtf "$enabled" "enabled" || enabled=true enabled=$(toml_get "$t" enabled) || enabled=true
vtf "$enabled" "enabled"
if [ "$enabled" = false ]; then continue; fi if [ "$enabled" = false ]; then continue; fi
if ((idx >= PARALLEL_JOBS)); then if ((idx >= PARALLEL_JOBS)); then
wait -n wait -n

View File

@ -10,19 +10,19 @@ if [ "${GITHUB_TOKEN-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')} NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
OS=$(uname -o) OS=$(uname -o)
toml_prep() { __TOML__=$(tr -d '\t\r' <<<"$1" | tr "'" '"' | grep -o '^[^#]*' | grep -v '^$' | sed -r 's/(\".*\")|\s*/\1/g; 1i []'); } toml_prep() { __TOML__=$($TOML get "$1" .); }
toml_get_table_names() { toml_get_table_names() { jq -r -e 'to_entries[] | select(.value | type == "object") | .key' <<<"$__TOML__"; }
local tn toml_get_table_main() { jq -r -e 'to_entries | map(select(.value | type != "object")) | from_entries' <<<"$__TOML__"; }
tn=$(grep -x '\[.*\]' <<<"$__TOML__" | tr -d '[]') || return 1 toml_get_table() { jq -r -e ".\"${1}\"" <<<"$__TOML__"; }
if [ "$(sort <<<"$tn" | uniq -u | wc -l)" != "$(wc -l <<<"$tn")" ]; then
abort "ERROR: Duplicate tables in TOML"
fi
echo "$tn"
}
toml_get_table() { sed -n "/\[${1}]/,/^\[.*]$/p" <<<"$__TOML__" | sed '${/^\[/d;}'; }
toml_get() { toml_get() {
local table=$1 key=$2 val local op
val=$(grep -m 1 "^${key}=" <<<"$table") && sed -e "s/^\"//; s/\"$//" <<<"${val#*=}" op=$(jq -r ".\"${2}\" | values" <<<"$1")
if [ "$op" ]; then
op="${op#"${op%%[![:space:]]*}"}"
op="${op%"${op##*[![:space:]]}"}"
op=${op//"'"/'"'}
echo "$op"
else return 1; fi
} }
pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; } pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }
@ -117,8 +117,10 @@ get_prebuilts() {
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
HTMLQ="${BIN_DIR}/htmlq/htmlq-${arch}" HTMLQ="${BIN_DIR}/htmlq/htmlq-${arch}"
AAPT2="${BIN_DIR}/aapt2/aapt2-${arch}" AAPT2="${BIN_DIR}/aapt2/aapt2-${arch}"
TOML="${BIN_DIR}/toml/toml-${arch}"
else else
HTMLQ="${BIN_DIR}/htmlq/htmlq-x86_64" HTMLQ="${BIN_DIR}/htmlq/htmlq-x86_64"
TOML="${BIN_DIR}/toml/toml-x86_64"
fi fi
mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/x86 ${MODULE_TEMPLATE_DIR}/bin/x64 mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/x86 ${MODULE_TEMPLATE_DIR}/bin/x64
gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a" gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a"
@ -404,7 +406,6 @@ get_archive_pkg_name() { echo "$__ARCHIVE_PKG_NAME__"; }
patch_apk() { patch_apk() {
local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5 local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5
# TODO: --options
local cmd="java -jar $rv_cli_jar patch $stock_input --purge -o $patched_apk -p $rv_patches_jar --keystore=ks.keystore \ local cmd="java -jar $rv_cli_jar patch $stock_input --purge -o $patched_apk -p $rv_patches_jar --keystore=ks.keystore \
--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc $patcher_args" --keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc $patcher_args"
if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi