| author | wenzelm | 
| Sat, 30 Nov 2024 21:01:59 +0100 | |
| changeset 81517 | 1b33a7a3c80c | 
| parent 81350 | 1818358373e2 | 
| child 82982 | cbeab5584c62 | 
| 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,  | 
| 79616 | 17  | 
max_jobs: Option[Int] = None,  | 
| 
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,  | 
| 76453 | 19  | 
docs: List[String] = Nil,  | 
20  | 
view: Boolean = false  | 
|
| 75393 | 21  | 
  ): Unit = {
 | 
| 67026 | 22  | 
val sessions_structure = Sessions.load_structure(options)  | 
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
23  | 
val selected =  | 
| 56429 | 24  | 
      for {
 | 
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
25  | 
session <- sessions_structure.build_topological_order  | 
| 
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
26  | 
info = sessions_structure(session)  | 
| 56429 | 27  | 
        if info.groups.contains("doc")
 | 
28  | 
        doc = info.options.string("document_variants")
 | 
|
29  | 
if all_docs || docs.contains(doc)  | 
|
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
30  | 
} yield (doc, session)  | 
| 56429 | 31  | 
|
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
32  | 
val documents = selected.map(_._1)  | 
| 
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
33  | 
val selection = Sessions.Selection(sessions = selected.map(_._2))  | 
| 56429 | 34  | 
|
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
35  | 
    docs.filter(doc => !documents.contains(doc)) match {
 | 
| 56429 | 36  | 
case Nil =>  | 
| 56432 | 37  | 
      case bad => error("No documentation session for " + commas_quote(bad))
 | 
| 56429 | 38  | 
}  | 
39  | 
||
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
40  | 
    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
 | 
41  | 
val build_results =  | 
| 
 
769a7cd5a16a
clarified signature: re-use store/cache from build results;
 
wenzelm 
parents: 
75782 
diff
changeset
 | 
42  | 
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
 | 
43  | 
    if (!build_results.ok) 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))
 | 
| 76741 | 46  | 
val deps = Sessions.load_structure(options + "document").selection_deps(selection)  | 
| 72597 | 47  | 
|
48  | 
val errs =  | 
|
| 80885 | 49  | 
Par_List.maps[(String, String), String](  | 
| 72675 | 50  | 
      {
 | 
51  | 
case (doc, session) =>  | 
|
52  | 
          try {
 | 
|
| 74814 | 53  | 
progress.expose_interrupt()  | 
| 72897 | 54  | 
            progress.echo("Documentation " + quote(doc) + " ...")
 | 
| 72683 | 55  | 
|
| 76656 | 56  | 
            using(Export.open_session_context(build_results.store, deps.background(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  | 
}  | 
| 80885 | 69  | 
}, selected, sequential = sequential)  | 
| 72597 | 70  | 
|
71  | 
if (errs.nonEmpty) error(cat_lines(errs))  | 
|
| 76453 | 72  | 
|
73  | 
    if (view) {
 | 
|
| 
81350
 
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
 
wenzelm 
parents: 
80885 
diff
changeset
 | 
74  | 
      for (entry <- Doc.main_contents().entries(name = docs.contains, pdf = true)) {
 | 
| 
 
1818358373e2
misc tuning and clarification: Doc.Entry supports both plain files and pdf documents;
 
wenzelm 
parents: 
80885 
diff
changeset
 | 
75  | 
entry.view()  | 
| 76453 | 76  | 
}  | 
77  | 
}  | 
|
| 56429 | 78  | 
}  | 
79  | 
||
80  | 
||
| 62838 | 81  | 
/* Isabelle tool wrapper */  | 
| 56429 | 82  | 
|
| 64161 | 83  | 
val isabelle_tool =  | 
| 75394 | 84  | 
    Isabelle_Tool("build_doc", "build Isabelle documentation", Scala_Project.here,
 | 
85  | 
      { args =>
 | 
|
| 76453 | 86  | 
var view = false  | 
| 75394 | 87  | 
var all_docs = false  | 
| 79616 | 88  | 
var max_jobs: Option[Int] = None  | 
| 75394 | 89  | 
var sequential = false  | 
90  | 
var options = Options.init()  | 
|
| 62435 | 91  | 
|
| 75394 | 92  | 
val getopts =  | 
93  | 
          Getopts("""
 | 
|
| 64310 | 94  | 
Usage: isabelle build_doc [OPTIONS] [DOCS ...]  | 
| 62435 | 95  | 
|
96  | 
Options are:  | 
|
| 
76455
 
74c3ecfeb3ea
clarified description, to fit better to e.g. "isabelle build_doc -a -V system jedit";
 
wenzelm 
parents: 
76453 
diff
changeset
 | 
97  | 
-V view explicitly given documents  | 
| 62435 | 98  | 
-a select all documentation sessions  | 
99  | 
-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
 | 
100  | 
-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
 | 
101  | 
-s sequential LaTeX jobs  | 
| 62435 | 102  | 
|
103  | 
Build Isabelle documentation from documentation sessions with  | 
|
104  | 
suitable document_variants entry.  | 
|
105  | 
""",  | 
|
| 76453 | 106  | 
"V" -> (_ => view = true),  | 
| 75394 | 107  | 
"a" -> (_ => all_docs = true),  | 
| 79616 | 108  | 
"j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))),  | 
| 75394 | 109  | 
"o:" -> (arg => options = options + arg),  | 
110  | 
"s" -> (_ => sequential = true))  | 
|
| 62838 | 111  | 
|
| 75394 | 112  | 
val docs = getopts(args)  | 
| 62435 | 113  | 
|
| 75394 | 114  | 
if (!all_docs && docs.isEmpty) getopts.usage()  | 
| 62435 | 115  | 
|
| 75394 | 116  | 
val progress = new Console_Progress()  | 
| 
72578
 
3e8395f9093a
clarified build_doc, based on Present.build_documents;
 
wenzelm 
parents: 
71981 
diff
changeset
 | 
117  | 
|
| 75394 | 118  | 
        progress.interrupt_handler {
 | 
119  | 
build_doc(options, progress = progress, all_docs = all_docs, max_jobs = max_jobs,  | 
|
| 76453 | 120  | 
sequential = sequential, docs = docs, view = view)  | 
| 75394 | 121  | 
}  | 
122  | 
})  | 
|
| 56429 | 123  | 
}  |