src/Pure/Tools/dump.scala
author wenzelm
Mon, 18 Mar 2019 21:06:26 +0100
changeset 69920 79c8ff387ed1
parent 69897 a9849222844d
child 70623 44090b702e11
permissions -rw-r--r--
support unicode_symbols in input source;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/dump.scala
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     3
68348
2ac3a5c07dfa documentation for "isabelle dump";
wenzelm
parents: 68347
diff changeset
     4
Dump cumulative PIDE session database.
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     5
*/
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     6
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     7
package isabelle
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     8
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
     9
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    10
object Dump
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    11
{
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    12
  /* aspects */
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    13
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    14
  sealed case class Aspect_Args(
68355
67a4db47e4f6 more args;
wenzelm
parents: 68348
diff changeset
    15
    options: Options,
67a4db47e4f6 more args;
wenzelm
parents: 68348
diff changeset
    16
    progress: Progress,
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
    17
    output_dir: Path,
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    18
    deps: Sessions.Deps,
68929
10cbb5d99081 tuned signature;
wenzelm
parents: 68927
diff changeset
    19
    snapshot: Document.Snapshot,
69534
913970ae2324 tuned, according to Isabelle/MMT;
wenzelm
parents: 69533
diff changeset
    20
    status: Document_Status.Node_Status)
68319
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    21
  {
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    22
    def write(file_name: Path, bytes: Bytes)
68319
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    23
    {
68929
10cbb5d99081 tuned signature;
wenzelm
parents: 68927
diff changeset
    24
      val path = output_dir + Path.basic(snapshot.node_name.theory) + file_name
68319
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    25
      Isabelle_System.mkdirs(path.dir)
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    26
      Bytes.write(path, bytes)
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    27
    }
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    28
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    29
    def write(file_name: Path, text: String): Unit =
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    30
      write(file_name, Bytes(text))
68332
7cb681615d0e store Isabelle symbols in canonical form;
wenzelm
parents: 68331
diff changeset
    31
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    32
    def write(file_name: Path, body: XML.Body): Unit =
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    33
      write(file_name, Symbol.encode(YXML.string_of_body(body)))
68319
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    34
  }
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    35
68347
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    36
  sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit,
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    37
    options: List[String] = Nil)
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
    38
  {
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
    39
    override def toString: String = name
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
    40
  }
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    41
69521
wenzelm
parents: 69520
diff changeset
    42
  val known_aspects: List[Aspect] =
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    43
    List(
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    44
      Aspect("markup", "PIDE markup (YXML format)",
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    45
        { case args =>
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    46
            args.write(Path.explode("markup.yxml"),
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    47
              args.snapshot.markup_to_XML(Text.Range.full, Markup.Elements.full))
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    48
        }),
68319
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    49
      Aspect("messages", "output messages (YXML format)",
2e168460a9c3 more operations;
wenzelm
parents: 68318
diff changeset
    50
        { case args =>
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    51
            args.write(Path.explode("messages.yxml"),
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    52
              args.snapshot.messages.iterator.map(_._1).toList)
68347
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    53
        }),
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    54
      Aspect("latex", "generated LaTeX source",
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    55
        { case args =>
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    56
            for (entry <- args.snapshot.exports if entry.name == "document.tex")
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    57
              args.write(Path.explode(entry.name), entry.uncompressed())
69533
1d2e6a4e073f clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
wenzelm
parents: 69532
diff changeset
    58
        }, options = List("export_document")),
68347
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    59
      Aspect("theory", "foundational theory content",
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    60
        { case args =>
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    61
            for {
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    62
              entry <- args.snapshot.exports
68347
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    63
              if entry.name.startsWith(Export_Theory.export_prefix)
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    64
            } args.write(Path.explode(entry.name), entry.uncompressed())
69533
1d2e6a4e073f clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
wenzelm
parents: 69532
diff changeset
    65
        }, options = List("export_theory"))
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
    66
    ).sortBy(_.name)
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    67
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    68
  def show_aspects: String =
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
    69
    cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description))
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    70
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    71
  def the_aspect(name: String): Aspect =
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    72
    known_aspects.find(aspect => aspect.name == name) getOrElse
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    73
      error("Unknown aspect " + quote(name))
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    74
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    75
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
    76
  /* dependencies */
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    77
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
    78
  def dependencies(
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
    79
    options: Options,
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    80
    progress: Progress = No_Progress,
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    81
    dirs: List[Path] = Nil,
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    82
    select_dirs: List[Path] = Nil,
69856
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
    83
    selection: Sessions.Selection = Sessions.Selection.empty): Sessions.Deps =
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    84
  {
69856
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
    85
    Sessions.load_structure(options, dirs = dirs, select_dirs = select_dirs).
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
    86
      selection_deps(options, selection, progress = progress,
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
    87
        uniform_session = true, loading_sessions = true)
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
    88
  }
68318
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
    89
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
    90
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
    91
  /* session */
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
    92
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
    93
  sealed case class Args(
69897
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
    94
    session: Headless.Session,
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
    95
    deps: Sessions.Deps,
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
    96
    snapshot: Document.Snapshot,
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
    97
    status: Document_Status.Node_Status)
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
    98
  {
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
    99
    def print_node: String = snapshot.node_name.toString
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   100
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   101
    def aspect_args(options: Options, progress: Progress, output_dir: Path): Aspect_Args =
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   102
      Aspect_Args(options, progress, output_dir, deps, snapshot, status)
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   103
  }
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   104
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   105
  def session(
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   106
    deps: Sessions.Deps,
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   107
    resources: Headless.Resources,
69920
79c8ff387ed1 support unicode_symbols in input source;
wenzelm
parents: 69897
diff changeset
   108
    unicode_symbols: Boolean = false,
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   109
    process_theory: Args => Unit,
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   110
    progress: Progress = No_Progress)
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   111
  {
69897
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
   112
    val session = resources.start_session(progress = progress)
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
   113
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
   114
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   115
    /* asynchronous consumer */
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   116
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   117
    object Consumer
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   118
    {
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   119
      sealed case class Bad_Theory(
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   120
        name: Document.Node.Name,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   121
        status: Document_Status.Node_Status,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   122
        errors: List[String])
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   123
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   124
      private val consumer_bad_theories = Synchronized(List.empty[Bad_Theory])
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   125
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   126
      private val consumer =
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   127
        Consumer_Thread.fork(name = "dump")(
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   128
          consume = (args: (Document.Snapshot, Document_Status.Node_Status)) =>
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   129
            {
69534
913970ae2324 tuned, according to Isabelle/MMT;
wenzelm
parents: 69533
diff changeset
   130
              val (snapshot, status) = args
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   131
              val name = snapshot.node_name
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   132
              if (status.ok) {
69897
a9849222844d tuned signature;
wenzelm
parents: 69896
diff changeset
   133
                try { process_theory(Args(session, deps, snapshot, status)) }
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   134
                catch {
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   135
                  case exn: Throwable if !Exn.is_interrupt(exn) =>
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   136
                  val msg = Exn.message(exn)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   137
                  progress.echo("FAILED to process theory " + name)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   138
                  progress.echo_error_message(msg)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   139
                  consumer_bad_theories.change(Bad_Theory(name, status, List(msg)) :: _)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   140
                }
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   141
              }
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   142
              else {
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   143
                val msgs =
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   144
                  for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree))
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   145
                  yield {
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   146
                    "Error" + Position.here(pos) + ":\n" +
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   147
                      XML.content(Pretty.formatted(List(tree)))
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   148
                  }
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   149
                progress.echo("FAILED to process theory " + name)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   150
                msgs.foreach(progress.echo_error_message)
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   151
                consumer_bad_theories.change(Bad_Theory(name, status, msgs) :: _)
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   152
              }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   153
              true
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   154
            })
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   155
69534
913970ae2324 tuned, according to Isabelle/MMT;
wenzelm
parents: 69533
diff changeset
   156
      def apply(snapshot: Document.Snapshot, status: Document_Status.Node_Status): Unit =
913970ae2324 tuned, according to Isabelle/MMT;
wenzelm
parents: 69533
diff changeset
   157
        consumer.send((snapshot, status))
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   158
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   159
      def shutdown(): List[Bad_Theory] =
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   160
      {
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   161
        consumer.shutdown()
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   162
        consumer_bad_theories.value.reverse
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   163
      }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   164
    }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   165
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   166
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   167
    /* run session */
68318
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
   168
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   169
    try {
69857
a4b430ad848a clarified signature;
wenzelm
parents: 69856
diff changeset
   170
      val use_theories = resources.used_theories(deps).map(_.theory)
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   171
      val use_theories_result =
69920
79c8ff387ed1 support unicode_symbols in input source;
wenzelm
parents: 69897
diff changeset
   172
        session.use_theories(use_theories,
79c8ff387ed1 support unicode_symbols in input source;
wenzelm
parents: 69897
diff changeset
   173
          unicode_symbols = unicode_symbols,
79c8ff387ed1 support unicode_symbols in input source;
wenzelm
parents: 69897
diff changeset
   174
          progress = progress,
79c8ff387ed1 support unicode_symbols in input source;
wenzelm
parents: 69897
diff changeset
   175
          commit = Some(Consumer.apply _))
68320
1d33697199c1 shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents: 68319
diff changeset
   176
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   177
      val bad_theories = Consumer.shutdown()
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   178
      val bad_msgs =
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   179
        bad_theories.map(bad =>
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   180
          Output.clean_yxml(
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   181
            "FAILED theory " + bad.name +
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   182
              (if (bad.status.consolidated) "" else ": " + bad.status.percentage + "% finished") +
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   183
              (if (bad.errors.isEmpty) "" else bad.errors.mkString("\n", "\n", ""))))
68320
1d33697199c1 shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents: 68319
diff changeset
   184
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   185
      val pending_msgs =
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   186
        use_theories_result.nodes_pending match {
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   187
          case Nil => Nil
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   188
          case pending => List("Pending theories: " + commas(pending.map(p => p._1.toString)))
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   189
        }
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   190
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   191
      val errors = bad_msgs ::: pending_msgs
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   192
      if (errors.nonEmpty) error(errors.mkString("\n\n"))
69032
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   193
    }
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   194
    finally { session.stop() }
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   195
  }
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   196
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   197
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   198
  /* dump */
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   199
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   200
  val default_output_dir: Path = Path.explode("dump")
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   201
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   202
  def make_options(options: Options, aspects: List[Aspect] = Nil): Options =
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   203
  {
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   204
    val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   205
    val options1 =
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   206
      options0 + "completion_limit=0" + "ML_statistics=false" +
69533
1d2e6a4e073f clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
wenzelm
parents: 69532
diff changeset
   207
        "parallel_proofs=0" + "editor_tracing_messages=0" + "editor_presentation"
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   208
    (options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) })
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   209
  }
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   210
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   211
  def dump(options: Options, logic: String,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   212
    aspects: List[Aspect] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   213
    progress: Progress = No_Progress,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   214
    log: Logger = No_Logger,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   215
    dirs: List[Path] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   216
    select_dirs: List[Path] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   217
    output_dir: Path = default_output_dir,
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   218
    selection: Sessions.Selection = Sessions.Selection.empty)
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   219
  {
69540
a1e8bcda8cec tuned signature;
wenzelm
parents: 69538
diff changeset
   220
    Build.build_logic(options, logic, build_heap = true, progress = progress,
69854
cc0b3e177b49 system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents: 69571
diff changeset
   221
      dirs = dirs ::: select_dirs, strict = true)
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   222
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   223
    val dump_options = make_options(options, aspects)
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   224
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   225
    val deps =
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   226
      dependencies(dump_options, progress = progress,
69856
bb41977edb7e tuned signature;
wenzelm
parents: 69854
diff changeset
   227
        dirs = dirs, select_dirs = select_dirs, selection = selection)
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   228
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   229
    val resources =
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   230
      Headless.Resources.make(dump_options, logic, progress = progress, log = log,
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   231
        session_dirs = dirs ::: select_dirs,
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   232
        include_sessions = deps.sessions_structure.imports_topological_order)
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   233
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   234
    session(deps, resources, progress = progress,
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   235
      process_theory = (args: Args) =>
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   236
        {
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   237
          progress.echo("Processing theory " + args.print_node + " ...")
69571
676182f2e375 tuned messages;
wenzelm
parents: 69540
diff changeset
   238
69896
be7243b97c41 tuned signature;
wenzelm
parents: 69857
diff changeset
   239
          val aspect_args = args.aspect_args(dump_options, progress, output_dir)
69538
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   240
          aspects.foreach(_.operation(aspect_args))
faf547d2834c clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents: 69537
diff changeset
   241
        })
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   242
  }
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   243
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   244
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   245
  /* Isabelle tool wrapper */
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   246
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   247
  val isabelle_tool =
68348
2ac3a5c07dfa documentation for "isabelle dump";
wenzelm
parents: 68347
diff changeset
   248
    Isabelle_Tool("dump", "dump cumulative PIDE session database", args =>
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   249
    {
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
   250
      var aspects: List[Aspect] = known_aspects
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   251
      var base_sessions: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   252
      var select_dirs: List[Path] = Nil
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   253
      var output_dir = default_output_dir
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   254
      var requirements = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   255
      var exclude_session_groups: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   256
      var all_sessions = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   257
      var dirs: List[Path] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   258
      var session_groups: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   259
      var logic = Isabelle_System.getenv("ISABELLE_LOGIC")
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   260
      var options = Options.init()
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   261
      var verbose = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   262
      var exclude_sessions: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   263
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   264
      val getopts = Getopts("""
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   265
Usage: isabelle dump [OPTIONS] [SESSIONS ...]
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   266
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   267
  Options are:
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
   268
    -A NAMES     dump named aspects (default: """ + known_aspects.mkString("\"", ",", "\"") + """)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   269
    -B NAME      include session NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   270
    -D DIR       include session directory and select its sessions
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   271
    -O DIR       output directory for dumped files (default: """ + default_output_dir + """)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   272
    -R           operate on requirements of selected sessions
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   273
    -X NAME      exclude sessions from group NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   274
    -a           select all sessions
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   275
    -d DIR       include session directory
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   276
    -g NAME      select session group NAME
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   277
    -l NAME      logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """)
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   278
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   279
    -v           verbose
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   280
    -x NAME      exclude session NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   281
68348
2ac3a5c07dfa documentation for "isabelle dump";
wenzelm
parents: 68347
diff changeset
   282
  Dump cumulative PIDE session database, with the following aspects:
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   283
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   284
""" + Library.prefix_lines("    ", show_aspects) + "\n",
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   285
      "A:" -> (arg => aspects = Library.distinct(space_explode(',', arg)).map(the_aspect(_))),
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   286
      "B:" -> (arg => base_sessions = base_sessions ::: List(arg)),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   287
      "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))),
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   288
      "O:" -> (arg => output_dir = Path.explode(arg)),
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   289
      "R" -> (_ => requirements = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   290
      "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   291
      "a" -> (_ => all_sessions = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   292
      "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
68741
wenzelm
parents: 68557
diff changeset
   293
      "g:" -> (arg => session_groups = session_groups ::: List(arg)),
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   294
      "l:" -> (arg => logic = arg),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   295
      "o:" -> (arg => options = options + arg),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   296
      "v" -> (_ => verbose = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   297
      "x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg)))
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   298
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   299
      val sessions = getopts(args)
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   300
68951
a7b1fe2d30ad more uniform Progress, with theory() for batch-build and theory_percentage() for PIDE session;
wenzelm
parents: 68948
diff changeset
   301
      val progress = new Console_Progress(verbose = verbose)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   302
69535
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   303
      progress.interrupt_handler {
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   304
        dump(options, logic,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   305
          aspects = aspects,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   306
          progress = progress,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   307
          dirs = dirs,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   308
          select_dirs = select_dirs,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   309
          output_dir = output_dir,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   310
          selection = Sessions.Selection(
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   311
            requirements = requirements,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   312
            all_sessions = all_sessions,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   313
            base_sessions = base_sessions,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   314
            exclude_session_groups = exclude_session_groups,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   315
            exclude_sessions = exclude_sessions,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   316
            session_groups = session_groups,
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   317
            sessions = sessions))
e3a9680d9ed8 clarified errors, according to Isabelle/MMT;
wenzelm
parents: 69534
diff changeset
   318
      }
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   319
    })
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   320
}