-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbum.lean
More file actions
83 lines (78 loc) · 2.75 KB
/
Copy pathbum.lean
File metadata and controls
83 lines (78 loc) · 2.75 KB
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
import bum.io
def getTools (conf : Project) : IO Tools := do
let leanHomeOpt ← IO.getEnv "LEAN_HOME"
match leanHomeOpt with
| some leanHome => do
discard (IO.setEnv "LEAN_PATH" "")
addToLeanPath [ leanHome, "lib", "lean" ].joinPath
let src ← IO.FS.realPath conf.srcDir
addToLeanPath src
discard (IO.Process.run { cmd := "mkdir", args := #["-p", toString conf.depsDir]})
pure ⟨leanHome, [ leanHome, "bin", "lean" ].joinPath, "ar", "c++"⟩
| none => throw (IO.Error.userError "Environment variable LEAN_HOME not found")
def eval : Command → IO Unit
| Command.start => do
let conf ← readConf config
match conf.build with
| BuildType.executable => do
let name := conf.getBinary
exec { cmd := toString (workdir / name) }
| BuildType.library =>
IO.println "Cannot start a library"
| Command.clean scale => do
let conf ← readConf config
(match scale with
| Scale.current => clean
| Scale.total => cleanRecur) conf
| Command.compile force? => do
let conf ← readConf config
let tools ← getTools conf
build tools conf force?
| Command.olean scale force? => do
let conf ← readConf config
let tools ← getTools conf
match scale with
| Scale.current => do
discard (setLeanPath conf)
let force ← IO.mkRef force?
olean force tools conf
| Scale.total => oleanRecur tools conf force?
| Command.deps => do
let conf ← readConf config
let deps ← resolveDeps conf true
let toPrint :=
List.map (String.append "==> dependency: " ∘
Project.name ∘ Prod.snd) deps
if toPrint ≠ [] then
IO.println (String.intercalate "\n" toPrint)
else pure ()
| Command.help => IO.println Command.helpString
| Command.app app => do
exec (Repo.cmd "." app.toRepo)
IO.Process.run { cmd := "rm", args := #["-rf", ".git"] }
|> discard
| Command.gitignore =>
"“gitignore” can only be called individually: bum gitignore"
|> IO.userError |> throw
| Command.leanPath =>
"“lean-path” can only be called individually: bum lean-path"
|> IO.userError |> throw
| Command.nope => pure ()
def evalList : List Command → IO Unit
| [] => eval Command.help
| [Command.nope, Command.leanPath] => do
let conf ← readConf config
let src ← IO.FS.realPath conf.srcDir
println! "export LEAN_PATH=$LEAN_PATH:{src}"
| [Command.nope, Command.gitignore] => do
let conf ← readConf config
List.filter Source.cpp? conf.files
|> List.map (λ file => s!"!{file.asCpp}")
|> (["*.olean", "*.o", "*.a", "*.cpp", [".", toString conf.getBinary].joinPath] ++ ·)
|> String.intercalate "\n"
|> IO.println
| xs => List.forM xs eval >> IO.println "OK"
def main (args : List String) : IO Unit :=
match Command.parse args with
| Except.ok v => evalList v
| Except.error err => IO.println err