author | wenzelm |
Thu, 16 Mar 2017 23:33:39 +0100 | |
changeset 65281 | c70e7d24a16d |
parent 65278 | b553d0edc440 |
child 65282 | f4c5f10829a0 |
permissions | -rw-r--r-- |
50686 | 1 |
/* Title: Pure/Tools/build.scala |
48276 | 2 |
Author: Makarius |
57923 | 3 |
Options: :folding=explicit: |
48276 | 4 |
|
5 |
Build and manage Isabelle sessions. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
48548 | 11 |
import java.io.{BufferedInputStream, FileInputStream, |
48494 | 12 |
BufferedReader, InputStreamReader, IOException} |
13 |
import java.util.zip.GZIPInputStream |
|
48335 | 14 |
|
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
15 |
import scala.collection.SortedSet |
51397
03b586ee5930
support for 'chapter' specifications within session ROOT;
wenzelm
parents:
51300
diff
changeset
|
16 |
import scala.collection.mutable |
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
17 |
import scala.annotation.tailrec |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
18 |
|
48335 | 19 |
|
48276 | 20 |
object Build |
21 |
{ |
|
62631 | 22 |
/** auxiliary **/ |
48424 | 23 |
|
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
24 |
/* queue */ |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
25 |
|
62631 | 26 |
private object Queue |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
27 |
{ |
62631 | 28 |
def apply(tree: Sessions.Tree, load_timings: String => (List[Properties.T], Double)): Queue = |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
29 |
{ |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
30 |
val graph = tree.graph |
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56208
diff
changeset
|
31 |
val sessions = graph.keys |
51220 | 32 |
|
59136
c2b23cb8a677
added Par_List in Scala, in accordance to ML version;
wenzelm
parents:
59083
diff
changeset
|
33 |
val timings = Par_List.map((name: String) => (name, load_timings(name)), sessions) |
51220 | 34 |
val command_timings = |
35 |
Map(timings.map({ case (name, (ts, _)) => (name, ts) }): _*).withDefaultValue(Nil) |
|
36 |
val session_timing = |
|
37 |
Map(timings.map({ case (name, (_, t)) => (name, t) }): _*).withDefaultValue(0.0) |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
38 |
|
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
39 |
def outdegree(name: String): Int = graph.imm_succs(name).size |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
40 |
|
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
41 |
object Ordering extends scala.math.Ordering[String] |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
42 |
{ |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
43 |
def compare_timing(name1: String, name2: String): Int = |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
44 |
{ |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
45 |
val t1 = session_timing(name1) |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
46 |
val t2 = session_timing(name2) |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
47 |
if (t1 == 0.0 || t2 == 0.0) 0 |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
48 |
else t1 compare t2 |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
49 |
} |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
50 |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
51 |
def compare(name1: String, name2: String): Int = |
51229
6e40d0bb89e3
prefer outdegree in comparison again (cf. 88c96e836ed6) -- NB: big jobs might hide behind small ones in this naive queuing scheme;
wenzelm
parents:
51227
diff
changeset
|
52 |
outdegree(name2) compare outdegree(name1) match { |
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
53 |
case 0 => |
51229
6e40d0bb89e3
prefer outdegree in comparison again (cf. 88c96e836ed6) -- NB: big jobs might hide behind small ones in this naive queuing scheme;
wenzelm
parents:
51227
diff
changeset
|
54 |
compare_timing(name2, name1) match { |
51220 | 55 |
case 0 => |
61602 | 56 |
tree(name2).timeout compare tree(name1).timeout match { |
51220 | 57 |
case 0 => name1 compare name2 |
58 |
case ord => ord |
|
59 |
} |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
60 |
case ord => ord |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
61 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
62 |
case ord => ord |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
63 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
64 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
65 |
|
51220 | 66 |
new Queue(graph, SortedSet(sessions: _*)(Ordering), command_timings) |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
67 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
68 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
69 |
|
62631 | 70 |
private final class Queue private( |
71 |
graph: Graph[String, Sessions.Info], |
|
51220 | 72 |
order: SortedSet[String], |
73 |
val command_timings: String => List[Properties.T]) |
|
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
74 |
{ |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
75 |
def is_inner(name: String): Boolean = !graph.is_maximal(name) |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
76 |
|
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
77 |
def is_empty: Boolean = graph.is_empty |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
78 |
|
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
79 |
def - (name: String): Queue = |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
80 |
new Queue(graph.del_node(name), |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
81 |
order - name, // FIXME scala-2.10.0 TreeSet problem!? |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
82 |
command_timings) |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
83 |
|
62631 | 84 |
def dequeue(skip: String => Boolean): Option[(String, Sessions.Info)] = |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
85 |
{ |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
86 |
val it = order.iterator.dropWhile(name => |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
87 |
skip(name) |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
88 |
|| !graph.defined(name) // FIXME scala-2.10.0 TreeSet problem!? |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
89 |
|| !graph.is_minimal(name)) |
48680 | 90 |
if (it.hasNext) { val name = it.next; Some((name, graph.get_node(name))) } |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
91 |
else None |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
92 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
93 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
94 |
|
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
95 |
|
48424 | 96 |
/* jobs */ |
48341 | 97 |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
98 |
private class Job(progress: Progress, name: String, val info: Sessions.Info, tree: Sessions.Tree, |
64265 | 99 |
store: Sessions.Store, do_output: Boolean, verbose: Boolean, val numa_node: Option[Int], |
62633 | 100 |
session_graph: Graph_Display.Graph, command_timings: List[Properties.T]) |
48418 | 101 |
{ |
62633 | 102 |
val output = store.output_dir + Path.basic(name) |
48674 | 103 |
def output_path: Option[Path] = if (do_output) Some(output) else None |
62630 | 104 |
def output_save_state: String = |
62825
e6e80a8bf624
structure PolyML is sealed after bootstrap: all ML system access is managed by Isabelle;
wenzelm
parents:
62714
diff
changeset
|
105 |
if (do_output) "ML_Heap.save_child " + ML_Syntax.print_string0(File.platform_path(output)) |
62630 | 106 |
else "" |
62633 | 107 |
output.file.delete |
48674 | 108 |
|
109 |
private val parent = info.parent.getOrElse("") |
|
48418 | 110 |
|
59445 | 111 |
private val graph_file = Isabelle_System.tmp_file("session_graph", "pdf") |
112 |
try { isabelle.graphview.Graph_File.write(info.options, graph_file, session_graph) } |
|
113 |
catch { case ERROR(_) => /*error should be exposed in ML*/ } |
|
114 |
||
62610
4c89504c76fb
more uniform signature for various process invocations;
wenzelm
parents:
62603
diff
changeset
|
115 |
private val env = |
4c89504c76fb
more uniform signature for various process invocations;
wenzelm
parents:
62603
diff
changeset
|
116 |
Isabelle_System.settings() + |
4c89504c76fb
more uniform signature for various process invocations;
wenzelm
parents:
62603
diff
changeset
|
117 |
("ISABELLE_ML_DEBUGGER" -> info.options.bool("ML_debugger").toString) |
48698
2585042b1a30
pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents:
48684
diff
changeset
|
118 |
|
62573 | 119 |
private val future_result: Future[Process_Result] = |
61559
313eca3fa847
more direct task future implementation, with proper cancel operation;
wenzelm
parents:
61556
diff
changeset
|
120 |
Future.thread("build") { |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
121 |
val args_file = Isabelle_System.tmp_file("build") |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
122 |
File.write(args_file, YXML.string_of_body( |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
123 |
{ |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
124 |
val theories = info.theories.map(x => (x._2, x._3)) |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
125 |
import XML.Encode._ |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
126 |
pair(list(pair(string, int)), pair(list(properties), pair(bool, pair(bool, |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
127 |
pair(Path.encode, pair(list(pair(Path.encode, Path.encode)), pair(string, |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
128 |
pair(string, pair(string, pair(string, |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
129 |
list(pair(Options.encode, list(Path.encode)))))))))))))( |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
130 |
(Symbol.codes, (command_timings, (do_output, (verbose, |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
131 |
(store.browser_info, (info.document_files, (File.standard_path(graph_file), |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
132 |
(parent, (info.chapter, (name, |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
133 |
theories))))))))))) |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
134 |
})) |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
135 |
|
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
136 |
val eval = |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
137 |
"Command_Line.tool0 (fn () => (" + |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
138 |
"Build.build " + ML_Syntax.print_string0(File.standard_path(args_file)) + |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
139 |
(if (do_output) "; ML_Heap.share_common_data (); " + output_save_state |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
140 |
else "") + "));" |
64265 | 141 |
|
142 |
val process_options = |
|
143 |
numa_node match { |
|
144 |
case None => info.options |
|
145 |
case Some(n) => info.options.string("ML_process_policy") = NUMA.policy(n) |
|
146 |
} |
|
62573 | 147 |
val process = |
62883 | 148 |
if (Sessions.pure_name(name)) { |
64265 | 149 |
ML_Process(process_options, raw_ml_system = true, cwd = info.dir.file, |
62946 | 150 |
args = |
151 |
(for ((root, _) <- Thy_Header.ml_roots) yield List("--use", root)).flatten ::: |
|
152 |
List("--eval", eval), |
|
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
153 |
env = env, tree = Some(tree), store = store, cleanup = () => args_file.delete) |
62573 | 154 |
} |
155 |
else { |
|
64265 | 156 |
ML_Process(process_options, parent, List("--eval", eval), cwd = info.dir.file, |
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
157 |
env = env, tree = Some(tree), store = store, cleanup = () => args_file.delete) |
62573 | 158 |
} |
64265 | 159 |
|
62573 | 160 |
process.result( |
51962
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
161 |
progress_stdout = (line: String) => |
50847 | 162 |
Library.try_unprefix("\floading_theory = ", line) match { |
163 |
case Some(theory) => progress.theory(name, theory) |
|
164 |
case None => |
|
51962
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
165 |
}, |
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
166 |
progress_limit = |
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
167 |
info.options.int("process_output_limit") match { |
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
168 |
case 0 => None |
016cb7d8f297
limit build process output, to avoid bombing Isabelle/Scala process by ill-behaved jobs (e.g. Containers in AFP/9025435b29cf);
wenzelm
parents:
51663
diff
changeset
|
169 |
case m => Some(m * 1000000L) |
56871
d06ff36b4fa7
expose interrupts more like ML version, but not in managed bash processes of Build;
wenzelm
parents:
56861
diff
changeset
|
170 |
}, |
d06ff36b4fa7
expose interrupts more like ML version, but not in managed bash processes of Build;
wenzelm
parents:
56861
diff
changeset
|
171 |
strict = false) |
50845 | 172 |
} |
48674 | 173 |
|
62572 | 174 |
def terminate: Unit = future_result.cancel |
175 |
def is_finished: Boolean = future_result.is_finished |
|
48674 | 176 |
|
62569 | 177 |
@volatile private var was_timeout = false |
56779 | 178 |
private val timeout_request: Option[Event_Timer.Request] = |
179 |
{ |
|
62569 | 180 |
if (info.timeout > Time.zero) |
181 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate; was_timeout = true }) |
|
48674 | 182 |
else None |
56779 | 183 |
} |
48674 | 184 |
|
62400 | 185 |
def join: Process_Result = |
50845 | 186 |
{ |
62572 | 187 |
val result = future_result.join |
50845 | 188 |
|
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
189 |
if (result.ok) |
62633 | 190 |
Present.finish(progress, store.browser_info, graph_file, info, name) |
61372 | 191 |
|
59445 | 192 |
graph_file.delete |
56779 | 193 |
timeout_request.foreach(_.cancel) |
48674 | 194 |
|
62572 | 195 |
if (result.interrupted) { |
196 |
if (was_timeout) result.error(Output.error_text("Timeout")).was_timeout |
|
197 |
else result.error(Output.error_text("Interrupt")) |
|
52063
fd533ac64390
timeout counts as regular error, with rc = 1 (cf. special Exn.Interrupt vs. regular TimeLimit.TimeOut in Isabelle/ML);
wenzelm
parents:
51987
diff
changeset
|
198 |
} |
62572 | 199 |
else result |
48674 | 200 |
} |
48364 | 201 |
} |
202 |
||
48424 | 203 |
|
50777 | 204 |
/* sources and heaps */ |
205 |
||
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
206 |
sealed case class Session_Info( |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
207 |
sources: String, input_heap: String, output_heap: String, return_code: Int) |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
208 |
|
62628 | 209 |
private val SOURCES = "sources: " |
210 |
private val INPUT_HEAP = "input_heap: " |
|
211 |
private val OUTPUT_HEAP = "output_heap: " |
|
212 |
private val LOG_START = "log:" |
|
213 |
private val line_prefixes = List(SOURCES, INPUT_HEAP, OUTPUT_HEAP, LOG_START) |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
214 |
|
62628 | 215 |
private def sources_stamp(digests: List[SHA1.Digest]): String = |
216 |
digests.map(_.toString).sorted.mkString(SOURCES, " ", "") |
|
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
217 |
|
62628 | 218 |
private def read_stamps(path: Path): Option[(String, List[String], List[String])] = |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
219 |
if (path.is_file) { |
62628 | 220 |
val stream = new GZIPInputStream(new BufferedInputStream(new FileInputStream(path.file))) |
50203 | 221 |
val reader = new BufferedReader(new InputStreamReader(stream, UTF8.charset)) |
62628 | 222 |
val lines = |
223 |
{ |
|
224 |
val lines = new mutable.ListBuffer[String] |
|
225 |
try { |
|
226 |
var finished = false |
|
227 |
while (!finished) { |
|
228 |
val line = reader.readLine |
|
229 |
if (line != null && line_prefixes.exists(line.startsWith(_))) |
|
230 |
lines += line |
|
231 |
else finished = true |
|
232 |
} |
|
233 |
} |
|
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
234 |
finally { reader.close } |
62628 | 235 |
lines.toList |
236 |
} |
|
237 |
||
238 |
if (!lines.isEmpty && lines.last.startsWith(LOG_START)) { |
|
239 |
lines.find(_.startsWith(SOURCES)).map(s => |
|
240 |
(s, lines.filter(_.startsWith(INPUT_HEAP)), lines.filter(_.startsWith(OUTPUT_HEAP)))) |
|
241 |
} |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
242 |
else None |
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
243 |
} |
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
244 |
else None |
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
245 |
|
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
246 |
|
62631 | 247 |
|
62641 | 248 |
/** build with results **/ |
48424 | 249 |
|
63996 | 250 |
class Results private[Build](results: Map[String, (Option[Process_Result], Sessions.Info)]) |
62403 | 251 |
{ |
252 |
def sessions: Set[String] = results.keySet |
|
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
253 |
def cancelled(name: String): Boolean = results(name)._1.isEmpty |
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
254 |
def apply(name: String): Process_Result = results(name)._1.getOrElse(Process_Result(1)) |
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
255 |
def info(name: String): Sessions.Info = results(name)._2 |
65253 | 256 |
val rc = |
257 |
(0 /: results.iterator.map( |
|
258 |
{ case (_, (Some(r), _)) => r.rc case (_, (None, _)) => 1 }))(_ max _) |
|
62641 | 259 |
def ok: Boolean = rc == 0 |
62406 | 260 |
|
261 |
override def toString: String = rc.toString |
|
62403 | 262 |
} |
263 |
||
62641 | 264 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
265 |
options: Options, |
64909 | 266 |
progress: Progress = No_Progress, |
48511
37999ee01156
remove old output heaps, to ensure that result is valid wrt. check_stamps;
wenzelm
parents:
48509
diff
changeset
|
267 |
build_heap: Boolean = false, |
48595 | 268 |
clean_build: Boolean = false, |
56890 | 269 |
dirs: List[Path] = Nil, |
270 |
select_dirs: List[Path] = Nil, |
|
64265 | 271 |
numa_shuffling: Boolean = false, |
48509 | 272 |
max_jobs: Int = 1, |
48903 | 273 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
274 |
check_keywords: Set[String] = Set.empty, |
48509 | 275 |
no_build: Boolean = false, |
276 |
system_mode: Boolean = false, |
|
277 |
verbose: Boolean = false, |
|
63224 | 278 |
requirements: Boolean = false, |
279 |
all_sessions: Boolean = false, |
|
280 |
exclude_session_groups: List[String] = Nil, |
|
59892
2a616319c171
added isabelle build option -x, to exclude sessions;
wenzelm
parents:
59891
diff
changeset
|
281 |
exclude_sessions: List[String] = Nil, |
63224 | 282 |
session_groups: List[String] = Nil, |
62641 | 283 |
sessions: List[String] = Nil): Results = |
48341 | 284 |
{ |
63224 | 285 |
build_selection( |
286 |
options = options, |
|
287 |
progress = progress, |
|
288 |
build_heap = build_heap, |
|
289 |
clean_build = clean_build, |
|
290 |
dirs = dirs, |
|
291 |
select_dirs = select_dirs, |
|
64265 | 292 |
numa_shuffling = numa_shuffling, |
63224 | 293 |
max_jobs = max_jobs, |
294 |
list_files = list_files, |
|
295 |
check_keywords = check_keywords, |
|
296 |
no_build = no_build, |
|
297 |
system_mode = system_mode, |
|
298 |
verbose = verbose, |
|
299 |
selection = { full_tree => |
|
300 |
full_tree.selection(requirements, all_sessions, |
|
301 |
exclude_session_groups, exclude_sessions, session_groups, sessions) }) |
|
302 |
} |
|
303 |
||
304 |
def build_selection( |
|
305 |
options: Options, |
|
64909 | 306 |
progress: Progress = No_Progress, |
63224 | 307 |
build_heap: Boolean = false, |
308 |
clean_build: Boolean = false, |
|
309 |
dirs: List[Path] = Nil, |
|
310 |
select_dirs: List[Path] = Nil, |
|
64265 | 311 |
numa_shuffling: Boolean = false, |
63224 | 312 |
max_jobs: Int = 1, |
313 |
list_files: Boolean = false, |
|
314 |
check_keywords: Set[String] = Set.empty, |
|
315 |
no_build: Boolean = false, |
|
316 |
system_mode: Boolean = false, |
|
317 |
verbose: Boolean = false, |
|
318 |
selection: Sessions.Tree => (List[String], Sessions.Tree) = |
|
319 |
(_.selection(all_sessions = true))): Results = |
|
320 |
{ |
|
321 |
/* session selection and dependencies */ |
|
51220 | 322 |
|
62714 | 323 |
val build_options = options.int.update("completion_limit", 0).bool.update("ML_statistics", true) |
324 |
val full_tree = Sessions.load(build_options, dirs, select_dirs) |
|
63224 | 325 |
val (selected, selected_tree) = selection(full_tree) |
65251 | 326 |
val deps = |
327 |
Sessions.dependencies(progress, true, verbose, list_files, check_keywords, selected_tree) |
|
48368 | 328 |
|
62628 | 329 |
def session_sources_stamp(name: String): String = |
62631 | 330 |
sources_stamp(selected_tree(name).meta_digest :: deps.sources(name)) |
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
331 |
|
62632 | 332 |
val store = Sessions.store(system_mode) |
51220 | 333 |
|
334 |
||
335 |
/* queue with scheduling information */ |
|
336 |
||
51230
19192615911e
option parallel_proofs_reuse_timing controls reuse of log information -- since it is not always beneficial for performance;
wenzelm
parents:
51229
diff
changeset
|
337 |
def load_timings(name: String): (List[Properties.T], Double) = |
51221 | 338 |
{ |
339 |
val (path, text) = |
|
62632 | 340 |
store.find_log_gz(name) match { |
341 |
case Some(path) => (path, File.read_gzip(path)) |
|
51221 | 342 |
case None => |
62632 | 343 |
store.find_log(name) match { |
344 |
case Some(path) => (path, File.read(path)) |
|
51221 | 345 |
case None => (Path.current, "") |
346 |
} |
|
347 |
} |
|
51244
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
348 |
|
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
349 |
def ignore_error(msg: String): (List[Properties.T], Double) = |
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
350 |
{ |
56782
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
56780
diff
changeset
|
351 |
Output.warning("Ignoring bad log file: " + path + (if (msg == "") "" else "\n" + msg)) |
51244
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
352 |
(Nil, 0.0) |
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
353 |
} |
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
354 |
|
51221 | 355 |
try { |
64082 | 356 |
val info = Build_Log.Log_File(name, text).parse_session_info(name, command_timings = true) |
51221 | 357 |
val session_timing = Markup.Elapsed.unapply(info.session_timing) getOrElse 0.0 |
358 |
(info.command_timings, session_timing) |
|
51220 | 359 |
} |
51221 | 360 |
catch { |
51244
d8ca566b22b3
more robust load_timings: ignore XML.Decode errors as well;
wenzelm
parents:
51230
diff
changeset
|
361 |
case ERROR(msg) => ignore_error(msg) |
51986
5fdca5bfc0b4
more robust load_timings: ignore JVM errors such as java.lang.OutOfMemoryError;
wenzelm
parents:
51983
diff
changeset
|
362 |
case exn: java.lang.Error => ignore_error(Exn.message(exn)) |
51987 | 363 |
case _: XML.Error => ignore_error("") |
51221 | 364 |
} |
365 |
} |
|
51220 | 366 |
|
51230
19192615911e
option parallel_proofs_reuse_timing controls reuse of log information -- since it is not always beneficial for performance;
wenzelm
parents:
51229
diff
changeset
|
367 |
val queue = Queue(selected_tree, load_timings) |
51220 | 368 |
|
369 |
||
370 |
/* main build process */ |
|
371 |
||
62632 | 372 |
store.prepare_output() |
48373 | 373 |
|
48595 | 374 |
// optional cleanup |
375 |
if (clean_build) { |
|
49131 | 376 |
for (name <- full_tree.graph.all_succs(selected)) { |
48595 | 377 |
val files = |
65278 | 378 |
List(Path.basic(name), store.log(name), store.log_gz(name)). |
62632 | 379 |
map(store.output_dir + _).filter(_.is_file) |
59319 | 380 |
if (files.nonEmpty) progress.echo("Cleaning " + name + " ...") |
50366 | 381 |
if (!files.forall(p => p.file.delete)) progress.echo(name + " FAILED to delete") |
48595 | 382 |
} |
383 |
} |
|
384 |
||
48425 | 385 |
// scheduler loop |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
386 |
case class Result( |
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
387 |
current: Boolean, heap_stamp: Option[String], |
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
388 |
process: Option[Process_Result], info: Sessions.Info) |
62402 | 389 |
{ |
390 |
def ok: Boolean = |
|
391 |
process match { |
|
392 |
case None => false |
|
393 |
case Some(res) => res.rc == 0 |
|
394 |
} |
|
395 |
} |
|
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
396 |
|
56837
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
397 |
def sleep() |
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
398 |
{ |
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
399 |
try { Thread.sleep(500) } |
56861 | 400 |
catch { case Exn.Interrupt() => Exn.Interrupt.impose() } |
56837
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
401 |
} |
50366 | 402 |
|
64265 | 403 |
val numa_nodes = new NUMA.Nodes(numa_shuffling) |
404 |
||
48425 | 405 |
@tailrec def loop( |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
406 |
pending: Queue, |
62628 | 407 |
running: Map[String, (List[String], Job)], |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
408 |
results: Map[String, Result]): Map[String, Result] = |
48425 | 409 |
{ |
64265 | 410 |
def used_node(i: Int): Boolean = |
411 |
running.iterator.exists( |
|
412 |
{ case (_, (_, job)) => job.numa_node.isDefined && job.numa_node.get == i }) |
|
413 |
||
48425 | 414 |
if (pending.is_empty) results |
51253 | 415 |
else { |
416 |
if (progress.stopped) |
|
417 |
for ((_, (_, job)) <- running) job.terminate |
|
418 |
||
48674 | 419 |
running.find({ case (_, (_, job)) => job.is_finished }) match { |
62628 | 420 |
case Some((name, (input_heaps, job))) => |
50367 | 421 |
//{{{ finish job |
48424 | 422 |
|
62401 | 423 |
val process_result = job.join |
62573 | 424 |
process_result.err_lines.foreach(progress.echo(_)) |
425 |
if (process_result.ok) |
|
426 |
progress.echo("Finished " + name + " (" + process_result.timing.message_resources + ")") |
|
48373 | 427 |
|
62404
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
428 |
val process_result_tail = |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
429 |
{ |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
430 |
val lines = process_result.out_lines.filterNot(_.startsWith("\f")) |
62409
e391528eff3b
proper option process_output_tail, more generous default;
wenzelm
parents:
62406
diff
changeset
|
431 |
val tail = job.info.options.int("process_output_tail") |
e391528eff3b
proper option process_output_tail, more generous default;
wenzelm
parents:
62406
diff
changeset
|
432 |
val lines1 = if (tail == 0) lines else lines.drop(lines.length - tail max 0) |
62632 | 433 |
process_result.copy( |
434 |
out_lines = |
|
65278 | 435 |
"(see also " + (store.output_dir + store.log(name)).file.toString + ")" :: |
62632 | 436 |
lines1) |
62404
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
437 |
} |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
438 |
|
62636 | 439 |
val heap_stamp = |
62401 | 440 |
if (process_result.ok) { |
65278 | 441 |
(store.output_dir + store.log(name)).file.delete |
62636 | 442 |
val heap_stamp = |
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62643
diff
changeset
|
443 |
for (path <- job.output_path if path.is_file) |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62643
diff
changeset
|
444 |
yield Sessions.write_heap_digest(path) |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
445 |
|
65278 | 446 |
File.write_gzip(store.output_dir + store.log_gz(name), |
64173 | 447 |
terminate_lines( |
62628 | 448 |
session_sources_stamp(name) :: |
449 |
input_heaps.map(INPUT_HEAP + _) ::: |
|
62636 | 450 |
heap_stamp.toList.map(OUTPUT_HEAP + _) ::: |
62628 | 451 |
List(LOG_START) ::: process_result.out_lines)) |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
452 |
|
62636 | 453 |
heap_stamp |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
454 |
} |
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
455 |
else { |
62632 | 456 |
(store.output_dir + Path.basic(name)).file.delete |
65278 | 457 |
(store.output_dir + store.log_gz(name)).file.delete |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
458 |
|
65278 | 459 |
File.write(store.output_dir + store.log(name), |
64173 | 460 |
terminate_lines(process_result.out_lines)) |
50366 | 461 |
progress.echo(name + " FAILED") |
62404
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
462 |
if (!process_result.interrupted) progress.echo(process_result_tail.out) |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
463 |
|
62636 | 464 |
None |
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
465 |
} |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
50686
diff
changeset
|
466 |
loop(pending - name, running - name, |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
467 |
results + (name -> Result(false, heap_stamp, Some(process_result_tail), job.info))) |
50367 | 468 |
//}}} |
60215 | 469 |
case None if running.size < (max_jobs max 1) => |
50367 | 470 |
//{{{ check/start next job |
48547 | 471 |
pending.dequeue(running.isDefinedAt(_)) match { |
472 |
case Some((name, info)) => |
|
62628 | 473 |
val ancestor_results = selected_tree.ancestors(name).map(results(_)) |
62636 | 474 |
val ancestor_heaps = ancestor_results.flatMap(_.heap_stamp) |
62628 | 475 |
|
62883 | 476 |
val do_output = build_heap || Sessions.pure_name(name) || queue.is_inner(name) |
48547 | 477 |
|
62636 | 478 |
val (current, heap_stamp) = |
48547 | 479 |
{ |
62632 | 480 |
store.find(name) match { |
62636 | 481 |
case Some((log_gz, heap_stamp)) => |
62632 | 482 |
read_stamps(log_gz) match { |
62628 | 483 |
case Some((sources, input_heaps, output_heaps)) => |
484 |
val current = |
|
485 |
sources == session_sources_stamp(name) && |
|
486 |
input_heaps == ancestor_heaps.map(INPUT_HEAP + _) && |
|
62636 | 487 |
output_heaps == heap_stamp.toList.map(OUTPUT_HEAP + _) && |
488 |
!(do_output && heap_stamp.isEmpty) |
|
489 |
(current, heap_stamp) |
|
490 |
case None => (false, None) |
|
48547 | 491 |
} |
62636 | 492 |
case None => (false, None) |
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
493 |
} |
48547 | 494 |
} |
62628 | 495 |
val all_current = current && ancestor_results.forall(_.current) |
48528
784c6f63d79c
proper all_current, which regards parent status as well;
wenzelm
parents:
48511
diff
changeset
|
496 |
|
48547 | 497 |
if (all_current) |
62402 | 498 |
loop(pending - name, running, |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
499 |
results + (name -> Result(true, heap_stamp, Some(Process_Result(0)), info))) |
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
500 |
else if (no_build) { |
50366 | 501 |
if (verbose) progress.echo("Skipping " + name + " ...") |
62402 | 502 |
loop(pending - name, running, |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
503 |
results + (name -> Result(false, heap_stamp, Some(Process_Result(1)), info))) |
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
504 |
} |
62628 | 505 |
else if (ancestor_results.forall(_.ok) && !progress.stopped) { |
64265 | 506 |
val numa_node = numa_nodes.next(used_node(_)) |
50366 | 507 |
progress.echo((if (do_output) "Building " else "Running ") + name + " ...") |
51220 | 508 |
val job = |
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
509 |
new Job(progress, name, info, selected_tree, store, do_output, verbose, |
64265 | 510 |
numa_node, deps(name).session_graph, queue.command_timings(name)) |
62628 | 511 |
loop(pending, running + (name -> (ancestor_heaps, job)), results) |
48547 | 512 |
} |
513 |
else { |
|
50366 | 514 |
progress.echo(name + " CANCELLED") |
65253 | 515 |
loop(pending - name, running, |
516 |
results + (name -> Result(false, heap_stamp, None, info))) |
|
48547 | 517 |
} |
518 |
case None => sleep(); loop(pending, running, results) |
|
48425 | 519 |
} |
50367 | 520 |
///}}} |
48425 | 521 |
case None => sleep(); loop(pending, running, results) |
48373 | 522 |
} |
51253 | 523 |
} |
48425 | 524 |
} |
525 |
||
51220 | 526 |
|
527 |
/* build results */ |
|
528 |
||
62641 | 529 |
val results0 = |
48583 | 530 |
if (deps.is_empty) { |
56782
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
56780
diff
changeset
|
531 |
progress.echo(Output.warning_text("Nothing to build")) |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
50686
diff
changeset
|
532 |
Map.empty[String, Result] |
48583 | 533 |
} |
534 |
else loop(queue, Map.empty, Map.empty) |
|
535 |
||
62641 | 536 |
val results = |
64265 | 537 |
new Results( |
538 |
(for ((name, result) <- results0.iterator) |
|
539 |
yield (name, (result.process, result.info))).toMap) |
|
62641 | 540 |
|
541 |
if (results.rc != 0 && (verbose || !no_build)) { |
|
542 |
val unfinished = |
|
543 |
(for { |
|
544 |
name <- results.sessions.iterator |
|
545 |
if !results(name).ok |
|
546 |
} yield name).toList.sorted |
|
547 |
progress.echo("Unfinished session(s): " + commas(unfinished)) |
|
548 |
} |
|
549 |
||
51418
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
550 |
|
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
551 |
/* global browser info */ |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
552 |
|
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
553 |
if (!no_build) { |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
554 |
val browser_chapters = |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
555 |
(for { |
62641 | 556 |
(name, result) <- results0.iterator |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
557 |
if result.ok |
51418
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
558 |
info = full_tree(name) |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
559 |
if info.options.bool("browser_info") |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
560 |
} yield (info.chapter, (name, info.description))).toList.groupBy(_._1). |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
561 |
map({ case (chapter, es) => (chapter, es.map(_._2)) }).filterNot(_._2.isEmpty) |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
562 |
|
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
563 |
for ((chapter, entries) <- browser_chapters) |
62632 | 564 |
Present.update_chapter_index(store.browser_info, chapter, entries) |
51418
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
565 |
|
62632 | 566 |
if (browser_chapters.nonEmpty) Present.make_global_index(store.browser_info) |
51418
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
567 |
} |
7b8ce8403340
more accurate handling of global browser info at the very end (without races), subject to no_build and info.browser_info;
wenzelm
parents:
51402
diff
changeset
|
568 |
|
62641 | 569 |
results |
48341 | 570 |
} |
571 |
||
572 |
||
62833 | 573 |
/* Isabelle tool wrapper */ |
48341 | 574 |
|
62833 | 575 |
val isabelle_tool = Isabelle_Tool("build", "build and manage Isabelle sessions", args => |
48341 | 576 |
{ |
62833 | 577 |
val build_options = Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS")) |
62590 | 578 |
|
62833 | 579 |
var select_dirs: List[Path] = Nil |
64265 | 580 |
var numa_shuffling = false |
62833 | 581 |
var requirements = false |
582 |
var exclude_session_groups: List[String] = Nil |
|
583 |
var all_sessions = false |
|
584 |
var build_heap = false |
|
585 |
var clean_build = false |
|
586 |
var dirs: List[Path] = Nil |
|
587 |
var session_groups: List[String] = Nil |
|
588 |
var max_jobs = 1 |
|
589 |
var check_keywords: Set[String] = Set.empty |
|
590 |
var list_files = false |
|
591 |
var no_build = false |
|
592 |
var options = (Options.init() /: build_options)(_ + _) |
|
593 |
var system_mode = false |
|
594 |
var verbose = false |
|
595 |
var exclude_sessions: List[String] = Nil |
|
62590 | 596 |
|
62833 | 597 |
val getopts = Getopts(""" |
62590 | 598 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
599 |
||
600 |
Options are: |
|
601 |
-D DIR include session directory and select its sessions |
|
64265 | 602 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
62590 | 603 |
-R operate on requirements of selected sessions |
604 |
-X NAME exclude sessions from group NAME and all descendants |
|
605 |
-a select all sessions |
|
606 |
-b build heap images |
|
607 |
-c clean build |
|
608 |
-d DIR include session directory |
|
609 |
-g NAME select session group NAME |
|
610 |
-j INT maximum number of parallel jobs (default 1) |
|
611 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
|
612 |
-l list session source files |
|
613 |
-n no build -- test dependencies only |
|
614 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
615 |
-s system build mode: produce output in ISABELLE_HOME |
|
616 |
-v verbose |
|
617 |
-x NAME exclude session NAME and all descendants |
|
618 |
||
62596 | 619 |
Build and manage Isabelle sessions, depending on implicit settings: |
620 |
||
64455 | 621 |
""" + Library.prefix_lines(" ", Build_Log.Settings.show()) + "\n", |
62833 | 622 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
64265 | 623 |
"N" -> (_ => numa_shuffling = true), |
62833 | 624 |
"R" -> (_ => requirements = true), |
625 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
|
626 |
"a" -> (_ => all_sessions = true), |
|
627 |
"b" -> (_ => build_heap = true), |
|
628 |
"c" -> (_ => clean_build = true), |
|
629 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
630 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
|
63805 | 631 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
62833 | 632 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
633 |
"l" -> (_ => list_files = true), |
|
634 |
"n" -> (_ => no_build = true), |
|
635 |
"o:" -> (arg => options = options + arg), |
|
636 |
"s" -> (_ => system_mode = true), |
|
637 |
"v" -> (_ => verbose = true), |
|
638 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
62590 | 639 |
|
62833 | 640 |
val sessions = getopts(args) |
62590 | 641 |
|
64115 | 642 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 643 |
|
64140 | 644 |
val start_date = Date.now() |
645 |
||
62833 | 646 |
if (verbose) { |
647 |
progress.echo( |
|
64155 | 648 |
"Started at " + Build_Log.print_date(start_date) + |
64140 | 649 |
" (" + Isabelle_System.getenv("ML_IDENTIFIER") + " on " + Isabelle_System.hostname() +")") |
64081 | 650 |
progress.echo(Build_Log.Settings.show() + "\n") |
62833 | 651 |
} |
62590 | 652 |
|
62833 | 653 |
val results = |
654 |
progress.interrupt_handler { |
|
63224 | 655 |
build(options, progress, |
656 |
build_heap = build_heap, |
|
657 |
clean_build = clean_build, |
|
658 |
dirs = dirs, |
|
659 |
select_dirs = select_dirs, |
|
64265 | 660 |
numa_shuffling = NUMA.enabled_warning(numa_shuffling), |
63224 | 661 |
max_jobs = max_jobs, |
662 |
list_files = list_files, |
|
663 |
check_keywords = check_keywords, |
|
664 |
no_build = no_build, |
|
665 |
system_mode = system_mode, |
|
666 |
verbose = verbose, |
|
667 |
requirements = requirements, |
|
668 |
all_sessions = all_sessions, |
|
669 |
exclude_session_groups = exclude_session_groups, |
|
670 |
exclude_sessions = exclude_sessions, |
|
671 |
session_groups = session_groups, |
|
672 |
sessions = sessions) |
|
62833 | 673 |
} |
64140 | 674 |
val end_date = Date.now() |
675 |
val elapsed_time = end_date.time - start_date.time |
|
62590 | 676 |
|
62833 | 677 |
if (verbose) { |
64155 | 678 |
progress.echo("\nFinished at " + Build_Log.print_date(end_date)) |
62833 | 679 |
} |
62590 | 680 |
|
62833 | 681 |
val total_timing = |
682 |
(Timing.zero /: results.sessions.iterator.map(a => results(a).timing))(_ + _). |
|
683 |
copy(elapsed = elapsed_time) |
|
684 |
progress.echo(total_timing.message_resources) |
|
62590 | 685 |
|
62833 | 686 |
sys.exit(results.rc) |
687 |
}) |
|
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
688 |
|
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
689 |
|
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
690 |
/* PIDE protocol */ |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
691 |
|
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
692 |
def build_theories( |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
693 |
session: Session, master_dir: Path, theories: List[(Options, List[Path])]): Promise[XML.Body] = |
59367 | 694 |
session.get_protocol_handler(classOf[Handler].getName) match { |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
695 |
case Some(handler: Handler) => handler.build_theories(session, master_dir, theories) |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
696 |
case _ => error("Cannot invoke build_theories: bad protocol handler") |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
697 |
} |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
698 |
|
59367 | 699 |
class Handler(progress: Progress, session_name: String) extends Session.Protocol_Handler |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
700 |
{ |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
701 |
private val pending = Synchronized(Map.empty[String, Promise[XML.Body]]) |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
702 |
|
65220 | 703 |
override def exit(): Unit = |
704 |
pending.change(promises => { for ((_, promise) <- promises) promise.cancel; Map.empty }) |
|
705 |
||
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
706 |
def build_theories( |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
707 |
session: Session, master_dir: Path, theories: List[(Options, List[Path])]): Promise[XML.Body] = |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
708 |
{ |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
709 |
val promise = Future.promise[XML.Body] |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
710 |
val id = Document_ID.make().toString |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
711 |
pending.change(promises => promises + (id -> promise)) |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
712 |
session.build_theories(id, master_dir, theories) |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
713 |
promise |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
714 |
} |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
715 |
|
65219 | 716 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
59367 | 717 |
msg.properties match { |
718 |
case Markup.Loading_Theory(name) => progress.theory(session_name, name); true |
|
719 |
case _ => false |
|
720 |
} |
|
721 |
||
65219 | 722 |
private def build_theories_result(msg: Prover.Protocol_Output): Boolean = |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
723 |
msg.properties match { |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
724 |
case Markup.Build_Theories_Result(id) => |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
725 |
pending.change_result(promises => |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
726 |
promises.get(id) match { |
59369
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
727 |
case Some(promise) => |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
728 |
val error_message = |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
729 |
try { YXML.parse_body(Symbol.decode(msg.text)) } |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
730 |
catch { case exn: Throwable => List(XML.Text(Exn.message(exn))) } |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
731 |
promise.fulfill(error_message) |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
732 |
(true, promises - id) |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
733 |
case None => |
7090199d3f78
more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents:
59367
diff
changeset
|
734 |
(false, promises) |
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
735 |
}) |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
736 |
case _ => false |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
737 |
} |
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
738 |
|
59367 | 739 |
val functions = |
65219 | 740 |
List( |
59367 | 741 |
Markup.BUILD_THEORIES_RESULT -> build_theories_result _, |
742 |
Markup.LOADING_THEORY -> loading_theory _) |
|
59366
e94df7f6b608
clarified build_theories: proper protocol handler;
wenzelm
parents:
59319
diff
changeset
|
743 |
} |
48276 | 744 |
} |