| 
56429
 | 
     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,
  | 
| 
61276
 | 
    19  | 
    progress: Progress = Ignore_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 {
 | 
| 
62631
 | 
    27  | 
        (name, info) <- Sessions.find(options).topological_order
  | 
| 
56429
 | 
    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 =>
  | 
| 
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  | 
  | 
| 
 | 
    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").
 | 
| 
60992
 | 
    53  | 
                string.update("document_output", File.standard_path(output)),
 | 
| 
56430
 | 
    54  | 
              progress, clean_build = true, max_jobs = max_jobs, system_mode = system_mode,
  | 
| 
 | 
    55  | 
              sessions = sessions)
  | 
| 
56429
 | 
    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 {
 | 
| 
62435
 | 
    75  | 
      var all_docs = false
  | 
| 
 | 
    76  | 
      var max_jobs = 1
  | 
| 
 | 
    77  | 
      var system_mode = false
  | 
| 
 | 
    78  | 
  | 
| 
 | 
    79  | 
      val getopts =
  | 
| 
62454
 | 
    80  | 
        Getopts("""
 | 
| 
62435
 | 
    81  | 
Usage: isabelle build_doc [OPTIONS] [DOCS ...]"
  | 
| 
 | 
    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  | 
""",
  | 
| 
 | 
    91  | 
        "a" -> (_ => all_docs = true),
  | 
| 
 | 
    92  | 
        "j:" -> (arg => max_jobs = Properties.Value.Int.parse(arg)),
  | 
| 
 | 
    93  | 
        "s" -> (_ => system_mode = true))
  | 
| 
 | 
    94  | 
  | 
| 
 | 
    95  | 
      val docs = getopts(args)
  | 
| 
 | 
    96  | 
  | 
| 
 | 
    97  | 
      if (!all_docs && docs.isEmpty) getopts.usage()
  | 
| 
 | 
    98  | 
  | 
| 
 | 
    99  | 
      val options = Options.init()
  | 
| 
 | 
   100  | 
      val progress = new Console_Progress()
  | 
| 
 | 
   101  | 
      progress.interrupt_handler {
 | 
| 
 | 
   102  | 
        build_doc(options, progress, all_docs, max_jobs, system_mode, docs)
  | 
| 
56429
 | 
   103  | 
      }
  | 
| 
 | 
   104  | 
    }
  | 
| 
 | 
   105  | 
  }
  | 
| 
 | 
   106  | 
}
  |