Skip to content

Commit

Permalink
feat: LAKE_OVERRIDE_LEAN
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed Oct 28, 2024
1 parent df69957 commit 2f218f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 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 @@ -63,7 +63,7 @@ def compute
lake, lean, elan?,
pkgUrlMap := ← computePkgUrlMap
reservoirApiUrl := ← getUrlD "RESERVOIR_API_URL" s!"{reservoirBaseUrl}/v1"
noCache := (noCache <|> (← IO.getEnv "LAKE_NO_CACHE").bind toBool?).getD false
noCache := (noCache <|> (← IO.getEnv "LAKE_NO_CACHE").bind envToBool?).getD false
githashOverride := (← IO.getEnv "LEAN_GITHASH").getD ""
initToolchain := (← IO.getEnv "ELAN_TOOLCHAIN").getD ""
initLeanPath := ← getSearchPath "LEAN_PATH",
Expand All @@ -72,10 +72,6 @@ def compute
initPath := ← getSearchPath "PATH"
}
where
toBool? (o : String) : Option Bool :=
if ["y", "yes", "t", "true", "on", "1"].contains o.toLower then true
else if ["n", "no", "f", "false", "off", "0"].contains o.toLower then false
else none
computePkgUrlMap := do
let some urlMapStr ← IO.getEnv "LAKE_PKG_URL_MAP" | return {}
match Json.parse urlMapStr |>.bind fromJson? with
Expand Down Expand Up @@ -149,6 +145,7 @@ def noToolchainVars : Array (String × Option String) :=
#[
("ELAN_TOOLCHAIN", none),
("LAKE", none),
("LAKE_OVERRIDE_LEAN", none),
("LAKE_HOME", none),
("LEAN", none),
("LEAN_GITHASH", none),
Expand Down
21 changes: 14 additions & 7 deletions src/lake/Lake/Config/InstallPath.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import Lake.Config.Defaults
open System
namespace Lake

/-- Convert the string value of an environment variable to a boolean. -/
def envToBool? (o : String) : Option Bool :=
if ["y", "yes", "t", "true", "on", "1"].contains o.toLower then true
else if ["n", "no", "f", "false", "off", "0"].contains o.toLower then false
else none

/-! ## Data Structures -/

/-- Information about the local Elan setup. -/
Expand Down Expand Up @@ -296,7 +302,8 @@ Then it attempts to detect if Lake and Lean are part of a single installation
where the `lake` executable is co-located with the `lean` executable (i.e., they
are in the same directory). If Lean and Lake are not co-located, Lake will
attempt to find the their installations separately by calling
`findLeanInstall?` and `findLakeInstall?`.
`findLeanInstall?` and `findLakeInstall?`. This behavior can be forced even
when Lake is co-located by setting `LAKE_OVERRIDE_LEAN` to true.
When co-located, Lake will assume that Lean and Lake's binaries are located in
`<sysroot>/bin`, their Lean libraries in `<sysroot>/lib/lean`, Lean's source files
Expand All @@ -305,9 +312,9 @@ following the pattern of a regular Lean toolchain.
-/
def findInstall? : BaseIO (Option ElanInstall × Option LeanInstall × Option LakeInstall) := do
let elan? ← findElanInstall?
if let some home ← findLakeLeanJointHome? then
let lean ← LeanInstall.get home (collocated := true)
let lake := LakeInstall.ofLean lean
return (elan?, lean, lake)
else
return (elan?, ← findLeanInstall?, ← findLakeInstall?)
unless (← IO.getEnv "LAKE_OVERRIDE_LEAN").bind envToBool? |>.getD false do
if let some home ← findLakeLeanJointHome? then
let lean ← LeanInstall.get home (collocated := true)
let lake := LakeInstall.ofLean lean
return (elan?, lean, lake)
return (elan?, ← findLeanInstall?, ← findLakeInstall?)

0 comments on commit 2f218f8

Please sign in to comment.