| author | wenzelm |
| Fri, 16 Dec 2022 18:12:48 +0100 | |
| changeset 76657 | a8d85b4a588c |
| parent 76656 | a8f452f7c503 |
| child 76667 | fa81f218c96e |
| 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 |
|
| 76087 | 11 |
import scala.util.matching.Regex |
| 72662 | 12 |
|
13 |
||
| 75393 | 14 |
object Build_Job {
|
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
15 |
/* theory markup/messages from session database */ |
| 72854 | 16 |
|
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
17 |
def read_theory( |
|
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
18 |
theory_context: Export.Theory_Context, |
|
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
19 |
unicode_symbols: Boolean = false |
| 76205 | 20 |
): Option[Document.Snapshot] = {
|
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
21 |
def read(name: String): Export.Entry = theory_context(name, permissive = true) |
|
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 = |
| 73033 | 24 |
YXML.parse_body( |
25 |
Symbol.output(unicode_symbols, UTF8.decode_permissive(read(name).uncompressed)), |
|
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
26 |
cache = theory_context.cache) |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
27 |
|
| 75733 | 28 |
for {
|
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
29 |
id <- theory_context.document_id() |
| 75903 | 30 |
(thy_file, blobs_files) <- theory_context.files(permissive = true) |
| 75733 | 31 |
} |
32 |
yield {
|
|
|
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
33 |
val master_dir = |
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
34 |
Thy_Header.split_file_name(thy_file) match {
|
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
35 |
case Some((dir, _)) => dir |
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
36 |
case None => error("Cannot determine theory master directory: " + quote(thy_file))
|
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
37 |
} |
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
38 |
val node_name = |
|
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
39 |
Document.Node.Name(thy_file, master_dir = master_dir, theory = theory_context.theory) |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
40 |
|
| 75733 | 41 |
val results = |
42 |
Command.Results.make( |
|
43 |
for (elem @ XML.Elem(Markup(_, Markup.Serial(i)), _) <- read_xml(Export.MESSAGES)) |
|
44 |
yield i -> elem) |
|
45 |
||
46 |
val blobs = |
|
47 |
blobs_files.map { file =>
|
|
|
75914
4da80799352f
more robust treatment of Document.Node.Name, following stored data;
wenzelm
parents:
75909
diff
changeset
|
48 |
val name = Document.Node.Name(file) |
| 75733 | 49 |
val path = Path.explode(file) |
50 |
val src_path = File.relative_path(node_name.master_dir_path, path).getOrElse(path) |
|
51 |
Command.Blob(name, src_path, None) |
|
52 |
} |
|
53 |
val blobs_xml = |
|
54 |
for (i <- (1 to blobs.length).toList) |
|
55 |
yield read_xml(Export.MARKUP + i) |
|
|
72865
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
56 |
|
| 75733 | 57 |
val blobs_info = |
58 |
Command.Blobs_Info( |
|
59 |
for { (Command.Blob(name, src_path, _), xml) <- blobs zip blobs_xml }
|
|
60 |
yield {
|
|
61 |
val text = XML.content(xml) |
|
62 |
val chunk = Symbol.Text_Chunk(text) |
|
63 |
val digest = SHA1.digest(Symbol.encode(text)) |
|
64 |
Exn.Res(Command.Blob(name, src_path, Some((digest, chunk)))) |
|
65 |
}) |
|
| 72864 | 66 |
|
| 75733 | 67 |
val thy_xml = read_xml(Export.MARKUP) |
68 |
val thy_source = XML.content(thy_xml) |
|
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
69 |
|
| 75733 | 70 |
val markups_index = |
71 |
Command.Markup_Index.markup :: blobs.map(Command.Markup_Index.blob) |
|
72 |
val markups = |
|
73 |
Command.Markups.make( |
|
74 |
for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml)) |
|
75 |
yield index -> Markup_Tree.from_XML(xml)) |
|
76 |
||
| 76205 | 77 |
val command = |
78 |
Command.unparsed(thy_source, theory = true, id = id, node_name = node_name, |
|
79 |
blobs_info = blobs_info, results = results, markups = markups) |
|
80 |
||
81 |
Document.State.init.snippet(command) |
|
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
82 |
} |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
83 |
} |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
84 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
85 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
86 |
/* print messages */ |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
87 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
88 |
def print_log( |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
89 |
options: Options, |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
90 |
sessions: List[String], |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
91 |
theories: List[String] = Nil, |
| 76087 | 92 |
message_head: List[Regex] = Nil, |
93 |
message_body: List[Regex] = Nil, |
|
| 72878 | 94 |
verbose: Boolean = false, |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
95 |
progress: Progress = new Progress, |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
96 |
margin: Double = Pretty.default_margin, |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
97 |
breakgain: Double = Pretty.default_breakgain, |
| 72873 | 98 |
metric: Pretty.Metric = Symbol.Metric, |
| 75393 | 99 |
unicode_symbols: Boolean = false |
100 |
): Unit = {
|
|
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
101 |
val store = Sessions.store(options) |
| 76654 | 102 |
val session = new Session(options, Resources.bootstrap) |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
103 |
|
| 76087 | 104 |
def check(filter: List[Regex], make_string: => String): Boolean = |
105 |
filter.isEmpty || {
|
|
106 |
val s = Output.clean_yxml(make_string) |
|
107 |
filter.forall(r => r.findFirstIn(Output.clean_yxml(s)).nonEmpty) |
|
108 |
} |
|
109 |
||
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
110 |
def print(session_name: String): Unit = {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
111 |
using(Export.open_session_context0(store, session_name)) { session_context =>
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
112 |
val result = |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
113 |
for {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
114 |
db <- session_context.session_db() |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
115 |
theories = store.read_theories(db, session_name) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
116 |
errors = store.read_errors(db, session_name) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
117 |
info <- store.read_build(db, session_name) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
118 |
} yield (theories, errors, info.return_code) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
119 |
result match {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
120 |
case None => store.error_database(session_name) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
121 |
case Some((used_theories, errors, rc)) => |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
122 |
theories.filterNot(used_theories.toSet) match {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
123 |
case Nil => |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
124 |
case bad => error("Unknown theories " + commas_quote(bad))
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
125 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
126 |
val print_theories = |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
127 |
if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet) |
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
128 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
129 |
for (thy <- print_theories) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
130 |
val thy_heading = "\nTheory " + quote(thy) + " (in " + session_name + ")" + ":" |
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
131 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
132 |
read_theory(session_context.theory(thy), unicode_symbols = unicode_symbols) match {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
133 |
case None => progress.echo(thy_heading + " MISSING") |
| 76205 | 134 |
case Some(snapshot) => |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
135 |
val rendering = new Rendering(snapshot, options, session) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
136 |
val messages = |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
137 |
rendering.text_messages(Text.Range.full) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
138 |
.filter(message => verbose || Protocol.is_exported(message.info)) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
139 |
if (messages.nonEmpty) {
|
| 76205 | 140 |
val line_document = Line.Document(snapshot.source) |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
141 |
val buffer = new mutable.ListBuffer[String] |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
142 |
for (Text.Info(range, elem) <- messages) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
143 |
val line = line_document.position(range.start).line1 |
| 76205 | 144 |
val pos = Position.Line_File(line, snapshot.node_name.node) |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
145 |
def message_text: String = |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
146 |
Protocol.message_text(elem, heading = true, pos = pos, |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
147 |
margin = margin, breakgain = breakgain, metric = metric) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
148 |
val ok = |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
149 |
check(message_head, Protocol.message_heading(elem, pos)) && |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
150 |
check(message_body, XML.content(Pretty.unformatted(List(elem)))) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
151 |
if (ok) buffer += message_text |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
152 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
153 |
if (buffer.nonEmpty) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
154 |
progress.echo(thy_heading) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
155 |
buffer.foreach(progress.echo) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
156 |
} |
| 76087 | 157 |
} |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
158 |
} |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
159 |
} |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
160 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
161 |
if (errors.nonEmpty) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
162 |
val msg = Symbol.output(unicode_symbols, cat_lines(errors)) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
163 |
progress.echo("\nBuild errors:\n" + Output.error_message_text(msg))
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
164 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
165 |
if (rc != Process_Result.RC.ok) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
166 |
progress.echo("\n" + Process_Result.RC.print_long(rc))
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
167 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
168 |
} |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
169 |
} |
| 75394 | 170 |
} |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
171 |
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
172 |
val errors = new mutable.ListBuffer[String] |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
173 |
for (session_name <- sessions) {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
174 |
Exn.interruptible_capture(print(session_name)) match {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
175 |
case Exn.Res(_) => |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
176 |
case Exn.Exn(exn) => errors += Exn.message(exn) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
177 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
178 |
} |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
179 |
if (errors.nonEmpty) error(cat_lines(errors.toList)) |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
180 |
} |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
181 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
182 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
183 |
/* Isabelle tool wrapper */ |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
184 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
185 |
val isabelle_tool = Isabelle_Tool("log", "print messages from build database",
|
| 75394 | 186 |
Scala_Project.here, |
187 |
{ args =>
|
|
188 |
/* arguments */ |
|
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
189 |
|
| 76087 | 190 |
var message_head = List.empty[Regex] |
191 |
var message_body = List.empty[Regex] |
|
| 75394 | 192 |
var unicode_symbols = false |
193 |
var theories: List[String] = Nil |
|
194 |
var margin = Pretty.default_margin |
|
195 |
var options = Options.init() |
|
196 |
var verbose = false |
|
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
197 |
|
| 75394 | 198 |
val getopts = Getopts("""
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
199 |
Usage: isabelle log [OPTIONS] [SESSIONS ...] |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
200 |
|
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
201 |
Options are: |
| 76087 | 202 |
-H REGEX filter messages by matching against head |
203 |
-M REGEX filter messages by matching against body |
|
| 72876 | 204 |
-T NAME restrict to given theories (multiple options possible) |
| 72867 | 205 |
-U output Unicode symbols |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
206 |
-m MARGIN margin for pretty printing (default: """ + margin + """) |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
207 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
73837
f72335f6a9ed
clarified documentation: tracing messages are not shown here;
wenzelm
parents:
73835
diff
changeset
|
208 |
-v print all messages, including information etc. |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
209 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
210 |
Print messages from the build database of the given sessions, without any |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
211 |
checks against current sources nor session structure: results from old |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
212 |
sessions or failed builds can be printed as well. |
| 76087 | 213 |
|
214 |
Multiple options -H and -M are conjunctive: all given patterns need to |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
215 |
match. Patterns match any substring, but ^ or $ may be used to match the |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
216 |
start or end explicitly. |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
217 |
""", |
| 76087 | 218 |
"H:" -> (arg => message_head = message_head ::: List(arg.r)), |
219 |
"M:" -> (arg => message_body = message_body ::: List(arg.r)), |
|
| 75394 | 220 |
"T:" -> (arg => theories = theories ::: List(arg)), |
221 |
"U" -> (_ => unicode_symbols = true), |
|
222 |
"m:" -> (arg => margin = Value.Double.parse(arg)), |
|
223 |
"o:" -> (arg => options = options + arg), |
|
224 |
"v" -> (_ => verbose = true)) |
|
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
225 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
226 |
val sessions = getopts(args) |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
227 |
|
| 75394 | 228 |
val progress = new Console_Progress() |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
229 |
|
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
230 |
if (sessions.isEmpty) progress.echo_warning("No sessions to print")
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
231 |
else {
|
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
232 |
print_log(options, sessions, theories = theories, message_head = message_head, |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
233 |
message_body = message_body, verbose = verbose, margin = margin, progress = progress, |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
234 |
unicode_symbols = unicode_symbols) |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
235 |
} |
| 75394 | 236 |
}) |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
237 |
} |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
238 |
|
| 72662 | 239 |
class Build_Job(progress: Progress, |
240 |
session_name: String, |
|
241 |
val info: Sessions.Info, |
|
242 |
deps: Sessions.Deps, |
|
243 |
store: Sessions.Store, |
|
244 |
do_store: Boolean, |
|
|
73777
52e43a93d51f
clarified system_log: make this work independently of the particular "isabelle build" command-line (e.g. "isabelle mirabelle");
wenzelm
parents:
73774
diff
changeset
|
245 |
log: Logger, |
|
73805
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
246 |
session_setup: (String, Session) => Unit, |
| 72662 | 247 |
val numa_node: Option[Int], |
| 75393 | 248 |
command_timings0: List[Properties.T] |
249 |
) {
|
|
| 72662 | 250 |
val options: Options = NUMA.policy_options(info.options, numa_node) |
251 |
||
| 76656 | 252 |
private val session_background = deps.background(session_name) |
| 72662 | 253 |
|
254 |
private val future_result: Future[Process_Result] = |
|
255 |
Future.thread("build", uninterruptible = true) {
|
|
256 |
val parent = info.parent.getOrElse("")
|
|
257 |
val base = deps(parent) |
|
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
258 |
val result_base = deps(session_name) |
| 72662 | 259 |
|
| 75454 | 260 |
val env = |
261 |
Isabelle_System.settings( |
|
262 |
List("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString))
|
|
| 72662 | 263 |
|
264 |
val is_pure = Sessions.is_pure(session_name) |
|
265 |
||
266 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
|
267 |
||
268 |
val eval_store = |
|
269 |
if (do_store) {
|
|
270 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) :::
|
|
271 |
List("ML_Heap.save_child " +
|
|
272 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
|
273 |
} |
|
274 |
else Nil |
|
275 |
||
| 73774 | 276 |
val resources = |
| 76657 | 277 |
new Resources(session_background, log = log, command_timings = command_timings0) |
| 72662 | 278 |
val session = |
279 |
new Session(options, resources) {
|
|
|
74731
161e84e6b40a
just one cache, via HTML_Context, via Sessions.Store or Session;
wenzelm
parents:
74712
diff
changeset
|
280 |
override val cache: Term.Cache = store.cache |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
281 |
|
| 75393 | 282 |
override def build_blobs_info(name: Document.Node.Name): Command.Blobs_Info = {
|
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
283 |
result_base.load_commands.get(name.expand) match {
|
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
284 |
case Some(spans) => |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
285 |
val syntax = result_base.theory_syntax(name) |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
286 |
Command.build_blobs_info(syntax, name, spans) |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
287 |
case None => Command.Blobs_Info.none |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
288 |
} |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
289 |
} |
| 72662 | 290 |
} |
291 |
||
| 75393 | 292 |
object Build_Session_Errors {
|
| 72662 | 293 |
private val promise: Promise[List[String]] = Future.promise |
294 |
||
295 |
def result: Exn.Result[List[String]] = promise.join_result |
|
| 73367 | 296 |
def cancel(): Unit = promise.cancel() |
| 75393 | 297 |
def apply(errs: List[String]): Unit = {
|
| 72662 | 298 |
try { promise.fulfill(errs) }
|
299 |
catch { case _: IllegalStateException => }
|
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
val export_consumer = |
|
| 74255 | 304 |
Export.consumer(store.open_database(session_name, output = true), store.cache, |
305 |
progress = progress) |
|
| 72662 | 306 |
|
307 |
val stdout = new StringBuilder(1000) |
|
308 |
val stderr = new StringBuilder(1000) |
|
309 |
val command_timings = new mutable.ListBuffer[Properties.T] |
|
310 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
311 |
val session_timings = new mutable.ListBuffer[Properties.T] |
|
312 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
|
313 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
314 |
||
315 |
def fun( |
|
316 |
name: String, |
|
317 |
acc: mutable.ListBuffer[Properties.T], |
|
| 75393 | 318 |
unapply: Properties.T => Option[Properties.T] |
319 |
): (String, Session.Protocol_Function) = {
|
|
| 72662 | 320 |
name -> ((msg: Prover.Protocol_Output) => |
321 |
unapply(msg.properties) match {
|
|
322 |
case Some(props) => acc += props; true |
|
323 |
case _ => false |
|
324 |
}) |
|
325 |
} |
|
326 |
||
| 75393 | 327 |
session.init_protocol_handler(new Session.Protocol_Handler {
|
| 73367 | 328 |
override def exit(): Unit = Build_Session_Errors.cancel() |
| 72662 | 329 |
|
| 75393 | 330 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = {
|
| 72662 | 331 |
val (rc, errors) = |
332 |
try {
|
|
| 75393 | 333 |
val (rc, errs) = {
|
| 72662 | 334 |
import XML.Decode._ |
335 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
336 |
} |
|
337 |
val errors = |
|
338 |
for (err <- errs) yield {
|
|
339 |
val prt = Protocol_Message.expose_no_reports(err) |
|
340 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
341 |
} |
|
342 |
(rc, errors) |
|
343 |
} |
|
| 74306 | 344 |
catch { case ERROR(err) => (Process_Result.RC.failure, List(err)) }
|
| 72662 | 345 |
|
346 |
session.protocol_command("Prover.stop", rc.toString)
|
|
347 |
Build_Session_Errors(errors) |
|
348 |
true |
|
349 |
} |
|
350 |
||
351 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
352 |
msg.properties match {
|
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
353 |
case Markup.Loading_Theory(Markup.Name(name)) => |
| 72662 | 354 |
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
|
355 |
false |
| 72662 | 356 |
case _ => false |
357 |
} |
|
358 |
||
| 74685 | 359 |
private def export_(msg: Prover.Protocol_Output): Boolean = |
| 72662 | 360 |
msg.properties match {
|
361 |
case Protocol.Export(args) => |
|
|
75762
985c3a64748c
clarified signature: more uniform treatment of empty exports;
wenzelm
parents:
75738
diff
changeset
|
362 |
export_consumer.make_entry(session_name, args, msg.chunk) |
| 72662 | 363 |
true |
364 |
case _ => false |
|
365 |
} |
|
366 |
||
| 75440 | 367 |
override val functions: Session.Protocol_Functions = |
| 72662 | 368 |
List( |
369 |
Markup.Build_Session_Finished.name -> build_session_finished, |
|
370 |
Markup.Loading_Theory.name -> loading_theory, |
|
| 74685 | 371 |
Markup.EXPORT -> export_, |
| 72662 | 372 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
373 |
fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply), |
|
374 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
375 |
}) |
|
376 |
||
| 75393 | 377 |
session.command_timings += Session.Consumer("command_timings") {
|
378 |
case Session.Command_Timing(props) => |
|
379 |
for {
|
|
380 |
elapsed <- Markup.Elapsed.unapply(props) |
|
381 |
elapsed_time = Time.seconds(elapsed) |
|
382 |
if elapsed_time.is_relevant && elapsed_time >= options.seconds("command_timing_threshold")
|
|
383 |
} command_timings += props.filter(Markup.command_timing_property) |
|
384 |
} |
|
| 72711 | 385 |
|
| 75393 | 386 |
session.runtime_statistics += Session.Consumer("ML_statistics") {
|
387 |
case Session.Runtime_Statistics(props) => runtime_statistics += props |
|
388 |
} |
|
| 72662 | 389 |
|
| 75393 | 390 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") {
|
391 |
case snapshot => |
|
392 |
if (!progress.stopped) {
|
|
393 |
val rendering = new Rendering(snapshot, options, session) |
|
| 72730 | 394 |
|
| 75393 | 395 |
def export_(name: String, xml: XML.Body, compress: Boolean = true): Unit = {
|
396 |
if (!progress.stopped) {
|
|
397 |
val theory_name = snapshot.node_name.theory |
|
398 |
val args = |
|
399 |
Protocol.Export.Args(theory_name = theory_name, name = name, compress = compress) |
|
|
75762
985c3a64748c
clarified signature: more uniform treatment of empty exports;
wenzelm
parents:
75738
diff
changeset
|
400 |
val body = Bytes(Symbol.encode(YXML.string_of_body(xml))) |
|
985c3a64748c
clarified signature: more uniform treatment of empty exports;
wenzelm
parents:
75738
diff
changeset
|
401 |
export_consumer.make_entry(session_name, args, body) |
| 74258 | 402 |
} |
| 75393 | 403 |
} |
404 |
def export_text(name: String, text: String, compress: Boolean = true): Unit = |
|
405 |
export_(name, List(XML.Text(text)), compress = compress) |
|
| 72730 | 406 |
|
| 75393 | 407 |
for (command <- snapshot.snippet_command) {
|
408 |
export_text(Export.DOCUMENT_ID, command.id.toString, compress = false) |
|
409 |
} |
|
| 72844 | 410 |
|
| 75393 | 411 |
export_text(Export.FILES, |
| 75909 | 412 |
cat_lines(snapshot.node_files.map(_.path.implode_symbolic)), compress = false) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
413 |
|
| 75393 | 414 |
for (((_, xml), i) <- snapshot.xml_markup_blobs().zipWithIndex) {
|
415 |
export_(Export.MARKUP + (i + 1), xml) |
|
416 |
} |
|
417 |
export_(Export.MARKUP, snapshot.xml_markup()) |
|
418 |
export_(Export.MESSAGES, snapshot.messages.map(_._1)) |
|
| 74258 | 419 |
|
| 75393 | 420 |
val citations = Library.distinct(rendering.citations(Text.Range.full).map(_.info)) |
421 |
export_text(Export.DOCUMENT_CITATIONS, cat_lines(citations)) |
|
422 |
} |
|
423 |
} |
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
424 |
|
| 75393 | 425 |
session.all_messages += Session.Consumer[Any]("build_session_output") {
|
426 |
case msg: Prover.Output => |
|
427 |
val message = msg.message |
|
428 |
if (msg.is_system) resources.log(Protocol.message_text(message)) |
|
| 73774 | 429 |
|
| 75393 | 430 |
if (msg.is_stdout) {
|
431 |
stdout ++= Symbol.encode(XML.content(message)) |
|
432 |
} |
|
433 |
else if (msg.is_stderr) {
|
|
434 |
stderr ++= Symbol.encode(XML.content(message)) |
|
435 |
} |
|
436 |
else if (msg.is_exit) {
|
|
437 |
val err = |
|
438 |
"Prover terminated" + |
|
439 |
(msg.properties match {
|
|
440 |
case Markup.Process_Result(result) => ": " + result.print_rc |
|
441 |
case _ => "" |
|
442 |
}) |
|
443 |
Build_Session_Errors(List(err)) |
|
444 |
} |
|
445 |
case _ => |
|
446 |
} |
|
| 72662 | 447 |
|
|
73805
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
448 |
session_setup(session_name, session) |
|
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
449 |
|
| 72662 | 450 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store)
|
451 |
||
452 |
val process = |
|
| 76656 | 453 |
Isabelle_Process.start(session, options, session_background, store, |
| 72662 | 454 |
logic = parent, raw_ml_system = is_pure, |
455 |
use_prelude = use_prelude, eval_main = eval_main, |
|
456 |
cwd = info.dir.file, env = env) |
|
457 |
||
458 |
val build_errors = |
|
| 73367 | 459 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) {
|
460 |
Exn.capture { process.await_startup() } match {
|
|
| 72662 | 461 |
case Exn.Res(_) => |
462 |
val resources_yxml = resources.init_session_yxml |
|
| 74144 | 463 |
val encode_options: XML.Encode.T[Options] = |
464 |
options => session.prover_options(options).encode |
|
| 72662 | 465 |
val args_yxml = |
466 |
YXML.string_of_body( |
|
467 |
{
|
|
468 |
import XML.Encode._ |
|
| 74144 | 469 |
pair(string, list(pair(encode_options, list(pair(string, properties)))))( |
| 72662 | 470 |
(session_name, info.theories)) |
471 |
}) |
|
472 |
session.protocol_command("build_session", resources_yxml, args_yxml)
|
|
473 |
Build_Session_Errors.result |
|
474 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
val process_result = |
|
| 73367 | 479 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) { process.await_shutdown() }
|
| 72662 | 480 |
|
| 72697 | 481 |
session.stop() |
482 |
||
| 72662 | 483 |
val export_errors = |
484 |
export_consumer.shutdown(close = true).map(Output.error_message_text) |
|
485 |
||
| 72699 | 486 |
val (document_output, document_errors) = |
| 72662 | 487 |
try {
|
| 72881 | 488 |
if (build_errors.isInstanceOf[Exn.Res[_]] && process_result.ok && info.documents.nonEmpty) {
|
| 75786 | 489 |
using(Export.open_database_context(store)) { database_context =>
|
| 75394 | 490 |
val documents = |
| 76656 | 491 |
using(database_context.open_session(deps.background(session_name))) {
|
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
492 |
session_context => |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
493 |
Document_Build.build_documents( |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
494 |
Document_Build.context(session_context, progress = progress), |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
495 |
output_sources = info.document_output, |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
496 |
output_pdf = info.document_output) |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75780
diff
changeset
|
497 |
} |
| 75970 | 498 |
using(database_context.open_database(session_name, output = true))(session_database => |
| 75787 | 499 |
documents.foreach(_.write(session_database.db, session_name))) |
| 75394 | 500 |
(documents.flatMap(_.log_lines), Nil) |
501 |
} |
|
| 72662 | 502 |
} |
| 72881 | 503 |
else (Nil, Nil) |
| 72662 | 504 |
} |
| 72882 | 505 |
catch {
|
| 73718 | 506 |
case exn: Document_Build.Build_Error => (exn.log_lines, List(exn.message)) |
| 72882 | 507 |
case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) |
508 |
} |
|
| 72662 | 509 |
|
| 75393 | 510 |
val result = {
|
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
511 |
val theory_timing = |
| 75438 | 512 |
theory_timings.iterator.flatMap( |
| 75425 | 513 |
{
|
| 75438 | 514 |
case props @ Markup.Name(name) => Some(name -> props) |
515 |
case _ => None |
|
| 75425 | 516 |
}).toMap |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
517 |
val used_theory_timings = |
|
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
518 |
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
|
519 |
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
|
520 |
|
| 72662 | 521 |
val more_output = |
522 |
Library.trim_line(stdout.toString) :: |
|
523 |
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
|
524 |
used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) ::: |
| 72662 | 525 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
526 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
|
527 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) ::: |
|
| 72699 | 528 |
document_output |
| 72662 | 529 |
|
|
72726
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
530 |
process_result.output(more_output) |
|
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
531 |
.error(Library.trim_line(stderr.toString)) |
|
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
532 |
.errors_rc(export_errors ::: document_errors) |
| 72662 | 533 |
} |
534 |
||
535 |
build_errors match {
|
|
536 |
case Exn.Res(build_errs) => |
|
537 |
val errs = build_errs ::: document_errors |
|
|
74259
6d48d6ba58df
more robust: progress.stopped means that build has failed;
wenzelm
parents:
74258
diff
changeset
|
538 |
if (errs.nonEmpty) {
|
| 72662 | 539 |
result.error_rc.output( |
540 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
541 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
542 |
} |
|
| 74306 | 543 |
else if (progress.stopped && result.ok) result.copy(rc = Process_Result.RC.interrupt) |
|
74259
6d48d6ba58df
more robust: progress.stopped means that build has failed;
wenzelm
parents:
74258
diff
changeset
|
544 |
else result |
| 72662 | 545 |
case Exn.Exn(Exn.Interrupt()) => |
| 74306 | 546 |
if (result.ok) result.copy(rc = Process_Result.RC.interrupt) |
|
74259
6d48d6ba58df
more robust: progress.stopped means that build has failed;
wenzelm
parents:
74258
diff
changeset
|
547 |
else result |
| 72662 | 548 |
case Exn.Exn(exn) => throw exn |
549 |
} |
|
550 |
} |
|
551 |
||
| 73367 | 552 |
def terminate(): Unit = future_result.cancel() |
| 72662 | 553 |
def is_finished: Boolean = future_result.is_finished |
554 |
||
| 75393 | 555 |
private val timeout_request: Option[Event_Timer.Request] = {
|
|
73700
908351c8c0b1
check timeout_ignored as in ML, before applying timeout_scale;
wenzelm
parents:
73559
diff
changeset
|
556 |
if (info.timeout_ignored) None |
|
908351c8c0b1
check timeout_ignored as in ML, before applying timeout_scale;
wenzelm
parents:
73559
diff
changeset
|
557 |
else Some(Event_Timer.request(Time.now() + info.timeout) { terminate() })
|
| 72662 | 558 |
} |
559 |
||
| 75393 | 560 |
def join: (Process_Result, Option[String]) = {
|
| 72662 | 561 |
val result1 = future_result.join |
562 |
||
563 |
val was_timeout = |
|
564 |
timeout_request match {
|
|
565 |
case None => false |
|
| 73367 | 566 |
case Some(request) => !request.cancel() |
| 72662 | 567 |
} |
568 |
||
569 |
val result2 = |
|
|
73134
8a8ffe78eee7
clarified return code: re-use SIGALRM for soft timeout;
wenzelm
parents:
73033
diff
changeset
|
570 |
if (result1.ok) result1 |
|
8a8ffe78eee7
clarified return code: re-use SIGALRM for soft timeout;
wenzelm
parents:
73033
diff
changeset
|
571 |
else if (was_timeout) result1.error(Output.error_message_text("Timeout")).timeout_rc
|
|
8a8ffe78eee7
clarified return code: re-use SIGALRM for soft timeout;
wenzelm
parents:
73033
diff
changeset
|
572 |
else if (result1.interrupted) result1.error(Output.error_message_text("Interrupt"))
|
| 72662 | 573 |
else result1 |
574 |
||
575 |
val heap_digest = |
|
576 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
|
577 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
578 |
else None |
|
579 |
||
580 |
(result2, heap_digest) |
|
581 |
} |
|
582 |
} |