| author | wenzelm |
| Mon, 24 Oct 2022 20:37:32 +0200 | |
| changeset 76371 | 1ac2416e8432 |
| parent 76206 | 769a7cd5a16a |
| child 76453 | 2ba80c2fc325 |
| 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 = {
|
|
| 67026 | 21 |
val sessions_structure = Sessions.load_structure(options) |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
22 |
val selected = |
| 56429 | 23 |
for {
|
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
24 |
session <- sessions_structure.build_topological_order |
|
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
25 |
info = sessions_structure(session) |
| 56429 | 26 |
if info.groups.contains("doc")
|
27 |
doc = info.options.string("document_variants")
|
|
28 |
if all_docs || docs.contains(doc) |
|
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
29 |
} yield (doc, session) |
| 56429 | 30 |
|
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
31 |
val documents = selected.map(_._1) |
|
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
32 |
val selection = Sessions.Selection(sessions = selected.map(_._2)) |
| 56429 | 33 |
|
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
34 |
docs.filter(doc => !documents.contains(doc)) match {
|
| 56429 | 35 |
case Nil => |
| 56432 | 36 |
case bad => error("No documentation session for " + commas_quote(bad))
|
| 56429 | 37 |
} |
38 |
||
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
39 |
progress.echo("Build started for sessions " + commas_quote(selection.sessions))
|
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75782
diff
changeset
|
40 |
val build_results = |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75782
diff
changeset
|
41 |
Build.build(options, selection = selection, progress = progress, max_jobs = max_jobs) |
|
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75782
diff
changeset
|
42 |
if (!build_results.ok) error("Build failed")
|
| 56429 | 43 |
|
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
44 |
progress.echo("Build started for documentation " + commas_quote(documents))
|
| 72675 | 45 |
val doc_options = options + "document=pdf" |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
46 |
val deps = Sessions.load_structure(doc_options).selection_deps(selection) |
| 72597 | 47 |
|
48 |
val errs = |
|
| 72675 | 49 |
Par_List.map[(String, String), Option[String]]( |
50 |
{
|
|
51 |
case (doc, session) => |
|
52 |
try {
|
|
| 74814 | 53 |
progress.expose_interrupt() |
| 72897 | 54 |
progress.echo("Documentation " + quote(doc) + " ...")
|
| 72683 | 55 |
|
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
75782
diff
changeset
|
56 |
using(Export.open_session_context(build_results.store, deps.base_info(session))) {
|
|
75782
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75758
diff
changeset
|
57 |
session_context => |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75758
diff
changeset
|
58 |
Document_Build.build_documents( |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75758
diff
changeset
|
59 |
Document_Build.context(session_context), |
|
dba571dd0ba9
clarified signature: prefer Export.Session_Context over Sessions.Database_Context;
wenzelm
parents:
75758
diff
changeset
|
60 |
output_pdf = Some(Path.explode("~~/doc")))
|
| 75758 | 61 |
} |
| 72675 | 62 |
None |
63 |
} |
|
64 |
catch {
|
|
65 |
case Exn.Interrupt.ERROR(msg) => |
|
66 |
val sep = if (msg.contains('\n')) "\n" else " "
|
|
| 72897 | 67 |
Some("Documentation " + quote(doc) + " failed:" + sep + msg)
|
| 72675 | 68 |
} |
|
73512
e52a9b208481
support sequential LaTeX jobs: more robust when TeX installation is self-installing packages etc.;
wenzelm
parents:
73340
diff
changeset
|
69 |
}, selected, sequential = sequential).flatten |
| 72597 | 70 |
|
71 |
if (errs.nonEmpty) error(cat_lines(errs)) |
|
| 56429 | 72 |
} |
73 |
||
74 |
||
| 62838 | 75 |
/* Isabelle tool wrapper */ |
| 56429 | 76 |
|
| 64161 | 77 |
val isabelle_tool = |
| 75394 | 78 |
Isabelle_Tool("build_doc", "build Isabelle documentation", Scala_Project.here,
|
79 |
{ args =>
|
|
80 |
var all_docs = false |
|
81 |
var max_jobs = 1 |
|
82 |
var sequential = false |
|
83 |
var options = Options.init() |
|
| 62435 | 84 |
|
| 75394 | 85 |
val getopts = |
86 |
Getopts("""
|
|
| 64310 | 87 |
Usage: isabelle build_doc [OPTIONS] [DOCS ...] |
| 62435 | 88 |
|
89 |
Options are: |
|
90 |
-a select all documentation sessions |
|
91 |
-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
|
92 |
-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
|
93 |
-s sequential LaTeX jobs |
| 62435 | 94 |
|
95 |
Build Isabelle documentation from documentation sessions with |
|
96 |
suitable document_variants entry. |
|
97 |
""", |
|
| 75394 | 98 |
"a" -> (_ => all_docs = true), |
99 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
|
100 |
"o:" -> (arg => options = options + arg), |
|
101 |
"s" -> (_ => sequential = true)) |
|
| 62838 | 102 |
|
| 75394 | 103 |
val docs = getopts(args) |
| 62435 | 104 |
|
| 75394 | 105 |
if (!all_docs && docs.isEmpty) getopts.usage() |
| 62435 | 106 |
|
| 75394 | 107 |
val progress = new Console_Progress() |
|
72578
3e8395f9093a
clarified build_doc, based on Present.build_documents;
wenzelm
parents:
71981
diff
changeset
|
108 |
|
| 75394 | 109 |
progress.interrupt_handler {
|
110 |
build_doc(options, progress = progress, all_docs = all_docs, max_jobs = max_jobs, |
|
111 |
sequential = sequential, docs = docs) |
|
112 |
} |
|
113 |
}) |
|
| 56429 | 114 |
} |