author | wenzelm |
Tue, 08 Dec 2020 17:30:24 +0100 | |
changeset 72854 | 6c660f05f70c |
parent 72853 | d0038b553e0e |
child 72856 | 3a27e6f83ce1 |
permissions | -rw-r--r-- |
72662 | 1 |
/* Title: Pure/Tools/build_job.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build job running prover process, with rudimentary PIDE session. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import scala.collection.mutable |
|
11 |
||
12 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
13 |
object Build_Job |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
14 |
{ |
72854 | 15 |
/* theory markup/messages from database */ |
16 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
17 |
def read_theory( |
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
18 |
db_context: Sessions.Database_Context, session: String, theory: String): Option[Command] = |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
19 |
{ |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
20 |
def read(name: String): Export.Entry = |
72854 | 21 |
db_context.get_export(List(session), theory, name) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
22 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
23 |
def read_xml(name: String): XML.Body = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
24 |
db_context.xml_cache.body( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
25 |
YXML.parse_body(Symbol.decode(UTF8.decode_permissive(read(name).uncompressed)))) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
26 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
27 |
(read(Export.DOCUMENT_ID).text, split_lines(read(Export.FILES).text)) match { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
28 |
case (Value.Long(id), thy_file :: blobs_files) => |
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
29 |
val node_name = Document.Node.Name(thy_file, Thy_Header.dir_name(thy_file), theory) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
30 |
val thy_path = Path.explode(thy_file) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
31 |
val thy_source = Symbol.decode(File.read(thy_path)) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
32 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
33 |
val blobs = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
34 |
blobs_files.map(file => |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
35 |
{ |
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
36 |
val master_dir = Thy_Header.dir_name(file) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
37 |
val path = Path.explode(file) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
38 |
val src_path = File.relative_path(thy_path, path).getOrElse(path) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
39 |
Command.Blob.read_file(Document.Node.Name(file, master_dir), src_path) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
40 |
}) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
41 |
val blobs_info = Command.Blobs_Info(blobs.map(Exn.Res(_))) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
42 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
43 |
val results = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
44 |
Command.Results.make( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
45 |
for { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
46 |
tree @ XML.Elem(markup, _) <- read_xml(Export.MESSAGES) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
47 |
i <- Markup.Serial.unapply(markup.properties) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
48 |
} yield i -> tree) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
49 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
50 |
val markup_index_blobs = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
51 |
Command.Markup_Index.markup :: blobs.map(Command.Markup_Index.blob) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
52 |
val markups = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
53 |
Command.Markups.make( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
54 |
for ((index, i) <- markup_index_blobs.zipWithIndex) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
55 |
yield { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
56 |
val xml = read_xml(Export.MARKUP + (if (i == 0) "" else i.toString)) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
57 |
index -> Markup_Tree.from_XML(xml) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
58 |
}) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
59 |
|
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
60 |
val command = |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
61 |
Command.unparsed(thy_source, theory = true, id = id, node_name = node_name, |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
62 |
blobs_info = blobs_info, results = results, markups = markups) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
63 |
Some(command) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
64 |
case _ => None |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
65 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
66 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
67 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
68 |
|
72662 | 69 |
class Build_Job(progress: Progress, |
70 |
session_name: String, |
|
71 |
val info: Sessions.Info, |
|
72 |
deps: Sessions.Deps, |
|
73 |
store: Sessions.Store, |
|
74 |
do_store: Boolean, |
|
75 |
verbose: Boolean, |
|
76 |
val numa_node: Option[Int], |
|
77 |
command_timings0: List[Properties.T]) |
|
78 |
{ |
|
79 |
val options: Options = NUMA.policy_options(info.options, numa_node) |
|
80 |
||
81 |
private val sessions_structure = deps.sessions_structure |
|
82 |
||
83 |
private val future_result: Future[Process_Result] = |
|
84 |
Future.thread("build", uninterruptible = true) { |
|
85 |
val parent = info.parent.getOrElse("") |
|
86 |
val base = deps(parent) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
87 |
val result_base = deps(session_name) |
72662 | 88 |
|
89 |
val env = |
|
90 |
Isabelle_System.settings() + |
|
91 |
("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString) |
|
92 |
||
93 |
val is_pure = Sessions.is_pure(session_name) |
|
94 |
||
95 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
|
96 |
||
97 |
val eval_store = |
|
98 |
if (do_store) { |
|
99 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) ::: |
|
100 |
List("ML_Heap.save_child " + |
|
101 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
|
102 |
} |
|
103 |
else Nil |
|
104 |
||
105 |
val resources = new Resources(sessions_structure, base, command_timings = command_timings0) |
|
106 |
val session = |
|
107 |
new Session(options, resources) { |
|
108 |
override val xml_cache: XML.Cache = store.xml_cache |
|
109 |
override val xz_cache: XZ.Cache = store.xz_cache |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
110 |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
111 |
override def build_blobs_info(name: Document.Node.Name): Command.Blobs_Info = |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
112 |
{ |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
113 |
result_base.load_commands.get(name.expand) match { |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
114 |
case Some(spans) => |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
115 |
val syntax = result_base.theory_syntax(name) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
116 |
Command.build_blobs_info(syntax, name, spans) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
117 |
case None => Command.Blobs_Info.none |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
118 |
} |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
119 |
} |
72662 | 120 |
} |
72730 | 121 |
def make_rendering(snapshot: Document.Snapshot): Rendering = |
122 |
new Rendering(snapshot, options, session) { |
|
123 |
override def model: Document.Model = ??? |
|
124 |
} |
|
72662 | 125 |
|
126 |
object Build_Session_Errors |
|
127 |
{ |
|
128 |
private val promise: Promise[List[String]] = Future.promise |
|
129 |
||
130 |
def result: Exn.Result[List[String]] = promise.join_result |
|
131 |
def cancel: Unit = promise.cancel |
|
132 |
def apply(errs: List[String]) |
|
133 |
{ |
|
134 |
try { promise.fulfill(errs) } |
|
135 |
catch { case _: IllegalStateException => } |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
val export_consumer = |
|
72849 | 140 |
Export.consumer(store.open_database(session_name, output = true), store.xz_cache) |
72662 | 141 |
|
142 |
val stdout = new StringBuilder(1000) |
|
143 |
val stderr = new StringBuilder(1000) |
|
144 |
val messages = new mutable.ListBuffer[XML.Elem] |
|
145 |
val command_timings = new mutable.ListBuffer[Properties.T] |
|
146 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
147 |
val session_timings = new mutable.ListBuffer[Properties.T] |
|
148 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
|
149 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
150 |
||
151 |
def fun( |
|
152 |
name: String, |
|
153 |
acc: mutable.ListBuffer[Properties.T], |
|
154 |
unapply: Properties.T => Option[Properties.T]): (String, Session.Protocol_Function) = |
|
155 |
{ |
|
156 |
name -> ((msg: Prover.Protocol_Output) => |
|
157 |
unapply(msg.properties) match { |
|
158 |
case Some(props) => acc += props; true |
|
159 |
case _ => false |
|
160 |
}) |
|
161 |
} |
|
162 |
||
163 |
session.init_protocol_handler(new Session.Protocol_Handler |
|
164 |
{ |
|
165 |
override def exit() { Build_Session_Errors.cancel } |
|
166 |
||
167 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = |
|
168 |
{ |
|
169 |
val (rc, errors) = |
|
170 |
try { |
|
171 |
val (rc, errs) = |
|
172 |
{ |
|
173 |
import XML.Decode._ |
|
174 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
175 |
} |
|
176 |
val errors = |
|
177 |
for (err <- errs) yield { |
|
178 |
val prt = Protocol_Message.expose_no_reports(err) |
|
179 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
180 |
} |
|
181 |
(rc, errors) |
|
182 |
} |
|
183 |
catch { case ERROR(err) => (2, List(err)) } |
|
184 |
||
185 |
session.protocol_command("Prover.stop", rc.toString) |
|
186 |
Build_Session_Errors(errors) |
|
187 |
true |
|
188 |
} |
|
189 |
||
190 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
191 |
msg.properties match { |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
192 |
case Markup.Loading_Theory(Markup.Name(name)) => |
72662 | 193 |
progress.theory(Progress.Theory(name, session = session_name)) |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
194 |
false |
72662 | 195 |
case _ => false |
196 |
} |
|
197 |
||
198 |
private def export(msg: Prover.Protocol_Output): Boolean = |
|
199 |
msg.properties match { |
|
200 |
case Protocol.Export(args) => |
|
201 |
export_consumer(session_name, args, msg.bytes) |
|
202 |
true |
|
203 |
case _ => false |
|
204 |
} |
|
205 |
||
206 |
override val functions = |
|
207 |
List( |
|
208 |
Markup.Build_Session_Finished.name -> build_session_finished, |
|
209 |
Markup.Loading_Theory.name -> loading_theory, |
|
210 |
Markup.EXPORT -> export, |
|
211 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
|
212 |
fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply), |
|
213 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
214 |
}) |
|
215 |
||
72711 | 216 |
session.command_timings += Session.Consumer("command_timings") |
217 |
{ |
|
218 |
case Session.Command_Timing(props) => |
|
219 |
for { |
|
220 |
elapsed <- Markup.Elapsed.unapply(props) |
|
221 |
elapsed_time = Time.seconds(elapsed) |
|
222 |
if elapsed_time.is_relevant && elapsed_time >= options.seconds("command_timing_threshold") |
|
223 |
} command_timings += props.filter(Markup.command_timing_property) |
|
224 |
} |
|
225 |
||
72662 | 226 |
session.runtime_statistics += Session.Consumer("ML_statistics") |
227 |
{ |
|
228 |
case Session.Runtime_Statistics(props) => runtime_statistics += props |
|
229 |
} |
|
230 |
||
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
231 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
232 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
233 |
case snapshot => |
72730 | 234 |
val rendering = make_rendering(snapshot) |
235 |
||
72844 | 236 |
def export(name: String, xml: XML.Body, compress: Boolean = true) |
72717 | 237 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
238 |
val theory_name = snapshot.node_name.theory |
72844 | 239 |
val args = |
240 |
Protocol.Export.Args(theory_name = theory_name, name = name, compress = compress) |
|
72783 | 241 |
val bytes = Bytes(Symbol.encode(YXML.string_of_body(xml))) |
72730 | 242 |
if (!bytes.is_empty) export_consumer(session_name, args, bytes) |
72717 | 243 |
} |
72844 | 244 |
def export_text(name: String, text: String, compress: Boolean = true): Unit = |
245 |
export(name, List(XML.Text(text)), compress = compress) |
|
72730 | 246 |
|
72844 | 247 |
for (command <- snapshot.snippet_command) { |
248 |
export_text(Export.DOCUMENT_ID, command.id.toString, compress = false) |
|
249 |
} |
|
250 |
||
251 |
export_text(Export.FILES, |
|
252 |
cat_lines(snapshot.node_files.map(_.symbolic.node)), compress = false) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
253 |
|
72817
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
254 |
for ((xml, i) <- snapshot.xml_markup_blobs().zipWithIndex) { |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
255 |
export(Export.MARKUP + (i + 1), xml) |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
256 |
} |
72723 | 257 |
export(Export.MARKUP, snapshot.xml_markup()) |
72725 | 258 |
export(Export.MESSAGES, snapshot.messages.map(_._1)) |
72730 | 259 |
|
260 |
val citations = Library.distinct(rendering.citations(Text.Range.full).map(_.info)) |
|
261 |
export_text(Export.CITATIONS, cat_lines(citations)) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
262 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
263 |
|
72662 | 264 |
session.all_messages += Session.Consumer[Any]("build_session_output") |
265 |
{ |
|
266 |
case msg: Prover.Output => |
|
267 |
val message = msg.message |
|
268 |
if (msg.is_stdout) { |
|
269 |
stdout ++= Symbol.encode(XML.content(message)) |
|
270 |
} |
|
271 |
else if (msg.is_stderr) { |
|
272 |
stderr ++= Symbol.encode(XML.content(message)) |
|
273 |
} |
|
274 |
else if (Protocol.is_exported(message)) { |
|
275 |
messages += message |
|
276 |
} |
|
277 |
else if (msg.is_exit) { |
|
278 |
val err = |
|
279 |
"Prover terminated" + |
|
280 |
(msg.properties match { |
|
281 |
case Markup.Process_Result(result) => ": " + result.print_rc |
|
282 |
case _ => "" |
|
283 |
}) |
|
284 |
Build_Session_Errors(List(err)) |
|
285 |
} |
|
286 |
case _ => |
|
287 |
} |
|
288 |
||
289 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store) |
|
290 |
||
291 |
val process = |
|
292 |
Isabelle_Process(session, options, sessions_structure, store, |
|
293 |
logic = parent, raw_ml_system = is_pure, |
|
294 |
use_prelude = use_prelude, eval_main = eval_main, |
|
295 |
cwd = info.dir.file, env = env) |
|
296 |
||
297 |
val build_errors = |
|
298 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
|
299 |
Exn.capture { process.await_startup } match { |
|
300 |
case Exn.Res(_) => |
|
301 |
val resources_yxml = resources.init_session_yxml |
|
302 |
val args_yxml = |
|
303 |
YXML.string_of_body( |
|
304 |
{ |
|
305 |
import XML.Encode._ |
|
306 |
pair(string, list(pair(Options.encode, list(pair(string, properties)))))( |
|
307 |
(session_name, info.theories)) |
|
308 |
}) |
|
309 |
session.protocol_command("build_session", resources_yxml, args_yxml) |
|
310 |
Build_Session_Errors.result |
|
311 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
val process_result = |
|
316 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { process.await_shutdown } |
|
317 |
||
72697 | 318 |
session.stop() |
319 |
||
72662 | 320 |
val export_errors = |
321 |
export_consumer.shutdown(close = true).map(Output.error_message_text) |
|
322 |
||
72699 | 323 |
val (document_output, document_errors) = |
72662 | 324 |
try { |
72675 | 325 |
if (build_errors.isInstanceOf[Exn.Res[_]] && process_result.ok && info.documents.nonEmpty) |
326 |
{ |
|
72854 | 327 |
using(store.open_database_context())(db_context => |
72715
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
328 |
{ |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
329 |
val documents = |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
330 |
Presentation.build_documents(session_name, deps, db_context, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
331 |
output_sources = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
332 |
output_pdf = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
333 |
progress = progress, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
334 |
verbose = verbose) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
335 |
db_context.output_database(session_name)(db => |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
336 |
documents.foreach(_.write(db, session_name))) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
337 |
(documents.flatMap(_.log_lines), Nil) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
338 |
}) |
72662 | 339 |
} |
72699 | 340 |
(Nil, Nil) |
72662 | 341 |
} |
72699 | 342 |
catch { case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) } |
72662 | 343 |
|
344 |
val result = |
|
345 |
{ |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
346 |
val theory_timing = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
347 |
theory_timings.iterator.map( |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
348 |
{ case props @ Markup.Name(name) => name -> props }).toMap |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
349 |
val used_theory_timings = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
350 |
for { (name, _) <- deps(session_name).used_theories } |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
351 |
yield theory_timing.getOrElse(name.theory, Markup.Name(name.theory)) |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
352 |
|
72662 | 353 |
val more_output = |
354 |
Library.trim_line(stdout.toString) :: |
|
355 |
messages.toList.map(message => |
|
356 |
Symbol.encode(Protocol.message_text(List(message), metric = Symbol.Metric))) ::: |
|
357 |
command_timings.toList.map(Protocol.Command_Timing_Marker.apply) ::: |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
358 |
used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) ::: |
72662 | 359 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
360 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
|
361 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) ::: |
|
72699 | 362 |
document_output |
72662 | 363 |
|
72726
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
364 |
process_result.output(more_output) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
365 |
.error(Library.trim_line(stderr.toString)) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
366 |
.errors_rc(export_errors ::: document_errors) |
72662 | 367 |
} |
368 |
||
369 |
build_errors match { |
|
370 |
case Exn.Res(build_errs) => |
|
371 |
val errs = build_errs ::: document_errors |
|
372 |
if (errs.isEmpty) result |
|
373 |
else { |
|
374 |
result.error_rc.output( |
|
375 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
376 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
377 |
} |
|
378 |
case Exn.Exn(Exn.Interrupt()) => |
|
379 |
if (result.ok) result.copy(rc = Exn.Interrupt.return_code) else result |
|
380 |
case Exn.Exn(exn) => throw exn |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
def terminate: Unit = future_result.cancel |
|
385 |
def is_finished: Boolean = future_result.is_finished |
|
386 |
||
387 |
private val timeout_request: Option[Event_Timer.Request] = |
|
388 |
{ |
|
389 |
if (info.timeout > Time.zero) |
|
390 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate }) |
|
391 |
else None |
|
392 |
} |
|
393 |
||
394 |
def join: (Process_Result, Option[String]) = |
|
395 |
{ |
|
396 |
val result1 = future_result.join |
|
397 |
||
398 |
val was_timeout = |
|
399 |
timeout_request match { |
|
400 |
case None => false |
|
401 |
case Some(request) => !request.cancel |
|
402 |
} |
|
403 |
||
404 |
val result2 = |
|
405 |
if (result1.interrupted) { |
|
406 |
if (was_timeout) result1.error(Output.error_message_text("Timeout")).was_timeout |
|
407 |
else result1.error(Output.error_message_text("Interrupt")) |
|
408 |
} |
|
409 |
else result1 |
|
410 |
||
411 |
val heap_digest = |
|
412 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
|
413 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
414 |
else None |
|
415 |
||
416 |
(result2, heap_digest) |
|
417 |
} |
|
418 |
} |