-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlakefile.lean
212 lines (179 loc) · 7.43 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import Lake
open Lake DSL
open System (FilePath)
-- Minimal compatibility infrastructure to make this file cross-compatible with more Lean/Lake versions
namespace Compat
open Lean Elab Command in
#eval show CommandElabM Unit from do
let env ← getEnv
let useOldBind := mkIdent `useOldBind
elabCommand <| ← `(def $useOldBind := !$(quote <| env.contains `Lake.buildFileUnlessUpToDate'))
-- Compatibility shims for older Lake (where logging was manual) and
-- newer Lake (where it isn't). Necessary from Lean 4.8.0 and up.
open Lean Elab Command in
#eval show CommandElabM Unit from do
let env ← getEnv
let m := mkIdent `m
if !env.contains `Lake.logStep || Linter.isDeprecated env `Lake.logStep then
elabCommand <| ← `(def $(mkIdent `logStep) [Pure $m] (message : String) : $m Unit := pure ())
else
elabCommand <| ← `(def $(mkIdent `logStep) := @Lake.logStep)
if !env.contains `Lake.logInfo || Linter.isDeprecated env `Lake.logStep then
elabCommand <| ← `(def $(mkIdent `logInfo) [Pure $m] (message : String) : $m Unit := pure ())
else
elabCommand <| ← `(def $(mkIdent `logInfo) := @Lake.logInfo)
open Lean Elab Command Term in
#eval show CommandElabM Unit from do
let ty ← liftTermElabM do
let e ← elabTerm (← `(fun (lib : Lake.LeanLib) => lib.modules.fetch)) none
let t ← Meta.inferType e
Meta.ppExpr t
let ty := toString ty
if ty == "LeanLib → FetchM (Job (Array Lake.Module))" then
elabCommand <| ← `(def $(mkIdent `getMods) (lib : LeanLib) : FetchM (Array Lake.Module) := do return ← (← lib.modules.fetch).await)
else if ty == "LeanLib → FetchM (Array Lake.Module)" then
elabCommand <| ← `(def $(mkIdent `getMods) (lib : LeanLib) : FetchM (Array Lake.Module) := lib.modules.fetch)
else if ty == "LeanLib → IndexBuildM (Array Lake.Module)" then
elabCommand <| ← `(def $(mkIdent `getMods) (lib : LeanLib) : IndexBuildM (Array Lake.Module) := lib.modules.fetch)
else throwError "Didn't recognize type of lib.modules.fetch to define compatibility shim for 'getMods': {ty}"
end Compat
-- End compatibility infrastructure
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
meta if Compat.useOldBind then
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
Compat.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)
else
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.bindM fun exeFile =>
modJob.mapM fun _oleanPath => do
buildFileUnlessUpToDate' (text := true) hlFile <|
proc {
cmd := exeFile.toString
args := #[mod.name.toString, hlFile.toString]
env := ← getAugmentedEnv
}
pure hlFile
meta if Compat.useOldBind then
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
Compat.logStep s!"Exporting highlighted example JSON for '{mod.name}'"
proc {
cmd := exeFile.toString
args := #[mod.name.toString, hlFile.toString]
env := ← getAugmentedEnv
}
pure (hlFile, trace)
else
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.bindM fun exeFile =>
modJob.mapM fun _oleanPath => do
buildFileUnlessUpToDate' (text := true) hlFile do
proc {
cmd := exeFile.toString
args := #[mod.name.toString, hlFile.toString]
env := ← getAugmentedEnv
}
pure hlFile
library_facet highlighted lib : FilePath := do
let ws ← getWorkspace
let mods ← Compat.getMods lib
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 ← Compat.getMods lib
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
Compat.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
Compat.logInfo s!"Highlighted code written to '{hlDir}'"
pure (hlDir, trace)