Skip to content

Commit fadd842

Browse files
authored
Fix the compile error #2930 (#2935)
Make checking python version code compatible with windows and *nix Redefine the python version detection code
1 parent 9f6b3a4 commit fadd842

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

core/build.gradle.kts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import com.android.build.gradle.internal.tasks.factory.dependsOn
2+
import org.jetbrains.kotlin.cli.common.ExitCode
3+
import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError
24

35
plugins {
46
id("com.android.library")
@@ -51,9 +53,24 @@ cargo {
5153
"aead-cipher-2022",
5254
))
5355
exec = { spec, toolchain ->
54-
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3")
55-
spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py")
56-
spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so")
56+
run {
57+
try {
58+
Runtime.getRuntime().exec("python3 -V >/dev/null 2>&1")
59+
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3")
60+
project.logger.lifecycle("Python 3 detected.")
61+
} catch (e: java.io.IOException) {
62+
project.logger.lifecycle("No python 3 detected.")
63+
try {
64+
Runtime.getRuntime().exec("python -V >/dev/null 2>&1")
65+
spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python")
66+
project.logger.lifecycle("Python detected.")
67+
} catch (e: java.io.IOException) {
68+
throw GradleException("No any python version detected. You should install the python first to compile project.")
69+
}
70+
}
71+
spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py")
72+
spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so")
73+
}
5774
}
5875
}
5976

0 commit comments

Comments
 (0)