Skip to content

Commit df6a654

Browse files
committed
Changes on PR feedback
Check rustup on common installation paths and user's $PATH or %PATH%
1 parent 9d7f885 commit df6a654

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

gradle/setupRustAndroidLocal.gradle

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,30 @@ tasks.register("setupRustAndroidLocal") {
77
}
88

99
// Detect existence of rustup.
10-
def rustupExists = exec {
11-
commandLine("which", "rustup")
12-
ignoreExitValue true
13-
}.exitValue == 0
10+
def rustupExists = {
11+
12+
// First check common installation path
13+
def isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
14+
def home = System.getProperty("user.home")
15+
def rustupPath = isWindows
16+
? new File(home, ".cargo/bin/rustup.exe")
17+
: new File(home, ".cargo/bin/rustup")
18+
19+
if (rustupPath.exists() && rustupPath.canExecute()) {
20+
return true
21+
}
22+
23+
// If not, check on user $PATH/%PATH%
24+
try {
25+
def process = new ProcessBuilder("rustup")
26+
.redirectErrorStream(true)
27+
.start()
28+
process.waitFor()
29+
return process.exitValue() == 0
30+
} catch (IOException ignored) {
31+
return false
32+
}
33+
}()
1434

1535
if (!rustupExists) {
1636
println("rustup not found. Installing rustup...")

0 commit comments

Comments
 (0)