Skip to content

Commit

Permalink
perf: do not detect lean's toolchain
Browse files Browse the repository at this point in the history
use `ELAN_TOOLCHAIN` only
  • Loading branch information
tydeu authored and kim-em committed Sep 26, 2023
1 parent 232b601 commit 94f3ec8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
7 changes: 2 additions & 5 deletions src/lake/Lake/Config/Env.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ def compute (lake : LakeInstall) (lean : LeanInstall) (elan? : Option ElanInstal

/--
The preferred toolchain of the environment. May be empty.
Order is: `env.lean.toolchain` or `env.initToolchain` or Lake's `Lean.toolchain`
Tries `env.initToolchain` first and then Lake's `Lean.toolchain`.
-/
def toolchain (env : Env) : String :=
if env.lean.toolchain.isEmpty then
if env.initToolchain.isEmpty then Lean.toolchain else env.initToolchain
else
env.lean.toolchain
if env.initToolchain.isEmpty then Lean.toolchain else env.initToolchain

/--
The binary search path of the environment (i.e., `PATH`).
Expand Down
15 changes: 1 addition & 14 deletions src/lake/Lake/Config/InstallPath.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def leanSharedLib (sysroot : FilePath) :=
structure LeanInstall where
sysroot : FilePath
githash : String
toolchain : String
srcDir := sysroot / "src" / "lean"
leanLibDir := sysroot / "lib" / "lean"
includeDir := sysroot / "include"
Expand Down Expand Up @@ -158,22 +157,10 @@ Lean libraries in `<lean-sysroot>/lib/lean`, and its system libraries in
-/
def LeanInstall.get (sysroot : FilePath) : BaseIO LeanInstall := do
let githash ← getGithash
let toolchain ← getToolchain
let (cc, customCc) ← findCc
let ar ← findAr
return {sysroot, githash, toolchain, ar, cc, customCc}
return {sysroot, githash, ar, cc, customCc}
where
getToolchain := do
EIO.catchExceptions (h := fun _ => pure "") do
let child ← IO.Process.spawn {
cmd := leanExe sysroot |>.toString,
args := #["--stdin"],
stdout := .piped,
stdin := .piped,
stderr := .null
}
child.stdin.putStr "#eval IO.print Lean.toolchain"
pure <| (← child.stdout.getLine).trim
getGithash := do
EIO.catchExceptions (h := fun _ => pure "") do
let out ← IO.Process.output {
Expand Down
9 changes: 1 addition & 8 deletions src/lake/tests/env/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@ $LAKE env printenv LEAN_SRC_PATH | grep lake
$LAKE -d ../../examples/hello env printenv LEAN_SRC_PATH | grep examples/hello
$LAKE -d ../../examples/hello env printenv PATH | grep examples/hello

# Test toolchain variable is set
toolchain=`echo "#eval IO.print Lean.toolchain" | $LAKE env lean --stdin`
if [ -n "$toolchain" ]; then
test "`$LAKE env printenv ELAN_TOOLCHAIN`" = "$toolchain"
else
test "`$LAKE env env ELAN_TOOLCHAIN=foo $LAKE env printenv ELAN_TOOLCHAIN`" = foo
fi

# Test that `env` preserves the input environment for certain variables
test "`$LAKE env env ELAN_TOOLCHAIN=foo $LAKE env printenv ELAN_TOOLCHAIN`" = foo
test "`LEAN_AR=foo $LAKE env printenv LEAN_AR`" = foo
test "`LEAN_CC=foo $LAKE env printenv LEAN_CC`" = foo

Expand Down

0 comments on commit 94f3ec8

Please sign in to comment.