author | wenzelm |
Thu, 10 Dec 2020 14:51:56 +0100 | |
changeset 72865 | ebf72a3b8daa |
parent 72864 | 612fbd881492 |
child 72867 | 7b10b40b1273 |
permissions | -rw-r--r-- |
72662 | 1 |
/* Title: Pure/Tools/build_job.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build job running prover process, with rudimentary PIDE session. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import scala.collection.mutable |
|
11 |
||
12 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
13 |
object Build_Job |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
14 |
{ |
72854 | 15 |
/* theory markup/messages from database */ |
16 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
17 |
def read_theory( |
72857 | 18 |
db_context: Sessions.Database_Context, |
19 |
resources: Resources, |
|
20 |
session: String, |
|
21 |
theory: String): Option[Command] = |
|
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(name: String): Export.Entry = |
72854 | 24 |
db_context.get_export(List(session), theory, name) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
25 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
26 |
def read_xml(name: String): XML.Body = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
27 |
db_context.xml_cache.body( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
28 |
YXML.parse_body(Symbol.decode(UTF8.decode_permissive(read(name).uncompressed)))) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
29 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
30 |
(read(Export.DOCUMENT_ID).text, split_lines(read(Export.FILES).text)) match { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
31 |
case (Value.Long(id), thy_file :: blobs_files) => |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
32 |
val thy_path = Path.explode(thy_file) |
72857 | 33 |
val node_name = resources.file_node(thy_path, theory = theory) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
34 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
35 |
val results = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
36 |
Command.Results.make( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
37 |
for { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
38 |
tree @ XML.Elem(markup, _) <- read_xml(Export.MESSAGES) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
39 |
i <- Markup.Serial.unapply(markup.properties) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
40 |
} yield i -> tree) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
41 |
|
72865
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
42 |
val blobs = |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
43 |
blobs_files.map(file => |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
44 |
{ |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
45 |
val path = Path.explode(file) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
46 |
val name = resources.file_node(path) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
47 |
val src_path = File.relative_path(thy_path, path).getOrElse(path) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
48 |
Command.Blob(name, src_path, None) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
49 |
}) |
72864 | 50 |
val blobs_xml = |
51 |
for (i <- (1 to blobs.length).toList) |
|
72865
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
52 |
yield read_xml(Export.MARKUP + i) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
53 |
|
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
54 |
val blobs_info = |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
55 |
Command.Blobs_Info( |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
56 |
for { (Command.Blob(name, src_path, _), xml) <- blobs zip blobs_xml } |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
57 |
yield { |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
58 |
val text = XML.content(xml) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
59 |
val chunk = Symbol.Text_Chunk(text) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
60 |
val digest = SHA1.digest(Symbol.encode(text)) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
61 |
Exn.Res(Command.Blob(name, src_path, Some((digest, chunk)))) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
62 |
}) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
63 |
|
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
64 |
val thy_xml = read_xml(Export.MARKUP) |
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
65 |
val thy_source = XML.content(thy_xml) |
72864 | 66 |
|
67 |
val markups_index = |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
68 |
Command.Markup_Index.markup :: blobs.map(Command.Markup_Index.blob) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
69 |
val markups = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
70 |
Command.Markups.make( |
72864 | 71 |
for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml)) |
72 |
yield index -> Markup_Tree.from_XML(xml)) |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
73 |
|
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
74 |
val command = |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
75 |
Command.unparsed(thy_source, theory = true, id = id, node_name = node_name, |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
76 |
blobs_info = blobs_info, results = results, markups = markups) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
77 |
Some(command) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
78 |
case _ => None |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
79 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
80 |
} |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
81 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
82 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
83 |
/* print messages */ |
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 |
def print_log( |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
86 |
options: Options, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
87 |
session_name: String, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
88 |
theories: List[String] = Nil, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
89 |
progress: Progress = new Progress, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
90 |
margin: Double = Pretty.default_margin, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
91 |
breakgain: Double = Pretty.default_breakgain, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
92 |
metric: Pretty.Metric = Pretty.Default_Metric) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
93 |
{ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
94 |
val store = Sessions.store(options) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
95 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
96 |
val resources = new Resources(Sessions.Structure.empty, Sessions.Structure.empty.bootstrap) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
97 |
val session = new Session(options, resources) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
98 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
99 |
using(store.open_database_context())(db_context => |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
100 |
{ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
101 |
val result = |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
102 |
db_context.input_database(session_name)((db, _) => |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
103 |
{ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
104 |
val theories = store.read_theories(db, session_name) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
105 |
val errors = store.read_errors(db, session_name) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
106 |
store.read_build(db, session_name).map(info => (theories, errors, info.return_code)) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
107 |
}) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
108 |
result match { |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
109 |
case None => error("Missing build database for session " + quote(session_name)) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
110 |
case Some((used_theories, errors, rc)) => |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
111 |
val bad_theories = theories.filterNot(used_theories.toSet) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
112 |
if (bad_theories.nonEmpty) error("Unknown theories " + commas_quote(bad_theories)) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
113 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
114 |
val print_theories = |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
115 |
if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
116 |
for (thy <- print_theories) { |
72863 | 117 |
val thy_heading = "Theory " + quote(thy) + ":" |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
118 |
read_theory(db_context, resources, session_name, thy) match { |
72863 | 119 |
case None => progress.echo(thy_heading + " MISSING") |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
120 |
case Some(command) => |
72859 | 121 |
val snapshot = Document.State.init.command_snippet(command) |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
122 |
val rendering = new Rendering(snapshot, options, session) |
72863 | 123 |
val messages = rendering.text_messages(Text.Range.full) |
124 |
if (messages.nonEmpty) { |
|
125 |
progress.echo(thy_heading) |
|
126 |
for (Text.Info(_, t) <- messages) { |
|
127 |
progress.echo( |
|
128 |
Protocol.message_text(List(t), margin = margin, breakgain = breakgain, |
|
129 |
metric = metric)) |
|
130 |
} |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
131 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
132 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
133 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
134 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
135 |
if (errors.nonEmpty) { |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
136 |
progress.echo("\nErrors:\n" + Output.error_message_text(cat_lines(errors))) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
137 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
138 |
if (rc != 0) progress.echo("\n" + Process_Result.print_return_code(rc)) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
139 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
140 |
}) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
141 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
142 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
143 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
144 |
/* Isabelle tool wrapper */ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
145 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
146 |
val isabelle_tool = Isabelle_Tool("log", "print messages from build database", |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
147 |
Scala_Project.here, args => |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
148 |
{ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
149 |
/* arguments */ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
150 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
151 |
var theories: List[String] = Nil |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
152 |
var margin = Pretty.default_margin |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
153 |
var options = Options.init() |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
154 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
155 |
val getopts = Getopts(""" |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
156 |
Usage: isabelle log [OPTIONS] SESSION |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
157 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
158 |
Options are: |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
159 |
-T NAME restrict to given theories (multiple options) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
160 |
-m MARGIN margin for pretty printing (default: """ + margin + """) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
161 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
162 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
163 |
Print messages from the build database of the given session, without any |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
164 |
checks against current sources: results from a failed build can be |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
165 |
printed as well. |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
166 |
""", |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
167 |
"T:" -> (arg => theories = theories ::: List(arg)), |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
168 |
"m:" -> (arg => margin = Value.Double.parse(arg)), |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
169 |
"o:" -> (arg => options = options + arg)) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
170 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
171 |
val more_args = getopts(args) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
172 |
val session_name = |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
173 |
more_args match { |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
174 |
case List(session_name) => session_name |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
175 |
case _ => getopts.usage() |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
176 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
177 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
178 |
val progress = new Console_Progress() |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
179 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
180 |
print_log(options, session_name, theories = theories, margin = margin, progress = progress) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
181 |
}) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
182 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
183 |
|
72662 | 184 |
class Build_Job(progress: Progress, |
185 |
session_name: String, |
|
186 |
val info: Sessions.Info, |
|
187 |
deps: Sessions.Deps, |
|
188 |
store: Sessions.Store, |
|
189 |
do_store: Boolean, |
|
190 |
verbose: Boolean, |
|
191 |
val numa_node: Option[Int], |
|
192 |
command_timings0: List[Properties.T]) |
|
193 |
{ |
|
194 |
val options: Options = NUMA.policy_options(info.options, numa_node) |
|
195 |
||
196 |
private val sessions_structure = deps.sessions_structure |
|
197 |
||
198 |
private val future_result: Future[Process_Result] = |
|
199 |
Future.thread("build", uninterruptible = true) { |
|
200 |
val parent = info.parent.getOrElse("") |
|
201 |
val base = deps(parent) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
202 |
val result_base = deps(session_name) |
72662 | 203 |
|
204 |
val env = |
|
205 |
Isabelle_System.settings() + |
|
206 |
("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString) |
|
207 |
||
208 |
val is_pure = Sessions.is_pure(session_name) |
|
209 |
||
210 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
|
211 |
||
212 |
val eval_store = |
|
213 |
if (do_store) { |
|
214 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) ::: |
|
215 |
List("ML_Heap.save_child " + |
|
216 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
|
217 |
} |
|
218 |
else Nil |
|
219 |
||
220 |
val resources = new Resources(sessions_structure, base, command_timings = command_timings0) |
|
221 |
val session = |
|
222 |
new Session(options, resources) { |
|
223 |
override val xml_cache: XML.Cache = store.xml_cache |
|
224 |
override val xz_cache: XZ.Cache = store.xz_cache |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
225 |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
226 |
override def build_blobs_info(name: Document.Node.Name): Command.Blobs_Info = |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
227 |
{ |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
228 |
result_base.load_commands.get(name.expand) match { |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
229 |
case Some(spans) => |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
230 |
val syntax = result_base.theory_syntax(name) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
231 |
Command.build_blobs_info(syntax, name, spans) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
232 |
case None => Command.Blobs_Info.none |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
233 |
} |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
234 |
} |
72662 | 235 |
} |
236 |
||
237 |
object Build_Session_Errors |
|
238 |
{ |
|
239 |
private val promise: Promise[List[String]] = Future.promise |
|
240 |
||
241 |
def result: Exn.Result[List[String]] = promise.join_result |
|
242 |
def cancel: Unit = promise.cancel |
|
243 |
def apply(errs: List[String]) |
|
244 |
{ |
|
245 |
try { promise.fulfill(errs) } |
|
246 |
catch { case _: IllegalStateException => } |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
val export_consumer = |
|
72849 | 251 |
Export.consumer(store.open_database(session_name, output = true), store.xz_cache) |
72662 | 252 |
|
253 |
val stdout = new StringBuilder(1000) |
|
254 |
val stderr = new StringBuilder(1000) |
|
255 |
val messages = new mutable.ListBuffer[XML.Elem] |
|
256 |
val command_timings = new mutable.ListBuffer[Properties.T] |
|
257 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
258 |
val session_timings = new mutable.ListBuffer[Properties.T] |
|
259 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
|
260 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
261 |
||
262 |
def fun( |
|
263 |
name: String, |
|
264 |
acc: mutable.ListBuffer[Properties.T], |
|
265 |
unapply: Properties.T => Option[Properties.T]): (String, Session.Protocol_Function) = |
|
266 |
{ |
|
267 |
name -> ((msg: Prover.Protocol_Output) => |
|
268 |
unapply(msg.properties) match { |
|
269 |
case Some(props) => acc += props; true |
|
270 |
case _ => false |
|
271 |
}) |
|
272 |
} |
|
273 |
||
274 |
session.init_protocol_handler(new Session.Protocol_Handler |
|
275 |
{ |
|
276 |
override def exit() { Build_Session_Errors.cancel } |
|
277 |
||
278 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = |
|
279 |
{ |
|
280 |
val (rc, errors) = |
|
281 |
try { |
|
282 |
val (rc, errs) = |
|
283 |
{ |
|
284 |
import XML.Decode._ |
|
285 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
286 |
} |
|
287 |
val errors = |
|
288 |
for (err <- errs) yield { |
|
289 |
val prt = Protocol_Message.expose_no_reports(err) |
|
290 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
291 |
} |
|
292 |
(rc, errors) |
|
293 |
} |
|
294 |
catch { case ERROR(err) => (2, List(err)) } |
|
295 |
||
296 |
session.protocol_command("Prover.stop", rc.toString) |
|
297 |
Build_Session_Errors(errors) |
|
298 |
true |
|
299 |
} |
|
300 |
||
301 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
302 |
msg.properties match { |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
303 |
case Markup.Loading_Theory(Markup.Name(name)) => |
72662 | 304 |
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
|
305 |
false |
72662 | 306 |
case _ => false |
307 |
} |
|
308 |
||
309 |
private def export(msg: Prover.Protocol_Output): Boolean = |
|
310 |
msg.properties match { |
|
311 |
case Protocol.Export(args) => |
|
312 |
export_consumer(session_name, args, msg.bytes) |
|
313 |
true |
|
314 |
case _ => false |
|
315 |
} |
|
316 |
||
317 |
override val functions = |
|
318 |
List( |
|
319 |
Markup.Build_Session_Finished.name -> build_session_finished, |
|
320 |
Markup.Loading_Theory.name -> loading_theory, |
|
321 |
Markup.EXPORT -> export, |
|
322 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
|
323 |
fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply), |
|
324 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
325 |
}) |
|
326 |
||
72711 | 327 |
session.command_timings += Session.Consumer("command_timings") |
328 |
{ |
|
329 |
case Session.Command_Timing(props) => |
|
330 |
for { |
|
331 |
elapsed <- Markup.Elapsed.unapply(props) |
|
332 |
elapsed_time = Time.seconds(elapsed) |
|
333 |
if elapsed_time.is_relevant && elapsed_time >= options.seconds("command_timing_threshold") |
|
334 |
} command_timings += props.filter(Markup.command_timing_property) |
|
335 |
} |
|
336 |
||
72662 | 337 |
session.runtime_statistics += Session.Consumer("ML_statistics") |
338 |
{ |
|
339 |
case Session.Runtime_Statistics(props) => runtime_statistics += props |
|
340 |
} |
|
341 |
||
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
342 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
343 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
344 |
case snapshot => |
72856 | 345 |
val rendering = new Rendering(snapshot, options, session) |
72730 | 346 |
|
72844 | 347 |
def export(name: String, xml: XML.Body, compress: Boolean = true) |
72717 | 348 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
349 |
val theory_name = snapshot.node_name.theory |
72844 | 350 |
val args = |
351 |
Protocol.Export.Args(theory_name = theory_name, name = name, compress = compress) |
|
72783 | 352 |
val bytes = Bytes(Symbol.encode(YXML.string_of_body(xml))) |
72730 | 353 |
if (!bytes.is_empty) export_consumer(session_name, args, bytes) |
72717 | 354 |
} |
72844 | 355 |
def export_text(name: String, text: String, compress: Boolean = true): Unit = |
356 |
export(name, List(XML.Text(text)), compress = compress) |
|
72730 | 357 |
|
72844 | 358 |
for (command <- snapshot.snippet_command) { |
359 |
export_text(Export.DOCUMENT_ID, command.id.toString, compress = false) |
|
360 |
} |
|
361 |
||
362 |
export_text(Export.FILES, |
|
363 |
cat_lines(snapshot.node_files.map(_.symbolic.node)), compress = false) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
364 |
|
72817
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
365 |
for ((xml, i) <- snapshot.xml_markup_blobs().zipWithIndex) { |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
366 |
export(Export.MARKUP + (i + 1), xml) |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
367 |
} |
72723 | 368 |
export(Export.MARKUP, snapshot.xml_markup()) |
72725 | 369 |
export(Export.MESSAGES, snapshot.messages.map(_._1)) |
72730 | 370 |
|
371 |
val citations = Library.distinct(rendering.citations(Text.Range.full).map(_.info)) |
|
372 |
export_text(Export.CITATIONS, cat_lines(citations)) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
373 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
374 |
|
72662 | 375 |
session.all_messages += Session.Consumer[Any]("build_session_output") |
376 |
{ |
|
377 |
case msg: Prover.Output => |
|
378 |
val message = msg.message |
|
379 |
if (msg.is_stdout) { |
|
380 |
stdout ++= Symbol.encode(XML.content(message)) |
|
381 |
} |
|
382 |
else if (msg.is_stderr) { |
|
383 |
stderr ++= Symbol.encode(XML.content(message)) |
|
384 |
} |
|
385 |
else if (Protocol.is_exported(message)) { |
|
386 |
messages += message |
|
387 |
} |
|
388 |
else if (msg.is_exit) { |
|
389 |
val err = |
|
390 |
"Prover terminated" + |
|
391 |
(msg.properties match { |
|
392 |
case Markup.Process_Result(result) => ": " + result.print_rc |
|
393 |
case _ => "" |
|
394 |
}) |
|
395 |
Build_Session_Errors(List(err)) |
|
396 |
} |
|
397 |
case _ => |
|
398 |
} |
|
399 |
||
400 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store) |
|
401 |
||
402 |
val process = |
|
403 |
Isabelle_Process(session, options, sessions_structure, store, |
|
404 |
logic = parent, raw_ml_system = is_pure, |
|
405 |
use_prelude = use_prelude, eval_main = eval_main, |
|
406 |
cwd = info.dir.file, env = env) |
|
407 |
||
408 |
val build_errors = |
|
409 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
|
410 |
Exn.capture { process.await_startup } match { |
|
411 |
case Exn.Res(_) => |
|
412 |
val resources_yxml = resources.init_session_yxml |
|
413 |
val args_yxml = |
|
414 |
YXML.string_of_body( |
|
415 |
{ |
|
416 |
import XML.Encode._ |
|
417 |
pair(string, list(pair(Options.encode, list(pair(string, properties)))))( |
|
418 |
(session_name, info.theories)) |
|
419 |
}) |
|
420 |
session.protocol_command("build_session", resources_yxml, args_yxml) |
|
421 |
Build_Session_Errors.result |
|
422 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
|
423 |
} |
|
424 |
} |
|
425 |
||
426 |
val process_result = |
|
427 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { process.await_shutdown } |
|
428 |
||
72697 | 429 |
session.stop() |
430 |
||
72662 | 431 |
val export_errors = |
432 |
export_consumer.shutdown(close = true).map(Output.error_message_text) |
|
433 |
||
72699 | 434 |
val (document_output, document_errors) = |
72662 | 435 |
try { |
72675 | 436 |
if (build_errors.isInstanceOf[Exn.Res[_]] && process_result.ok && info.documents.nonEmpty) |
437 |
{ |
|
72854 | 438 |
using(store.open_database_context())(db_context => |
72715
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
439 |
{ |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
440 |
val documents = |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
441 |
Presentation.build_documents(session_name, deps, db_context, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
442 |
output_sources = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
443 |
output_pdf = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
444 |
progress = progress, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
445 |
verbose = verbose) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
446 |
db_context.output_database(session_name)(db => |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
447 |
documents.foreach(_.write(db, session_name))) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
448 |
(documents.flatMap(_.log_lines), Nil) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
449 |
}) |
72662 | 450 |
} |
72699 | 451 |
(Nil, Nil) |
72662 | 452 |
} |
72699 | 453 |
catch { case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) } |
72662 | 454 |
|
455 |
val result = |
|
456 |
{ |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
457 |
val theory_timing = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
458 |
theory_timings.iterator.map( |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
459 |
{ case props @ Markup.Name(name) => name -> props }).toMap |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
460 |
val used_theory_timings = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
461 |
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
|
462 |
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
|
463 |
|
72662 | 464 |
val more_output = |
465 |
Library.trim_line(stdout.toString) :: |
|
466 |
messages.toList.map(message => |
|
467 |
Symbol.encode(Protocol.message_text(List(message), metric = Symbol.Metric))) ::: |
|
468 |
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
|
469 |
used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) ::: |
72662 | 470 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
471 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
|
472 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) ::: |
|
72699 | 473 |
document_output |
72662 | 474 |
|
72726
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
475 |
process_result.output(more_output) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
476 |
.error(Library.trim_line(stderr.toString)) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
477 |
.errors_rc(export_errors ::: document_errors) |
72662 | 478 |
} |
479 |
||
480 |
build_errors match { |
|
481 |
case Exn.Res(build_errs) => |
|
482 |
val errs = build_errs ::: document_errors |
|
483 |
if (errs.isEmpty) result |
|
484 |
else { |
|
485 |
result.error_rc.output( |
|
486 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
487 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
488 |
} |
|
489 |
case Exn.Exn(Exn.Interrupt()) => |
|
490 |
if (result.ok) result.copy(rc = Exn.Interrupt.return_code) else result |
|
491 |
case Exn.Exn(exn) => throw exn |
|
492 |
} |
|
493 |
} |
|
494 |
||
495 |
def terminate: Unit = future_result.cancel |
|
496 |
def is_finished: Boolean = future_result.is_finished |
|
497 |
||
498 |
private val timeout_request: Option[Event_Timer.Request] = |
|
499 |
{ |
|
500 |
if (info.timeout > Time.zero) |
|
501 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate }) |
|
502 |
else None |
|
503 |
} |
|
504 |
||
505 |
def join: (Process_Result, Option[String]) = |
|
506 |
{ |
|
507 |
val result1 = future_result.join |
|
508 |
||
509 |
val was_timeout = |
|
510 |
timeout_request match { |
|
511 |
case None => false |
|
512 |
case Some(request) => !request.cancel |
|
513 |
} |
|
514 |
||
515 |
val result2 = |
|
516 |
if (result1.interrupted) { |
|
517 |
if (was_timeout) result1.error(Output.error_message_text("Timeout")).was_timeout |
|
518 |
else result1.error(Output.error_message_text("Interrupt")) |
|
519 |
} |
|
520 |
else result1 |
|
521 |
||
522 |
val heap_digest = |
|
523 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
|
524 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
525 |
else None |
|
526 |
||
527 |
(result2, heap_digest) |
|
528 |
} |
|
529 |
} |