Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 63f575b

Browse files
committed
feat: ws.runBuild
1 parent 967c01a commit 63f575b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Diff for: Lake/Build/Monad.lean

+9
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ If a cycle is encountered, log it and then fail.
4848
-/
4949
@[inline] def RecBuildM.run (build : RecBuildM α) : BuildM α := do
5050
(·.1) <$> build.runIn {}
51+
52+
/-- Run the given build function in the Workspace's context. -/
53+
@[inline] def Workspace.runBuild (ws : Workspace) (build : BuildM α) (oldMode := false) : LogIO α := do
54+
let ctx ← mkBuildContext ws oldMode
55+
build.run ctx
56+
57+
/-- Run the given build function in the Lake monad's workspace. -/
58+
@[inline] def runBuild (build : BuildM α) (oldMode := false) : LakeT LogIO α := do
59+
(← getWorkspace).runBuild build oldMode

Diff for: Lake/CLI/Main.lean

+5-8
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ def printPaths (config : LoadConfig) (imports : List String := []) (oldMode : Bo
190190
IO.eprintln s!"Error parsing '{configFile}'. Please restart the lean server after fixing the Lake configuration file."
191191
exit 1
192192
let ws ← MainM.runLogIO (loadWorkspace config) config.verbosity
193-
let ctx ← mkBuildContext ws oldMode
194-
let dynlibs ← buildImportsAndDeps imports
195-
|>.run ctx |>.run (MonadLog.eio config.verbosity)
193+
let dynlibs ← ws.runBuild (buildImportsAndDeps imports) oldMode
194+
|>.run (MonadLog.eio config.verbosity)
196195
IO.println <| Json.compress <| toJson {
197196
oleanPath := ws.leanPath
198197
srcPath := ws.leanSrcPath
@@ -220,11 +219,10 @@ def serve (config : LoadConfig) (args : Array String) : LogIO UInt32 := do
220219
env := extraEnv
221220
}).wait
222221

223-
def exe (name : Name) (args : Array String := #[]) (oldMode : Bool := false) : LakeT LogIO UInt32 := do
222+
def exe (name : Name) (args : Array String := #[]) (oldMode := false) : LakeT LogIO UInt32 := do
224223
let ws ← getWorkspace
225224
if let some exe := ws.findLeanExe? name then
226-
let ctx ← mkBuildContext ws oldMode
227-
let exeFile ← (exe.build >>= (·.await)).run ctx
225+
let exeFile ← ws.runBuild (exe.build >>= (·.await)) oldMode
228226
env exeFile.toString args
229227
else
230228
error s!"unknown executable `{name}`"
@@ -332,8 +330,7 @@ protected def build : CliM PUnit := do
332330
let ws ← loadWorkspace config
333331
let targetSpecs ← takeArgs
334332
let specs ← parseTargetSpecs ws targetSpecs
335-
let ctx ← mkBuildContext ws opts.oldMode
336-
buildSpecs specs |>.run ctx |>.run (MonadLog.io config.verbosity)
333+
ws.runBuild (buildSpecs specs) opts.oldMode |>.run (MonadLog.io config.verbosity)
337334

338335
protected def resolveDeps : CliM PUnit := do
339336
processOptions lakeOption

0 commit comments

Comments
 (0)