| 64161 |      1 | /*  Title:      Pure/Admin/build_doc.scala
 | 
| 56429 |      2 |     Author:     Makarius
 | 
|  |      3 | 
 | 
|  |      4 | Build Isabelle documentation.
 | 
|  |      5 | */
 | 
|  |      6 | 
 | 
|  |      7 | package isabelle
 | 
|  |      8 | 
 | 
|  |      9 | 
 | 
|  |     10 | import java.io.{File => JFile}
 | 
|  |     11 | 
 | 
|  |     12 | 
 | 
|  |     13 | object Build_Doc
 | 
|  |     14 | {
 | 
|  |     15 |   /* build_doc */
 | 
|  |     16 | 
 | 
|  |     17 |   def build_doc(
 | 
|  |     18 |     options: Options,
 | 
| 64909 |     19 |     progress: Progress = No_Progress,
 | 
| 56429 |     20 |     all_docs: Boolean = false,
 | 
|  |     21 |     max_jobs: Int = 1,
 | 
|  |     22 |     system_mode: Boolean = false,
 | 
|  |     23 |     docs: List[String] = Nil): Int =
 | 
|  |     24 |   {
 | 
|  |     25 |     val selection =
 | 
|  |     26 |       for {
 | 
| 65519 |     27 |         info <- Sessions.load(options).build_topological_order
 | 
| 56429 |     28 |         if info.groups.contains("doc")
 | 
|  |     29 |         doc = info.options.string("document_variants")
 | 
|  |     30 |         if all_docs || docs.contains(doc)
 | 
| 65519 |     31 |       } yield (doc, info.name)
 | 
| 56429 |     32 | 
 | 
|  |     33 |     val selected_docs = selection.map(_._1)
 | 
|  |     34 |     val sessions = selection.map(_._2)
 | 
|  |     35 | 
 | 
|  |     36 |     docs.filter(doc => !selected_docs.contains(doc)) match {
 | 
|  |     37 |       case Nil =>
 | 
| 56432 |     38 |       case bad => error("No documentation session for " + commas_quote(bad))
 | 
| 56429 |     39 |     }
 | 
|  |     40 | 
 | 
| 56432 |     41 |     progress.echo("Build started for documentation " + commas_quote(selected_docs))
 | 
| 56429 |     42 | 
 | 
| 62641 |     43 |     val res1 =
 | 
| 56429 |     44 |       Build.build(options, progress, requirements = true, build_heap = true,
 | 
|  |     45 |         max_jobs = max_jobs, system_mode = system_mode, sessions = sessions)
 | 
| 62641 |     46 |     if (res1.ok) {
 | 
| 56429 |     47 |       Isabelle_System.with_tmp_dir("document_output")(output =>
 | 
|  |     48 |         {
 | 
| 62641 |     49 |           val res2 =
 | 
| 56429 |     50 |             Build.build(
 | 
|  |     51 |               options.bool.update("browser_info", false).
 | 
|  |     52 |                 string.update("document", "pdf").
 | 
| 64220 |     53 |                 string.update("document_output", output.implode),
 | 
| 56430 |     54 |               progress, clean_build = true, max_jobs = max_jobs, system_mode = system_mode,
 | 
|  |     55 |               sessions = sessions)
 | 
| 62641 |     56 |           if (res2.ok) {
 | 
| 65082 |     57 |             val doc_dir = Path.explode("~~/doc")
 | 
| 56429 |     58 |             for (doc <- selected_docs) {
 | 
| 64220 |     59 |               val name = Path.explode(doc + ".pdf")
 | 
|  |     60 |               File.copy(output + name, doc_dir + name)
 | 
| 56429 |     61 |             }
 | 
|  |     62 |           }
 | 
| 62641 |     63 |           res2.rc
 | 
| 56429 |     64 |         })
 | 
|  |     65 |     }
 | 
| 62641 |     66 |     else res1.rc
 | 
| 56429 |     67 |   }
 | 
|  |     68 | 
 | 
|  |     69 | 
 | 
| 62838 |     70 |   /* Isabelle tool wrapper */
 | 
| 56429 |     71 | 
 | 
| 64161 |     72 |   val isabelle_tool =
 | 
|  |     73 |     Isabelle_Tool("build_doc", "build Isabelle documentation", args =>
 | 
|  |     74 |     {
 | 
|  |     75 |       var all_docs = false
 | 
|  |     76 |       var max_jobs = 1
 | 
|  |     77 |       var system_mode = false
 | 
| 62435 |     78 | 
 | 
| 64161 |     79 |       val getopts =
 | 
|  |     80 |         Getopts("""
 | 
| 64310 |     81 | Usage: isabelle build_doc [OPTIONS] [DOCS ...]
 | 
| 62435 |     82 | 
 | 
|  |     83 |   Options are:
 | 
|  |     84 |     -a           select all documentation sessions
 | 
|  |     85 |     -j INT       maximum number of parallel jobs (default 1)
 | 
|  |     86 |     -s           system build mode
 | 
|  |     87 | 
 | 
|  |     88 |   Build Isabelle documentation from documentation sessions with
 | 
|  |     89 |   suitable document_variants entry.
 | 
|  |     90 | """,
 | 
| 64310 |     91 |           "a" -> (_ => all_docs = true),
 | 
|  |     92 |           "j:" -> (arg => max_jobs = Value.Int.parse(arg)),
 | 
|  |     93 |           "s" -> (_ => system_mode = true))
 | 
| 62838 |     94 | 
 | 
| 64161 |     95 |       val docs = getopts(args)
 | 
| 62435 |     96 | 
 | 
| 64161 |     97 |       if (!all_docs && docs.isEmpty) getopts.usage()
 | 
| 62435 |     98 | 
 | 
| 64161 |     99 |       val options = Options.init()
 | 
|  |    100 |       val progress = new Console_Progress()
 | 
|  |    101 |       val rc =
 | 
|  |    102 |         progress.interrupt_handler {
 | 
|  |    103 |           build_doc(options, progress, all_docs, max_jobs, system_mode, docs)
 | 
|  |    104 |         }
 | 
|  |    105 |       sys.exit(rc)
 | 
|  |    106 |     }, admin = true)
 | 
| 56429 |    107 | }
 |