Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ The plugin invokes Python, Cargo and Rustc. In order of preference, the plugin
1. the value of `cargo { pythonCommand = "..." }`, if non-empty
1. `rust.pythonCommand` in `${rootDir}/local.properties`
1. the environment variable `RUST_ANDROID_GRADLE_PYTHON_COMMAND`
1. the default, `python`
1. the default: `python3` if it is on the `PATH`, otherwise `python` (always `python` on Windows)
Comment thread
segunfamisa marked this conversation as resolved.
Resolved

In order of preference, the plugin determines what command to invoke for Cargo by:

Expand Down
11 changes: 10 additions & 1 deletion plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,19 @@ open class CargoExtension {
return if (!field.isEmpty()) {
field
} else {
getProperty("rust.pythonCommand", "RUST_ANDROID_GRADLE_PYTHON_COMMAND") ?: "python"
getProperty("rust.pythonCommand", "RUST_ANDROID_GRADLE_PYTHON_COMMAND") ?: defaultPythonCommand()
}
}

private fun defaultPythonCommand(): String {
if (System.getProperty("os.name").startsWith("Windows")) {
return "python"
}
Comment thread
segunfamisa marked this conversation as resolved.
Resolved
val path = System.getenv("PATH") ?: return "python"
val hasPython3 = path.split(File.pathSeparator).any { File(it, "python3").canExecute() }
return if (hasPython3) "python3" else "python"
}

// Required so that we can parse the default triple out of `rustc --version --verbose`. Sadly,
// there seems to be no way to get this information out of cargo directly. Failure to locate
// this isn't fatal, however.
Expand Down
Loading