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