From 1fdeefe3130ccb3f859f1780eaf49731b3bfdd94 Mon Sep 17 00:00:00 2001 From: dev4u Date: Sun, 18 Sep 2022 00:51:22 +0800 Subject: [PATCH 1/4] Fix the compile error #2930 --- core/build.gradle.kts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index af9ab5248b..fb3cf94c6b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -51,9 +51,17 @@ cargo { "aead-cipher-2022", )) exec = { spec, toolchain -> - spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") - spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") - spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") + run { + val process: Process = Runtime.getRuntime().exec("command -v python3 >/dev/null 2>&1 && echo python3 installed") + val output = process.inputStream.bufferedReader().lineSequence().joinToString("\n") + if (output.contains("python3")) { + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") + } else { + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") + } + spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") + spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") + } } } From b20d1eb68e82d1ecf7ac7a5192e04b89ce0af249 Mon Sep 17 00:00:00 2001 From: dev4u Date: Sun, 18 Sep 2022 00:51:22 +0800 Subject: [PATCH 2/4] Fix the compile error #2930 --- core/build.gradle.kts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index af9ab5248b..b678d647d0 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -51,9 +51,17 @@ cargo { "aead-cipher-2022", )) exec = { spec, toolchain -> - spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") - spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") - spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") + run { + val process: Process = Runtime.getRuntime().exec("which python3 >/dev/null 2>&1 && echo python3 installed") + val output = process.inputStream.bufferedReader().lineSequence().joinToString("\n") + if (output.contains("python3")) { + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") + } else { + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") + } + spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") + spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") + } } } From 474d162f88176ff65223c5850249e81ee8ac6b72 Mon Sep 17 00:00:00 2001 From: dev4u Date: Sun, 18 Sep 2022 12:00:51 +0800 Subject: [PATCH 3/4] Make checking python version code compatible with windows and *nix --- core/build.gradle.kts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index b678d647d0..798235ce70 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -52,11 +52,10 @@ cargo { )) exec = { spec, toolchain -> run { - val process: Process = Runtime.getRuntime().exec("which python3 >/dev/null 2>&1 && echo python3 installed") - val output = process.inputStream.bufferedReader().lineSequence().joinToString("\n") - if (output.contains("python3")) { + try { + Runtime.getRuntime().exec("python3 -V >/dev/null 2>&1") spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") - } else { + } catch (e: java.io.IOException) { spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") } spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") From 8786d49876c9bb3156d0fa7bca2aede0d363a416 Mon Sep 17 00:00:00 2001 From: dev4u Date: Mon, 19 Sep 2022 22:55:25 +0800 Subject: [PATCH 4/4] Redefine the python version detection code --- core/build.gradle.kts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 798235ce70..3bbacb17b5 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,4 +1,6 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError plugins { id("com.android.library") @@ -55,8 +57,16 @@ cargo { try { Runtime.getRuntime().exec("python3 -V >/dev/null 2>&1") spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") + project.logger.lifecycle("Python 3 detected.") } catch (e: java.io.IOException) { - spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") + project.logger.lifecycle("No python 3 detected.") + try { + Runtime.getRuntime().exec("python -V >/dev/null 2>&1") + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") + project.logger.lifecycle("Python detected.") + } catch (e: java.io.IOException) { + throw GradleException("No any python version detected. You should install the python first to compile project.") + } } spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so")