lean4-htt/Lake/Build/Monad.lean

36 lines
1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2021 Mac Malone. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mac Malone
-/
import Lake.Config.Monad
import Lake.Build.Context
open System
open Lean (Name)
namespace Lake
deriving instance Inhabited for BuildContext
def mkBuildContext (ws : Workspace) (lean : LeanInstall) (lake : LakeInstall) : IO BuildContext := do
let leanTrace :=
if lean.githash.isEmpty then
mixTrace (← computeTrace lean.lean) (← computeTrace lean.sharedLib)
else
Hash.ofString lean.githash
return {opaqueWs := ws, lean, lake, leanTrace}
instance [Monad m] : MonadLake (BuildT m) where
getLeanInstall := (·.lean) <$> read
getLakeInstall := (·.lake) <$> read
getWorkspace := (·.workspace) <$> read
@[inline] def getLeanTrace : BuildM BuildTrace :=
(·.leanTrace) <$> read
def failOnBuildCycle [ToString k] : Except (List k) α → BuildM α
| Except.ok a => a
| Except.error cycle => do
let cycle := cycle.map (s!" {·}")
error s!"build cycle detected:\n{"\n".intercalate cycle}"