author | wenzelm |
Sat, 27 Jun 2020 11:25:30 +0200 | |
changeset 71981 | 0be06f99b210 |
parent 71978 | 3e54088a7119 |
child 71982 | cea6087e8a70 |
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 |
|
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
227 |
val build_session_errors: Promise[List[String]] = Future.promise |
71648 | 228 |
val stdout = new StringBuilder(1000) |
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
229 |
val messages = new mutable.ListBuffer[XML.Elem] |
71652 | 230 |
val command_timings = new mutable.ListBuffer[Properties.T] |
231 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
232 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
|
233 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
71648 | 234 |
|
71970 | 235 |
def fun( |
236 |
name: String, |
|
237 |
acc: mutable.ListBuffer[Properties.T], |
|
238 |
unapply: Properties.T => Option[Properties.T]): (String, Session.Protocol_Function) = |
|
239 |
{ |
|
240 |
name -> ((msg: Prover.Protocol_Output) => |
|
241 |
unapply(msg.properties) match { |
|
242 |
case Some(props) => acc += props; true |
|
243 |
case _ => false |
|
244 |
}) |
|
245 |
} |
|
246 |
||
71672 | 247 |
session.init_protocol_handler(new Session.Protocol_Handler |
248 |
{ |
|
249 |
override def exit() { build_session_errors.cancel } |
|
250 |
||
251 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = |
|
252 |
{ |
|
71879 | 253 |
val (rc, errors) = |
71672 | 254 |
try { |
71879 | 255 |
val (rc, errs) = |
256 |
{ |
|
257 |
import XML.Decode._ |
|
258 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
71672 | 259 |
} |
71879 | 260 |
val errors = |
261 |
for (err <- errs) yield { |
|
262 |
val prt = Protocol_Message.expose_no_reports(err) |
|
263 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
264 |
} |
|
265 |
(rc, errors) |
|
71672 | 266 |
} |
71879 | 267 |
catch { case ERROR(err) => (2, List(err)) } |
268 |
||
269 |
session.protocol_command("Prover.stop", rc.toString) |
|
71672 | 270 |
build_session_errors.fulfill(errors) |
271 |
true |
|
272 |
} |
|
273 |
||
274 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
275 |
msg.properties match { |
|
276 |
case Markup.Loading_Theory(name) => |
|
277 |
progress.theory(Progress.Theory(name, session = session_name)) |
|
278 |
true |
|
279 |
case _ => false |
|
280 |
} |
|
281 |
||
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
282 |
private def export(msg: Prover.Protocol_Output): Boolean = |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
283 |
msg.properties match { |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
284 |
case Protocol.Export(args) => |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
285 |
export_consumer(session_name, args, msg.bytes) |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
286 |
true |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
287 |
case _ => false |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
288 |
} |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
289 |
|
71672 | 290 |
val functions = |
291 |
List( |
|
71673 | 292 |
Markup.Build_Session_Finished.name -> build_session_finished, |
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
293 |
Markup.Loading_Theory.name -> loading_theory, |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
294 |
Markup.EXPORT -> export, |
71970 | 295 |
fun(Markup.Command_Timing.name, command_timings, Markup.Command_Timing.unapply), |
296 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
|
297 |
fun(Markup.ML_Statistics.name, runtime_statistics, Markup.ML_Statistics.unapply), |
|
298 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
71672 | 299 |
}) |
300 |
||
71676
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
301 |
session.all_messages += Session.Consumer[Any]("build_session_output") |
da49285a0adf
more official handling of protocol messages, including export;
wenzelm
parents:
71675
diff
changeset
|
302 |
{ |
71648 | 303 |
case msg: Prover.Output => |
304 |
val message = msg.message |
|
305 |
if (msg.is_stdout) { |
|
306 |
stdout ++= Symbol.encode(XML.content(message)) |
|
307 |
} |
|
308 |
else if (Protocol.is_exported(message)) { |
|
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
309 |
messages += message |
71648 | 310 |
} |
311 |
case _ => |
|
312 |
} |
|
313 |
||
71644 | 314 |
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
|
315 |
|
71607 | 316 |
val process = |
71677 | 317 |
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
|
318 |
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
|
319 |
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
|
320 |
cwd = info.dir.file, env = env) |
65313 | 321 |
|
71668
25ef5c7287a7
proper treatment of startup errors, notably for Pure ROOT.ML;
wenzelm
parents:
71667
diff
changeset
|
322 |
val errors = |
71718 | 323 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
324 |
Exn.capture { process.await_startup } match { |
|
325 |
case Exn.Res(_) => |
|
326 |
session.protocol_command("build_session", args_yxml) |
|
327 |
build_session_errors.join_result |
|
328 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
|
329 |
} |
|
71668
25ef5c7287a7
proper treatment of startup errors, notably for Pure ROOT.ML;
wenzelm
parents:
71667
diff
changeset
|
330 |
} |
71607 | 331 |
|
71718 | 332 |
val process_result = |
333 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { process.await_shutdown } |
|
71652 | 334 |
val process_output = |
71978
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
335 |
stdout.toString :: |
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
336 |
messages.toList.map(message => |
3e54088a7119
clarified use of memory: prefer share tree structures over fresh strings;
wenzelm
parents:
71971
diff
changeset
|
337 |
Symbol.encode(Protocol.message_text(List(message), metric = Symbol.Metric))) ::: |
71652 | 338 |
command_timings.toList.map(Protocol.Command_Timing_Marker.apply) ::: |
339 |
theory_timings.toList.map(Protocol.Theory_Timing_Marker.apply) ::: |
|
340 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
|
341 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) |
|
71648 | 342 |
|
71652 | 343 |
val result = process_result.output(process_output) |
71718 | 344 |
|
345 |
errors match { |
|
346 |
case Exn.Res(Nil) => result |
|
347 |
case Exn.Res(errs) => |
|
348 |
result.error_rc.output( |
|
349 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
350 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
351 |
case Exn.Exn(Exn.Interrupt()) => |
|
352 |
if (result.ok) result.copy(rc = Exn.Interrupt.return_code) else result |
|
353 |
case Exn.Exn(exn) => throw exn |
|
65313 | 354 |
} |
65308 | 355 |
} |
356 |
else { |
|
357 |
val args_file = Isabelle_System.tmp_file("build") |
|
358 |
File.write(args_file, args_yxml) |
|
359 |
||
71639
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
360 |
val eval_build = |
ec84f542e411
clarified signature of ML_Process vs. Isabelle_Process: proper support for "isabelle build -P -b";
wenzelm
parents:
71632
diff
changeset
|
361 |
"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
|
362 |
val eval_main = Command_Line.ML_tool(eval_build :: eval_store) |
64265 | 363 |
|
65308 | 364 |
val process = |
71677 | 365 |
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
|
366 |
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
|
367 |
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
|
368 |
cwd = info.dir.file, env = env, cleanup = () => args_file.delete) |
64265 | 369 |
|
71718 | 370 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
371 |
process.result( |
|
372 |
progress_stdout = |
|
373 |
{ |
|
374 |
case Protocol.Loading_Theory_Marker(theory) => |
|
375 |
progress.theory(Progress.Theory(theory, session = session_name)) |
|
376 |
case Protocol.Export.Marker((args, path)) => |
|
377 |
val body = |
|
378 |
try { Bytes.read(path) } |
|
379 |
catch { |
|
380 |
case ERROR(msg) => |
|
381 |
error("Failed to read export " + quote(args.compound_name) + "\n" + msg) |
|
382 |
} |
|
383 |
path.file.delete |
|
384 |
export_consumer(session_name, args, body) |
|
385 |
case _ => |
|
386 |
}, |
|
387 |
progress_limit = |
|
388 |
options.int("process_output_limit") match { |
|
389 |
case 0 => None |
|
390 |
case m => Some(m * 1000000L) |
|
391 |
}, |
|
392 |
strict = false) |
|
393 |
} |
|
65308 | 394 |
} |
50845 | 395 |
} |
48674 | 396 |
|
62572 | 397 |
def terminate: Unit = future_result.cancel |
398 |
def is_finished: Boolean = future_result.is_finished |
|
48674 | 399 |
|
56779 | 400 |
private val timeout_request: Option[Event_Timer.Request] = |
401 |
{ |
|
62569 | 402 |
if (info.timeout > Time.zero) |
66943 | 403 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate }) |
48674 | 404 |
else None |
56779 | 405 |
} |
48674 | 406 |
|
68217 | 407 |
def join: (Process_Result, Option[String]) = |
50845 | 408 |
{ |
68217 | 409 |
val result0 = future_result.join |
410 |
val result1 = |
|
71601 | 411 |
export_consumer.shutdown(close = true).map(Output.error_message_text) match { |
68217 | 412 |
case Nil => result0 |
68928 | 413 |
case errs => result0.errors(errs).error_rc |
68092
888d35a19866
store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
68088
diff
changeset
|
414 |
} |
50845 | 415 |
|
68198
6710167e17af
avoid race condition wrt. ISABELLE_TMP, which is removed in Bash.cleanup() before Bash.result(progress_stdout);
wenzelm
parents:
68148
diff
changeset
|
416 |
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
|
417 |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
418 |
if (result1.ok) |
71669 | 419 |
Present.finish(progress, store.browser_info, graph_file, info, session_name) |
61372 | 420 |
|
59445 | 421 |
graph_file.delete |
66943 | 422 |
|
423 |
val was_timeout = |
|
424 |
timeout_request match { |
|
425 |
case None => false |
|
426 |
case Some(request) => !request.cancel |
|
427 |
} |
|
48674 | 428 |
|
68217 | 429 |
val result2 = |
430 |
if (result1.interrupted) { |
|
431 |
if (was_timeout) result1.error(Output.error_message_text("Timeout")).was_timeout |
|
432 |
else result1.error(Output.error_message_text("Interrupt")) |
|
433 |
} |
|
434 |
else result1 |
|
435 |
||
436 |
val heap_digest = |
|
71669 | 437 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
438 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
68217 | 439 |
else None |
440 |
||
441 |
(result2, heap_digest) |
|
48674 | 442 |
} |
48364 | 443 |
} |
444 |
||
48424 | 445 |
|
62631 | 446 |
|
62641 | 447 |
/** build with results **/ |
48424 | 448 |
|
63996 | 449 |
class Results private[Build](results: Map[String, (Option[Process_Result], Sessions.Info)]) |
62403 | 450 |
{ |
451 |
def sessions: Set[String] = results.keySet |
|
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
452 |
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
|
453 |
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
|
454 |
def info(name: String): Sessions.Info = results(name)._2 |
71601 | 455 |
val rc: Int = |
65253 | 456 |
(0 /: results.iterator.map( |
457 |
{ case (_, (Some(r), _)) => r.rc case (_, (None, _)) => 1 }))(_ max _) |
|
62641 | 458 |
def ok: Boolean = rc == 0 |
62406 | 459 |
|
460 |
override def toString: String = rc.toString |
|
62403 | 461 |
} |
462 |
||
62641 | 463 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
464 |
options: Options, |
71981 | 465 |
selection: Sessions.Selection = Sessions.Selection.empty, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
466 |
progress: Progress = new Progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
467 |
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
|
468 |
build_heap: Boolean = false, |
48595 | 469 |
clean_build: Boolean = false, |
56890 | 470 |
dirs: List[Path] = Nil, |
471 |
select_dirs: List[Path] = Nil, |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66962
diff
changeset
|
472 |
infos: List[Sessions.Info] = Nil, |
64265 | 473 |
numa_shuffling: Boolean = false, |
48509 | 474 |
max_jobs: Int = 1, |
48903 | 475 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
476 |
check_keywords: Set[String] = Set.empty, |
66841 | 477 |
fresh_build: Boolean = false, |
48509 | 478 |
no_build: Boolean = false, |
66745 | 479 |
soft_build: Boolean = false, |
48509 | 480 |
verbose: Boolean = false, |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
481 |
export_files: Boolean = false): Results = |
63224 | 482 |
{ |
71677 | 483 |
val build_options = |
71679
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
484 |
options + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
485 |
"ML_statistics" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
486 |
"completion_limit=0" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
487 |
"editor_tracing_messages=0" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
488 |
"pide_reports=false" |
51220 | 489 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69811
diff
changeset
|
490 |
val store = Sessions.store(build_options) |
66745 | 491 |
|
69369
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
492 |
Isabelle_Fonts.init() |
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
493 |
|
66745 | 494 |
|
495 |
/* session selection and dependencies */ |
|
65422 | 496 |
|
66961 | 497 |
val full_sessions = |
67026 | 498 |
Sessions.load_structure(build_options, dirs = dirs, select_dirs = select_dirs, infos = infos) |
65422 | 499 |
|
71669 | 500 |
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
|
501 |
{ |
0445cfaf6132
more compact (second-order) digest for 10^2..10^3 source files, with slightly increased risk of collisions;
wenzelm
parents:
66747
diff
changeset
|
502 |
val digests = |
71669 | 503 |
full_sessions(session_name).meta_digest :: |
504 |
deps.sources(session_name) ::: |
|
505 |
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
|
506 |
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
|
507 |
} |
66745 | 508 |
|
68204 | 509 |
val deps = |
66745 | 510 |
{ |
511 |
val deps0 = |
|
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
512 |
Sessions.deps(full_sessions.selection(selection), |
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
513 |
progress = progress, inlined_files = true, verbose = verbose, |
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
514 |
list_files = list_files, check_keywords = check_keywords).check_errors |
66745 | 515 |
|
66841 | 516 |
if (soft_build && !fresh_build) { |
66745 | 517 |
val outdated = |
68204 | 518 |
deps0.sessions_structure.build_topological_order.flatMap(name => |
68221 | 519 |
store.access_database(name) match { |
68214 | 520 |
case Some(db) => |
68216 | 521 |
using(db)(store.read_build(_, name)) match { |
66745 | 522 |
case Some(build) |
66747 | 523 |
if build.ok && build.sources == sources_stamp(deps0, name) => None |
66745 | 524 |
case _ => Some(name) |
525 |
} |
|
526 |
case None => Some(name) |
|
527 |
}) |
|
68204 | 528 |
|
529 |
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
|
530 |
progress = progress, inlined_files = true).check_errors |
66745 | 531 |
} |
68204 | 532 |
else deps0 |
66745 | 533 |
} |
534 |
||
535 |
||
536 |
/* check unknown files */ |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
537 |
|
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
538 |
if (check_unknown_files) { |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
539 |
val source_files = |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
540 |
(for { |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
541 |
(_, base) <- deps.session_bases.iterator |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
542 |
(path, _) <- base.sources.iterator |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
543 |
} yield path).toList |
67098 | 544 |
val exclude_files = List(Path.explode("$POLYML_EXE")).map(_.canonical_file) |
545 |
val unknown_files = |
|
67782
7e223a05e6d8
clarified notion of unknown files: ignore files outside of a Mercurial repository;
wenzelm
parents:
67493
diff
changeset
|
546 |
Mercurial.check_files(source_files)._2. |
67098 | 547 |
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
|
548 |
if (unknown_files.nonEmpty) { |
67782
7e223a05e6d8
clarified notion of unknown files: ignore files outside of a Mercurial repository;
wenzelm
parents:
67493
diff
changeset
|
549 |
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
|
550 |
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
|
551 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
552 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
553 |
|
51220 | 554 |
|
555 |
/* main build process */ |
|
556 |
||
68204 | 557 |
val queue = Queue(progress, deps.sessions_structure, store) |
65289 | 558 |
|
68219 | 559 |
store.prepare_output_dir() |
48373 | 560 |
|
48595 | 561 |
if (clean_build) { |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
562 |
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
|
563 |
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
|
564 |
if (relevant) { |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
565 |
if (ok) progress.echo("Cleaned " + name) |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
566 |
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
|
567 |
} |
48595 | 568 |
} |
569 |
} |
|
570 |
||
48425 | 571 |
// scheduler loop |
63082
6af03422535a
expose Sessions.Info in Build.Results
Lars Hupel <lars.hupel@mytum.de>
parents:
62946
diff
changeset
|
572 |
case class Result( |
66594 | 573 |
current: Boolean, |
68213 | 574 |
heap_digest: Option[String], |
66594 | 575 |
process: Option[Process_Result], |
576 |
info: Sessions.Info) |
|
62402 | 577 |
{ |
578 |
def ok: Boolean = |
|
579 |
process match { |
|
580 |
case None => false |
|
581 |
case Some(res) => res.rc == 0 |
|
582 |
} |
|
583 |
} |
|
48639
675988e64bf9
store parent heap stamp as well -- needs to be propagated through the build hierarchy;
wenzelm
parents:
48626
diff
changeset
|
584 |
|
56837
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
585 |
def sleep() |
5a598f1eecfd
more robust interrupt handling for Scala_Console, which uses JVM Thread.interrupt instead of POSIX SIGINT;
wenzelm
parents:
56831
diff
changeset
|
586 |
{ |
71727
0cb14b7455ee
more careful handling of interrupts, notably for Isabelle/jEdit Scala Console;
wenzelm
parents:
71726
diff
changeset
|
587 |
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
|
588 |
} |
50366 | 589 |
|
64265 | 590 |
val numa_nodes = new NUMA.Nodes(numa_shuffling) |
591 |
||
48425 | 592 |
@tailrec def loop( |
48676
3ef82491cdd6
clarified Session_Tree (with proper integrity check) vs. Queue (with provision for alternative ordering);
wenzelm
parents:
48675
diff
changeset
|
593 |
pending: Queue, |
62628 | 594 |
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
|
595 |
results: Map[String, Result]): Map[String, Result] = |
48425 | 596 |
{ |
64265 | 597 |
def used_node(i: Int): Boolean = |
598 |
running.iterator.exists( |
|
599 |
{ case (_, (_, job)) => job.numa_node.isDefined && job.numa_node.get == i }) |
|
600 |
||
48425 | 601 |
if (pending.is_empty) results |
51253 | 602 |
else { |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
603 |
if (progress.stopped) { |
51253 | 604 |
for ((_, (_, job)) <- running) job.terminate |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
605 |
} |
51253 | 606 |
|
48674 | 607 |
running.find({ case (_, (_, job)) => job.is_finished }) match { |
71669 | 608 |
case Some((session_name, (input_heaps, job))) => |
50367 | 609 |
//{{{ finish job |
48424 | 610 |
|
68217 | 611 |
val (process_result, heap_digest) = job.join |
48373 | 612 |
|
71623
b3bddebe44ca
clarified signature: more explicit type Protocol_Message.Marker;
wenzelm
parents:
71614
diff
changeset
|
613 |
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
|
614 |
val process_result_tail = |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
615 |
{ |
62409
e391528eff3b
proper option process_output_tail, more generous default;
wenzelm
parents:
62406
diff
changeset
|
616 |
val tail = job.info.options.int("process_output_tail") |
62632 | 617 |
process_result.copy( |
618 |
out_lines = |
|
71669 | 619 |
"(see also " + store.output_log(session_name).file.toString + ")" :: |
65294 | 620 |
(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
|
621 |
} |
13a0f537e232
retain tail out_lines as printed, but not the whole log content;
wenzelm
parents:
62403
diff
changeset
|
622 |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
623 |
|
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
624 |
// write log file |
68217 | 625 |
if (process_result.ok) { |
71669 | 626 |
File.write_gzip(store.output_log_gz(session_name), terminate_lines(log_lines)) |
68217 | 627 |
} |
71669 | 628 |
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
|
629 |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
630 |
// write database |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
631 |
{ |
66944
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
632 |
val build_log = |
71669 | 633 |
Build_Log.Log_File(session_name, process_result.out_lines). |
66944
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
634 |
parse_session_info( |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
635 |
command_timings = true, |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
636 |
theory_timings = true, |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
637 |
ml_statistics = true, |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
638 |
task_statistics = true) |
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
639 |
|
71669 | 640 |
using(store.open_database(session_name, output = true))(db => |
641 |
store.write_session_info(db, session_name, |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
642 |
build_log = |
66944
05df740cb54b
more informative timeout message, notably for build_status;
wenzelm
parents:
66943
diff
changeset
|
643 |
if (process_result.timeout) build_log.error("Timeout") else build_log, |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
644 |
build = |
71669 | 645 |
Session_Info(sources_stamp(deps, session_name), input_heaps, heap_digest, |
66744 | 646 |
process_result.rc))) |
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
647 |
} |
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65289
diff
changeset
|
648 |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
649 |
// messages |
71601 | 650 |
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
|
651 |
|
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
652 |
if (process_result.ok) |
71669 | 653 |
progress.echo( |
654 |
"Finished " + session_name + " (" + process_result.timing.message_resources + ")") |
|
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
655 |
else { |
71669 | 656 |
progress.echo(session_name + " FAILED") |
66666
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
657 |
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
|
658 |
} |
1a620647285c
clarified messages: after writing all files (see also 27f90319a499 and 57c85c83c11b);
wenzelm
parents:
66595
diff
changeset
|
659 |
|
71669 | 660 |
loop(pending - session_name, running - session_name, |
661 |
results + |
|
662 |
(session_name -> Result(false, heap_digest, Some(process_result_tail), job.info))) |
|
50367 | 663 |
//}}} |
60215 | 664 |
case None if running.size < (max_jobs max 1) => |
50367 | 665 |
//{{{ check/start next job |
71601 | 666 |
pending.dequeue(running.isDefinedAt) match { |
71669 | 667 |
case Some((session_name, info)) => |
66848 | 668 |
val ancestor_results = |
71669 | 669 |
deps.sessions_structure.build_requirements(List(session_name)). |
670 |
filterNot(_ == session_name).map(results(_)) |
|
68213 | 671 |
val ancestor_heaps = ancestor_results.flatMap(_.heap_digest) |
62628 | 672 |
|
71669 | 673 |
val do_store = |
674 |
build_heap || Sessions.is_pure(session_name) || queue.is_inner(session_name) |
|
48547 | 675 |
|
68213 | 676 |
val (current, heap_digest) = |
48547 | 677 |
{ |
71669 | 678 |
store.access_database(session_name) match { |
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68209
diff
changeset
|
679 |
case Some(db) => |
71669 | 680 |
using(db)(store.read_build(_, session_name)) match { |
68216 | 681 |
case Some(build) => |
71669 | 682 |
val heap_digest = store.find_heap_digest(session_name) |
68216 | 683 |
val current = |
684 |
!fresh_build && |
|
685 |
build.ok && |
|
71669 | 686 |
build.sources == sources_stamp(deps, session_name) && |
68216 | 687 |
build.input_heaps == ancestor_heaps && |
688 |
build.output_heap == heap_digest && |
|
71614 | 689 |
!(do_store && heap_digest.isEmpty) |
68216 | 690 |
(current, heap_digest) |
691 |
case None => (false, None) |
|
692 |
} |
|
62636 | 693 |
case None => (false, None) |
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
694 |
} |
48547 | 695 |
} |
62628 | 696 |
val all_current = current && ancestor_results.forall(_.current) |
48528
784c6f63d79c
proper all_current, which regards parent status as well;
wenzelm
parents:
48511
diff
changeset
|
697 |
|
48547 | 698 |
if (all_current) |
71669 | 699 |
loop(pending - session_name, running, |
700 |
results + |
|
701 |
(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
|
702 |
else if (no_build) { |
71894 | 703 |
progress.echo_if(verbose, "Skipping " + session_name + " ...") |
71669 | 704 |
loop(pending - session_name, running, |
705 |
results + |
|
706 |
(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
|
707 |
} |
62628 | 708 |
else if (ancestor_results.forall(_.ok) && !progress.stopped) { |
71669 | 709 |
progress.echo((if (do_store) "Building " else "Running ") + session_name + " ...") |
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
710 |
|
71669 | 711 |
store.clean_output(session_name) |
712 |
using(store.open_database(session_name, output = true))( |
|
713 |
store.init_session_info(_, session_name)) |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
67852
diff
changeset
|
714 |
|
71601 | 715 |
val numa_node = numa_nodes.next(used_node) |
51220 | 716 |
val job = |
71669 | 717 |
new Job(progress, session_name, info, deps, store, do_store, verbose, |
718 |
numa_node, queue.command_timings(session_name)) |
|
719 |
loop(pending, running + (session_name -> (ancestor_heaps, job)), results) |
|
48547 | 720 |
} |
721 |
else { |
|
71669 | 722 |
progress.echo(session_name + " CANCELLED") |
723 |
loop(pending - session_name, running, |
|
724 |
results + (session_name -> Result(false, heap_digest, None, info))) |
|
48547 | 725 |
} |
726 |
case None => sleep(); loop(pending, running, results) |
|
48425 | 727 |
} |
50367 | 728 |
///}}} |
48425 | 729 |
case None => sleep(); loop(pending, running, results) |
48373 | 730 |
} |
51253 | 731 |
} |
48425 | 732 |
} |
733 |
||
51220 | 734 |
|
735 |
/* build results */ |
|
736 |
||
62641 | 737 |
val results0 = |
48583 | 738 |
if (deps.is_empty) { |
65827 | 739 |
progress.echo_warning("Nothing to build") |
50707
5b2bf7611662
maintain session index on Scala side, for more determistic results;
wenzelm
parents:
50686
diff
changeset
|
740 |
Map.empty[String, Result] |
48583 | 741 |
} |
71727
0cb14b7455ee
more careful handling of interrupts, notably for Isabelle/jEdit Scala Console;
wenzelm
parents:
71726
diff
changeset
|
742 |
else Isabelle_Thread.uninterruptible { loop(queue, Map.empty, Map.empty) } |
48583 | 743 |
|
62641 | 744 |
val results = |
64265 | 745 |
new Results( |
746 |
(for ((name, result) <- results0.iterator) |
|
747 |
yield (name, (result.process, result.info))).toMap) |
|
62641 | 748 |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
749 |
if (export_files) { |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
750 |
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
|
751 |
val info = results.info(name) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
752 |
if (info.export_files.nonEmpty) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
753 |
progress.echo("Exporting " + info.name + " ...") |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
754 |
for ((dir, prune, pats) <- info.export_files) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
755 |
Export.export_files(store, name, info.dir + dir, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
756 |
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
|
757 |
export_prune = prune, |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
758 |
export_patterns = pats) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
759 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
760 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
761 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
762 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
763 |
|
62641 | 764 |
if (results.rc != 0 && (verbose || !no_build)) { |
765 |
val unfinished = |
|
766 |
(for { |
|
767 |
name <- results.sessions.iterator |
|
768 |
if !results(name).ok |
|
769 |
} yield name).toList.sorted |
|
770 |
progress.echo("Unfinished session(s): " + commas(unfinished)) |
|
771 |
} |
|
772 |
||
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
|
773 |
|
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
|
774 |
/* 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
|
775 |
|
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
|
776 |
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
|
777 |
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
|
778 |
(for { |
62641 | 779 |
(name, result) <- results0.iterator |
62944
3ee643c5ed00
more standard session build process, including browser_info;
wenzelm
parents:
62902
diff
changeset
|
780 |
if result.ok |
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65406
diff
changeset
|
781 |
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
|
782 |
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
|
783 |
} 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
|
784 |
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
|
785 |
|
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
|
786 |
for ((chapter, entries) <- browser_chapters) |
62632 | 787 |
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
|
788 |
|
62632 | 789 |
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
|
790 |
} |
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
|
791 |
|
62641 | 792 |
results |
48341 | 793 |
} |
794 |
||
795 |
||
62833 | 796 |
/* Isabelle tool wrapper */ |
48341 | 797 |
|
62833 | 798 |
val isabelle_tool = Isabelle_Tool("build", "build and manage Isabelle sessions", args => |
48341 | 799 |
{ |
62833 | 800 |
val build_options = Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS")) |
62590 | 801 |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
802 |
var base_sessions: List[String] = Nil |
62833 | 803 |
var select_dirs: List[Path] = Nil |
64265 | 804 |
var numa_shuffling = false |
62833 | 805 |
var requirements = false |
66745 | 806 |
var soft_build = false |
62833 | 807 |
var exclude_session_groups: List[String] = Nil |
808 |
var all_sessions = false |
|
809 |
var build_heap = false |
|
810 |
var clean_build = false |
|
811 |
var dirs: List[Path] = Nil |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
812 |
var export_files = false |
66841 | 813 |
var fresh_build = false |
62833 | 814 |
var session_groups: List[String] = Nil |
815 |
var max_jobs = 1 |
|
816 |
var check_keywords: Set[String] = Set.empty |
|
817 |
var list_files = false |
|
818 |
var no_build = false |
|
67847 | 819 |
var options = Options.init(opts = build_options) |
62833 | 820 |
var verbose = false |
821 |
var exclude_sessions: List[String] = Nil |
|
62590 | 822 |
|
62833 | 823 |
val getopts = Getopts(""" |
62590 | 824 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
825 |
||
826 |
Options are: |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
827 |
-B NAME include session NAME and all descendants |
62590 | 828 |
-D DIR include session directory and select its sessions |
64265 | 829 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
71807 | 830 |
-R refer to requirements of selected sessions |
66745 | 831 |
-S soft build: only observe changes of sources, not heap images |
62590 | 832 |
-X NAME exclude sessions from group NAME and all descendants |
833 |
-a select all sessions |
|
834 |
-b build heap images |
|
835 |
-c clean build |
|
836 |
-d DIR include session directory |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
837 |
-e export files from session specification into file-system |
66841 | 838 |
-f fresh build |
62590 | 839 |
-g NAME select session group NAME |
840 |
-j INT maximum number of parallel jobs (default 1) |
|
841 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
|
842 |
-l list session source files |
|
843 |
-n no build -- test dependencies only |
|
844 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
845 |
-v verbose |
|
846 |
-x NAME exclude session NAME and all descendants |
|
847 |
||
62596 | 848 |
Build and manage Isabelle sessions, depending on implicit settings: |
849 |
||
64455 | 850 |
""" + Library.prefix_lines(" ", Build_Log.Settings.show()) + "\n", |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
851 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
62833 | 852 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
64265 | 853 |
"N" -> (_ => numa_shuffling = true), |
62833 | 854 |
"R" -> (_ => requirements = true), |
66745 | 855 |
"S" -> (_ => soft_build = true), |
62833 | 856 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
857 |
"a" -> (_ => all_sessions = true), |
|
858 |
"b" -> (_ => build_heap = true), |
|
859 |
"c" -> (_ => clean_build = true), |
|
860 |
"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
|
861 |
"e" -> (_ => export_files = true), |
66841 | 862 |
"f" -> (_ => fresh_build = true), |
62833 | 863 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
63805 | 864 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
62833 | 865 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
866 |
"l" -> (_ => list_files = true), |
|
867 |
"n" -> (_ => no_build = true), |
|
868 |
"o:" -> (arg => options = options + arg), |
|
869 |
"v" -> (_ => verbose = true), |
|
870 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
62590 | 871 |
|
62833 | 872 |
val sessions = getopts(args) |
62590 | 873 |
|
64115 | 874 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 875 |
|
64140 | 876 |
val start_date = Date.now() |
877 |
||
62833 | 878 |
if (verbose) { |
879 |
progress.echo( |
|
64155 | 880 |
"Started at " + Build_Log.print_date(start_date) + |
64140 | 881 |
" (" + Isabelle_System.getenv("ML_IDENTIFIER") + " on " + Isabelle_System.hostname() +")") |
64081 | 882 |
progress.echo(Build_Log.Settings.show() + "\n") |
62833 | 883 |
} |
62590 | 884 |
|
62833 | 885 |
val results = |
886 |
progress.interrupt_handler { |
|
67846 | 887 |
build(options, |
71981 | 888 |
selection = Sessions.Selection( |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
889 |
requirements = requirements, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
890 |
all_sessions = all_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
891 |
base_sessions = base_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
892 |
exclude_session_groups = exclude_session_groups, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
893 |
exclude_sessions = exclude_sessions, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
894 |
session_groups = session_groups, |
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
895 |
sessions = sessions), |
67846 | 896 |
progress = progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
897 |
check_unknown_files = Mercurial.is_repository(Path.explode("~~")), |
63224 | 898 |
build_heap = build_heap, |
899 |
clean_build = clean_build, |
|
900 |
dirs = dirs, |
|
901 |
select_dirs = select_dirs, |
|
65831 | 902 |
numa_shuffling = NUMA.enabled_warning(progress, numa_shuffling), |
63224 | 903 |
max_jobs = max_jobs, |
904 |
list_files = list_files, |
|
905 |
check_keywords = check_keywords, |
|
66841 | 906 |
fresh_build = fresh_build, |
63224 | 907 |
no_build = no_build, |
66745 | 908 |
soft_build = soft_build, |
63224 | 909 |
verbose = verbose, |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
910 |
export_files = export_files) |
62833 | 911 |
} |
64140 | 912 |
val end_date = Date.now() |
913 |
val elapsed_time = end_date.time - start_date.time |
|
62590 | 914 |
|
62833 | 915 |
if (verbose) { |
64155 | 916 |
progress.echo("\nFinished at " + Build_Log.print_date(end_date)) |
62833 | 917 |
} |
62590 | 918 |
|
62833 | 919 |
val total_timing = |
920 |
(Timing.zero /: results.sessions.iterator.map(a => results(a).timing))(_ + _). |
|
921 |
copy(elapsed = elapsed_time) |
|
922 |
progress.echo(total_timing.message_resources) |
|
62590 | 923 |
|
62833 | 924 |
sys.exit(results.rc) |
925 |
}) |
|
68305 | 926 |
|
927 |
||
928 |
/* build logic image */ |
|
929 |
||
930 |
def build_logic(options: Options, logic: String, |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
931 |
progress: Progress = new Progress, |
68305 | 932 |
build_heap: Boolean = false, |
933 |
dirs: List[Path] = Nil, |
|
70791 | 934 |
fresh: Boolean = false, |
69540 | 935 |
strict: Boolean = false): Int = |
68305 | 936 |
{ |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
937 |
val selection = Sessions.Selection.session(logic) |
69540 | 938 |
val rc = |
71981 | 939 |
if (!fresh && build(options, selection = selection, |
940 |
build_heap = build_heap, no_build = true, dirs = dirs).ok) 0 |
|
69540 | 941 |
else { |
942 |
progress.echo("Build started for Isabelle/" + logic + " ...") |
|
71981 | 943 |
Build.build(options, selection = selection, progress = progress, |
944 |
build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc |
|
69540 | 945 |
} |
946 |
if (strict && rc != 0) error("Failed to build Isabelle/" + logic) else rc |
|
68305 | 947 |
} |
48276 | 948 |
} |