src/Pure/Tools/build_doc.scala
author wenzelm
Wed Nov 26 20:05:34 2014 +0100 (2014-11-26)
changeset 59058 a78612c67ec0
parent 56890 7f120d227ca5
child 60992 89effcb342df
permissions -rw-r--r--
renamed "pairself" to "apply2", in accordance to @{apply 2};
     1 /*  Title:      Pure/Tools/build_doc.scala
     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,
    19     progress: Build.Progress = Build.Ignore_Progress,
    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 {
    27         (name, info) <- Build.find_sessions(options).topological_order
    28         if info.groups.contains("doc")
    29         doc = info.options.string("document_variants")
    30         if all_docs || docs.contains(doc)
    31       } yield (doc, name)
    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 =>
    38       case bad => error("No documentation session for " + commas_quote(bad))
    39     }
    40 
    41     progress.echo("Build started for documentation " + commas_quote(selected_docs))
    42 
    43     val rc1 =
    44       Build.build(options, progress, requirements = true, build_heap = true,
    45         max_jobs = max_jobs, system_mode = system_mode, sessions = sessions)
    46     if (rc1 == 0) {
    47       Isabelle_System.with_tmp_dir("document_output")(output =>
    48         {
    49           val rc2 =
    50             Build.build(
    51               options.bool.update("browser_info", false).
    52                 string.update("document", "pdf").
    53                 string.update("document_output", Isabelle_System.posix_path(output)),
    54               progress, clean_build = true, max_jobs = max_jobs, system_mode = system_mode,
    55               sessions = sessions)
    56           if (rc2 == 0) {
    57             val doc_dir = Path.explode("$ISABELLE_HOME/doc").file
    58             for (doc <- selected_docs) {
    59               val name = doc + ".pdf"
    60               File.copy(new JFile(output, name), new JFile(doc_dir, name))
    61             }
    62           }
    63           rc2
    64         })
    65     }
    66     else rc1
    67   }
    68 
    69 
    70   /* command line entry point */
    71 
    72   def main(args: Array[String])
    73   {
    74     Command_Line.tool {
    75       args.toList match {
    76         case
    77           Properties.Value.Boolean(all_docs) ::
    78           Properties.Value.Int(max_jobs) ::
    79           Properties.Value.Boolean(system_mode) ::
    80           Command_Line.Chunks(docs) =>
    81             val options = Options.init()
    82             val progress = new Build.Console_Progress()
    83             progress.interrupt_handler {
    84               build_doc(options, progress, all_docs, max_jobs, system_mode, docs)
    85             }
    86         case _ => error("Bad arguments:\n" + cat_lines(args))
    87       }
    88     }
    89   }
    90 }
    91