@@ -20,41 +20,51 @@ require mathlib from git
20
20
lean_lib Examples where
21
21
globs := #[.submodules `Examples]
22
22
23
- @[inline]
24
- def runCmd (cmd : String) (args : Array String) : ScriptM Bool := do
23
+ section Script
24
+
25
+ /-- 与えられた文字列をシェルで実行する -/
26
+ @[inline] def runCmd (input : String) : IO Unit := do
27
+ let cmdList := input.splitOn " "
28
+ let cmd := cmdList.head!
29
+ let args := cmdList.tail |>.toArray
25
30
let out ← IO.Process.output {
26
- cmd := cmd
31
+ cmd := cmd
27
32
args := args
28
33
}
29
- let hasError := out.exitCode != 0
30
- if hasError then
31
- IO.eprint out.stderr
32
- return hasError
34
+ if out.exitCode != 0 then
35
+ IO.eprintln out.stderr
36
+ throw <| IO.userError s! "Failed to execute: { input} "
37
+ else if !out.stdout.isEmpty then
38
+ IO.println out.stdout
33
39
34
40
/-- mk_exercise を実行し、演習問題の解答に
35
41
解答部分を sorry に置き換えるなどの処理を施して演習問題ファイルを生成する。-/
36
42
script mk_exercise do
37
- if ← runCmd "lake" #[ " exe" , " mk_exercise" , " Examples/Solution" , " Examples/Exercise"] then return 1
43
+ runCmd "lake exe mk_exercise Examples/Solution Examples/Exercise"
38
44
return 0
39
45
40
- @[inline]
41
- macro "with_time" x:doElem : doElem => `(doElem| do
42
- let start_time ← IO.monoMsNow;
43
- $x;
44
- let end_time ← IO.monoMsNow;
45
- IO.println s! "{ end_time - start_time} ms" )
46
+ syntax (name := with_time) "with_time" "running" str doElem : doElem
47
+
48
+ macro_rules
49
+ | `(doElem| with_time running $s $x) => `(doElem| do
50
+ let start_time ← IO.monoMsNow;
51
+ $x;
52
+ let end_time ← IO.monoMsNow;
53
+ IO.println s! "Running { $s} : { end_time - start_time} ms" )
46
54
47
55
/-- mk_exercise と mdgen と mdbook を順に実行し、
48
56
Lean ファイルから Markdown ファイルと HTML ファイルを生成する。-/
49
57
script build do
50
58
-- `lake run mk_exercise` を使用すると遅くなってしまうのでコピペしている
51
- IO.print "Running mk_exercise: "
52
- with_time if ← runCmd "lake" #[ " exe" , " mk_exercise" , " Examples/Solution" , " Examples/Exercise"] then return 1
59
+ with_time running " mk_exercise"
60
+ runCmd "lake exe mk_exercise Examples/Solution Examples/Exercise"
53
61
54
- IO.print "Running mdgen: "
55
- with_time if ← runCmd "lake" #[ " exe" , " mdgen" , " Examples" , " src"] then return 1
62
+ with_time running " mdgen"
63
+ runCmd "lake exe mdgen Examples src"
56
64
57
- IO.print "Running mdbook: "
58
- with_time if ← runCmd "mdbook" #[ " build"] then return 1
65
+ with_time running " mdbook"
66
+ runCmd "mdbook build"
59
67
60
68
return 0
69
+
70
+ end Script
0 commit comments