| author | wenzelm |
| Wed, 28 Jun 2023 16:01:34 +0200 | |
| changeset 78229 | 524ba83940c2 |
| parent 78153 | 55a6aa77f3d8 |
| child 78260 | 0a7f7abbe4f0 |
| permissions | -rw-r--r-- |
| 73718 | 1 |
/* Title: Pure/Thy/document_build.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build theory document (PDF) from session database. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 75393 | 10 |
object Document_Build {
|
| 73718 | 11 |
/* document variants */ |
12 |
||
| 75393 | 13 |
abstract class Document_Name {
|
| 73718 | 14 |
def name: String |
15 |
def path: Path = Path.basic(name) |
|
16 |
||
17 |
override def toString: String = name |
|
18 |
} |
|
19 |
||
| 75393 | 20 |
object Document_Variant {
|
| 73718 | 21 |
def parse(opt: String): Document_Variant = |
| 77218 | 22 |
space_explode('=', opt) match {
|
| 74839 | 23 |
case List(name) => Document_Variant(name, Latex.Tags.empty) |
24 |
case List(name, tags) => Document_Variant(name, Latex.Tags(tags)) |
|
| 73718 | 25 |
case _ => error("Malformed document variant: " + quote(opt))
|
26 |
} |
|
27 |
} |
|
28 |
||
| 75393 | 29 |
sealed case class Document_Variant(name: String, tags: Latex.Tags) extends Document_Name {
|
| 74839 | 30 |
def print: String = if (tags.toString.isEmpty) name else name + "=" + tags.toString |
| 73718 | 31 |
} |
32 |
||
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
33 |
sealed case class Document_Input(name: String, sources: SHA1.Shasum) |
| 75822 | 34 |
extends Document_Name { override def toString: String = name }
|
| 73718 | 35 |
|
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
36 |
sealed case class Document_Output(name: String, sources: SHA1.Shasum, log_xz: Bytes, pdf: Bytes) |
| 75393 | 37 |
extends Document_Name {
|
| 75822 | 38 |
override def toString: String = name |
39 |
||
| 73718 | 40 |
def log: String = log_xz.uncompress().text |
41 |
def log_lines: List[String] = split_lines(log) |
|
42 |
||
43 |
def write(db: SQL.Database, session_name: String): Unit = |
|
44 |
write_document(db, session_name, this) |
|
| 73719 | 45 |
|
| 75393 | 46 |
def write(dir: Path): Path = {
|
| 73719 | 47 |
val path = dir + Path.basic(name).pdf |
48 |
Isabelle_System.make_directory(path.expand.dir) |
|
49 |
Bytes.write(path, pdf) |
|
50 |
path |
|
51 |
} |
|
| 73718 | 52 |
} |
53 |
||
54 |
||
55 |
/* SQL data model */ |
|
56 |
||
| 75393 | 57 |
object Data {
|
| 73718 | 58 |
val session_name = SQL.Column.string("session_name").make_primary_key
|
59 |
val name = SQL.Column.string("name").make_primary_key
|
|
60 |
val sources = SQL.Column.string("sources")
|
|
61 |
val log_xz = SQL.Column.bytes("log_xz")
|
|
62 |
val pdf = SQL.Column.bytes("pdf")
|
|
63 |
||
64 |
val table = SQL.Table("isabelle_documents", List(session_name, name, sources, log_xz, pdf))
|
|
65 |
||
66 |
def where_equal(session_name: String, name: String = ""): SQL.Source = |
|
| 78153 | 67 |
SQL.where_and( |
68 |
Data.session_name.equal(session_name), |
|
69 |
if_proper(name, Data.name.equal(name))) |
|
| 73718 | 70 |
} |
71 |
||
|
77381
a86e346b20d8
misc tuning and clarification: more uniform use of optional "sql" in SQL.Table.delete/select;
wenzelm
parents:
77370
diff
changeset
|
72 |
def read_documents(db: SQL.Database, session_name: String): List[Document_Input] = |
| 77552 | 73 |
db.execute_query_statement( |
74 |
Data.table.select(List(Data.name, Data.sources), sql = Data.where_equal(session_name)), |
|
75 |
List.from[Document_Input], |
|
76 |
{ res =>
|
|
77 |
val name = res.string(Data.name) |
|
78 |
val sources = res.string(Data.sources) |
|
79 |
Document_Input(name, SHA1.fake_shasum(sources)) |
|
|
77381
a86e346b20d8
misc tuning and clarification: more uniform use of optional "sql" in SQL.Table.delete/select;
wenzelm
parents:
77370
diff
changeset
|
80 |
} |
| 77552 | 81 |
) |
| 73718 | 82 |
|
| 75393 | 83 |
def read_document( |
84 |
db: SQL.Database, |
|
85 |
session_name: String, |
|
86 |
name: String |
|
87 |
): Option[Document_Output] = {
|
|
| 77552 | 88 |
db.execute_query_statementO[Document_Output]( |
89 |
Data.table.select(sql = Data.where_equal(session_name, name)), |
|
90 |
{ res =>
|
|
| 73718 | 91 |
val name = res.string(Data.name) |
92 |
val sources = res.string(Data.sources) |
|
93 |
val log_xz = res.bytes(Data.log_xz) |
|
94 |
val pdf = res.bytes(Data.pdf) |
|
| 77544 | 95 |
Document_Output(name, SHA1.fake_shasum(sources), log_xz, pdf) |
| 77552 | 96 |
} |
97 |
) |
|
| 73718 | 98 |
} |
99 |
||
| 77543 | 100 |
def write_document(db: SQL.Database, session_name: String, doc: Document_Output): Unit = |
| 77541 | 101 |
db.execute_statement(Data.table.insert(), body = |
102 |
{ stmt =>
|
|
103 |
stmt.string(1) = session_name |
|
104 |
stmt.string(2) = doc.name |
|
105 |
stmt.string(3) = doc.sources.toString |
|
106 |
stmt.bytes(4) = doc.log_xz |
|
107 |
stmt.bytes(5) = doc.pdf |
|
108 |
}) |
|
| 73718 | 109 |
|
110 |
||
| 76677 | 111 |
/* background context */ |
112 |
||
113 |
def session_background( |
|
114 |
options: Options, |
|
115 |
session: String, |
|
|
77520
84aa349ed597
removed unused arguments: avoid ambiguity concerning progress/verbose;
wenzelm
parents:
77517
diff
changeset
|
116 |
dirs: List[Path] = Nil |
| 76677 | 117 |
): Sessions.Background = {
|
| 76741 | 118 |
Sessions.load_structure(options + "document", dirs = dirs). |
|
77520
84aa349ed597
removed unused arguments: avoid ambiguity concerning progress/verbose;
wenzelm
parents:
77517
diff
changeset
|
119 |
selection_deps(Sessions.Selection.session(session)).background(session) |
| 76677 | 120 |
} |
121 |
||
122 |
||
123 |
/* document context */ |
|
| 73719 | 124 |
|
|
74840
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
125 |
val texinputs: Path = Path.explode("~~/lib/texinputs")
|
|
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
126 |
|
| 73724 | 127 |
val isabelle_styles: List[Path] = |
|
74840
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
128 |
List("isabelle.sty", "isabellesym.sty", "pdfsetup.sty", "railsetup.sty").
|
|
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
129 |
map(name => texinputs + Path.basic(name)) |
| 73724 | 130 |
|
|
77173
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77025
diff
changeset
|
131 |
def program_start(title: String): String = |
|
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77025
diff
changeset
|
132 |
"PROGRAM START \"" + title + "\" ..." |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76884
diff
changeset
|
133 |
|
| 77174 | 134 |
def program_running_script(title: String): String = |
135 |
"echo " + Bash.string(program_start("Running " + title)) + ";"
|
|
|
77173
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77025
diff
changeset
|
136 |
|
|
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77025
diff
changeset
|
137 |
def detect_program_start(s: String): Option[String] = |
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76884
diff
changeset
|
138 |
for {
|
|
77173
f1063cdb0093
clarified terminology of inlined "PROGRAM START" messages;
wenzelm
parents:
77025
diff
changeset
|
139 |
s1 <- Library.try_unprefix("PROGRAM START \"", s)
|
|
76994
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76884
diff
changeset
|
140 |
s2 <- Library.try_unsuffix("\" ...", s1)
|
|
7c23db6b857b
more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents:
76884
diff
changeset
|
141 |
} yield s2 |
| 76769 | 142 |
|
| 77005 | 143 |
sealed case class Document_Latex( |
144 |
name: Document.Node.Name, |
|
145 |
body: XML.Body, |
|
146 |
line_pos: Properties.T => Option[Int] |
|
147 |
) {
|
|
| 76757 | 148 |
def content: File.Content_XML = File.content(Path.basic(tex_name(name)), body) |
| 76884 | 149 |
def file_pos: String = File.symbolic_path(name.path) |
| 76757 | 150 |
def write(latex_output: Latex.Output, dir: Path): Unit = |
| 77005 | 151 |
content.output(latex_output.make(_, file_pos = file_pos, line_pos = line_pos)) |
152 |
.write(dir) |
|
| 76757 | 153 |
} |
154 |
||
| 73719 | 155 |
def context( |
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
156 |
session_context: Export.Session_Context, |
|
75821
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
157 |
document_session: Option[Sessions.Base] = None, |
|
77197
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77186
diff
changeset
|
158 |
document_selection: String => Boolean = _ => true, |
| 75393 | 159 |
progress: Progress = new Progress |
| 76732 | 160 |
): Context = new Context(session_context, document_session, document_selection, progress) |
| 73719 | 161 |
|
162 |
final class Context private[Document_Build]( |
|
| 76370 | 163 |
val session_context: Export.Session_Context, |
|
75821
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
164 |
document_session: Option[Sessions.Base], |
|
77197
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77186
diff
changeset
|
165 |
document_selection: String => Boolean, |
| 76731 | 166 |
val progress: Progress |
| 75393 | 167 |
) {
|
| 75826 | 168 |
context => |
169 |
||
170 |
||
| 73719 | 171 |
/* session info */ |
172 |
||
|
75821
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
173 |
private val base = document_session getOrElse session_context.session_base |
|
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
174 |
private val info = session_context.sessions_structure(base.session_name) |
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
175 |
|
|
75821
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
176 |
def session: String = info.name |
|
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
177 |
def options: Options = info.options |
|
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
178 |
|
|
affd69bad2d4
clarified signature: support different document_session, e.g. within running PIDE session;
wenzelm
parents:
75782
diff
changeset
|
179 |
override def toString: String = session |
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
180 |
|
| 75825 | 181 |
val classpath: List[File.Content] = session_context.classpath() |
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
182 |
|
| 73743 | 183 |
def document_bibliography: Boolean = options.bool("document_bibliography")
|
184 |
||
| 73723 | 185 |
def document_logo: Option[String] = |
186 |
options.string("document_logo") match {
|
|
187 |
case "" => None |
|
188 |
case "_" => Some("")
|
|
189 |
case name => Some(name) |
|
190 |
} |
|
191 |
||
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
192 |
def document_build: String = options.string("document_build")
|
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
193 |
|
| 75393 | 194 |
def get_engine(): Engine = {
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
195 |
val name = document_build |
| 75702 | 196 |
Classpath(jar_contents = classpath).make_services(classOf[Engine]) |
| 75697 | 197 |
.find(_.name == name).getOrElse(error("Bad document_build engine " + quote(name)))
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
198 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
199 |
|
| 73719 | 200 |
|
201 |
/* document content */ |
|
202 |
||
203 |
def documents: List[Document_Variant] = info.documents |
|
204 |
||
| 76628 | 205 |
def session_document_theories: List[Document.Node.Name] = base.proper_session_theories |
206 |
def all_document_theories: List[Document.Node.Name] = base.all_document_theories |
|
| 73719 | 207 |
|
| 76758 | 208 |
lazy val isabelle_logo: Option[File.Content] = {
|
209 |
document_logo.map(logo_name => |
|
210 |
Isabelle_System.with_tmp_file("logo", ext = "pdf") { tmp_path =>
|
|
211 |
Logo.create_logo(logo_name, output_file = tmp_path, quiet = true) |
|
212 |
val path = Path.basic("isabelle_logo.pdf")
|
|
213 |
val content = Bytes.read(tmp_path) |
|
214 |
File.content(path, content) |
|
215 |
}) |
|
216 |
} |
|
| 73719 | 217 |
|
| 75393 | 218 |
lazy val session_graph: File.Content = {
|
| 75941 | 219 |
val path = Browser_Info.session_graph_path |
| 73778 | 220 |
val content = graphview.Graph_File.make_pdf(options, base.session_graph_display) |
| 75824 | 221 |
File.content(path, content) |
| 73719 | 222 |
} |
223 |
||
| 75393 | 224 |
lazy val session_tex: File.Content = {
|
| 73719 | 225 |
val path = Path.basic("session.tex")
|
| 73778 | 226 |
val content = |
| 77216 | 227 |
terminate_lines( |
| 76628 | 228 |
session_document_theories.map(name => "\\input{" + tex_name(name) + "}"))
|
| 75824 | 229 |
File.content(path, content) |
| 73719 | 230 |
} |
231 |
||
| 76758 | 232 |
lazy val document_latex: List[Document_Latex] = |
233 |
for (name <- all_document_theories) |
|
234 |
yield {
|
|
|
77197
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77186
diff
changeset
|
235 |
val selected = document_selection(name.theory) |
| 77018 | 236 |
|
| 76758 | 237 |
val body = |
| 77018 | 238 |
if (selected) {
|
| 76758 | 239 |
val entry = session_context(name.theory, Export.DOCUMENT_LATEX, permissive = true) |
240 |
YXML.parse_body(entry.text) |
|
241 |
} |
|
|
77025
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
242 |
else {
|
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
243 |
val text = |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
244 |
proper_string(session_context.theory_source(name.theory)) getOrElse |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
245 |
File.read(name.path) |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
246 |
(for {
|
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
247 |
outer <- Bibtex.Cite.parse(Bibtex.cite_commands(options), text) |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
248 |
inner <- outer.parse |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
249 |
} yield inner.nocite.latex_text).flatten |
|
34219d664854
proper citations for unselected theories, notably for the default selection of the GUI panel;
wenzelm
parents:
77018
diff
changeset
|
250 |
} |
| 77005 | 251 |
|
252 |
def line_pos(props: Properties.T): Option[Int] = |
|
253 |
Position.Line.unapply(props) orElse {
|
|
| 77018 | 254 |
if (selected) {
|
255 |
for {
|
|
256 |
snapshot <- session_context.document_snapshot |
|
257 |
id <- Position.Id.unapply(props) |
|
258 |
offset <- Position.Offset.unapply(props) |
|
259 |
line <- snapshot.find_command_line(id, offset) |
|
260 |
} yield line |
|
261 |
} |
|
262 |
else None |
|
| 77005 | 263 |
} |
264 |
||
265 |
Document_Latex(name, body, line_pos) |
|
| 76758 | 266 |
} |
| 73723 | 267 |
|
| 73719 | 268 |
|
269 |
/* document directory */ |
|
270 |
||
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
271 |
def make_directory(dir: Path, doc: Document_Variant): Path = |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
272 |
Isabelle_System.make_directory(dir + Path.basic(doc.name)) |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
273 |
|
| 75393 | 274 |
def prepare_directory( |
275 |
dir: Path, |
|
276 |
doc: Document_Variant, |
|
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
277 |
latex_output: Latex.Output, |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
278 |
verbose: Boolean |
| 75393 | 279 |
): Directory = {
|
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
280 |
val doc_dir = make_directory(dir, doc) |
| 73719 | 281 |
|
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
282 |
if (verbose) progress.echo(program_start("Creating directory"))
|
| 77174 | 283 |
|
| 73719 | 284 |
|
| 74747 | 285 |
/* actual sources: with SHA1 digest */ |
| 73719 | 286 |
|
|
77000
ffc0774e0efe
clarified file positions: retain original source path;
wenzelm
parents:
76994
diff
changeset
|
287 |
isabelle_styles.foreach(Latex.copy_file(_, doc_dir)) |
|
74840
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
288 |
|
|
76450
107d8203fbd7
clarified signature: allow to change options in instances of Document_Build.Engine;
wenzelm
parents:
76370
diff
changeset
|
289 |
val comment_latex = latex_output.options.bool("document_comment_latex")
|
|
77000
ffc0774e0efe
clarified file positions: retain original source path;
wenzelm
parents:
76994
diff
changeset
|
290 |
if (!comment_latex) Latex.copy_file(texinputs + Path.basic("comment.sty"), doc_dir)
|
|
74840
4faf0ec33cbf
option document_comment_latex supports e.g. Dagstuhl LIPIcs;
wenzelm
parents:
74839
diff
changeset
|
291 |
doc.tags.sty(comment_latex).write(doc_dir) |
| 73724 | 292 |
|
| 73719 | 293 |
for ((base_dir, src) <- info.document_files) {
|
|
77000
ffc0774e0efe
clarified file positions: retain original source path;
wenzelm
parents:
76994
diff
changeset
|
294 |
Latex.copy_file_base(info.dir + base_dir, src, doc_dir) |
| 73719 | 295 |
} |
296 |
||
297 |
session_tex.write(doc_dir) |
|
| 76757 | 298 |
document_latex.foreach(_.write(latex_output, doc_dir)) |
| 73719 | 299 |
|
300 |
val root_name1 = "root_" + doc.name |
|
301 |
val root_name = if ((doc_dir + Path.explode(root_name1).tex).is_file) root_name1 else "root" |
|
302 |
||
| 77618 | 303 |
val document_prefs = latex_output.options.make_prefs(filter = _.for_document) |
304 |
||
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
305 |
val meta_info = |
|
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
306 |
SHA1.shasum_meta_info( |
| 77618 | 307 |
SHA1.digest( |
308 |
List(doc.print, document_logo.toString, document_build, document_prefs).toString)) |
|
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
309 |
|
|
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
310 |
val manifest = |
| 77211 | 311 |
SHA1.shasum_sorted( |
312 |
for (file <- File.find_files(doc_dir.file, follow_links = true)) |
|
313 |
yield SHA1.digest(file) -> File.path(doc_dir.java_path.relativize(file.toPath)).implode) |
|
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
314 |
|
|
77214
df8d71edbc79
clarified signature, using right-associative operation;
wenzelm
parents:
77211
diff
changeset
|
315 |
val sources = meta_info ::: manifest |
| 73719 | 316 |
|
317 |
||
| 74747 | 318 |
/* derived material: without SHA1 digest */ |
| 73723 | 319 |
|
320 |
isabelle_logo.foreach(_.write(doc_dir)) |
|
| 73719 | 321 |
session_graph.write(doc_dir) |
322 |
||
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
323 |
if (verbose) {
|
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
324 |
progress.bash("ls -alR", echo = true, cwd = doc_dir.file).check
|
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
325 |
progress match {
|
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
326 |
case program_progress: Program_Progress => program_progress.stop_program() |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
327 |
case _ => |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
328 |
} |
| 77176 | 329 |
} |
| 77174 | 330 |
|
| 73719 | 331 |
Directory(doc_dir, doc, root_name, sources) |
332 |
} |
|
333 |
||
334 |
def old_document(directory: Directory): Option[Document_Output] = |
|
335 |
for {
|
|
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
336 |
db <- session_context.session_db() |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75748
diff
changeset
|
337 |
old_doc <- read_document(db, session, directory.doc.name) |
| 73719 | 338 |
if old_doc.sources == directory.sources |
339 |
} |
|
| 73720 | 340 |
yield old_doc |
| 73719 | 341 |
} |
342 |
||
343 |
sealed case class Directory( |
|
344 |
doc_dir: Path, |
|
345 |
doc: Document_Variant, |
|
346 |
root_name: String, |
|
|
77210
1ffee8893b12
prefer explicit shasum: more robust due to explicit file names, which often work implicitly in LaTeX;
wenzelm
parents:
77197
diff
changeset
|
347 |
sources: SHA1.Shasum |
| 75393 | 348 |
) {
|
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
349 |
def root_name_script(ext: String = ""): String = |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
350 |
Bash.string(if (ext.isEmpty) root_name else root_name + "." + ext) |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
351 |
|
| 76769 | 352 |
def conditional_script( |
353 |
ext: String, exe: String, title: String = "", after: String = "" |
|
354 |
): String = {
|
|
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
355 |
"if [ -f " + root_name_script(ext) + " ]\n" + |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
356 |
"then\n" + |
| 77174 | 357 |
" " + (if (title.nonEmpty) program_running_script(title) else "") + |
| 76769 | 358 |
exe + " " + root_name_script() + "\n" + |
| 77368 | 359 |
if_proper(after, " " + after) + |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
360 |
"fi\n" |
| 76769 | 361 |
} |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
362 |
|
| 73719 | 363 |
def log_errors(): List[String] = |
364 |
Latex.latex_errors(doc_dir, root_name) ::: |
|
365 |
Bibtex.bibtex_errors(doc_dir, root_name) |
|
366 |
||
| 75393 | 367 |
def make_document(log: List[String], errors: List[String]): Document_Output = {
|
| 73719 | 368 |
val root_pdf = Path.basic(root_name).pdf |
369 |
val result_pdf = doc_dir + root_pdf |
|
370 |
||
371 |
if (errors.nonEmpty) {
|
|
| 76734 | 372 |
val message = "Failed to build document " + quote(doc.name) |
373 |
throw new Build_Error(log, errors ::: List(message)) |
|
| 73719 | 374 |
} |
375 |
else if (!result_pdf.is_file) {
|
|
376 |
val message = "Bad document result: expected to find " + root_pdf |
|
| 76734 | 377 |
throw new Build_Error(log, List(message)) |
| 73719 | 378 |
} |
379 |
else {
|
|
380 |
val log_xz = Bytes(cat_lines(log)).compress() |
|
381 |
val pdf = Bytes.read(result_pdf) |
|
382 |
Document_Output(doc.name, sources, log_xz, pdf) |
|
383 |
} |
|
384 |
} |
|
385 |
} |
|
386 |
||
| 73718 | 387 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
388 |
/* build engines */ |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
389 |
|
| 75393 | 390 |
abstract class Engine(val name: String) extends Isabelle_System.Service {
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
391 |
override def toString: String = name |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
392 |
|
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
393 |
def prepare_directory(context: Context, dir: Path, doc: Document_Variant, verbose: Boolean): Directory |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
394 |
def build_document(context: Context, directory: Directory, verbose: Boolean): Document_Output |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
395 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
396 |
|
| 75393 | 397 |
abstract class Bash_Engine(name: String) extends Engine(name) {
|
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
398 |
def prepare_directory(context: Context, dir: Path, doc: Document_Variant, verbose: Boolean): Directory = |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
399 |
context.prepare_directory(dir, doc, new Latex.Output(context.options), verbose) |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
400 |
|
| 73759 | 401 |
def use_pdflatex: Boolean = false |
| 77174 | 402 |
def running_latex: String = program_running_script(if (use_pdflatex) "pdflatex" else "lualatex") |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
403 |
def latex_script(context: Context, directory: Directory): String = |
| 77174 | 404 |
running_latex + (if (use_pdflatex) "$ISABELLE_PDFLATEX" else "$ISABELLE_LUALATEX") + |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
405 |
" " + directory.root_name_script() + "\n" |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
406 |
|
| 75393 | 407 |
def bibtex_script(context: Context, directory: Directory, latex: Boolean = false): String = {
|
| 73743 | 408 |
val ext = if (context.document_bibliography) "aux" else "bib" |
| 76769 | 409 |
directory.conditional_script(ext, "$ISABELLE_BIBTEX", title = "bibtex", |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
410 |
after = if (latex) latex_script(context, directory) else "") |
| 73743 | 411 |
} |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
412 |
|
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
413 |
def makeindex_script(context: Context, directory: Directory, latex: Boolean = false): String = |
| 76769 | 414 |
directory.conditional_script("idx", "$ISABELLE_MAKEINDEX", title = "makeindex",
|
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
415 |
after = if (latex) latex_script(context, directory) else "") |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
416 |
|
| 73759 | 417 |
def use_build_script: Boolean = false |
| 75393 | 418 |
def build_script(context: Context, directory: Directory): String = {
|
| 73759 | 419 |
val has_build_script = (directory.doc_dir + Path.explode("build")).is_file
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
420 |
|
| 73759 | 421 |
if (!use_build_script && has_build_script) {
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
422 |
error("Unexpected document build script for option document_build=" +
|
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
423 |
quote(context.document_build)) |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
424 |
} |
| 73759 | 425 |
else if (use_build_script && !has_build_script) error("Missing document build script")
|
426 |
else if (has_build_script) "./build pdf " + Bash.string(directory.doc.name) |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
427 |
else {
|
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
428 |
"set -e\n" + |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
429 |
latex_script(context, directory) + |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
430 |
bibtex_script(context, directory, latex = true) + |
|
73738
d701bd96e323
more robust: allow \printindex within the document;
wenzelm
parents:
73737
diff
changeset
|
431 |
makeindex_script(context, directory) + |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
432 |
latex_script(context, directory) + |
|
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
433 |
makeindex_script(context, directory, latex = true) |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
434 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
435 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
436 |
|
| 75393 | 437 |
def build_document( |
438 |
context: Context, |
|
439 |
directory: Directory, |
|
440 |
verbose: Boolean |
|
441 |
): Document_Output = {
|
|
| 77517 | 442 |
val progress = context.progress |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
443 |
val result = |
| 77517 | 444 |
progress.bash( |
|
73737
6638323d2774
clarified bash scripts, with public interfaces for user-defined Document_Build.Engine;
wenzelm
parents:
73735
diff
changeset
|
445 |
build_script(context, directory), |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
446 |
cwd = directory.doc_dir.file, |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
447 |
echo = verbose, |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
448 |
watchdog = Time.seconds(0.5)) |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
449 |
|
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
450 |
val log = result.out_lines ::: result.err_lines |
| 76734 | 451 |
val err = result.err |
452 |
||
453 |
val errors1 = directory.log_errors() |
|
454 |
val errors2 = |
|
455 |
if (result.ok) errors1 |
|
456 |
else if (err.nonEmpty) err :: errors1 |
|
457 |
else if (errors1.nonEmpty) errors1 |
|
458 |
else List("Error")
|
|
459 |
directory.make_document(log, errors2) |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
460 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
461 |
} |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
462 |
|
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
463 |
class LuaLaTeX_Engine extends Bash_Engine("lualatex")
|
| 73759 | 464 |
class PDFLaTeX_Engine extends Bash_Engine("pdflatex") { override def use_pdflatex: Boolean = true }
|
465 |
class Build_Engine extends Bash_Engine("build") { override def use_build_script: Boolean = true }
|
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
466 |
|
|
76454
f2d17e69e520
clarified options: support lualatex as well, but prefer old pdflatex for demos;
wenzelm
parents:
76451
diff
changeset
|
467 |
class LIPIcs_Engine(name: String) extends Bash_Engine(name) {
|
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
468 |
def lipics_options(options: Options): Options = |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
469 |
options + "document_heading_prefix=" + "document_comment_latex" |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
470 |
|
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
471 |
override def use_pdflatex: Boolean = true |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
472 |
|
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
473 |
override def prepare_directory( |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
474 |
context: Context, dir: Path, doc: Document_Variant, verbose: Boolean |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
475 |
): Directory = {
|
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
476 |
val doc_dir = context.make_directory(dir, doc) |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77552
diff
changeset
|
477 |
Component_LIPIcs.document_files.foreach(Latex.copy_file(_, doc_dir)) |
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
478 |
|
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
479 |
val latex_output = new Latex.Output(lipics_options(context.options)) |
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
480 |
context.prepare_directory(dir, doc, latex_output, verbose) |
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
481 |
} |
|
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
482 |
} |
|
76454
f2d17e69e520
clarified options: support lualatex as well, but prefer old pdflatex for demos;
wenzelm
parents:
76451
diff
changeset
|
483 |
class LIPIcs_LuaLaTeX_Engine extends LIPIcs_Engine("lipics")
|
|
f2d17e69e520
clarified options: support lualatex as well, but prefer old pdflatex for demos;
wenzelm
parents:
76451
diff
changeset
|
484 |
class LIPIcs_PDFLaTeX_Engine extends LIPIcs_Engine("lipics_pdflatex") {
|
|
f2d17e69e520
clarified options: support lualatex as well, but prefer old pdflatex for demos;
wenzelm
parents:
76451
diff
changeset
|
485 |
override def use_pdflatex: Boolean = true |
|
f2d17e69e520
clarified options: support lualatex as well, but prefer old pdflatex for demos;
wenzelm
parents:
76451
diff
changeset
|
486 |
} |
|
76451
87cd8506e000
document_build engine for "lipics", with options and document_files;
wenzelm
parents:
76450
diff
changeset
|
487 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
488 |
|
| 73718 | 489 |
/* build documents */ |
490 |
||
491 |
def tex_name(name: Document.Node.Name): String = name.theory_base_name + ".tex" |
|
492 |
||
| 76734 | 493 |
class Build_Error(val log_lines: List[String], val log_errors: List[String]) |
494 |
extends Exn.User_Error(Exn.cat_message(log_errors: _*)) |
|
| 73718 | 495 |
|
496 |
def build_documents( |
|
| 73719 | 497 |
context: Context, |
| 73718 | 498 |
output_sources: Option[Path] = None, |
499 |
output_pdf: Option[Path] = None, |
|
| 75393 | 500 |
verbose: Boolean = false |
501 |
): List[Document_Output] = {
|
|
| 73719 | 502 |
val progress = context.progress |
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
503 |
val engine = context.get_engine() |
| 73718 | 504 |
|
505 |
val documents = |
|
| 73719 | 506 |
for (doc <- context.documents) |
| 73718 | 507 |
yield {
|
| 75394 | 508 |
Isabelle_System.with_tmp_dir("document") { tmp_dir =>
|
| 73719 | 509 |
progress.echo("Preparing " + context.session + "/" + doc.name + " ...")
|
| 73718 | 510 |
val start = Time.now() |
511 |
||
|
77178
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
512 |
output_sources.foreach(engine.prepare_directory(context, _, doc, false)) |
|
4aff4a84b8af
less verbosity by default, notably for regular "isabelle build -o document";
wenzelm
parents:
77176
diff
changeset
|
513 |
val directory = engine.prepare_directory(context, tmp_dir, doc, verbose) |
| 73718 | 514 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
515 |
val document = |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
516 |
context.old_document(directory) getOrElse |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
517 |
engine.build_document(context, directory, verbose) |
| 73718 | 518 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
519 |
val stop = Time.now() |
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
520 |
val timing = stop - start |
| 73718 | 521 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
522 |
progress.echo("Finished " + context.session + "/" + doc.name +
|
|
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
523 |
" (" + timing.message_hms + " elapsed time)")
|
| 73718 | 524 |
|
|
73721
52030acb19ac
option document_build refers to build engine in Isabelle/Scala;
wenzelm
parents:
73720
diff
changeset
|
525 |
document |
| 75394 | 526 |
} |
| 73718 | 527 |
} |
528 |
||
529 |
for (dir <- output_pdf; doc <- documents) {
|
|
| 73719 | 530 |
val path = doc.write(dir) |
| 73718 | 531 |
progress.echo("Document at " + path.absolute)
|
532 |
} |
|
533 |
||
534 |
documents |
|
535 |
} |
|
536 |
||
537 |
||
538 |
/* Isabelle tool wrapper */ |
|
539 |
||
540 |
val isabelle_tool = |
|
| 75394 | 541 |
Isabelle_Tool("document", "prepare session theory document", Scala_Project.here,
|
542 |
{ args =>
|
|
543 |
var output_sources: Option[Path] = None |
|
544 |
var output_pdf: Option[Path] = None |
|
545 |
var verbose_latex = false |
|
546 |
var dirs: List[Path] = Nil |
|
547 |
var options = Options.init() |
|
548 |
var verbose_build = false |
|
| 73718 | 549 |
|
| 75394 | 550 |
val getopts = Getopts("""
|
| 73718 | 551 |
Usage: isabelle document [OPTIONS] SESSION |
552 |
||
553 |
Options are: |
|
554 |
-O DIR output directory for LaTeX sources and resulting PDF |
|
555 |
-P DIR output directory for resulting PDF |
|
556 |
-S DIR output directory for LaTeX sources |
|
557 |
-V verbose latex |
|
558 |
-d DIR include session directory |
|
559 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
560 |
-v verbose build |
|
561 |
||
562 |
Prepare the theory document of a session. |
|
563 |
""", |
|
| 75394 | 564 |
"O:" -> (arg => |
565 |
{
|
|
566 |
val dir = Path.explode(arg) |
|
567 |
output_sources = Some(dir) |
|
568 |
output_pdf = Some(dir) |
|
569 |
}), |
|
570 |
"P:" -> (arg => { output_pdf = Some(Path.explode(arg)) }),
|
|
571 |
"S:" -> (arg => { output_sources = Some(Path.explode(arg)) }),
|
|
572 |
"V" -> (_ => verbose_latex = true), |
|
573 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
574 |
"o:" -> (arg => options = options + arg), |
|
575 |
"v" -> (_ => verbose_build = true)) |
|
| 73718 | 576 |
|
| 75394 | 577 |
val more_args = getopts(args) |
578 |
val session = |
|
579 |
more_args match {
|
|
580 |
case List(a) => a |
|
581 |
case _ => getopts.usage() |
|
582 |
} |
|
| 73718 | 583 |
|
| 75394 | 584 |
val progress = new Console_Progress(verbose = verbose_build) |
| 73718 | 585 |
|
| 75394 | 586 |
progress.interrupt_handler {
|
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
587 |
val build_results = |
| 75394 | 588 |
Build.build(options, selection = Sessions.Selection.session(session), |
|
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77520
diff
changeset
|
589 |
dirs = dirs, progress = progress) |
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
590 |
if (!build_results.ok) error("Failed to build session " + quote(session))
|
| 73718 | 591 |
|
| 75394 | 592 |
if (output_sources.isEmpty && output_pdf.isEmpty) {
|
593 |
progress.echo_warning("No output directory")
|
|
594 |
} |
|
| 73718 | 595 |
|
| 76731 | 596 |
val session_background = Document_Build.session_background(options, session, dirs = dirs) |
597 |
using(Export.open_session_context(build_results.store, session_background)) {
|
|
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
598 |
session_context => |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
599 |
build_documents( |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
600 |
context(session_context, progress = progress), |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
601 |
output_sources = output_sources, output_pdf = output_pdf, |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75941
diff
changeset
|
602 |
verbose = verbose_latex) |
| 75394 | 603 |
} |
604 |
} |
|
605 |
}) |
|
| 73718 | 606 |
} |