src/Pure/Tools/dump.scala
author wenzelm
Sat, 29 Dec 2018 12:52:58 +0100
changeset 69532 e2edf24b960e
parent 69524 fa94f2b2a877
child 69533 1d2e6a4e073f
permissions -rw-r--r--
tuned;
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,
68365
f9379279f98c clarified signature: prefer Document.Snapshot;
wenzelm
parents: 68355
diff changeset
    17
    deps: Sessions.Deps,
68355
67a4db47e4f6 more args;
wenzelm
parents: 68348
diff changeset
    18
    output_dir: Path,
68929
10cbb5d99081 tuned signature;
wenzelm
parents: 68927
diff changeset
    19
    snapshot: Document.Snapshot,
10cbb5d99081 tuned signature;
wenzelm
parents: 68927
diff changeset
    20
    node_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())
68491
f0f83ce0badd disable export_document by default (presently unused and for demo/testing purposes): avoid spurious IO exception in highly parallel environment;
wenzelm
parents: 68416
diff changeset
    58
        }, options = List("editor_presentation", "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())
68347
9e6e7ab77434 more dump aspects, with options;
wenzelm
parents: 68345
diff changeset
    65
        }, options = List("editor_presentation", "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
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
    76
  /* session */
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
    77
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
    78
  def session(dump_options: Options, logic: String,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
    79
    consume: (Sessions.Deps, Document.Snapshot, Document_Status.Node_Status) => Unit,
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
    log: Logger = No_Logger,
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    82
    dirs: List[Path] = Nil,
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    83
    select_dirs: List[Path] = Nil,
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    84
    system_mode: Boolean = false,
69032
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
    85
    selection: Sessions.Selection = Sessions.Selection.empty): Boolean =
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    86
  {
68318
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
    87
    /* dependencies */
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
    88
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    89
    val deps =
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
    90
      Sessions.load_structure(dump_options, dirs = dirs, select_dirs = select_dirs).
69532
wenzelm
parents: 69524
diff changeset
    91
        selection_deps(dump_options, selection, progress = progress,
wenzelm
parents: 69524
diff changeset
    92
          uniform_session = true, loading_sessions = true)
68318
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
    93
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
    94
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
    95
    /* dump aspects asynchronously */
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
    96
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
    97
    object Consumer
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
    98
    {
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
    99
      private val consumer_ok = Synchronized(true)
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   100
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   101
      private val consumer =
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   102
        Consumer_Thread.fork(name = "dump")(
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   103
          consume = (args: (Document.Snapshot, Document_Status.Node_Status)) =>
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   104
            {
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   105
              val (snapshot, node_status) = args
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   106
              if (node_status.ok) consume(deps, snapshot, node_status)
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   107
              else {
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   108
                consumer_ok.change(_ => false)
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   109
                for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree)) {
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   110
                  val msg = XML.content(Pretty.formatted(List(tree)))
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   111
                  progress.echo_error_message("Error" + Position.here(pos) + ":\n" + msg)
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   112
                }
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   113
              }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   114
              true
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   115
            })
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   116
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   117
      def apply(snapshot: Document.Snapshot, node_status: Document_Status.Node_Status): Unit =
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   118
        consumer.send((snapshot, node_status))
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   119
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   120
      def shutdown(): Boolean =
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   121
      {
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   122
        consumer.shutdown()
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   123
        consumer_ok.value
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   124
      }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   125
    }
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   126
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   127
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   128
    /* run session */
68318
5971199863ea more accurate dependencies;
wenzelm
parents: 68316
diff changeset
   129
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   130
    val session =
69532
wenzelm
parents: 69524
diff changeset
   131
      Headless.start_session(dump_options, logic, progress = progress, log = log,
wenzelm
parents: 69524
diff changeset
   132
        session_dirs = dirs ::: select_dirs,
wenzelm
parents: 69524
diff changeset
   133
        include_sessions = deps.sessions_structure.imports_topological_order)
wenzelm
parents: 69524
diff changeset
   134
wenzelm
parents: 69524
diff changeset
   135
    val use_theories =
wenzelm
parents: 69524
diff changeset
   136
      for { (_, name) <- deps.used_theories_condition(dump_options, progress.echo_warning) }
wenzelm
parents: 69524
diff changeset
   137
      yield name.theory
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   138
69013
bb4e4c253ebe tuned signature;
wenzelm
parents: 69012
diff changeset
   139
    val use_theories_result =
69520
16779868de1f clarified defaults via system options;
wenzelm
parents: 69103
diff changeset
   140
      session.use_theories(use_theories, progress = progress, commit = Some(Consumer.apply _))
68926
5129fcc1b6c0 dump aspects asynchronously;
wenzelm
parents: 68899
diff changeset
   141
69032
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   142
    session.stop()
68320
1d33697199c1 shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents: 68319
diff changeset
   143
68930
19ddfe546620 clarified error progress and error_rc;
wenzelm
parents: 68929
diff changeset
   144
    val consumer_ok = Consumer.shutdown()
68320
1d33697199c1 shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents: 68319
diff changeset
   145
69032
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   146
    use_theories_result.nodes_pending match {
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   147
      case Nil =>
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   148
      case pending => error("Pending theories " + commas_quote(pending.map(p => p._1.toString)))
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   149
    }
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   150
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   151
    use_theories_result.ok && consumer_ok
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   152
  }
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   153
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   154
69523
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   155
  /* dump */
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   156
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   157
  val default_output_dir: Path = Path.explode("dump")
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   158
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   159
  def make_options(options: Options, aspects: List[Aspect] = Nil): Options =
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   160
  {
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   161
    val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   162
    val options1 =
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   163
      options0 + "completion_limit=0" + "ML_statistics=false" +
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   164
        "parallel_proofs=0" + "editor_tracing_messages=0"
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   165
    (options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) })
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   166
  }
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   167
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   168
  def dump(options: Options, logic: String,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   169
    aspects: List[Aspect] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   170
    progress: Progress = No_Progress,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   171
    log: Logger = No_Logger,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   172
    dirs: List[Path] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   173
    select_dirs: List[Path] = Nil,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   174
    output_dir: Path = default_output_dir,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   175
    system_mode: Boolean = false,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   176
    selection: Sessions.Selection = Sessions.Selection.empty): Boolean =
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   177
  {
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   178
    if (Build.build_logic(options, logic, build_heap = true, progress = progress,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   179
      dirs = dirs ::: select_dirs, system_mode = system_mode) != 0) error(logic + " FAILED")
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   180
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   181
    val dump_options = make_options(options, aspects)
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   182
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   183
    def consume(
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   184
      deps: Sessions.Deps,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   185
      snapshot: Document.Snapshot,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   186
      node_status: Document_Status.Node_Status)
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   187
    {
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   188
      val aspect_args = Aspect_Args(dump_options, progress, deps, output_dir, snapshot, node_status)
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   189
      aspects.foreach(_.operation(aspect_args))
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   190
    }
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   191
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   192
    session(dump_options, logic, consume _,
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   193
      progress = progress, log = log, dirs = dirs, select_dirs = select_dirs, selection = selection)
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   194
  }
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   195
9403ff523825 tuned signature: for other dump-like tools;
wenzelm
parents: 69522
diff changeset
   196
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   197
  /* Isabelle tool wrapper */
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   198
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   199
  val isabelle_tool =
68348
2ac3a5c07dfa documentation for "isabelle dump";
wenzelm
parents: 68347
diff changeset
   200
    Isabelle_Tool("dump", "dump cumulative PIDE session database", args =>
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   201
    {
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
   202
      var aspects: List[Aspect] = known_aspects
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   203
      var base_sessions: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   204
      var select_dirs: List[Path] = Nil
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   205
      var output_dir = default_output_dir
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   206
      var requirements = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   207
      var exclude_session_groups: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   208
      var all_sessions = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   209
      var dirs: List[Path] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   210
      var session_groups: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   211
      var logic = Isabelle_System.getenv("ISABELLE_LOGIC")
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   212
      var options = Options.init()
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   213
      var system_mode = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   214
      var verbose = false
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   215
      var exclude_sessions: List[String] = Nil
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   216
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   217
      val getopts = Getopts("""
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   218
Usage: isabelle dump [OPTIONS] [SESSIONS ...]
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   219
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   220
  Options are:
68345
5bc1e1ac7955 clarified default: all aspects;
wenzelm
parents: 68332
diff changeset
   221
    -A NAMES     dump named aspects (default: """ + known_aspects.mkString("\"", ",", "\"") + """)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   222
    -B NAME      include session NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   223
    -D DIR       include session directory and select its sessions
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   224
    -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
   225
    -R           operate on requirements of selected sessions
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   226
    -X NAME      exclude sessions from group NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   227
    -a           select all sessions
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   228
    -d DIR       include session directory
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   229
    -g NAME      select session group NAME
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   230
    -l NAME      logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """)
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   231
    -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
   232
    -s           system build mode for logic image
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   233
    -v           verbose
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   234
    -x NAME      exclude session NAME and all descendants
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   235
68348
2ac3a5c07dfa documentation for "isabelle dump";
wenzelm
parents: 68347
diff changeset
   236
  Dump cumulative PIDE session database, with the following aspects:
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   237
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   238
""" + Library.prefix_lines("    ", show_aspects) + "\n",
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   239
      "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
   240
      "B:" -> (arg => base_sessions = base_sessions ::: List(arg)),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   241
      "D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))),
68316
a1e5de3681f0 more formal dump aspects;
wenzelm
parents: 68308
diff changeset
   242
      "O:" -> (arg => output_dir = Path.explode(arg)),
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   243
      "R" -> (_ => requirements = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   244
      "X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   245
      "a" -> (_ => all_sessions = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   246
      "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
68741
wenzelm
parents: 68557
diff changeset
   247
      "g:" -> (arg => session_groups = session_groups ::: List(arg)),
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   248
      "l:" -> (arg => logic = arg),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   249
      "o:" -> (arg => options = options + arg),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   250
      "s" -> (_ => system_mode = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   251
      "v" -> (_ => verbose = true),
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   252
      "x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg)))
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   253
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   254
      val sessions = getopts(args)
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   255
68951
a7b1fe2d30ad more uniform Progress, with theory() for batch-build and theory_percentage() for PIDE session;
wenzelm
parents: 68948
diff changeset
   256
      val progress = new Console_Progress(verbose = verbose)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   257
69032
90bb4cabe1e8 clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents: 69026
diff changeset
   258
      val ok =
68331
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   259
        progress.interrupt_handler {
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   260
          dump(options, logic,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   261
            aspects = aspects,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   262
            progress = progress,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   263
            dirs = dirs,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   264
            select_dirs = select_dirs,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   265
            output_dir = output_dir,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   266
            selection = Sessions.Selection(
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   267
              requirements = requirements,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   268
              all_sessions = all_sessions,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   269
              base_sessions = base_sessions,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   270
              exclude_session_groups = exclude_session_groups,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   271
              exclude_sessions = exclude_sessions,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   272
              session_groups = session_groups,
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   273
              sessions = sessions))
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68330
diff changeset
   274
        }
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   275
69033
c5db368833b1 proper return code for runtime failure;
wenzelm
parents: 69032
diff changeset
   276
      if (!ok) sys.exit(2)
68308
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   277
    })
119fc05f6b00 support to dump build database produced by PIDE session;
wenzelm
parents:
diff changeset
   278
}