-
Notifications
You must be signed in to change notification settings - Fork 2
/
lakefile.lean
139 lines (115 loc) · 4.42 KB
/
lakefile.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import Lake
open Lake DSL
open System (FilePath)
package «subverso» where
precompileModules := true
-- add package configuration options here
lean_lib SubVersoCompat where
srcDir := "src/compat"
roots := #[`SubVerso.Compat]
lean_lib SubVersoHighlighting where
srcDir := "src/highlighting"
roots := #[`SubVerso.Highlighting]
lean_lib SubVersoExamples where
srcDir := "src/examples"
roots := #[`SubVerso.Examples]
@[default_target]
lean_exe «subverso-tests» where
root := `Tests
supportInterpreter := true
@[default_target]
lean_exe «subverso-internal-tests» where
root := `InternalTests
supportInterpreter := true
@[default_target]
lean_exe «subverso-extract» where
root := `Extract
supportInterpreter := true
@[default_target]
lean_exe «subverso-extract-mod» where
root := `ExtractModule
supportInterpreter := true
-- Compatibility shims for older Lake (where logging was manual) and
-- newer Lake (where it isn't). Necessary from Lean 4.8.0 and up.
section
open Lean Elab Command
#eval show CommandElabM Unit from do
let env ← getEnv
if !env.contains `Lake.logStep then
elabCommand <| ← `(def $(mkIdent `logStep) [Pure $(mkIdent `m)] (message : String) : $(mkIdent `m) Unit := pure ())
if !env.contains `Lake.logInfo then
elabCommand <| ← `(def $(mkIdent `logInfo) [Pure $(mkIdent `m)] (message : String) : $(mkIdent `m) Unit := pure ())
end
module_facet highlighted mod : FilePath := do
let ws ← getWorkspace
let some extract ← findLeanExe? `«subverso-extract-mod»
| error "The subverso-extract-mod executable was not found"
let exeJob ← extract.exe.fetch
let modJob ← mod.olean.fetch
let buildDir := ws.root.buildDir
let hlFile := mod.filePath (buildDir / "highlighted") "json"
exeJob.bindAsync fun exeFile exeTrace =>
modJob.bindSync fun _oleanPath modTrace => do
let depTrace := mixTrace exeTrace modTrace
let trace ← buildFileUnlessUpToDate hlFile depTrace do
logStep s!"Exporting highlighted source file JSON for '{mod.name}'"
proc {
cmd := exeFile.toString
args := #[mod.name.toString, hlFile.toString]
env := ← getAugmentedEnv
}
pure (hlFile, trace)
module_facet examples mod : FilePath := do
let ws ← getWorkspace
let some extract ← findLeanExe? `«subverso-extract»
| error "The subverso-extract executable was not found"
let exeJob ← extract.exe.fetch
let modJob ← mod.olean.fetch
let buildDir := ws.root.buildDir
let hlFile := mod.filePath (buildDir / "examples") "json"
exeJob.bindAsync fun exeFile exeTrace =>
modJob.bindSync fun _oleanPath modTrace => do
let depTrace := mixTrace exeTrace modTrace
let trace ← buildFileUnlessUpToDate hlFile depTrace do
logStep s!"Exporting highlighted example JSON for '{mod.name}'"
proc {
cmd := exeFile.toString
args := #[mod.name.toString, hlFile.toString]
env := ← getAugmentedEnv
}
pure (hlFile, trace)
library_facet highlighted lib : FilePath := do
let ws ← getWorkspace
let mods ← lib.modules.fetch
let moduleJobs ← BuildJob.mixArray <| ← mods.mapM (fetch <| ·.facet `highlighted)
let buildDir := ws.root.buildDir
let hlDir := buildDir / "highlighted"
moduleJobs.bindSync fun () trace => do
pure (hlDir, trace)
library_facet examples lib : FilePath := do
let ws ← getWorkspace
let mods ← lib.modules.fetch
let moduleJobs ← BuildJob.mixArray <| ← mods.mapM (fetch <| ·.facet `examples)
let buildDir := ws.root.buildDir
let hlDir := buildDir / "examples"
moduleJobs.bindSync fun () trace => do
pure (hlDir, trace)
package_facet highlighted pkg : FilePath := do
let ws ← getWorkspace
let libs := pkg.leanLibs
let exes := pkg.leanExes.map (·.toLeanLib)
let libJobs ← BuildJob.mixArray <| ← (libs ++ exes).mapM (fetch <| ·.facet `highlighted)
let buildDir := ws.root.buildDir
let hlDir := buildDir / "highlighted"
libJobs.bindSync fun () trace => do
logInfo s!"Highlighted code written to '{hlDir}'"
pure (hlDir, trace)
package_facet examples pkg : FilePath := do
let ws ← getWorkspace
let libs := pkg.leanLibs
let libJobs ← BuildJob.mixArray <| ← libs.mapM (fetch <| ·.facet `examples)
let buildDir := ws.root.buildDir
let hlDir := buildDir / "examples"
libJobs.bindSync fun () trace => do
logInfo s!"Highlighted code written to '{hlDir}'"
pure (hlDir, trace)