From abd98a13781146de087d800218ee4a098d176a40 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Sat, 25 Nov 2023 18:04:19 +0800 Subject: [PATCH] Replace Python script with Unix Shell and Powershell script. Fixes #246. --- love/src/jni/Android.mk | 15 ++++++++++++--- love/src/jni/detect_androidapi.ps1 | 13 +++++++++++++ love/src/jni/detect_androidapi.py | 17 ----------------- love/src/jni/detect_androidapi.sh | 15 +++++++++++++++ love/src/jni/detect_love.ps1 | 7 +++++++ love/src/jni/detect_love.py | 14 -------------- love/src/jni/detect_love.sh | 7 +++++++ love/src/jni/detect_ndkrel.ps1 | 15 +++++++++++++++ love/src/jni/detect_ndkrel.py | 20 -------------------- love/src/jni/detect_ndkrel.sh | 15 +++++++++++++++ 10 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 love/src/jni/detect_androidapi.ps1 delete mode 100644 love/src/jni/detect_androidapi.py create mode 100755 love/src/jni/detect_androidapi.sh create mode 100644 love/src/jni/detect_love.ps1 delete mode 100644 love/src/jni/detect_love.py create mode 100755 love/src/jni/detect_love.sh create mode 100644 love/src/jni/detect_ndkrel.ps1 delete mode 100644 love/src/jni/detect_ndkrel.py create mode 100755 love/src/jni/detect_ndkrel.sh diff --git a/love/src/jni/Android.mk b/love/src/jni/Android.mk index 1163c25b3..77f88956c 100644 --- a/love/src/jni/Android.mk +++ b/love/src/jni/Android.mk @@ -1,7 +1,16 @@ LOVE_JNI_DIR := $(call my-dir) -IS_NDK_R17 := $(shell python ${LOVE_JNI_DIR}/detect_ndkrel.py $(NDK_ROOT)/source.properties 17) -IS_ANDROID_21 := $(shell python ${LOVE_JNI_DIR}/detect_androidapi.py $(TARGET_PLATFORM) 21) -HAS_LOVE := $(shell python ${LOVE_JNI_DIR}/detect_love.py ${LOVE_JNI_DIR}) + +ifeq ($(OS),Windows_NT) + SHELL_EXECUTOR := powershell -executionpolicy unrestricted + SCRIPT_EXTENSION := ps1 +else + SHELL_EXECUTOR := sh + SCRIPT_EXTENSION := sh +endif + +IS_NDK_R17 := $(shell ${SHELL_EXECUTOR} ${LOVE_JNI_DIR}/detect_ndkrel.${SCRIPT_EXTENSION} $(NDK_ROOT)/source.properties 17) +IS_ANDROID_21 := $(shell ${SHELL_EXECUTOR} ${LOVE_JNI_DIR}/detect_androidapi.${SCRIPT_EXTENSION} $(TARGET_PLATFORM) 21) +HAS_LOVE := $(shell ${SHELL_EXECUTOR} ${LOVE_JNI_DIR}/detect_love.${SCRIPT_EXTENSION} ${LOVE_JNI_DIR}) ifneq (${HAS_LOVE},yes) $(error Missing LOVE. Make sure to initialize the submodule correctly!) diff --git a/love/src/jni/detect_androidapi.ps1 b/love/src/jni/detect_androidapi.ps1 new file mode 100644 index 000000000..35e4d881e --- /dev/null +++ b/love/src/jni/detect_androidapi.ps1 @@ -0,0 +1,13 @@ +if ($args.Length -gt 1) { + # $args[0] = android-%d + # $args[1] = %d + $found = $args[0] -match 'android-(\d+)' + + if ($found -and $matches[1] -ge $args[1]) { + Write-Output "yes" + } else { + Write-Output "no" + } +} else { + Write-Output "unknown" +} diff --git a/love/src/jni/detect_androidapi.py b/love/src/jni/detect_androidapi.py deleted file mode 100644 index 80c06890f..000000000 --- a/love/src/jni/detect_androidapi.py +++ /dev/null @@ -1,17 +0,0 @@ -import sys -import re - -def main(argv): - if len(argv) > 1: - # argv[0] = android-%d - # argv[1] = %d - matches = re.findall("android-(\d+)", argv[0]) - if len(matches) >= 1 and int(matches[0]) >= int(argv[1]): - print("yes") - else: - print("no") - else: - print("unknown") - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/love/src/jni/detect_androidapi.sh b/love/src/jni/detect_androidapi.sh new file mode 100755 index 000000000..d58632887 --- /dev/null +++ b/love/src/jni/detect_androidapi.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ $# -gt 1 ]; then + # $1 = android-%d + # $2 = %d + version=$(echo $1 | grep -o 'android-[0-9]*' | grep -o '[0-9]*') + + if [ $version -ge $2 ]; then + echo "yes" + else + echo "no" + fi +else + echo "unknown" +fi diff --git a/love/src/jni/detect_love.ps1 b/love/src/jni/detect_love.ps1 new file mode 100644 index 000000000..bf811f635 --- /dev/null +++ b/love/src/jni/detect_love.ps1 @@ -0,0 +1,7 @@ +$path = $args[0] + +if (Test-Path -Path "$path/love/Android.mk") { + Write-Output "yes" +} else { + Write-Output "no" +} diff --git a/love/src/jni/detect_love.py b/love/src/jni/detect_love.py deleted file mode 100644 index 8fc93dc9e..000000000 --- a/love/src/jni/detect_love.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys -from os import path - -def main(argv): - if len(argv) > 0: - if path.isdir(argv[0] + "/love") and path.isfile(argv[0] + "/love/Android.mk"): - print("yes") - else: - print("no") - else: - print("no") - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/love/src/jni/detect_love.sh b/love/src/jni/detect_love.sh new file mode 100755 index 000000000..1cc8ebafb --- /dev/null +++ b/love/src/jni/detect_love.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ -d "$1/love" ] && [ -f "$1/love/Android.mk" ]; then + echo "yes" +else + echo "no" +fi diff --git a/love/src/jni/detect_ndkrel.ps1 b/love/src/jni/detect_ndkrel.ps1 new file mode 100644 index 000000000..80223944c --- /dev/null +++ b/love/src/jni/detect_ndkrel.ps1 @@ -0,0 +1,15 @@ +# $args[0] = source.properties +# $args[1] = NDK version to be checked + +if ($args.Count -ne 2) { + Write-Output "unknown" + exit 1 +} + +$ndkVersion = (Select-String -Pattern "Pkg.Revision = (\d+)" -Path $args[0] | ForEach-Object { $_.Matches[0].Groups[1].Value }) + +if ($ndkVersion -ge $args[1]) { + Write-Output "yes" +} else { + Write-Output "no" +} diff --git a/love/src/jni/detect_ndkrel.py b/love/src/jni/detect_ndkrel.py deleted file mode 100644 index df96a312d..000000000 --- a/love/src/jni/detect_ndkrel.py +++ /dev/null @@ -1,20 +0,0 @@ -import sys -import re - -def main(argv): - if len(argv) > 1: - # argv[0] = source.properties - # argv[1] = desired NDK version - f = open(argv[0], "r") - contents = f.read() - f.close() - matches = re.findall("Pkg.Revision = (\d+)", contents) - if len(matches) >= 1 and int(matches[0]) >= int(argv[1]): - print("yes") - else: - print("no") - else: - print("unknown") - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/love/src/jni/detect_ndkrel.sh b/love/src/jni/detect_ndkrel.sh new file mode 100755 index 000000000..cbb7aa7a2 --- /dev/null +++ b/love/src/jni/detect_ndkrel.sh @@ -0,0 +1,15 @@ +# $1 = source.properties +# $2 = NDK version to be checked + +if [ $# -ne 2 ]; then + echo "unknown" + exit 1 +fi + +ndkVersion=$(grep -Po 'Pkg.Revision = (\d+)' "$1" | grep -Po '\d+') + +if [ "$ndkVersion" -ge "$2" ]; then + echo "yes" +else + echo "no" +fi