author | wenzelm |
Sat, 11 Jul 2020 16:58:38 +0200 | |
changeset 72019 | 940195fbb282 |
parent 72018 | 5c9984820caa |
child 72021 | 664e90313a54 |
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 |
||
71648 | 11 |
import scala.collection.{SortedSet, mutable} |
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
12 |
import scala.annotation.tailrec |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
13 |
|
48335 | 14 |
|
48276 | 15 |
object Build |
16 |
{ |
|
62631 | 17 |
/** auxiliary **/ |
48424 | 18 |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
19 |
/* persistent build info */ |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
20 |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
21 |
sealed case class Session_Info( |
66749
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
22 |
sources: String, |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
23 |
input_heaps: List[String], |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
24 |
output_heap: Option[String], |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
25 |
return_code: Int) |
66747 | 26 |
{ |
27 |
def ok: Boolean = return_code == 0 |
|
28 |
} |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
29 |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
30 |
|
65289 | 31 |
/* queue with scheduling information */ |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
32 |
|
62631 | 33 |
private object Queue |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
34 |
{ |
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
35 |
type Timings = (List[Properties.T], Double) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
36 |
|
71669 | 37 |
def load_timings(progress: Progress, store: Sessions.Store, session_name: String): Timings = |
65289 | 38 |
{ |
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
39 |
val no_timings: Timings = (Nil, 0.0) |
65289 | 40 |
|
71669 | 41 |
store.access_database(session_name) match { |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
42 |
case None => no_timings |
68214 | 43 |
case Some(db) => |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
44 |
def ignore_error(msg: String) = |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
45 |
{ |
68214 | 46 |
progress.echo_warning("Ignoring bad database " + db + (if (msg == "") "" else "\n" + msg)) |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
47 |
no_timings |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
48 |
} |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
49 |
try { |
71669 | 50 |
val command_timings = store.read_command_timings(db, session_name) |
68214 | 51 |
val session_timing = |
71669 | 52 |
store.read_session_timing(db, session_name) match { |
68214 | 53 |
case Markup.Elapsed(t) => t |
54 |
case _ => 0.0 |
|
55 |
} |
|
56 |
(command_timings, session_timing) |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
57 |
} |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
58 |
catch { |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
59 |
case ERROR(msg) => ignore_error(msg) |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
60 |
case exn: java.lang.Error => ignore_error(Exn.message(exn)) |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
61 |
case _: XML.Error => ignore_error("") |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
62 |
} |
68214 | 63 |
finally { db.close } |
65289 | 64 |
} |
65 |
} |
|
66 |
||
68731 | 67 |
def make_session_timing(sessions_structure: Sessions.Structure, timing: Map[String, Double]) |
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
68 |
: Map[String, Double] = |
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
69 |
{ |
68731 | 70 |
val maximals = sessions_structure.build_graph.maximals.toSet |
71669 | 71 |
def desc_timing(session_name: String): Double = |
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
72 |
{ |
71669 | 73 |
if (maximals.contains(session_name)) timing(session_name) |
68487 | 74 |
else { |
71669 | 75 |
val descendants = sessions_structure.build_descendants(List(session_name)).toSet |
68731 | 76 |
val g = sessions_structure.build_graph.restrict(descendants) |
68487 | 77 |
(0.0 :: g.maximals.flatMap(desc => { |
78 |
val ps = g.all_preds(List(desc)) |
|
71895 | 79 |
if (ps.exists(p => !timing.isDefinedAt(p))) None |
68487 | 80 |
else Some(ps.map(timing(_)).sum) |
81 |
})).max |
|
82 |
} |
|
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
83 |
} |
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
84 |
timing.keySet.iterator.map(name => (name -> desc_timing(name))).toMap.withDefaultValue(0.0) |
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
85 |
} |
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
86 |
|
68731 | 87 |
def apply(progress: Progress, sessions_structure: Sessions.Structure, store: Sessions.Store) |
88 |
: Queue = |
|
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
89 |
{ |
68731 | 90 |
val graph = sessions_structure.build_graph |
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65406
diff
changeset
|
91 |
val names = graph.keys |
51220 | 92 |
|
65831 | 93 |
val timings = names.map(name => (name, load_timings(progress, store, name))) |
51220 | 94 |
val command_timings = |
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
95 |
timings.map({ case (name, (ts, _)) => (name, ts) }).toMap.withDefaultValue(Nil) |
51220 | 96 |
val session_timing = |
68731 | 97 |
make_session_timing(sessions_structure, |
98 |
timings.map({ case (name, (_, t)) => (name, t) }).toMap) |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
99 |
|
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
100 |
object Ordering extends scala.math.Ordering[String] |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
101 |
{ |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
102 |
def compare_timing(name1: String, name2: String): Int = |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
103 |
{ |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
104 |
val t1 = session_timing(name1) |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
105 |
val t2 = session_timing(name2) |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
106 |
if (t1 == 0.0 || t2 == 0.0) 0 |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
107 |
else t1 compare t2 |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
108 |
} |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
109 |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
110 |
def compare(name1: String, name2: String): Int = |
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
111 |
compare_timing(name2, name1) match { |
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
112 |
case 0 => |
68731 | 113 |
sessions_structure(name2).timeout compare sessions_structure(name1).timeout match { |
68486
6984a55f3cba
clarified queue ordering: take session descendants into account, notably for "slow" AFP sessions;
wenzelm
parents:
68331
diff
changeset
|
114 |
case 0 => name1 compare name2 |
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
115 |
case ord => ord |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
116 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
117 |
case ord => ord |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
118 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
119 |
} |
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
120 |
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65406
diff
changeset
|
121 |
new Queue(graph, SortedSet(names: _*)(Ordering), command_timings) |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
122 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
123 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
124 |
|
65314 | 125 |
private class Queue( |
62631 | 126 |
graph: Graph[String, Sessions.Info], |
51220 | 127 |
order: SortedSet[String], |
128 |
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
|
129 |
{ |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
130 |
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
|
131 |
|
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
132 |
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
|
133 |
|
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
134 |
def - (name: String): Queue = |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
135 |
new Queue(graph.del_node(name), |
67011 | 136 |
order - name, // FIXME scala-2.10.0 .. 2.12.4 TreeSet problem!? |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
137 |
command_timings) |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
138 |
|
62631 | 139 |
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
|
140 |
{ |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
141 |
val it = order.iterator.dropWhile(name => |
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
142 |
skip(name) |
67011 | 143 |
|| !graph.defined(name) // FIXME scala-2.10.0 .. 2.12.4 TreeSet problem!? |
51227
88c96e836ed6
prefer comparison of session timing, if this is known already;
wenzelm
parents:
51223
diff
changeset
|
144 |
|| !graph.is_minimal(name)) |
48680 | 145 |
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
|
146 |
else None |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
147 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
148 |
} |
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
149 |
|
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
150 |
|
65313 | 151 |
/* PIDE protocol handler */ |
152 |
||
65308 | 153 |
/* job: running prover process */ |
48341 | 154 |
|
65308 | 155 |
private class Job(progress: Progress, |
71669 | 156 |
session_name: String, |
65308 | 157 |
val info: Sessions.Info, |
65313 | 158 |
deps: Sessions.Deps, |
65308 | 159 |
store: Sessions.Store, |
71614 | 160 |
do_store: Boolean, |
65308 | 161 |
verbose: Boolean, |
162 |
val numa_node: Option[Int], |
|
163 |
command_timings: List[Properties.T]) |
|
48418 | 164 |
{ |
71895 | 165 |
val options: Options = NUMA.policy_options(info.options, numa_node) |
65312 | 166 |
|
71610 | 167 |
private val sessions_structure = deps.sessions_structure |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
168 |
|
59445 | 169 |
private val graph_file = Isabelle_System.tmp_file("session_graph", "pdf") |
71677 | 170 |
graphview.Graph_File.write(options, graph_file, deps(session_name).session_graph_display) |
59445 | 171 |
|
68198
6710167e17af
avoid race condition wrt. ISABELLE_TMP, which is removed in Bash.cleanup() before Bash.result(progress_stdout);
wenzelm
parents:
68148
diff
changeset
|
172 |
private val export_tmp_dir = Isabelle_System.tmp_dir("export") |
68289 | 173 |
private val export_consumer = |
71669 | 174 |
Export.consumer(store.open_database(session_name, output = true), cache = store.xz_cache) |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
68088
diff
changeset
|
175 |
|
62573 | 176 |
private val future_result: Future[Process_Result] = |
71718 | 177 |
Future.thread("build", uninterruptible = true) { |
65308 | 178 |
val parent = info.parent.getOrElse("") |
71645 | 179 |
val base = deps(parent) |
65308 | 180 |
val args_yxml = |
181 |
YXML.string_of_body( |
|
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
182 |
{ |
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
183 |
import XML.Encode._ |
71611
fb6953e77000
eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents:
71610
diff
changeset
|
184 |
pair(list(pair(string, int)), pair(list(properties), pair(bool, |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
185 |
pair(Path.encode, pair(list(pair(Path.encode, Path.encode)), pair(string, |
65307 | 186 |
pair(string, pair(string, pair(string, pair(Path.encode, |
71677 | 187 |
pair(list(pair(Options.encode, list(pair(string, properties)))), |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
188 |
pair(list(pair(string, properties)), |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
189 |
pair(list(pair(string, string)), |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
190 |
pair(list(string), pair(list(pair(string, string)), |
71611
fb6953e77000
eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents:
71610
diff
changeset
|
191 |
pair(list(string), list(string)))))))))))))))))( |
fb6953e77000
eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents:
71610
diff
changeset
|
192 |
(Symbol.codes, (command_timings, (verbose, |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
193 |
(store.browser_info, (info.document_files, (File.standard_path(graph_file), |
71669 | 194 |
(parent, (info.chapter, (session_name, (Path.current, |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
195 |
(info.theories, |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
196 |
(sessions_structure.session_positions, |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
197 |
(sessions_structure.dest_session_directories, |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70671
diff
changeset
|
198 |
(base.doc_names, (base.global_theories.toList, |
71611
fb6953e77000
eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents:
71610
diff
changeset
|
199 |
(base.loaded_theories.keys, info.bibtex_entries.map(_.info)))))))))))))))))) |
65308 | 200 |
}) |
201 |
||
202 |
val env = |
|
203 |
Isabelle_System.settings() + |
|
68198
6710167e17af
avoid race condition wrt. ISABELLE_TMP, which is removed in Bash.cleanup() before Bash.result(progress_stdout);
wenzelm
parents:
68148
diff
changeset
|
204 |
("ISABELLE_EXPORT_TMP" -> File.standard_path(export_tmp_dir)) + |
71677 | 205 |
("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString) |
65308 | 206 |
|
71669 | 207 |
val is_pure = Sessions.is_pure(session_name) |
71610 | 208 |
|
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
209 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
210 |
|
71613 | 211 |
val eval_store = |
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
212 |
if (do_store) { |
71613 | 213 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) ::: |
214 |
List("ML_Heap.save_child " + |
|
71669 | 215 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
71613 | 216 |
} |
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
217 |
else Nil |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
218 |
|
71877 | 219 |
if (options.bool("pide_session")) { |
71643 | 220 |
val resources = new Resources(sessions_structure, deps(parent)) |
71971 | 221 |
val session = |
222 |
new Session(options, resources) { |
|
223 |
override val xml_cache: XML.Cache = store.xml_cache |
|
224 |
override val xz_cache: XZ.Cache = store.xz_cache |
|
225 |
} |
|
65313 | 226 |
|
72007 | 227 |
object Build_Session_Errors |
228 |
{ |
|
229 |
private val promise: Promise[List[String]] = Future.promise |
|
230 |
||
231 |
def result: Exn.Result[List[String]] = promise.join_result |
|
232 |
def cancel: Unit = promise.cancel |
|
233 |
def apply(errs: List[String]) |
|
234 |
{ |
|
235 |
try { promise.fulfill(errs) } |
|
236 |
catch { case _: IllegalStateException => } |
|
237 |
} |
|
238 |
} |
|
239 |
||
71648 | 240 |
val stdout = new StringBuilder(1000) |
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
241 |
val messages = new mutable.ListBuffer[XML.Elem] |
71652 | 242 |
val command_timings = new mutable.ListBuffer[Properties.T] |
243 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
72002
5c4800f6b25a
more robust protocol for "Timing ..." messages, notably for pide_session=true;
wenzelm
parents:
71992
diff
changeset
|
244 |
val session_timings = new mutable.ListBuffer[Properties.T] |
71652 | 245 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
246 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
71648 | 247 |
|
71970 | 248 |
def fun( |
249 |
name: String, |
|
250 |
acc: mutable.ListBuffer[Properties.T], |
|
251 |
unapply: Properties.T => Option[Properties.T]): (String, Session.Protocol_Function) = |
|
252 |
{ |
|
253 |
name -> ((msg: Prover.Protocol_Output) => |
|
254 |
unapply(msg.properties) match { |
|
255 |
case Some(props) => acc += props; true |
|
256 |
case _ => false |
|
257 |
}) |
|
258 |
} |
|
259 |
||
71672 | 260 |
session.init_protocol_handler(new Session.Protocol_Handler |
261 |
{ |
|
72007 | 262 |
override def exit() { Build_Session_Errors.cancel } |
71672 | 263 |
|
264 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = |
|
265 |
{ |
|
71879 | 266 |
val (rc, errors) = |
71672 | 267 |
try { |
71879 | 268 |
val (rc, errs) = |
269 |
{ |
|
270 |
import XML.Decode._ |
|
271 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
71672 | 272 |
} |
71879 | 273 |
val errors = |
274 |
for (err <- errs) yield { |
|
275 |
val prt = Protocol_Message.expose_no_reports(err) |
|
276 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
277 |
} |
|
278 |
(rc, errors) |
|
71672 | 279 |
} |
71879 | 280 |
catch { case ERROR(err) => (2, List(err)) } |
281 |
||
282 |
session.protocol_command("Prover.stop", rc.toString) |
|
72007 | 283 |
Build_Session_Errors(errors) |
71672 | 284 |
true |
285 |
} |
|
286 |
||
287 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
288 |
msg.properties match { |
|
289 |
case Markup.Loading_Theory(name) => |
|
290 |
progress.theory(Progress.Theory(name, session = session_name)) |
|
291 |
true |
|
292 |
case _ => false |
|
293 |
} |
|
294 |
||
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
295 |
private def export(msg: Prover.Protocol_Output): Boolean = |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
296 |
msg.properties match { |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
297 |
case Protocol.Export(args) => |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
298 |
export_consumer(session_name, args, msg.bytes) |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
299 |
true |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
300 |
case _ => false |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
301 |
} |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
302 |
|
71672 | 303 |
val functions = |
304 |
List( |
|
71673 | 305 |
Markup.Build_Session_Finished.name -> build_session_finished, |
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
306 |
Markup.Loading_Theory.name -> loading_theory, |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
307 |
Markup.EXPORT -> export, |
71970 | 308 |
fun(Markup.Command_Timing.name, command_timings, Markup.Command_Timing.unapply), |
309 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
|
72002
5c4800f6b25a
more robust protocol for "Timing ..." messages, notably for pide_session=true;
wenzelm
parents:
71992
diff
changeset
|
310 |
fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply), |
71970 | 311 |
fun(Markup.ML_Statistics.name, runtime_statistics, Markup.ML_Statistics.unapply), |
312 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
71672 | 313 |
}) |
314 |
||
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
315 |
session.all_messages += Session.Consumer[Any]("build_session_output") |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
316 |
{ |
71648 | 317 |
case msg: Prover.Output => |
318 |
val message = msg.message |
|
319 |
if (msg.is_stdout) { |
|
320 |
stdout ++= Symbol.encode(XML.content(message)) |
|
321 |
} |
|
322 |
else if (Protocol.is_exported(message)) { |
|
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
323 |
messages += message |
71648 | 324 |
} |
72005
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
325 |
else if (msg.is_exit) { |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
326 |
val err = |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
327 |
"Prover terminated" + |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
328 |
(msg.properties match { |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
329 |
case Markup.Process_Result(result) => ": " + result.print_rc |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
330 |
case _ => "" |
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
331 |
}) |
72007 | 332 |
Build_Session_Errors(List(err)) |
72005
11c46b8e91c0
more robust build_session protocol: allow prover process to terminate/crash without build_session_finished message;
wenzelm
parents:
72002
diff
changeset
|
333 |
} |
71648 | 334 |
case _ => |
335 |
} |
|
336 |
||
71644 | 337 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store) |
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
338 |
|
71607 | 339 |
val process = |
71677 | 340 |
Isabelle_Process(session, options, sessions_structure, store, |
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
341 |
logic = parent, raw_ml_system = is_pure, |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
342 |
use_prelude = use_prelude, eval_main = eval_main, |
71668
25ef5c7287a7
proper treatment of startup errors, notably for Pure ROOT.ML;
wenzelm
parents:
71667
diff
changeset
|
343 |
cwd = info.dir.file, env = env) |
65313 | 344 |
|
71668
25ef5c7287a7
proper treatment of startup errors, notably for Pure ROOT.ML;
wenzelm
parents:
71667
diff
changeset
|
345 |
val errors = |
71718 | 346 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
347 |
Exn.capture { process.await_startup } match { |
|
348 |
case Exn.Res(_) => |
|
349 |
session.protocol_command("build_session", args_yxml) |
|
72007 | 350 |
Build_Session_Errors.result |
71718 | 351 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
352 |
} |
|
71668
25ef5c7287a7
proper treatment of startup errors, notably for Pure ROOT.ML;
wenzelm
parents:
71667
diff
changeset
|
353 |
} |
71607 | 354 |
|
71718 | 355 |
val process_result = |
356 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { process.await_shutdown } |
|
71652 | 357 |
val process_output = |
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
358 |
stdout.toString :: |
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
359 |
messages.toList.map(message => |
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
360 |
Symbol.encode(Protocol.message_text(List(message), metric = Symbol.Metric))) ::: |
71652 | 361 |
command_timings.toList.map(Protocol.Command_Timing_Marker.apply) ::: |
362 |
theory_timings.toList.map(Protocol.Theory_Timing_Marker.apply) ::: |
|
72012 | 363 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
71652 | 364 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
365 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) |
|
71648 | 366 |
|
72016
5469bacf5573
avoid duplicate Timing messages (see also 5c4800f6b25a);
wenzelm
parents:
72015
diff
changeset
|
367 |
val result = process_result.output(process_output) |
71718 | 368 |
|
369 |
errors match { |
|
370 |
case Exn.Res(Nil) => result |
|
371 |
case Exn.Res(errs) => |
|
372 |
result.error_rc.output( |
|
373 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
374 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
375 |
case Exn.Exn(Exn.Interrupt()) => |
|
376 |
if (result.ok) result.copy(rc = Exn.Interrupt.return_code) else result |
|
377 |
case Exn.Exn(exn) => throw exn |
|
65313 | 378 |
} |
65308 | 379 |
} |
380 |
else { |
|
381 |
val args_file = Isabelle_System.tmp_file("build") |
|
382 |
File.write(args_file, args_yxml) |
|
383 |
||
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
384 |
val eval_build = |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
385 |
"Build.build " + ML_Syntax.print_string_bytes(File.standard_path(args_file)) |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
386 |
val eval_main = Command_Line.ML_tool(eval_build :: eval_store) |
64265 | 387 |
|
65308 | 388 |
val process = |
71677 | 389 |
ML_Process(options, deps.sessions_structure, store, |
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
390 |
logic = parent, raw_ml_system = is_pure, |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
391 |
use_prelude = use_prelude, eval_main = eval_main, |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
392 |
cwd = info.dir.file, env = env, cleanup = () => args_file.delete) |
64265 | 393 |
|
71718 | 394 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
395 |
process.result( |
|
396 |
progress_stdout = |
|
397 |
{ |
|
398 |
case Protocol.Loading_Theory_Marker(theory) => |
|
399 |
progress.theory(Progress.Theory(theory, session = session_name)) |
|
400 |
case Protocol.Export.Marker((args, path)) => |
|
401 |
val body = |
|
402 |
try { Bytes.read(path) } |
|
403 |
catch { |
|
404 |
case ERROR(msg) => |
|
405 |
error("Failed to read export " + quote(args.compound_name) + "\n" + msg) |
|
406 |
} |
|
407 |
path.file.delete |
|
408 |
export_consumer(session_name, args, body) |
|
409 |
case _ => |
|
410 |
}, |
|
411 |
progress_limit = |
|
412 |
options.int("process_output_limit") match { |
|
413 |
case 0 => None |
|
414 |
case m => Some(m * 1000000L) |
|
415 |
}, |
|
416 |
strict = false) |
|
417 |
} |
|
65308 | 418 |
} |
50845 | 419 |
} |
48674 | 420 |
|
62572 | 421 |
def terminate: Unit = future_result.cancel |
422 |
def is_finished: Boolean = future_result.is_finished |
|
48674 | 423 |
|
56779 | 424 |
private val timeout_request: Option[Event_Timer.Request] = |
425 |
{ |
|
62569 | 426 |
if (info.timeout > Time.zero) |
66943 | 427 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate }) |
48674 | 428 |
else None |
56779 | 429 |
} |
48674 | 430 |
|
68217 | 431 |
def join: (Process_Result, Option[String]) = |
50845 | 432 |
{ |
68217 | 433 |
val result0 = future_result.join |
434 |
val result1 = |
|
71601 | 435 |
export_consumer.shutdown(close = true).map(Output.error_message_text) match { |
68217 | 436 |
case Nil => result0 |
68928 | 437 |
case errs => result0.errors(errs).error_rc |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
68088
diff
changeset
|
438 |
} |
50845 | 439 |
|
68198
6710167e17af
avoid race condition wrt. ISABELLE_TMP, which is removed in Bash.cleanup() before Bash.result(progress_stdout);
wenzelm
parents:
68148
diff
changeset
|
440 |
Isabelle_System.rm_tree(export_tmp_dir) |
6710167e17af
avoid race condition wrt. ISABELLE_TMP, which is removed in Bash.cleanup() before Bash.result(progress_stdout);
wenzelm
parents:
68148
diff
changeset
|
441 |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
442 |
if (result1.ok) |
71669 | 443 |
Present.finish(progress, store.browser_info, graph_file, info, session_name) |
61372 | 444 |
|
59445 | 445 |
graph_file.delete |
66943 | 446 |
|
447 |
val was_timeout = |
|
448 |
timeout_request match { |
|
449 |
case None => false |
|
450 |
case Some(request) => !request.cancel |
|
451 |
} |
|
48674 | 452 |
|
68217 | 453 |
val result2 = |
454 |
if (result1.interrupted) { |
|
455 |
if (was_timeout) result1.error(Output.error_message_text("Timeout")).was_timeout |
|
456 |
else result1.error(Output.error_message_text("Interrupt")) |
|
457 |
} |
|
458 |
else result1 |
|
459 |
||
460 |
val heap_digest = |
|
71669 | 461 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
462 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
68217 | 463 |
else None |
464 |
||
465 |
(result2, heap_digest) |
|
48674 | 466 |
} |
48364 | 467 |
} |
468 |
||
48424 | 469 |
|
62631 | 470 |
|
62641 | 471 |
/** build with results **/ |
48424 | 472 |
|
63996 | 473 |
class Results private[Build](results: Map[String, (Option[Process_Result], Sessions.Info)]) |
62403 | 474 |
{ |
475 |
def sessions: Set[String] = results.keySet |
|
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
476 |
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
|
477 |
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
|
478 |
def info(name: String): Sessions.Info = results(name)._2 |
71601 | 479 |
val rc: Int = |
65253 | 480 |
(0 /: results.iterator.map( |
481 |
{ case (_, (Some(r), _)) => r.rc case (_, (None, _)) => 1 }))(_ max _) |
|
62641 | 482 |
def ok: Boolean = rc == 0 |
62406 | 483 |
|
484 |
override def toString: String = rc.toString |
|
62403 | 485 |
} |
486 |
||
72013 | 487 |
def session_finished(session_name: String, timing: Timing): String = |
488 |
"Finished " + session_name + " (" + timing.message_resources + ")" |
|
489 |
||
490 |
def session_timing(session_name: String, threads: Int, timing: Timing): String = |
|
72015 | 491 |
"Timing " + session_name + " (" + threads + " threads, " + timing.message_factor + ")" |
72013 | 492 |
|
72018 | 493 |
def session_timing(session_name: String, props: Properties.T): String = |
494 |
session_timing(session_name, |
|
495 |
Markup.Session_Timing.Threads.unapply(props) getOrElse 1, |
|
496 |
Markup.Timing_Properties.parse(props)) |
|
497 |
||
62641 | 498 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
499 |
options: Options, |
71981 | 500 |
selection: Sessions.Selection = Sessions.Selection.empty, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
501 |
progress: Progress = new Progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
502 |
check_unknown_files: Boolean = false, |
48511
37999ee01156
remove old output heaps, to ensure that result is valid wrt. check_stamps;
wenzelm
parents:
48509
diff
changeset
|
503 |
build_heap: Boolean = false, |
48595 | 504 |
clean_build: Boolean = false, |
56890 | 505 |
dirs: List[Path] = Nil, |
506 |
select_dirs: List[Path] = Nil, |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66962
diff
changeset
|
507 |
infos: List[Sessions.Info] = Nil, |
64265 | 508 |
numa_shuffling: Boolean = false, |
48509 | 509 |
max_jobs: Int = 1, |
48903 | 510 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
511 |
check_keywords: Set[String] = Set.empty, |
66841 | 512 |
fresh_build: Boolean = false, |
48509 | 513 |
no_build: Boolean = false, |
66745 | 514 |
soft_build: Boolean = false, |
48509 | 515 |
verbose: Boolean = false, |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
516 |
export_files: Boolean = false): Results = |
63224 | 517 |
{ |
71677 | 518 |
val build_options = |
71679
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
519 |
options + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
520 |
"ML_statistics" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
521 |
"completion_limit=0" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
522 |
"editor_tracing_messages=0" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
523 |
"pide_reports=false" |
51220 | 524 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69811
diff
changeset
|
525 |
val store = Sessions.store(build_options) |
66745 | 526 |
|
69369
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
527 |
Isabelle_Fonts.init() |
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
528 |
|
66745 | 529 |
|
530 |
/* session selection and dependencies */ |
|
65422 | 531 |
|
66961 | 532 |
val full_sessions = |
67026 | 533 |
Sessions.load_structure(build_options, dirs = dirs, select_dirs = select_dirs, infos = infos) |
65422 | 534 |
|
71669 | 535 |
def sources_stamp(deps: Sessions.Deps, session_name: String): String = |
66749
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
536 |
{ |
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
537 |
val digests = |
71669 | 538 |
full_sessions(session_name).meta_digest :: |
539 |
deps.sources(session_name) ::: |
|
540 |
deps.imported_sources(session_name) |
|
66749
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
541 |
SHA1.digest(cat_lines(digests.map(_.toString).sorted)).toString |
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
542 |
} |
66745 | 543 |
|
68204 | 544 |
val deps = |
66745 | 545 |
{ |
546 |
val deps0 = |
|
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
547 |
Sessions.deps(full_sessions.selection(selection), |
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
548 |
progress = progress, inlined_files = true, verbose = verbose, |
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
549 |
list_files = list_files, check_keywords = check_keywords).check_errors |
66745 | 550 |
|
66841 | 551 |
if (soft_build && !fresh_build) { |
66745 | 552 |
val outdated = |
68204 | 553 |
deps0.sessions_structure.build_topological_order.flatMap(name => |
68221 | 554 |
store.access_database(name) match { |
68214 | 555 |
case Some(db) => |
68216 | 556 |
using(db)(store.read_build(_, name)) match { |
66745 | 557 |
case Some(build) |
66747 | 558 |
if build.ok && build.sources == sources_stamp(deps0, name) => None |
66745 | 559 |
case _ => Some(name) |
560 |
} |
|
561 |
case None => Some(name) |
|
562 |
}) |
|
68204 | 563 |
|
564 |
Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)), |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70509
diff
changeset
|
565 |
progress = progress, inlined_files = true).check_errors |
66745 | 566 |
} |
68204 | 567 |
else deps0 |
66745 | 568 |
} |
569 |
||
570 |
||
571 |
/* check unknown files */ |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
572 |
|
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
573 |
if (check_unknown_files) { |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
574 |
val source_files = |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
575 |
(for { |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
576 |
(_, base) <- deps.session_bases.iterator |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
577 |
(path, _) <- base.sources.iterator |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
578 |
} yield path).toList |
67098 | 579 |
val exclude_files = List(Path.explode("$POLYML_EXE")).map(_.canonical_file) |
580 |
val unknown_files = |
|
67782
7e223a05e6d8
clarified notion of unknown files: ignore files outside of a Mercurial repository;
wenzelm
parents:
67493
diff
changeset
|
581 |
Mercurial.check_files(source_files)._2. |
67098 | 582 |
filterNot(path => exclude_files.contains(path.canonical_file)) |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
583 |
if (unknown_files.nonEmpty) { |
67782
7e223a05e6d8
clarified notion of unknown files: ignore files outside of a Mercurial repository;
wenzelm
parents:
67493
diff
changeset
|
584 |
progress.echo_warning("Unknown files (not part of the underlying Mercurial repository):" + |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
585 |
unknown_files.map(path => path.expand.implode).sorted.mkString("\n ", "\n ", "")) |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
586 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
587 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
588 |
|
51220 | 589 |
|
590 |
/* main build process */ |
|
591 |
||
68204 | 592 |
val queue = Queue(progress, deps.sessions_structure, store) |
65289 | 593 |
|
68219 | 594 |
store.prepare_output_dir() |
48373 | 595 |
|
48595 | 596 |
if (clean_build) { |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
597 |
for (name <- full_sessions.imports_descendants(full_sessions.imports_selection(selection))) { |
68220
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
598 |
val (relevant, ok) = store.clean_output(name) |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
599 |
if (relevant) { |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
600 |
if (ok) progress.echo("Cleaned " + name) |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
601 |
else progress.echo(name + " FAILED to clean") |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
602 |
} |
48595 | 603 |
} |
604 |
} |
|
605 |
||
48425 | 606 |
// scheduler loop |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
607 |
case class Result( |
66594 | 608 |
current: Boolean, |
68213 | 609 |
heap_digest: Option[String], |
66594 | 610 |
process: Option[Process_Result], |
611 |
info: Sessions.Info) |
|
62402 | 612 |
{ |
613 |
def ok: Boolean = |
|
614 |
process match { |
|
615 |
case None => false |
|
616 |
case Some(res) => res.rc == 0 |
|
617 |
} |
|
618 |
} |
|
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
619 |
|
56837
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
620 |
def sleep() |
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
621 |
{ |
71727
0cb14b7455ee
more careful handling of interrupts, notably for Isabelle/jEdit Scala Console;
wenzelm
parents:
71726
diff
changeset
|
622 |
Isabelle_Thread.interrupt_handler(_ => progress.stop) { Time.seconds(0.5).sleep } |
56837
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
623 |
} |
50366 | 624 |
|
64265 | 625 |
val numa_nodes = new NUMA.Nodes(numa_shuffling) |
626 |
||
48425 | 627 |
@tailrec def loop( |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
628 |
pending: Queue, |
62628 | 629 |
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
|
630 |
results: Map[String, Result]): Map[String, Result] = |
48425 | 631 |
{ |
64265 | 632 |
def used_node(i: Int): Boolean = |
633 |
running.iterator.exists( |
|
634 |
{ case (_, (_, job)) => job.numa_node.isDefined && job.numa_node.get == i }) |
|
635 |
||
48425 | 636 |
if (pending.is_empty) results |
51253 | 637 |
else { |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
638 |
if (progress.stopped) { |
51253 | 639 |
for ((_, (_, job)) <- running) job.terminate |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
640 |
} |
51253 | 641 |
|
48674 | 642 |
running.find({ case (_, (_, job)) => job.is_finished }) match { |
71669 | 643 |
case Some((session_name, (input_heaps, job))) => |
50367 | 644 |
//{{{ finish job |
48424 | 645 |
|
68217 | 646 |
val (process_result, heap_digest) = job.join |
48373 | 647 |
|
71623
b3bddebe44ca
clarified signature: more explicit type Protocol_Message.Marker;
wenzelm
parents:
71614
diff
changeset
|
648 |
val log_lines = process_result.out_lines.filterNot(Protocol_Message.Marker.test) |
62404
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
649 |
val process_result_tail = |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
650 |
{ |
62409
e391528eff3b
proper option process_output_tail, more generous default;
wenzelm
parents:
62406
diff
changeset
|
651 |
val tail = job.info.options.int("process_output_tail") |
62632 | 652 |
process_result.copy( |
653 |
out_lines = |
|
71669 | 654 |
"(see also " + store.output_log(session_name).file.toString + ")" :: |
65294 | 655 |
(if (tail == 0) log_lines else log_lines.drop(log_lines.length - tail max 0))) |
62404
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
656 |
} |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
657 |
|
72017 | 658 |
val build_log = |
659 |
Build_Log.Log_File(session_name, process_result.out_lines). |
|
660 |
parse_session_info( |
|
661 |
command_timings = true, |
|
662 |
theory_timings = true, |
|
663 |
ml_statistics = true, |
|
664 |
task_statistics = true) |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
665 |
|
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
666 |
// write log file |
68217 | 667 |
if (process_result.ok) { |
71669 | 668 |
File.write_gzip(store.output_log_gz(session_name), terminate_lines(log_lines)) |
68217 | 669 |
} |
71669 | 670 |
else File.write(store.output_log(session_name), terminate_lines(log_lines)) |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
671 |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
672 |
// write database |
72017 | 673 |
using(store.open_database(session_name, output = true))(db => |
674 |
store.write_session_info(db, session_name, |
|
675 |
build_log = |
|
676 |
if (process_result.timeout) build_log.error("Timeout") else build_log, |
|
677 |
build = |
|
678 |
Session_Info(sources_stamp(deps, session_name), input_heaps, heap_digest, |
|
679 |
process_result.rc))) |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
680 |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
681 |
// messages |
71601 | 682 |
process_result.err_lines.foreach(progress.echo) |
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
683 |
|
72019 | 684 |
if (verbose) progress.echo(session_timing(session_name, build_log.session_timing)) |
685 |
||
72013 | 686 |
if (process_result.ok) { |
687 |
progress.echo(session_finished(session_name, process_result.timing)) |
|
688 |
} |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
689 |
else { |
71669 | 690 |
progress.echo(session_name + " FAILED") |
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
691 |
if (!process_result.interrupted) progress.echo(process_result_tail.out) |
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
692 |
} |
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
693 |
|
71669 | 694 |
loop(pending - session_name, running - session_name, |
695 |
results + |
|
696 |
(session_name -> Result(false, heap_digest, Some(process_result_tail), job.info))) |
|
50367 | 697 |
//}}} |
60215 | 698 |
case None if running.size < (max_jobs max 1) => |
50367 | 699 |
//{{{ check/start next job |
71601 | 700 |
pending.dequeue(running.isDefinedAt) match { |
71669 | 701 |
case Some((session_name, info)) => |
66848 | 702 |
val ancestor_results = |
71669 | 703 |
deps.sessions_structure.build_requirements(List(session_name)). |
704 |
filterNot(_ == session_name).map(results(_)) |
|
68213 | 705 |
val ancestor_heaps = ancestor_results.flatMap(_.heap_digest) |
62628 | 706 |
|
71669 | 707 |
val do_store = |
708 |
build_heap || Sessions.is_pure(session_name) || queue.is_inner(session_name) |
|
48547 | 709 |
|
68213 | 710 |
val (current, heap_digest) = |
48547 | 711 |
{ |
71669 | 712 |
store.access_database(session_name) match { |
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68209
diff
changeset
|
713 |
case Some(db) => |
71669 | 714 |
using(db)(store.read_build(_, session_name)) match { |
68216 | 715 |
case Some(build) => |
71669 | 716 |
val heap_digest = store.find_heap_digest(session_name) |
68216 | 717 |
val current = |
718 |
!fresh_build && |
|
719 |
build.ok && |
|
71669 | 720 |
build.sources == sources_stamp(deps, session_name) && |
68216 | 721 |
build.input_heaps == ancestor_heaps && |
722 |
build.output_heap == heap_digest && |
|
71614 | 723 |
!(do_store && heap_digest.isEmpty) |
68216 | 724 |
(current, heap_digest) |
725 |
case None => (false, None) |
|
726 |
} |
|
62636 | 727 |
case None => (false, None) |
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
728 |
} |
48547 | 729 |
} |
62628 | 730 |
val all_current = current && ancestor_results.forall(_.current) |
48528
784c6f63d79c
proper all_current, which regards parent status as well;
wenzelm
parents:
48511
diff
changeset
|
731 |
|
48547 | 732 |
if (all_current) |
71669 | 733 |
loop(pending - session_name, running, |
734 |
results + |
|
735 |
(session_name -> Result(true, heap_digest, Some(Process_Result(0)), info))) |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
736 |
else if (no_build) { |
71894 | 737 |
progress.echo_if(verbose, "Skipping " + session_name + " ...") |
71669 | 738 |
loop(pending - session_name, running, |
739 |
results + |
|
740 |
(session_name -> Result(false, heap_digest, Some(Process_Result(1)), info))) |
|
48678
ff27af15530c
queue ordering by descending outdegree and timeout;
wenzelm
parents:
48676
diff
changeset
|
741 |
} |
62628 | 742 |
else if (ancestor_results.forall(_.ok) && !progress.stopped) { |
71669 | 743 |
progress.echo((if (do_store) "Building " else "Running ") + session_name + " ...") |
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
744 |
|
71669 | 745 |
store.clean_output(session_name) |
746 |
using(store.open_database(session_name, output = true))( |
|
747 |
store.init_session_info(_, session_name)) |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
748 |
|
71601 | 749 |
val numa_node = numa_nodes.next(used_node) |
51220 | 750 |
val job = |
71669 | 751 |
new Job(progress, session_name, info, deps, store, do_store, verbose, |
752 |
numa_node, queue.command_timings(session_name)) |
|
753 |
loop(pending, running + (session_name -> (ancestor_heaps, job)), results) |
|
48547 | 754 |
} |
755 |
else { |
|
71669 | 756 |
progress.echo(session_name + " CANCELLED") |
757 |
loop(pending - session_name, running, |
|
758 |
results + (session_name -> Result(false, heap_digest, None, info))) |
|
48547 | 759 |
} |
760 |
case None => sleep(); loop(pending, running, results) |
|
48425 | 761 |
} |
50367 | 762 |
///}}} |
48425 | 763 |
case None => sleep(); loop(pending, running, results) |
48373 | 764 |
} |
51253 | 765 |
} |
48425 | 766 |
} |
767 |
||
51220 | 768 |
|
769 |
/* build results */ |
|
770 |
||
62641 | 771 |
val results0 = |
48583 | 772 |
if (deps.is_empty) { |
65827 | 773 |
progress.echo_warning("Nothing to build") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
50686
diff
changeset
|
774 |
Map.empty[String, Result] |
48583 | 775 |
} |
71727
0cb14b7455ee
more careful handling of interrupts, notably for Isabelle/jEdit Scala Console;
wenzelm
parents:
71726
diff
changeset
|
776 |
else Isabelle_Thread.uninterruptible { loop(queue, Map.empty, Map.empty) } |
48583 | 777 |
|
62641 | 778 |
val results = |
64265 | 779 |
new Results( |
780 |
(for ((name, result) <- results0.iterator) |
|
781 |
yield (name, (result.process, result.info))).toMap) |
|
62641 | 782 |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
783 |
if (export_files) { |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
784 |
for (name <- full_sessions.imports_selection(selection).iterator if results(name).ok) { |
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
785 |
val info = results.info(name) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
786 |
if (info.export_files.nonEmpty) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
787 |
progress.echo("Exporting " + info.name + " ...") |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
788 |
for ((dir, prune, pats) <- info.export_files) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
789 |
Export.export_files(store, name, info.dir + dir, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
790 |
progress = if (verbose) progress else new Progress, |
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
791 |
export_prune = prune, |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
792 |
export_patterns = pats) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
793 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
794 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
795 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
796 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
797 |
|
62641 | 798 |
if (results.rc != 0 && (verbose || !no_build)) { |
799 |
val unfinished = |
|
800 |
(for { |
|
801 |
name <- results.sessions.iterator |
|
802 |
if !results(name).ok |
|
803 |
} yield name).toList.sorted |
|
804 |
progress.echo("Unfinished session(s): " + commas(unfinished)) |
|
805 |
} |
|
806 |
||
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
|
807 |
|
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
|
808 |
/* 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
|
809 |
|
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
|
810 |
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
|
811 |
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
|
812 |
(for { |
62641 | 813 |
(name, result) <- results0.iterator |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
814 |
if result.ok |
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65406
diff
changeset
|
815 |
info = full_sessions(name) |
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
|
816 |
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
|
817 |
} 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
|
818 |
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
|
819 |
|
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
|
820 |
for ((chapter, entries) <- browser_chapters) |
62632 | 821 |
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
|
822 |
|
62632 | 823 |
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
|
824 |
} |
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
|
825 |
|
62641 | 826 |
results |
48341 | 827 |
} |
828 |
||
829 |
||
62833 | 830 |
/* Isabelle tool wrapper */ |
48341 | 831 |
|
62833 | 832 |
val isabelle_tool = Isabelle_Tool("build", "build and manage Isabelle sessions", args => |
48341 | 833 |
{ |
62833 | 834 |
val build_options = Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS")) |
62590 | 835 |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
836 |
var base_sessions: List[String] = Nil |
62833 | 837 |
var select_dirs: List[Path] = Nil |
64265 | 838 |
var numa_shuffling = false |
62833 | 839 |
var requirements = false |
66745 | 840 |
var soft_build = false |
62833 | 841 |
var exclude_session_groups: List[String] = Nil |
842 |
var all_sessions = false |
|
843 |
var build_heap = false |
|
844 |
var clean_build = false |
|
845 |
var dirs: List[Path] = Nil |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
846 |
var export_files = false |
66841 | 847 |
var fresh_build = false |
62833 | 848 |
var session_groups: List[String] = Nil |
849 |
var max_jobs = 1 |
|
850 |
var check_keywords: Set[String] = Set.empty |
|
851 |
var list_files = false |
|
852 |
var no_build = false |
|
67847 | 853 |
var options = Options.init(opts = build_options) |
62833 | 854 |
var verbose = false |
855 |
var exclude_sessions: List[String] = Nil |
|
62590 | 856 |
|
62833 | 857 |
val getopts = Getopts(""" |
62590 | 858 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
859 |
||
860 |
Options are: |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
861 |
-B NAME include session NAME and all descendants |
62590 | 862 |
-D DIR include session directory and select its sessions |
64265 | 863 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
71807 | 864 |
-R refer to requirements of selected sessions |
66745 | 865 |
-S soft build: only observe changes of sources, not heap images |
62590 | 866 |
-X NAME exclude sessions from group NAME and all descendants |
867 |
-a select all sessions |
|
868 |
-b build heap images |
|
869 |
-c clean build |
|
870 |
-d DIR include session directory |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
871 |
-e export files from session specification into file-system |
66841 | 872 |
-f fresh build |
62590 | 873 |
-g NAME select session group NAME |
874 |
-j INT maximum number of parallel jobs (default 1) |
|
875 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
|
876 |
-l list session source files |
|
877 |
-n no build -- test dependencies only |
|
878 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
879 |
-v verbose |
|
880 |
-x NAME exclude session NAME and all descendants |
|
881 |
||
62596 | 882 |
Build and manage Isabelle sessions, depending on implicit settings: |
883 |
||
71992 | 884 |
""" + Library.prefix_lines(" ", Build_Log.Settings.show()) + "\n", |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
885 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
62833 | 886 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
64265 | 887 |
"N" -> (_ => numa_shuffling = true), |
62833 | 888 |
"R" -> (_ => requirements = true), |
66745 | 889 |
"S" -> (_ => soft_build = true), |
62833 | 890 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
891 |
"a" -> (_ => all_sessions = true), |
|
892 |
"b" -> (_ => build_heap = true), |
|
893 |
"c" -> (_ => clean_build = true), |
|
894 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
895 |
"e" -> (_ => export_files = true), |
66841 | 896 |
"f" -> (_ => fresh_build = true), |
62833 | 897 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
63805 | 898 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
62833 | 899 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
900 |
"l" -> (_ => list_files = true), |
|
901 |
"n" -> (_ => no_build = true), |
|
902 |
"o:" -> (arg => options = options + arg), |
|
903 |
"v" -> (_ => verbose = true), |
|
904 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
62590 | 905 |
|
62833 | 906 |
val sessions = getopts(args) |
62590 | 907 |
|
64115 | 908 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 909 |
|
64140 | 910 |
val start_date = Date.now() |
911 |
||
62833 | 912 |
if (verbose) { |
913 |
progress.echo( |
|
64155 | 914 |
"Started at " + Build_Log.print_date(start_date) + |
64140 | 915 |
" (" + Isabelle_System.getenv("ML_IDENTIFIER") + " on " + Isabelle_System.hostname() +")") |
64081 | 916 |
progress.echo(Build_Log.Settings.show() + "\n") |
62833 | 917 |
} |
62590 | 918 |
|
62833 | 919 |
val results = |
920 |
progress.interrupt_handler { |
|
67846 | 921 |
build(options, |
71981 | 922 |
selection = Sessions.Selection( |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
923 |
requirements = requirements, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
924 |
all_sessions = all_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
925 |
base_sessions = base_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
926 |
exclude_session_groups = exclude_session_groups, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
927 |
exclude_sessions = exclude_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
928 |
session_groups = session_groups, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
929 |
sessions = sessions), |
67846 | 930 |
progress = progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
931 |
check_unknown_files = Mercurial.is_repository(Path.explode("~~")), |
63224 | 932 |
build_heap = build_heap, |
933 |
clean_build = clean_build, |
|
934 |
dirs = dirs, |
|
935 |
select_dirs = select_dirs, |
|
65831 | 936 |
numa_shuffling = NUMA.enabled_warning(progress, numa_shuffling), |
63224 | 937 |
max_jobs = max_jobs, |
938 |
list_files = list_files, |
|
939 |
check_keywords = check_keywords, |
|
66841 | 940 |
fresh_build = fresh_build, |
63224 | 941 |
no_build = no_build, |
66745 | 942 |
soft_build = soft_build, |
63224 | 943 |
verbose = verbose, |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
944 |
export_files = export_files) |
62833 | 945 |
} |
64140 | 946 |
val end_date = Date.now() |
947 |
val elapsed_time = end_date.time - start_date.time |
|
62590 | 948 |
|
62833 | 949 |
if (verbose) { |
64155 | 950 |
progress.echo("\nFinished at " + Build_Log.print_date(end_date)) |
62833 | 951 |
} |
62590 | 952 |
|
62833 | 953 |
val total_timing = |
954 |
(Timing.zero /: results.sessions.iterator.map(a => results(a).timing))(_ + _). |
|
955 |
copy(elapsed = elapsed_time) |
|
956 |
progress.echo(total_timing.message_resources) |
|
62590 | 957 |
|
62833 | 958 |
sys.exit(results.rc) |
959 |
}) |
|
68305 | 960 |
|
961 |
||
962 |
/* build logic image */ |
|
963 |
||
964 |
def build_logic(options: Options, logic: String, |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
965 |
progress: Progress = new Progress, |
68305 | 966 |
build_heap: Boolean = false, |
967 |
dirs: List[Path] = Nil, |
|
70791 | 968 |
fresh: Boolean = false, |
69540 | 969 |
strict: Boolean = false): Int = |
68305 | 970 |
{ |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
971 |
val selection = Sessions.Selection.session(logic) |
69540 | 972 |
val rc = |
71981 | 973 |
if (!fresh && build(options, selection = selection, |
974 |
build_heap = build_heap, no_build = true, dirs = dirs).ok) 0 |
|
69540 | 975 |
else { |
976 |
progress.echo("Build started for Isabelle/" + logic + " ...") |
|
71981 | 977 |
Build.build(options, selection = selection, progress = progress, |
978 |
build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc |
|
69540 | 979 |
} |
980 |
if (strict && rc != 0) error("Failed to build Isabelle/" + logic) else rc |
|
68305 | 981 |
} |
48276 | 982 |
} |