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