author | wenzelm |
Fri, 08 Apr 2022 16:42:52 +0200 | |
changeset 75421 | 3c710067b178 |
parent 75394 | 42267c650205 |
child 75758 | 5ad049a5f6a8 |
permissions | -rw-r--r-- |
64161 | 1 |
/* Title: Pure/Admin/build_doc.scala |
56429 | 2 |
Author: Makarius |
3 |
||
4 |
Build Isabelle documentation. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75393 | 10 |
object Build_Doc { |
56429 | 11 |
/* build_doc */ |
12 |
||
13 |
def build_doc( |
|
14 |
options: Options, |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
69854
diff
changeset
|
15 |
progress: Progress = new Progress, |
56429 | 16 |
all_docs: Boolean = false, |
17 |
max_jobs: Int = 1, |
|
73512
e52a9b208481
support sequential LaTeX jobs: more robust when TeX installation is self-installing packages etc.;
wenzelm
parents:
73340
diff
changeset
|
18 |
sequential: Boolean = false, |
75393 | 19 |
docs: List[String] = Nil |
20 |
): Unit = { |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
21 |
val store = Sessions.store(options) |
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
22 |
|
67026 | 23 |
val sessions_structure = Sessions.load_structure(options) |
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
24 |
val selected = |
56429 | 25 |
for { |
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
26 |
session <- sessions_structure.build_topological_order |
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
27 |
info = sessions_structure(session) |
56429 | 28 |
if info.groups.contains("doc") |
29 |
doc = info.options.string("document_variants") |
|
30 |
if all_docs || docs.contains(doc) |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
31 |
} yield (doc, session) |
56429 | 32 |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
33 |
val documents = selected.map(_._1) |
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
34 |
val selection = Sessions.Selection(sessions = selected.map(_._2)) |
56429 | 35 |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
36 |
docs.filter(doc => !documents.contains(doc)) match { |
56429 | 37 |
case Nil => |
56432 | 38 |
case bad => error("No documentation session for " + commas_quote(bad)) |
56429 | 39 |
} |
40 |
||
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
41 |
progress.echo("Build started for sessions " + commas_quote(selection.sessions)) |
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
42 |
Build.build(options, selection = selection, progress = progress, max_jobs = max_jobs).ok || |
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
43 |
error("Build failed") |
56429 | 44 |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
45 |
progress.echo("Build started for documentation " + commas_quote(documents)) |
72675 | 46 |
val doc_options = options + "document=pdf" |
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
47 |
val deps = Sessions.load_structure(doc_options).selection_deps(selection) |
72597 | 48 |
|
49 |
val errs = |
|
72675 | 50 |
Par_List.map[(String, String), Option[String]]( |
51 |
{ |
|
52 |
case (doc, session) => |
|
53 |
try { |
|
74814 | 54 |
progress.expose_interrupt() |
72897 | 55 |
progress.echo("Documentation " + quote(doc) + " ...") |
72683 | 56 |
|
72854 | 57 |
using(store.open_database_context())(db_context => |
73719 | 58 |
Document_Build.build_documents(Document_Build.context(session, deps, db_context), |
72685 | 59 |
output_pdf = Some(Path.explode("~~/doc")))) |
72675 | 60 |
None |
61 |
} |
|
62 |
catch { |
|
63 |
case Exn.Interrupt.ERROR(msg) => |
|
64 |
val sep = if (msg.contains('\n')) "\n" else " " |
|
72897 | 65 |
Some("Documentation " + quote(doc) + " failed:" + sep + msg) |
72675 | 66 |
} |
73512
e52a9b208481
support sequential LaTeX jobs: more robust when TeX installation is self-installing packages etc.;
wenzelm
parents:
73340
diff
changeset
|
67 |
}, selected, sequential = sequential).flatten |
72597 | 68 |
|
69 |
if (errs.nonEmpty) error(cat_lines(errs)) |
|
56429 | 70 |
} |
71 |
||
72 |
||
62838 | 73 |
/* Isabelle tool wrapper */ |
56429 | 74 |
|
64161 | 75 |
val isabelle_tool = |
75394 | 76 |
Isabelle_Tool("build_doc", "build Isabelle documentation", Scala_Project.here, |
77 |
{ args => |
|
78 |
var all_docs = false |
|
79 |
var max_jobs = 1 |
|
80 |
var sequential = false |
|
81 |
var options = Options.init() |
|
62435 | 82 |
|
75394 | 83 |
val getopts = |
84 |
Getopts(""" |
|
64310 | 85 |
Usage: isabelle build_doc [OPTIONS] [DOCS ...] |
62435 | 86 |
|
87 |
Options are: |
|
88 |
-a select all documentation sessions |
|
89 |
-j INT maximum number of parallel jobs (default 1) |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69277
diff
changeset
|
90 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
73512
e52a9b208481
support sequential LaTeX jobs: more robust when TeX installation is self-installing packages etc.;
wenzelm
parents:
73340
diff
changeset
|
91 |
-s sequential LaTeX jobs |
62435 | 92 |
|
93 |
Build Isabelle documentation from documentation sessions with |
|
94 |
suitable document_variants entry. |
|
95 |
""", |
|
75394 | 96 |
"a" -> (_ => all_docs = true), |
97 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
|
98 |
"o:" -> (arg => options = options + arg), |
|
99 |
"s" -> (_ => sequential = true)) |
|
62838 | 100 |
|
75394 | 101 |
val docs = getopts(args) |
62435 | 102 |
|
75394 | 103 |
if (!all_docs && docs.isEmpty) getopts.usage() |
62435 | 104 |
|
75394 | 105 |
val progress = new Console_Progress() |
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
106 |
|
75394 | 107 |
progress.interrupt_handler { |
108 |
build_doc(options, progress = progress, all_docs = all_docs, max_jobs = max_jobs, |
|
109 |
sequential = sequential, docs = docs) |
|
110 |
} |
|
111 |
}) |
|
56429 | 112 |
} |