| author | wenzelm |
| Tue, 04 Nov 2025 20:11:15 +0100 | |
| changeset 83503 | 7b1b7ac616c0 |
| parent 83315 | 03dfb684a50d |
| child 83504 | 24998f6c9c15 |
| permissions | -rw-r--r-- |
| 79502 | 1 |
/* Title: Pure/Build/build_job.scala |
| 72662 | 2 |
Author: Makarius |
3 |
||
4 |
Build job running prover process, with rudimentary PIDE session. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 83262 | 10 |
import java.io.BufferedWriter |
11 |
import java.nio.file.Files |
|
| 72662 | 12 |
|
13 |
||
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
14 |
trait Build_Job {
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
15 |
def cancel(): Unit = () |
| 77298 | 16 |
def is_finished: Boolean = false |
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
17 |
def join: Build_Job.Result = Build_Job.no_result |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
18 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
19 |
|
| 75393 | 20 |
object Build_Job {
|
| 78530 | 21 |
sealed case class Result(process_result: Process_Result, output_shasum: SHA1.Shasum) |
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
22 |
val no_result: Result = Result(Process_Result.undefined, SHA1.no_shasum) |
| 78530 | 23 |
|
24 |
||
| 77396 | 25 |
/* build session */ |
26 |
||
| 77474 | 27 |
def start_session( |
| 78421 | 28 |
build_context: Build.Context, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
29 |
session_context: Session_Context, |
| 77505 | 30 |
progress: Progress, |
31 |
log: Logger, |
|
| 78372 | 32 |
server: SSH.Server, |
| 77474 | 33 |
session_background: Sessions.Background, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
34 |
sources_shasum: SHA1.Shasum, |
| 77474 | 35 |
input_shasum: SHA1.Shasum, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
36 |
node_info: Host.Node_Info, |
|
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
37 |
store_heap: Boolean |
| 77505 | 38 |
): Session_Job = {
|
| 78372 | 39 |
new Session_Job(build_context, session_context, progress, log, server, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
40 |
session_background, sources_shasum, input_shasum, node_info, store_heap) |
| 77505 | 41 |
} |
| 77474 | 42 |
|
| 77442 | 43 |
object Session_Context {
|
44 |
def load( |
|
| 78374 | 45 |
database_server: Option[SQL.Database], |
|
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77521
diff
changeset
|
46 |
build_uuid: String, |
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77442
diff
changeset
|
47 |
name: String, |
|
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77442
diff
changeset
|
48 |
deps: List[String], |
|
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77442
diff
changeset
|
49 |
ancestors: List[String], |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77587
diff
changeset
|
50 |
session_prefs: String, |
| 77458 | 51 |
sources_shasum: SHA1.Shasum, |
| 77442 | 52 |
timeout: Time, |
| 78178 | 53 |
store: Store, |
| 78374 | 54 |
progress: Progress = new Progress |
| 77442 | 55 |
): Session_Context = {
|
| 77450 | 56 |
def default: Session_Context = |
| 77496 | 57 |
Session_Context( |
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77587
diff
changeset
|
58 |
name, deps, ancestors, session_prefs, sources_shasum, timeout, |
|
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77587
diff
changeset
|
59 |
Time.zero, Bytes.empty, build_uuid) |
|
77444
0c704aba71e3
clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents:
77442
diff
changeset
|
60 |
|
| 78374 | 61 |
def read(db: SQL.Database): Session_Context = {
|
62 |
def ignore_error(msg: String) = {
|
|
63 |
progress.echo_warning( |
|
64 |
"Ignoring bad database " + db + " for session " + quote(name) + |
|
65 |
if_proper(msg, ":\n" + msg)) |
|
66 |
default |
|
67 |
} |
|
68 |
try {
|
|
69 |
val command_timings = store.read_command_timings(db, name) |
|
| 83243 | 70 |
val elapsed = Time.seconds(Markup.Elapsed.get(store.read_session_timing(db, name))) |
| 78374 | 71 |
new Session_Context( |
72 |
name, deps, ancestors, session_prefs, sources_shasum, timeout, |
|
73 |
elapsed, command_timings, build_uuid) |
|
74 |
} |
|
75 |
catch {
|
|
76 |
case ERROR(msg) => ignore_error(msg) |
|
77 |
case exn: java.lang.Error => ignore_error(Exn.message(exn)) |
|
78 |
case _: XML.Error => ignore_error("XML.Error")
|
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
database_server match {
|
|
83 |
case Some(db) => if (store.session_info_exists(db)) read(db) else default |
|
84 |
case None => using_option(store.try_open_database(name))(read) getOrElse default |
|
| 77442 | 85 |
} |
86 |
} |
|
87 |
} |
|
88 |
||
| 77496 | 89 |
sealed case class Session_Context( |
90 |
name: String, |
|
91 |
deps: List[String], |
|
92 |
ancestors: List[String], |
|
|
77610
3b09ae9e40cb
clarified session prefs (or "options" within the database);
wenzelm
parents:
77587
diff
changeset
|
93 |
session_prefs: String, |
| 77496 | 94 |
sources_shasum: SHA1.Shasum, |
95 |
timeout: Time, |
|
96 |
old_time: Time, |
|
97 |
old_command_timings_blob: Bytes, |
|
|
77529
40ccee0fe19a
separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents:
77521
diff
changeset
|
98 |
build_uuid: String |
| 80270 | 99 |
) extends Name.T |
| 77442 | 100 |
|
| 83259 | 101 |
abstract class Build_Session(progress: Progress) extends Session {
|
| 83262 | 102 |
/* additional process output */ |
103 |
||
104 |
private val process_output_file = Isabelle_System.tmp_file("process_output")
|
|
105 |
private var process_output_writer: Option[BufferedWriter] = None |
|
106 |
||
107 |
def read_process_output(): List[String] = synchronized {
|
|
108 |
require(process_output_writer.isEmpty, "read_process_output") |
|
109 |
using(Files.newBufferedReader(process_output_file.toPath))(File.read_lines(_, _ => ())) |
|
110 |
} |
|
111 |
||
112 |
def write_process_output(str: String): Unit = synchronized {
|
|
113 |
require(process_output_writer.isDefined, "write_process_output") |
|
114 |
process_output_writer.get.write(str) |
|
115 |
process_output_writer.get.write("\n")
|
|
116 |
} |
|
117 |
||
118 |
def start_process_output(): Unit = synchronized {
|
|
119 |
require(process_output_writer.isEmpty, "start_process_output") |
|
120 |
process_output_file.delete |
|
121 |
process_output_writer = Some(File.writer(process_output_file)) |
|
122 |
} |
|
123 |
||
124 |
def stop_process_output(): Unit = synchronized {
|
|
| 83313 | 125 |
process_output_writer.foreach(_.close()) |
126 |
process_output_writer = None |
|
| 83262 | 127 |
} |
128 |
||
129 |
def clean_process_output(): Unit = synchronized {
|
|
130 |
process_output_file.delete |
|
131 |
} |
|
132 |
||
133 |
||
| 83259 | 134 |
/* options */ |
135 |
||
136 |
val build_progress_delay: Time = session_options.seconds("build_progress_delay")
|
|
137 |
val build_timing_threshold: Time = session_options.seconds("build_timing_threshold")
|
|
138 |
val editor_timing_threshold: Time = session_options.seconds("editor_timing_threshold")
|
|
139 |
||
140 |
||
| 83258 | 141 |
/* errors */ |
142 |
||
143 |
private val build_errors: Promise[List[String]] = Future.promise |
|
144 |
||
145 |
def errors_result(): Exn.Result[List[String]] = build_errors.join_result |
|
146 |
def errors_cancel(): Unit = build_errors.cancel() |
|
147 |
def errors(errs: List[String]): Unit = {
|
|
148 |
try { build_errors.fulfill(errs) }
|
|
149 |
catch { case _: IllegalStateException => }
|
|
150 |
} |
|
| 83259 | 151 |
|
152 |
||
153 |
/* document nodes --- session theories */ |
|
154 |
||
155 |
def nodes_domain: List[Document.Node.Name] |
|
156 |
||
157 |
private var nodes_changed = Set.empty[Document_ID.Generic] |
|
158 |
private var nodes_status = Document_Status.Nodes_Status.empty |
|
159 |
||
|
83312
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
160 |
private def nodes_status_progress(state: Document.State = get_state()): Unit = {
|
| 83259 | 161 |
val result = |
162 |
synchronized {
|
|
| 83310 | 163 |
for (id <- state.progress_theories if !nodes_changed(id)) nodes_changed += id |
| 83259 | 164 |
val nodes_status1 = |
165 |
nodes_changed.foldLeft(nodes_status)({ case (status, state_id) =>
|
|
166 |
state.theory_snapshot(state_id, build_blobs) match {
|
|
167 |
case None => status |
|
168 |
case Some(snapshot) => |
|
169 |
Exn.Interrupt.expose() |
|
|
83503
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83315
diff
changeset
|
170 |
status.update_node(Date.now(), |
|
7b1b7ac616c0
more robust representation of start time as Date;
wenzelm
parents:
83315
diff
changeset
|
171 |
snapshot.state, snapshot.version, snapshot.node_name, |
| 83259 | 172 |
threshold = editor_timing_threshold) |
173 |
} |
|
174 |
}) |
|
175 |
val result = |
|
176 |
if (nodes_changed.isEmpty) None |
|
177 |
else {
|
|
178 |
Some(Progress.Nodes_Status( |
|
179 |
nodes_domain, nodes_status1, |
|
180 |
session = resources.session_background.session_name, |
|
181 |
old = Some(nodes_status))) |
|
182 |
} |
|
183 |
||
184 |
nodes_changed = Set.empty |
|
185 |
nodes_status = nodes_status1 |
|
186 |
||
187 |
result |
|
188 |
} |
|
189 |
result.foreach(progress.nodes_status) |
|
190 |
} |
|
191 |
||
|
83301
88e33d16f2de
more thorough update of nodes_status, while commands are running silently;
wenzelm
parents:
83299
diff
changeset
|
192 |
private lazy val nodes_delay: Delay = |
|
88e33d16f2de
more thorough update of nodes_status, while commands are running silently;
wenzelm
parents:
83299
diff
changeset
|
193 |
Delay.first(build_progress_delay) { nodes_status_progress(); nodes_delay.invoke() }
|
| 83259 | 194 |
|
|
83315
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83313
diff
changeset
|
195 |
def nodes_status_exit(state: Document.State): Unit = synchronized {
|
| 83259 | 196 |
nodes_delay.revoke() |
|
83312
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
197 |
nodes_status_progress(state = state) |
|
83315
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83313
diff
changeset
|
198 |
progress.nodes_status(Progress.Nodes_Status.empty(resources.session_background.session_name)) |
| 83259 | 199 |
} |
200 |
||
| 83262 | 201 |
override def start(start_prover: Prover.Receiver => Prover): Unit = {
|
202 |
start_process_output() |
|
203 |
super.start(start_prover) |
|
204 |
} |
|
205 |
||
| 83259 | 206 |
def command_timing(state_id: Document_ID.Generic, props: Properties.T): Unit = synchronized {
|
207 |
val elapsed = Time.seconds(Markup.Elapsed.get(props)) |
|
208 |
if (elapsed.is_notable(build_timing_threshold)) {
|
|
| 83295 | 209 |
write_process_output( |
| 83299 | 210 |
Protocol.Command_Timing_Marker(props.filter(Markup.command_timing_export))) |
| 83259 | 211 |
} |
212 |
||
213 |
nodes_changed += state_id |
|
214 |
nodes_delay.invoke() |
|
215 |
} |
|
| 83258 | 216 |
} |
217 |
||
| 77474 | 218 |
class Session_Job private[Build_Job]( |
| 78421 | 219 |
build_context: Build.Context, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
220 |
session_context: Session_Context, |
| 77505 | 221 |
progress: Progress, |
222 |
log: Logger, |
|
| 78372 | 223 |
server: SSH.Server, |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
224 |
session_background: Sessions.Background, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
225 |
sources_shasum: SHA1.Shasum, |
|
77460
ccca589d7027
tuned signature: support general Build_Job instances;
wenzelm
parents:
77458
diff
changeset
|
226 |
input_shasum: SHA1.Shasum, |
|
78237
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
227 |
node_info: Host.Node_Info, |
|
c2c59de57df9
clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents:
78213
diff
changeset
|
228 |
store_heap: Boolean |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
229 |
) extends Build_Job {
|
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
230 |
def session_name: String = session_background.session_name |
|
77349
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
231 |
|
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
232 |
private val future_result: Future[Result] = |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
233 |
Future.thread("build", uninterruptible = true) {
|
|
78359
cb0a90df4871
prefer asynchronous operations: reduce time spent within synchronized_database("Build_Process.start_job");
wenzelm
parents:
78280
diff
changeset
|
234 |
val info = session_background.sessions_structure(session_name) |
|
78842
eb572f7b6689
prefer extensible next_node_info in build process over process_options in build engine (which needs the final node info anyway);
Fabian Huch <huch@in.tum.de>
parents:
78674
diff
changeset
|
235 |
val options = Host.node_options(info.options, node_info) |
|
78359
cb0a90df4871
prefer asynchronous operations: reduce time spent within synchronized_database("Build_Process.start_job");
wenzelm
parents:
78280
diff
changeset
|
236 |
val store = build_context.store |
|
cb0a90df4871
prefer asynchronous operations: reduce time spent within synchronized_database("Build_Process.start_job");
wenzelm
parents:
78280
diff
changeset
|
237 |
|
| 78372 | 238 |
using_optional(store.maybe_open_database_server(server = server)) { database_server =>
|
239 |
store.clean_output(database_server, session_name, session_init = true) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
240 |
|
| 78372 | 241 |
val session_sources = |
242 |
Store.Sources.load(session_background.base, cache = store.cache.compress) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
243 |
|
| 78372 | 244 |
val env = |
| 82706 | 245 |
Isabelle_System.Settings.env( |
| 78372 | 246 |
List("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString))
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
247 |
|
| 78372 | 248 |
val session_heaps = |
249 |
session_background.info.parent match {
|
|
250 |
case None => Nil |
|
| 82752 | 251 |
case Some(logic) => store.session_heaps(session_background, logic = logic) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
252 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
253 |
|
| 78372 | 254 |
val use_prelude = if (session_heaps.isEmpty) Thy_Header.ml_roots.map(_._1) else Nil |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
255 |
|
| 78372 | 256 |
val eval_store = |
257 |
if (store_heap) {
|
|
258 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) :::
|
|
259 |
List("ML_Heap.save_child " +
|
|
260 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
|
261 |
} |
|
262 |
else Nil |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
263 |
|
| 78372 | 264 |
def session_blobs(node_name: Document.Node.Name): List[(Command.Blob, Document.Blobs.Item)] = |
265 |
session_background.base.theory_load_commands.get(node_name.theory) match {
|
|
266 |
case None => Nil |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
267 |
case Some(load_commands) => |
| 78372 | 268 |
val syntax = session_background.base.theory_syntax(node_name) |
269 |
val master_dir = Path.explode(node_name.master_dir) |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
270 |
for {
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
271 |
(command_span, command_offset) <- load_commands |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
272 |
file <- command_span.loaded_files(syntax).files |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
273 |
} yield {
|
| 78372 | 274 |
val src_path = Path.explode(file) |
275 |
val blob_name = Document.Node.Name(File.symbolic_path(master_dir + src_path)) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
276 |
|
| 78372 | 277 |
val bytes = session_sources(blob_name.node).bytes |
278 |
val text = bytes.text |
|
279 |
val chunk = Symbol.Text_Chunk(text) |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
280 |
val content = Some((SHA1.digest(bytes), chunk)) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
281 |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
282 |
Command.Blob(command_offset, blob_name, src_path, content) -> |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
283 |
Document.Blobs.Item(bytes, text, chunk, command_offset = command_offset) |
| 78372 | 284 |
} |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
285 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
286 |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
287 |
|
| 78372 | 288 |
/* session */ |
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
289 |
|
|
82744
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
290 |
val session = |
| 83259 | 291 |
new Build_Session(progress) {
|
| 82780 | 292 |
override def session_options: Options = options |
293 |
||
|
82769
7cb5ef6da1f0
proper build_context.store, instead of circular null value (amending 0e36478a1b6a and e891ff63e6db);
wenzelm
parents:
82752
diff
changeset
|
294 |
override val store: Store = build_context.store |
|
82750
0e36478a1b6a
clarified signature: Session always provides Store (with Rich_Text.Cache);
wenzelm
parents:
82744
diff
changeset
|
295 |
|
|
82744
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
296 |
override val resources: Resources = |
|
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
297 |
new Resources(session_background, log = log, |
|
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
298 |
command_timings = |
|
82750
0e36478a1b6a
clarified signature: Session always provides Store (with Rich_Text.Cache);
wenzelm
parents:
82744
diff
changeset
|
299 |
Properties.uncompress(session_context.old_command_timings_blob, cache = cache)) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
300 |
|
| 78372 | 301 |
override def build_blobs_info(node_name: Document.Node.Name): Command.Blobs_Info = |
302 |
Command.Blobs_Info.make(session_blobs(node_name)) |
|
303 |
||
304 |
override def build_blobs(node_name: Document.Node.Name): Document.Blobs = |
|
305 |
Document.Blobs.make(session_blobs(node_name)) |
|
| 83259 | 306 |
|
307 |
override val nodes_domain: List[Document.Node.Name] = |
|
308 |
session_background.base.used_theories.map(_._1.symbolic_path) |
|
| 78372 | 309 |
} |
310 |
||
311 |
val export_consumer = |
|
312 |
Export.consumer(store.open_database(session_name, output = true, server = server), |
|
313 |
store.cache, progress = progress) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
314 |
|
| 83204 | 315 |
// mutable state: session.synchronized |
| 78372 | 316 |
val stdout = new StringBuilder(1000) |
317 |
val stderr = new StringBuilder(1000) |
|
| 83249 | 318 |
|
| 78372 | 319 |
def fun( |
320 |
name: String, |
|
| 83262 | 321 |
marker: Protocol_Message.Marker, |
| 78372 | 322 |
unapply: Properties.T => Option[Properties.T] |
323 |
): (String, Session.Protocol_Function) = {
|
|
324 |
name -> ((msg: Prover.Protocol_Output) => |
|
325 |
unapply(msg.properties) match {
|
|
| 83262 | 326 |
case Some(props) => session.write_process_output(marker(props)); true |
| 78372 | 327 |
case _ => false |
328 |
}) |
|
| 77485 | 329 |
} |
330 |
||
| 78372 | 331 |
session.init_protocol_handler(new Session.Protocol_Handler {
|
|
83312
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
332 |
override def exit(exit_state: Document.State): Unit = {
|
|
83315
03dfb684a50d
more robust nodes_status_exit: make double-sure that progress.nodes_status is finally empty, even after a crash of the prover process (where command_timings might be missing);
wenzelm
parents:
83313
diff
changeset
|
333 |
session.nodes_status_exit(exit_state) |
|
83312
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
334 |
session.errors_cancel() |
|
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
335 |
} |
| 78372 | 336 |
|
337 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = {
|
|
338 |
val (rc, errors) = |
|
339 |
try {
|
|
340 |
val (rc, errs) = {
|
|
341 |
import XML.Decode._ |
|
| 80463 | 342 |
pair(int, list(self))(Symbol.decode_yxml(msg.text)) |
| 78372 | 343 |
} |
344 |
val errors = |
|
345 |
for (err <- errs) yield {
|
|
| 80872 | 346 |
Pretty.string_of(err, metric = Symbol.Metric, pure = true) |
| 78372 | 347 |
} |
348 |
(rc, errors) |
|
349 |
} |
|
350 |
catch { case ERROR(err) => (Process_Result.RC.failure, List(err)) }
|
|
351 |
||
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
352 |
session.protocol_command("Prover.stop", XML.Encode.int(rc))
|
| 83258 | 353 |
session.errors(errors) |
| 78372 | 354 |
true |
355 |
} |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
356 |
|
| 78372 | 357 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
358 |
msg.properties match {
|
|
359 |
case Markup.Loading_Theory(Markup.Name(name)) => |
|
360 |
progress.theory(Progress.Theory(name, session = session_name)) |
|
361 |
false |
|
362 |
case _ => false |
|
363 |
} |
|
364 |
||
365 |
private def export_(msg: Prover.Protocol_Output): Boolean = |
|
366 |
msg.properties match {
|
|
367 |
case Protocol.Export(args) => |
|
368 |
export_consumer.make_entry(session_name, args, msg.chunk) |
|
369 |
true |
|
370 |
case _ => false |
|
371 |
} |
|
372 |
||
373 |
override val functions: Session.Protocol_Functions = |
|
374 |
List( |
|
375 |
Markup.Build_Session_Finished.name -> build_session_finished, |
|
376 |
Markup.Loading_Theory.name -> loading_theory, |
|
377 |
Markup.EXPORT -> export_, |
|
| 83262 | 378 |
fun(Markup.Session_Timing.name, |
379 |
Protocol.Session_Timing_Marker, Markup.Session_Timing.unapply), |
|
380 |
fun(Markup.Task_Statistics.name, |
|
381 |
Protocol.Task_Statistics_Marker, Markup.Task_Statistics.unapply)) |
|
| 78372 | 382 |
}) |
383 |
||
384 |
session.command_timings += Session.Consumer("command_timings") {
|
|
| 83259 | 385 |
case Session.Command_Timing(state_id, props) => session.command_timing(state_id, props) |
| 78372 | 386 |
} |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
387 |
|
| 78372 | 388 |
session.runtime_statistics += Session.Consumer("ML_statistics") {
|
| 83260 | 389 |
case Session.Runtime_Statistics(props) => |
| 83262 | 390 |
session.write_process_output(Protocol.ML_Statistics_Marker(props)) |
| 78372 | 391 |
} |
392 |
||
393 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") {
|
|
394 |
case snapshot => |
|
395 |
if (!progress.stopped) {
|
|
396 |
def export_(name: String, xml: XML.Body, compress: Boolean = true): Unit = {
|
|
397 |
if (!progress.stopped) {
|
|
398 |
val theory_name = snapshot.node_name.theory |
|
399 |
val args = |
|
| 79692 | 400 |
Protocol.Export.Args( |
401 |
theory_name = theory_name, name = name, compress = compress) |
|
|
80437
2c07b9b2f9f4
minor performance tuning: more direct Bytes with Symbol.encode;
wenzelm
parents:
80270
diff
changeset
|
402 |
val body = YXML.bytes_of_body(xml, recode = Symbol.encode) |
| 78372 | 403 |
export_consumer.make_entry(session_name, args, body) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
404 |
} |
| 78372 | 405 |
} |
406 |
def export_text(name: String, text: String, compress: Boolean = true): Unit = |
|
407 |
export_(name, List(XML.Text(text)), compress = compress) |
|
408 |
||
|
82741
0c83a22d8556
more robust: assertion holds, because session.finished_theories provides Snapshot from Document.State.end_theory;
wenzelm
parents:
82706
diff
changeset
|
409 |
assert(snapshot.snippet_commands.length == 1) |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
80872
diff
changeset
|
410 |
for (command <- snapshot.snippet_commands) {
|
| 78372 | 411 |
export_text(Export.DOCUMENT_ID, command.id.toString, compress = false) |
412 |
} |
|
413 |
||
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
414 |
export_(Export.FILES, |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
415 |
{
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
416 |
import XML.Encode._ |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
417 |
list(pair(int, string))(snapshot.node_export_files) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82780
diff
changeset
|
418 |
}) |
| 78372 | 419 |
|
420 |
for ((blob_name, i) <- snapshot.node_files.tail.zipWithIndex) {
|
|
421 |
val xml = snapshot.switch(blob_name).xml_markup() |
|
422 |
export_(Export.MARKUP + (i + 1), xml) |
|
423 |
} |
|
424 |
export_(Export.MARKUP, snapshot.xml_markup()) |
|
425 |
export_(Export.MESSAGES, snapshot.messages.map(_._1)) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
426 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
427 |
} |
| 78372 | 428 |
|
429 |
session.all_messages += Session.Consumer[Any]("build_session_output") {
|
|
430 |
case msg: Prover.Output => |
|
431 |
val message = msg.message |
|
|
82744
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
432 |
if (msg.is_system) session.resources.log(Protocol.message_text(message)) |
| 78372 | 433 |
|
434 |
if (msg.is_stdout) {
|
|
| 83204 | 435 |
session.synchronized { stdout ++= Symbol.encode(XML.content(message)) }
|
| 78372 | 436 |
} |
437 |
else if (msg.is_stderr) {
|
|
| 83204 | 438 |
session.synchronized { stderr ++= Symbol.encode(XML.content(message)) }
|
| 78372 | 439 |
} |
440 |
else if (msg.is_exit) {
|
|
441 |
val err = |
|
442 |
"Prover terminated" + |
|
443 |
(msg.properties match {
|
|
444 |
case Markup.Process_Result(result) => ": " + result.print_rc |
|
445 |
case _ => "" |
|
446 |
}) |
|
| 83258 | 447 |
session.errors(List(err)) |
| 78372 | 448 |
} |
449 |
case _ => |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
450 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
451 |
|
| 78372 | 452 |
build_context.session_setup(session_name, session) |
453 |
||
454 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store)
|
|
455 |
||
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
456 |
|
| 78372 | 457 |
/* process */ |
458 |
||
459 |
val process = |
|
460 |
Isabelle_Process.start(options, session, session_background, session_heaps, |
|
|
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
80121
diff
changeset
|
461 |
use_prelude = use_prelude, eval_main = eval_main, cwd = info.dir, env = env) |
| 78372 | 462 |
|
463 |
val timeout_request: Option[Event_Timer.Request] = |
|
464 |
if (info.timeout_ignored) None |
|
465 |
else Some(Event_Timer.request(Time.now() + info.timeout) { process.terminate() })
|
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
466 |
|
| 78372 | 467 |
val build_errors = |
468 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) {
|
|
469 |
Exn.capture { process.await_startup() } match {
|
|
470 |
case Exn.Res(_) => |
|
|
82744
0ca8b1861fa3
clarified signature: more explicit subtypes of Session, with corresponding subtypes of Resources;
wenzelm
parents:
82742
diff
changeset
|
471 |
val resources_xml = session.resources.init_session_xml |
| 78372 | 472 |
val encode_options: XML.Encode.T[Options] = |
473 |
options => session.prover_options(options).encode |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
474 |
val args_xml = |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
475 |
{
|
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
476 |
import XML.Encode._ |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
477 |
pair(string, list(pair(encode_options, list(pair(string, properties)))))( |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
478 |
(session_name, info.theories)) |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
479 |
} |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
80437
diff
changeset
|
480 |
session.protocol_command("build_session", resources_xml, args_xml)
|
| 83258 | 481 |
session.errors_result() |
| 78372 | 482 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
483 |
} |
|
484 |
} |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
485 |
|
| 78372 | 486 |
val result0 = |
487 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) { process.await_shutdown() }
|
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
488 |
|
| 78372 | 489 |
val was_timeout = |
490 |
timeout_request match {
|
|
491 |
case None => false |
|
492 |
case Some(request) => !request.cancel() |
|
493 |
} |
|
494 |
||
495 |
session.stop() |
|
|
83312
6b4028763591
more robust nodes_status_sync, just before exit/shutdown --- Document.state content gets removed afterwards;
wenzelm
parents:
83311
diff
changeset
|
496 |
session.stop_process_output() |
|
83209
a39fde2f020a
basic setup for build progress with nodes_status;
wenzelm
parents:
83207
diff
changeset
|
497 |
|
| 78372 | 498 |
val export_errors = |
499 |
export_consumer.shutdown(close = true).map(Output.error_message_text) |
|
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
500 |
|
| 78372 | 501 |
val (document_output, document_errors) = |
502 |
try {
|
|
| 78674 | 503 |
if (Exn.is_res(build_errors) && result0.ok && info.documents.nonEmpty) {
|
| 78379 | 504 |
using(Export.open_database_context(store, server = server)) { database_context =>
|
| 78372 | 505 |
val documents = |
506 |
using(database_context.open_session(session_background)) {
|
|
507 |
session_context => |
|
508 |
Document_Build.build_documents( |
|
509 |
Document_Build.context(session_context, progress = progress), |
|
510 |
output_sources = info.document_output, |
|
511 |
output_pdf = info.document_output) |
|
512 |
} |
|
| 79692 | 513 |
using(database_context.open_database(session_name, output = true))( |
514 |
session_database => |
|
515 |
documents.foreach(_.write(session_database.db, session_name))) |
|
| 78372 | 516 |
(documents.flatMap(_.log_lines), Nil) |
517 |
} |
|
| 77484 | 518 |
} |
| 78372 | 519 |
else (Nil, Nil) |
520 |
} |
|
521 |
catch {
|
|
522 |
case exn: Document_Build.Build_Error => (exn.log_lines, exn.log_errors) |
|
523 |
case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) |
|
524 |
} |
|
| 77485 | 525 |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
526 |
|
| 78372 | 527 |
/* process result */ |
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
528 |
|
| 78372 | 529 |
val result1 = {
|
530 |
val more_output = |
|
| 83204 | 531 |
session.synchronized {
|
532 |
Library.trim_line(stdout.toString) :: |
|
| 83262 | 533 |
session.read_process_output() ::: |
| 83204 | 534 |
document_output |
535 |
} |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
536 |
|
| 78372 | 537 |
result0.output(more_output) |
538 |
.error(Library.trim_line(stderr.toString)) |
|
539 |
.errors_rc(export_errors ::: document_errors) |
|
540 |
} |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
541 |
|
| 78372 | 542 |
val result2 = |
543 |
build_errors match {
|
|
544 |
case Exn.Res(build_errs) => |
|
545 |
val errs = build_errs ::: document_errors |
|
546 |
if (errs.nonEmpty) {
|
|
547 |
result1.error_rc.output( |
|
548 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
549 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
550 |
} |
|
| 79692 | 551 |
else if (progress.stopped && result1.ok) {
|
552 |
result1.copy(rc = Process_Result.RC.interrupt) |
|
553 |
} |
|
| 78372 | 554 |
else result1 |
555 |
case Exn.Exn(Exn.Interrupt()) => |
|
556 |
if (result1.ok) result1.copy(rc = Process_Result.RC.interrupt) |
|
557 |
else result1 |
|
558 |
case Exn.Exn(exn) => throw exn |
|
559 |
} |
|
560 |
||
561 |
val process_result = |
|
562 |
if (result2.ok) result2 |
|
563 |
else if (was_timeout) result2.error(Output.error_message_text("Timeout")).timeout_rc
|
|
564 |
else if (result2.interrupted) result2.error(Output.error_message_text("Interrupt"))
|
|
565 |
else result2 |
|
566 |
||
|
79691
d298c5b65d8e
clarified store_session: heap requires process_result.ok, but log_db is always stored;
wenzelm
parents:
79682
diff
changeset
|
567 |
val store_session = |
|
d298c5b65d8e
clarified store_session: heap requires process_result.ok, but log_db is always stored;
wenzelm
parents:
79682
diff
changeset
|
568 |
store.output_session(session_name, store_heap = process_result.ok && store_heap) |
|
d298c5b65d8e
clarified store_session: heap requires process_result.ok, but log_db is always stored;
wenzelm
parents:
79682
diff
changeset
|
569 |
|
| 83262 | 570 |
session.clean_process_output() |
571 |
||
| 78372 | 572 |
|
573 |
/* output heap */ |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
574 |
|
|
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79678
diff
changeset
|
575 |
val output_shasum = |
|
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79678
diff
changeset
|
576 |
store_session.heap match {
|
|
79691
d298c5b65d8e
clarified store_session: heap requires process_result.ok, but log_db is always stored;
wenzelm
parents:
79682
diff
changeset
|
577 |
case Some(path) => SHA1.shasum(ML_Heap.write_file_digest(path), session_name) |
|
d298c5b65d8e
clarified store_session: heap requires process_result.ok, but log_db is always stored;
wenzelm
parents:
79682
diff
changeset
|
578 |
case None => SHA1.no_shasum |
| 78372 | 579 |
} |
580 |
||
581 |
val log_lines = process_result.out_lines.filterNot(Protocol_Message.Marker.test) |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
582 |
|
| 78372 | 583 |
val build_log = |
|
78985
24e686fe043e
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents:
78842
diff
changeset
|
584 |
Build_Log.Log_File(session_name, process_result.out_lines, cache = store.cache). |
| 78372 | 585 |
parse_session_info( |
586 |
command_timings = true, |
|
587 |
theory_timings = true, |
|
588 |
ml_statistics = true, |
|
589 |
task_statistics = true) |
|
590 |
||
591 |
// write log file |
|
592 |
if (process_result.ok) {
|
|
593 |
File.write_gzip(store.output_log_gz(session_name), terminate_lines(log_lines)) |
|
594 |
} |
|
595 |
else File.write(store.output_log(session_name), terminate_lines(log_lines)) |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
596 |
|
| 78372 | 597 |
// write database |
| 78374 | 598 |
def write_info(db: SQL.Database): Unit = |
| 78372 | 599 |
store.write_session_info(db, session_name, session_sources, |
600 |
build_log = |
|
601 |
if (process_result.timeout) build_log.error("Timeout") else build_log,
|
|
602 |
build = |
|
603 |
Store.Build_Info( |
|
604 |
sources = sources_shasum, |
|
605 |
input_heaps = input_shasum, |
|
606 |
output_heap = output_shasum, |
|
607 |
process_result.rc, |
|
| 78374 | 608 |
build_context.build_uuid)) |
|
78529
0e79fa88cab6
build_worker is stopped independently from master build_process;
wenzelm
parents:
78435
diff
changeset
|
609 |
|
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
610 |
database_server match {
|
|
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
611 |
case Some(db) => write_info(db) |
|
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
612 |
case None => using(store.open_database(session_name, output = true))(write_info) |
|
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
613 |
} |
| 78372 | 614 |
|
| 80121 | 615 |
store.in_heaps_database( |
616 |
List(store_session), database_server, server = server, progress = progress) |
|
|
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79678
diff
changeset
|
617 |
|
| 78372 | 618 |
// messages |
619 |
process_result.err_lines.foreach(progress.echo(_)) |
|
620 |
||
621 |
if (process_result.ok) {
|
|
622 |
val props = build_log.session_timing |
|
623 |
val threads = Markup.Session_Timing.Threads.unapply(props) getOrElse 1 |
|
624 |
val timing = Markup.Timing_Properties.get(props) |
|
625 |
progress.echo( |
|
626 |
"Timing " + session_name + " (" + threads + " threads, " + timing.message_factor + ")",
|
|
627 |
verbose = true) |
|
628 |
progress.echo( |
|
629 |
"Finished " + session_name + " (" + process_result.timing.message_resources + ")")
|
|
630 |
} |
|
631 |
else {
|
|
632 |
progress.echo( |
|
| 79692 | 633 |
session_name + " FAILED (see also \"isabelle build_log -H Error " + |
634 |
session_name + "\")") |
|
| 78372 | 635 |
if (!process_result.interrupted) {
|
636 |
val tail = info.options.int("process_output_tail")
|
|
| 79692 | 637 |
val suffix = |
638 |
if (tail == 0) log_lines else log_lines.drop(log_lines.length - tail max 0) |
|
639 |
val prefix = |
|
640 |
if (log_lines.length == suffix.length) Nil else List("...")
|
|
| 78372 | 641 |
progress.echo(Library.trim_line(cat_lines(prefix ::: suffix))) |
642 |
} |
|
643 |
} |
|
644 |
||
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
645 |
Result(process_result.copy(out_lines = log_lines), output_shasum) |
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
646 |
} |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
647 |
} |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
648 |
|
|
77486
032c76e04475
clarified execution context: main work happens within Future.thread;
wenzelm
parents:
77485
diff
changeset
|
649 |
override def cancel(): Unit = future_result.cancel() |
| 77298 | 650 |
override def is_finished: Boolean = future_result.is_finished |
|
79887
17220dc05991
revert most parts of 0e79fa88cab6: somewhat ambitious attempt to move towards "editing" builds via added/canceled workers;
wenzelm
parents:
79718
diff
changeset
|
651 |
override def join: Result = future_result.join |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
652 |
} |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
653 |
} |