author | wenzelm |
Wed, 04 Sep 2019 22:12:44 +0200 | |
changeset 70655 | f51955effb02 |
parent 70653 | f7c5b30fc432 |
child 70659 | 44588e355ca8 |
permissions | -rw-r--r-- |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Tools/dump.scala |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
3 |
|
68348 | 4 |
Dump cumulative PIDE session database. |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
6 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
8 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
9 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
10 |
object Dump |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
11 |
{ |
68316 | 12 |
/* aspects */ |
13 |
||
14 |
sealed case class Aspect_Args( |
|
68355 | 15 |
options: Options, |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
16 |
deps: Sessions.Deps, |
68355 | 17 |
progress: Progress, |
69896 | 18 |
output_dir: Path, |
68929 | 19 |
snapshot: Document.Snapshot, |
69534 | 20 |
status: Document_Status.Node_Status) |
68319 | 21 |
{ |
68365 | 22 |
def write(file_name: Path, bytes: Bytes) |
68319 | 23 |
{ |
68929 | 24 |
val path = output_dir + Path.basic(snapshot.node_name.theory) + file_name |
68319 | 25 |
Isabelle_System.mkdirs(path.dir) |
26 |
Bytes.write(path, bytes) |
|
27 |
} |
|
28 |
||
68365 | 29 |
def write(file_name: Path, text: String): Unit = |
30 |
write(file_name, Bytes(text)) |
|
68332 | 31 |
|
68365 | 32 |
def write(file_name: Path, body: XML.Body): Unit = |
33 |
write(file_name, Symbol.encode(YXML.string_of_body(body))) |
|
68319 | 34 |
} |
68316 | 35 |
|
68347 | 36 |
sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit, |
37 |
options: List[String] = Nil) |
|
68345 | 38 |
{ |
39 |
override def toString: String = name |
|
40 |
} |
|
68316 | 41 |
|
69521 | 42 |
val known_aspects: List[Aspect] = |
68316 | 43 |
List( |
68365 | 44 |
Aspect("markup", "PIDE markup (YXML format)", |
45 |
{ case args => |
|
46 |
args.write(Path.explode("markup.yxml"), |
|
47 |
args.snapshot.markup_to_XML(Text.Range.full, Markup.Elements.full)) |
|
48 |
}), |
|
68319 | 49 |
Aspect("messages", "output messages (YXML format)", |
50 |
{ case args => |
|
68365 | 51 |
args.write(Path.explode("messages.yxml"), |
52 |
args.snapshot.messages.iterator.map(_._1).toList) |
|
68347 | 53 |
}), |
54 |
Aspect("latex", "generated LaTeX source", |
|
55 |
{ case args => |
|
68365 | 56 |
for (entry <- args.snapshot.exports if entry.name == "document.tex") |
57 |
args.write(Path.explode(entry.name), entry.uncompressed()) |
|
69533
1d2e6a4e073f
clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
wenzelm
parents:
69532
diff
changeset
|
58 |
}, options = List("export_document")), |
68347 | 59 |
Aspect("theory", "foundational theory content", |
60 |
{ case args => |
|
61 |
for { |
|
68365 | 62 |
entry <- args.snapshot.exports |
68347 | 63 |
if entry.name.startsWith(Export_Theory.export_prefix) |
68365 | 64 |
} args.write(Path.explode(entry.name), entry.uncompressed()) |
69533
1d2e6a4e073f
clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
wenzelm
parents:
69532
diff
changeset
|
65 |
}, options = List("export_theory")) |
68345 | 66 |
).sortBy(_.name) |
68316 | 67 |
|
68 |
def show_aspects: String = |
|
68345 | 69 |
cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description)) |
68316 | 70 |
|
71 |
def the_aspect(name: String): Aspect = |
|
72 |
known_aspects.find(aspect => aspect.name == name) getOrElse |
|
73 |
error("Unknown aspect " + quote(name)) |
|
74 |
||
75 |
||
69538
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents:
69537
diff
changeset
|
76 |
/* session */ |
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents:
69537
diff
changeset
|
77 |
|
69896 | 78 |
sealed case class Args( |
69897 | 79 |
session: Headless.Session, |
80 |
snapshot: Document.Snapshot, |
|
81 |
status: Document_Status.Node_Status) |
|
69896 | 82 |
{ |
83 |
def print_node: String = snapshot.node_name.toString |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
84 |
} |
69896 | 85 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
86 |
object Session |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
87 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
88 |
def apply( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
89 |
options: Options, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
90 |
logic: String, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
91 |
aspects: List[Aspect] = Nil, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
92 |
progress: Progress = No_Progress, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
93 |
log: Logger = No_Logger, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
94 |
dirs: List[Path] = Nil, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
95 |
select_dirs: List[Path] = Nil, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
96 |
selection: Sessions.Selection = Sessions.Selection.empty): Session = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
97 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
98 |
new Session(options, logic, aspects, progress, log, dirs, select_dirs, selection) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
99 |
} |
69896 | 100 |
} |
101 |
||
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
102 |
class Session private( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
103 |
options: Options, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
104 |
logic: String, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
105 |
aspects: List[Aspect], |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
106 |
progress: Progress, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
107 |
log: Logger, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
108 |
dirs: List[Path], |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
109 |
select_dirs: List[Path], |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
110 |
selection: Sessions.Selection) |
69538
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents:
69537
diff
changeset
|
111 |
{ |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
112 |
/* context */ |
69897 | 113 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
114 |
Build.build_logic(options, logic, build_heap = true, progress = progress, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
115 |
dirs = dirs ::: select_dirs, strict = true) |
68926 | 116 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
117 |
val dump_options: Options = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
118 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
119 |
val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
120 |
val options1 = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
121 |
options0 + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
122 |
"completion_limit=0" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
123 |
"ML_statistics=false" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
124 |
"parallel_proofs=0" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
125 |
"editor_tracing_messages=0" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
126 |
"editor_presentation" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
127 |
"execution_eager" |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
128 |
(options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) }) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
129 |
} |
68926 | 130 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
131 |
val deps: Sessions.Deps = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
132 |
Sessions.load_structure(dump_options, dirs = dirs, select_dirs = select_dirs). |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
133 |
selection_deps(dump_options, selection, progress = progress, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
134 |
uniform_session = true, loading_sessions = true) |
68926 | 135 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
136 |
val resources: Headless.Resources = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
137 |
Headless.Resources.make(dump_options, logic, progress = progress, log = log, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
138 |
session_dirs = dirs ::: select_dirs, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
139 |
include_sessions = deps.sessions_structure.imports_topological_order) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
140 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
141 |
val used_theories: List[Document.Node.Name] = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
142 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
143 |
for { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
144 |
name <- deps.used_theories_condition(dump_options, progress = progress).topological_order |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
145 |
if !resources.session_base.loaded_theory(name.theory) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
146 |
} yield name |
68926 | 147 |
} |
148 |
||
149 |
||
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
150 |
/* run */ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
151 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
152 |
def run(process_theory: Args => Unit, unicode_symbols: Boolean = false) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
153 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
154 |
val session = resources.start_session(progress = progress) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
155 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
156 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
157 |
// asynchronous consumer |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
158 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
159 |
object Consumer |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
160 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
161 |
sealed case class Bad_Theory( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
162 |
name: Document.Node.Name, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
163 |
status: Document_Status.Node_Status, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
164 |
errors: List[String]) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
165 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
166 |
private val consumer_bad_theories = Synchronized(List.empty[Bad_Theory]) |
68318 | 167 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
168 |
private val consumer = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
169 |
Consumer_Thread.fork(name = "dump")( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
170 |
consume = (args: (Document.Snapshot, Document_Status.Node_Status)) => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
171 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
172 |
val (snapshot, status) = args |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
173 |
val name = snapshot.node_name |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
174 |
if (status.ok) { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
175 |
try { process_theory(Args(session, snapshot, status)) } |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
176 |
catch { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
177 |
case exn: Throwable if !Exn.is_interrupt(exn) => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
178 |
val msg = Exn.message(exn) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
179 |
progress.echo("FAILED to process theory " + name) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
180 |
progress.echo_error_message(msg) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
181 |
consumer_bad_theories.change(Bad_Theory(name, status, List(msg)) :: _) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
182 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
183 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
184 |
else { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
185 |
val msgs = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
186 |
for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree)) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
187 |
yield { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
188 |
"Error" + Position.here(pos) + ":\n" + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
189 |
XML.content(Pretty.formatted(List(tree))) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
190 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
191 |
progress.echo("FAILED to process theory " + name) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
192 |
msgs.foreach(progress.echo_error_message) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
193 |
consumer_bad_theories.change(Bad_Theory(name, status, msgs) :: _) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
194 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
195 |
true |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
196 |
}) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
197 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
198 |
def apply(snapshot: Document.Snapshot, status: Document_Status.Node_Status): Unit = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
199 |
consumer.send((snapshot, status)) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
200 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
201 |
def shutdown(): List[Bad_Theory] = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
202 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
203 |
consumer.shutdown() |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
204 |
consumer_bad_theories.value.reverse |
70634
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
70626
diff
changeset
|
205 |
} |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
70626
diff
changeset
|
206 |
} |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
70626
diff
changeset
|
207 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
208 |
|
70653
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
wenzelm
parents:
70645
diff
changeset
|
209 |
// synchronous body |
68320
1d33697199c1
shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents:
68319
diff
changeset
|
210 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
211 |
try { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
212 |
val use_theories_result = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
213 |
session.use_theories(used_theories.map(_.theory), |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
214 |
unicode_symbols = unicode_symbols, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
215 |
progress = progress, |
70653
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
wenzelm
parents:
70645
diff
changeset
|
216 |
checkpoints = deps.dump_checkpoints, |
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
wenzelm
parents:
70645
diff
changeset
|
217 |
commit = Some(Consumer.apply _)) |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
218 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
219 |
val bad_theories = Consumer.shutdown() |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
220 |
val bad_msgs = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
221 |
bad_theories.map(bad => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
222 |
Output.clean_yxml( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
223 |
"FAILED theory " + bad.name + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
224 |
(if (bad.status.consolidated) "" else ": " + bad.status.percentage + "% finished") + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
225 |
(if (bad.errors.isEmpty) "" else bad.errors.mkString("\n", "\n", "")))) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
226 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
227 |
val pending_msgs = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
228 |
use_theories_result.nodes_pending match { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
229 |
case Nil => Nil |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
230 |
case pending => List("Pending theories: " + commas(pending.map(p => p._1.toString))) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
231 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
232 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
233 |
val errors = bad_msgs ::: pending_msgs |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
234 |
if (errors.nonEmpty) error(errors.mkString("\n\n")) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
235 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
236 |
finally { session.stop() } |
69032
90bb4cabe1e8
clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents:
69026
diff
changeset
|
237 |
} |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
238 |
} |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
239 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
240 |
|
69523 | 241 |
/* dump */ |
242 |
||
243 |
val default_output_dir: Path = Path.explode("dump") |
|
244 |
||
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
245 |
def dump( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
246 |
options: Options, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
247 |
logic: String, |
69523 | 248 |
aspects: List[Aspect] = Nil, |
249 |
progress: Progress = No_Progress, |
|
250 |
log: Logger = No_Logger, |
|
251 |
dirs: List[Path] = Nil, |
|
252 |
select_dirs: List[Path] = Nil, |
|
253 |
output_dir: Path = default_output_dir, |
|
69535 | 254 |
selection: Sessions.Selection = Sessions.Selection.empty) |
69523 | 255 |
{ |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
256 |
val session = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
257 |
Session(options, logic, aspects = aspects, progress = progress, log = log, |
69856 | 258 |
dirs = dirs, select_dirs = select_dirs, selection = selection) |
69523 | 259 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
260 |
session.run((args: Args) => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
261 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
262 |
progress.echo("Processing theory " + args.print_node + " ...") |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
263 |
val aspect_args = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
264 |
Aspect_Args(session.dump_options, session.deps, progress, output_dir, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
265 |
args.snapshot, args.status) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
266 |
aspects.foreach(_.operation(aspect_args)) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
267 |
}) |
69523 | 268 |
} |
269 |
||
270 |
||
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
271 |
/* Isabelle tool wrapper */ |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
272 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
273 |
val isabelle_tool = |
68348 | 274 |
Isabelle_Tool("dump", "dump cumulative PIDE session database", args => |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
275 |
{ |
68345 | 276 |
var aspects: List[Aspect] = known_aspects |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
277 |
var base_sessions: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
278 |
var select_dirs: List[Path] = Nil |
68316 | 279 |
var output_dir = default_output_dir |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
280 |
var requirements = false |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
281 |
var exclude_session_groups: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
282 |
var all_sessions = false |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
283 |
var dirs: List[Path] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
284 |
var session_groups: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
285 |
var logic = Isabelle_System.getenv("ISABELLE_LOGIC") |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
286 |
var options = Options.init() |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
287 |
var verbose = false |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
288 |
var exclude_sessions: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
289 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
290 |
val getopts = Getopts(""" |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
291 |
Usage: isabelle dump [OPTIONS] [SESSIONS ...] |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
292 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
293 |
Options are: |
68345 | 294 |
-A NAMES dump named aspects (default: """ + known_aspects.mkString("\"", ",", "\"") + """) |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
295 |
-B NAME include session NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
296 |
-D DIR include session directory and select its sessions |
68316 | 297 |
-O DIR output directory for dumped files (default: """ + default_output_dir + """) |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
298 |
-R operate on requirements of selected sessions |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
299 |
-X NAME exclude sessions from group NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
300 |
-a select all sessions |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
301 |
-d DIR include session directory |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
302 |
-g NAME select session group NAME |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
303 |
-l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
304 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
305 |
-v verbose |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
306 |
-x NAME exclude session NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
307 |
|
68348 | 308 |
Dump cumulative PIDE session database, with the following aspects: |
68316 | 309 |
|
310 |
""" + Library.prefix_lines(" ", show_aspects) + "\n", |
|
311 |
"A:" -> (arg => aspects = Library.distinct(space_explode(',', arg)).map(the_aspect(_))), |
|
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
312 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
313 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
68316 | 314 |
"O:" -> (arg => output_dir = Path.explode(arg)), |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
315 |
"R" -> (_ => requirements = true), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
316 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
317 |
"a" -> (_ => all_sessions = true), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
318 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
68741 | 319 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
320 |
"l:" -> (arg => logic = arg), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
321 |
"o:" -> (arg => options = options + arg), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
322 |
"v" -> (_ => verbose = true), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
323 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
324 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
325 |
val sessions = getopts(args) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
326 |
|
68951
a7b1fe2d30ad
more uniform Progress, with theory() for batch-build and theory_percentage() for PIDE session;
wenzelm
parents:
68948
diff
changeset
|
327 |
val progress = new Console_Progress(verbose = verbose) |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
328 |
|
69535 | 329 |
progress.interrupt_handler { |
330 |
dump(options, logic, |
|
331 |
aspects = aspects, |
|
332 |
progress = progress, |
|
333 |
dirs = dirs, |
|
334 |
select_dirs = select_dirs, |
|
335 |
output_dir = output_dir, |
|
336 |
selection = Sessions.Selection( |
|
337 |
requirements = requirements, |
|
338 |
all_sessions = all_sessions, |
|
339 |
base_sessions = base_sessions, |
|
340 |
exclude_session_groups = exclude_session_groups, |
|
341 |
exclude_sessions = exclude_sessions, |
|
342 |
session_groups = session_groups, |
|
343 |
sessions = sessions)) |
|
344 |
} |
|
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
345 |
}) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
346 |
} |