equal
deleted
inserted
replaced
5 *) |
5 *) |
6 |
6 |
7 signature CACHE_IO = |
7 signature CACHE_IO = |
8 sig |
8 sig |
9 (*IO wrapper*) |
9 (*IO wrapper*) |
10 val with_tmp_file: string -> (Path.T -> 'a) -> 'a |
|
11 val with_tmp_dir: string -> (Path.T -> 'a) -> 'a |
|
12 type result = { |
10 type result = { |
13 output: string list, |
11 output: string list, |
14 redirected_output: string list, |
12 redirected_output: string list, |
15 return_code: int} |
13 return_code: int} |
16 val raw_run: (Path.T -> Path.T -> string) -> string -> Path.T -> Path.T -> |
14 val raw_run: (Path.T -> Path.T -> string) -> string -> Path.T -> Path.T -> |
32 |
30 |
33 (* IO wrapper *) |
31 (* IO wrapper *) |
34 |
32 |
35 val cache_io_prefix = "cache-io-" |
33 val cache_io_prefix = "cache-io-" |
36 |
34 |
37 fun with_tmp_file name f = |
|
38 let |
|
39 val path = File.tmp_path (Path.explode (name ^ serial_string ())) |
|
40 val x = Exn.capture f path |
|
41 val _ = try File.rm path |
|
42 in Exn.release x end |
|
43 |
|
44 fun with_tmp_dir name f = |
|
45 let |
|
46 val path = File.tmp_path (Path.explode (name ^ serial_string ())) |
|
47 val _ = Isabelle_System.mkdirs path |
|
48 val x = Exn.capture f path |
|
49 val _ = try Isabelle_System.rm_tree path |
|
50 in Exn.release x end |
|
51 |
|
52 type result = { |
35 type result = { |
53 output: string list, |
36 output: string list, |
54 redirected_output: string list, |
37 redirected_output: string list, |
55 return_code: int} |
38 return_code: int} |
56 |
39 |
60 val (out2, rc) = bash_output (make_cmd in_path out_path) |
43 val (out2, rc) = bash_output (make_cmd in_path out_path) |
61 val out1 = the_default [] (try (rev o File.fold_lines cons out_path) []) |
44 val out1 = the_default [] (try (rev o File.fold_lines cons out_path) []) |
62 in {output=split_lines out2, redirected_output=out1, return_code=rc} end |
45 in {output=split_lines out2, redirected_output=out1, return_code=rc} end |
63 |
46 |
64 fun run make_cmd str = |
47 fun run make_cmd str = |
65 with_tmp_file cache_io_prefix (fn in_path => |
48 Isabelle_System.with_tmp_file cache_io_prefix (fn in_path => |
66 with_tmp_file cache_io_prefix (raw_run make_cmd str in_path)) |
49 Isabelle_System.with_tmp_file cache_io_prefix (fn out_path => |
|
50 raw_run make_cmd str in_path out_path)) |
67 |
51 |
68 |
52 |
69 (* cache *) |
53 (* cache *) |
70 |
54 |
71 abstype cache = Cache of { |
55 abstype cache = Cache of { |