src/Pure/PIDE/document_editor.scala
author wenzelm
Sun, 19 May 2024 18:43:45 +0200
changeset 80181 aa92c0f96036
parent 77202 064566bc1f35
permissions -rw-r--r--
provide scala-3.4.2, but do not activate it: scala-3.3.x is LTS version;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/PIDE/document_editor.scala
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     3
76730
1b8dd8c0492f tuned comments;
wenzelm
parents: 76716
diff changeset
     4
Central resources and configuration for interactive document preparation.
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     6
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     8
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
     9
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    10
import scala.collection.immutable.SortedSet
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    11
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    12
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    13
object Document_Editor {
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    14
  /* document output */
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    15
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    16
  def document_name: String = "document"
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    17
  def document_output_dir(): Path = Path.explode("$ISABELLE_HOME_USER/document_output")
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    18
  def document_output(name: String): Path = document_output_dir() + Path.basic(name)
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    19
77202
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
    20
  object Meta_Info {
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
    21
    def read(name: String = document_name): Option[Meta_Info] = {
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    22
      val json_path = document_output(name).json
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    23
      if (json_path.is_file) {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    24
        val json = JSON.parse(File.read(json_path))
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    25
        for {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    26
          selection <- JSON.list(json, "selection", JSON.Value.String.unapply)
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    27
          sources <- JSON.string(json, "sources")
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    28
          log <- JSON.string(json, "log")
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    29
          pdf <- JSON.string(json, "pdf")
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    30
        } yield {
77202
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
    31
          Meta_Info(name,
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    32
            SortedSet.from(selection),
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    33
            SHA1.fake_digest(sources),
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    34
            SHA1.fake_digest(log),
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    35
            SHA1.fake_digest(pdf))
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    36
        }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    37
      }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    38
      else None
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    39
    }
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    40
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    41
    def write(
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    42
      selection: SortedSet[String],
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    43
      doc: Document_Build.Document_Output,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    44
      name: String = document_name
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    45
    ): Unit = {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    46
      val json =
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    47
        JSON.Object(
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    48
          "selection" -> selection.toList,
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    49
          "sources" -> doc.sources.toString,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    50
          "log" -> SHA1.digest(doc.log).toString,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    51
          "pdf" -> SHA1.digest(doc.pdf).toString)
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    52
      File.write(document_output(name).json, JSON.Format.pretty_print(json))
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    53
    }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    54
  }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    55
77202
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
    56
  sealed case class Meta_Info(
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    57
    name: String,
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    58
    selection: SortedSet[String],
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    59
    sources: SHA1.Digest,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    60
    log: SHA1.Digest,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    61
    pdf: SHA1.Digest
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    62
  ) {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    63
    def check_files(): Boolean = {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    64
      val path = document_output(name)
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    65
      path.log.is_file &&
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    66
      path.pdf.is_file &&
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    67
      log == SHA1.digest(File.read(path.log)) &&
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    68
      pdf == SHA1.digest(path.pdf)
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    69
    }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    70
  }
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    71
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    72
  def write_document(
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    73
    selection: SortedSet[String],
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    74
    doc: Document_Build.Document_Output,
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    75
    name: String = document_name
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    76
  ): Unit = {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    77
    val output = document_output(name)
77184
861777e58b77 clarified modules;
wenzelm
parents: 77161
diff changeset
    78
    File.write(output.log, doc.log)
861777e58b77 clarified modules;
wenzelm
parents: 77161
diff changeset
    79
    Bytes.write(output.pdf, doc.pdf)
77202
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
    80
    Meta_Info.write(selection, doc, name = name)
77184
861777e58b77 clarified modules;
wenzelm
parents: 77161
diff changeset
    81
  }
861777e58b77 clarified modules;
wenzelm
parents: 77161
diff changeset
    82
77185
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    83
  def view_document(name: String = document_name): Unit = {
9dc4d9ed886f maintain document_output meta data;
wenzelm
parents: 77184
diff changeset
    84
    val path = document_output(name).pdf
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    85
    if (path.is_file) Isabelle_System.pdf_viewer(path)
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    86
  }
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    87
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
    88
76730
1b8dd8c0492f tuned comments;
wenzelm
parents: 76716
diff changeset
    89
  /* configuration state */
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    90
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    91
  sealed case class Session(
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    92
    background: Option[Sessions.Background],
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
    93
    selection: SortedSet[String],
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    94
    snapshot: Option[Document.Snapshot]
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    95
  ) {
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    96
    def is_vacuous: Boolean = background.isEmpty
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    97
    def is_pending: Boolean = snapshot.isEmpty
77149
3991a35cd740 automatically build document when selected theories are finished;
wenzelm
parents: 77147
diff changeset
    98
    def is_ready: Boolean = background.isDefined && snapshot.isDefined
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
    99
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   100
    def get_background: Sessions.Background = background.get
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   101
    def get_variant: Document_Build.Document_Variant = get_background.info.documents.head
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   102
    def get_snapshot: Document.Snapshot = snapshot.get
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   103
  }
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   104
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   105
  sealed case class State(
76678
f34b923ff2c9 clarified signature;
wenzelm
parents: 76610
diff changeset
   106
    session_background: Option[Sessions.Background] = None,
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   107
    selection: SortedSet[String] = SortedSet.empty,
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   108
    views: Set[AnyRef] = Set.empty,
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   109
  ) {
76678
f34b923ff2c9 clarified signature;
wenzelm
parents: 76610
diff changeset
   110
    def is_active: Boolean = session_background.isDefined && views.nonEmpty
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   111
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   112
    def all_document_theories: List[Document.Node.Name] =
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   113
      session_background match {
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   114
        case Some(background) => background.base.all_document_theories
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   115
        case None => Nil
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   116
      }
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   117
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
   118
    def active_document_theories: List[Document.Node.Name] =
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
   119
      if (is_active) all_document_theories else Nil
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76715
diff changeset
   120
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   121
    def select(
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   122
      theories: Iterable[String],
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   123
      set: Boolean = false,
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   124
      toggle: Boolean = false
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   125
    ): State = {
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   126
      copy(selection =
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   127
        theories.foldLeft(selection) {
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   128
          case (sel, theory) =>
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   129
            val b = if (toggle) !selection(theory) else set
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   130
            if (b) sel + theory else sel - theory
76715
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   131
        })
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   132
    }
bf5ff407f32f clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents: 76678
diff changeset
   133
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   134
    def register_view(id: AnyRef): State = copy(views = views + id)
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   135
    def unregister_view(id: AnyRef): State = copy(views = views - id)
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   136
77161
913c781ff6ba support document preparation from already loaded theories;
wenzelm
parents: 77149
diff changeset
   137
    def session(pide_session: isabelle.Session): Session = {
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   138
      val background = session_background.filter(_.info.documents.nonEmpty)
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   139
      val snapshot =
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   140
        if (background.isEmpty) None
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   141
        else {
77161
913c781ff6ba support document preparation from already loaded theories;
wenzelm
parents: 77149
diff changeset
   142
          val snapshot = pide_session.snapshot()
77197
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   143
          def document_ready(theory: String): Boolean =
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   144
            pide_session.resources.session_base.loaded_theory(theory) ||
a541da01ba67 clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents: 77195
diff changeset
   145
            snapshot.theory_consolidated(theory)
77161
913c781ff6ba support document preparation from already loaded theories;
wenzelm
parents: 77149
diff changeset
   146
          if (snapshot.is_outdated || !selection.forall(document_ready)) None
77147
38077c938d01 defer build until document nodes are ready;
wenzelm
parents: 77144
diff changeset
   147
          else Some(snapshot)
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   148
        }
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   149
      Session(background, selection, snapshot)
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 76994
diff changeset
   150
    }
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
   151
  }
77195
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   152
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   153
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   154
  /* build */
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   155
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   156
  def build(
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   157
    session_context: Export.Session_Context,
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   158
    document_session: Document_Editor.Session,
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   159
    progress: Progress
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   160
  ): Unit = {
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   161
    val session_background = document_session.get_background
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   162
    val context =
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   163
      Document_Build.context(session_context,
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   164
        document_session = Some(session_background.base),
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   165
        document_selection = document_session.selection,
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   166
        progress = progress)
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   167
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   168
    Isabelle_System.make_directory(document_output_dir())
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   169
    Isabelle_System.with_tmp_dir("document") { tmp_dir =>
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   170
      val engine = context.get_engine()
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   171
      val variant = document_session.get_variant
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   172
      val directory = engine.prepare_directory(context, tmp_dir, variant, verbose = true)
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   173
      val ok =
77202
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
   174
        Meta_Info.read() match {
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
   175
          case Some(meta_info) =>
064566bc1f35 clarified signature: follow terminology of isabelle.Sessions and isabelle.Build;
wenzelm
parents: 77197
diff changeset
   176
            meta_info.check_files() && meta_info.sources == directory.sources
77195
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   177
          case None => false
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   178
        }
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   179
      if (!ok) {
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   180
        write_document(document_session.selection,
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   181
          engine.build_document(context, directory, verbose = true))
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   182
      }
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   183
    }
e312c7fa3bad clarified modules;
wenzelm
parents: 77185
diff changeset
   184
  }
76606
3558388330f8 clarified modules;
wenzelm
parents:
diff changeset
   185
}