src/Pure/Thy/export.scala
author wenzelm
Sat, 10 Aug 2019 12:53:35 +0200
changeset 70499 f389019024ce
parent 69854 cc0b3e177b49
child 70539 30b3c58a1933
permissions -rw-r--r--
allow duplicate exports via strict = false;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/export.scala
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     3
68102
813b5d0904c6 clarified signature;
wenzelm
parents: 68101
diff changeset
     4
Manage theory exports: compressed blobs.
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     5
*/
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     6
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     7
package isabelle
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
     8
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
     9
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    10
import scala.annotation.tailrec
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    11
import scala.util.matching.Regex
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    12
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    13
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    14
object Export
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    15
{
69756
1907222d974e clarified modules;
wenzelm
parents: 69671
diff changeset
    16
  /* name structure */
69634
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    17
69756
1907222d974e clarified modules;
wenzelm
parents: 69671
diff changeset
    18
  def explode_name(s: String): List[String] = space_explode('/', s)
1907222d974e clarified modules;
wenzelm
parents: 69671
diff changeset
    19
  def implode_name(elems: Iterable[String]): String = elems.mkString("/")
69634
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    20
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    21
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    22
  /* SQL data model */
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    23
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    24
  object Data
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    25
  {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    26
    val session_name = SQL.Column.string("session_name").make_primary_key
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    27
    val theory_name = SQL.Column.string("theory_name").make_primary_key
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    28
    val name = SQL.Column.string("name").make_primary_key
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
    29
    val executable = SQL.Column.bool("executable")
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    30
    val compressed = SQL.Column.bool("compressed")
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    31
    val body = SQL.Column.bytes("body")
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    32
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    33
    val table =
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
    34
      SQL.Table("isabelle_exports",
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
    35
        List(session_name, theory_name, name, executable, compressed, body))
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    36
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    37
    def where_equal(session_name: String, theory_name: String = "", name: String = ""): SQL.Source =
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    38
      "WHERE " + Data.session_name.equal(session_name) +
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    39
        (if (theory_name == "") "" else " AND " + Data.theory_name.equal(theory_name)) +
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    40
        (if (name == "") "" else " AND " + Data.name.equal(name))
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    41
  }
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    42
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    43
  def read_name(db: SQL.Database, session_name: String, theory_name: String, name: String): Boolean =
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    44
  {
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    45
    val select =
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    46
      Data.table.select(List(Data.name), Data.where_equal(session_name, theory_name, name))
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    47
    db.using_statement(select)(stmt => stmt.execute_query().next())
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    48
  }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    49
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    50
  def read_names(db: SQL.Database, session_name: String, theory_name: String): List[String] =
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    51
  {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    52
    val select = Data.table.select(List(Data.name), Data.where_equal(session_name, theory_name))
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    53
    db.using_statement(select)(stmt =>
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    54
      stmt.execute_query().iterator(res => res.string(Data.name)).toList)
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    55
  }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    56
68222
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    57
  def read_theory_names(db: SQL.Database, session_name: String): List[String] =
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    58
  {
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    59
    val select =
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    60
      Data.table.select(List(Data.theory_name), Data.where_equal(session_name), distinct = true)
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    61
    db.using_statement(select)(stmt =>
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    62
      stmt.execute_query().iterator(_.string(Data.theory_name)).toList)
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    63
  }
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    64
3c1a716e7f59 tuned queries;
wenzelm
parents: 68221
diff changeset
    65
  def read_theory_exports(db: SQL.Database, session_name: String): List[(String, String)] =
68115
23c6ae3dd3a0 more efficient query;
wenzelm
parents: 68104
diff changeset
    66
  {
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    67
    val select = Data.table.select(List(Data.theory_name, Data.name), Data.where_equal(session_name))
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    68
    db.using_statement(select)(stmt =>
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    69
      stmt.execute_query().iterator(res =>
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    70
        (res.string(Data.theory_name), res.string(Data.name))).toList)
68115
23c6ae3dd3a0 more efficient query;
wenzelm
parents: 68104
diff changeset
    71
  }
23c6ae3dd3a0 more efficient query;
wenzelm
parents: 68104
diff changeset
    72
68104
wenzelm
parents: 68103
diff changeset
    73
  def message(msg: String, theory_name: String, name: String): String =
wenzelm
parents: 68103
diff changeset
    74
    msg + " " + quote(name) + " for theory " + quote(theory_name)
wenzelm
parents: 68103
diff changeset
    75
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    76
  def compound_name(a: String, b: String): String = a + ":" + b
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
    77
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    78
  sealed case class Entry(
68103
c5764b8b2a87 more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents: 68102
diff changeset
    79
    session_name: String,
c5764b8b2a87 more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents: 68102
diff changeset
    80
    theory_name: String,
c5764b8b2a87 more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents: 68102
diff changeset
    81
    name: String,
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
    82
    executable: Boolean,
68167
327bb0f5f768 clarified implicit compression;
wenzelm
parents: 68166
diff changeset
    83
    body: Future[(Boolean, Bytes)])
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    84
  {
69635
95dc926fa39c clarified output (again);
wenzelm
parents: 69634
diff changeset
    85
    override def toString: String = name
69630
aaa0b5f571e8 clarified output;
wenzelm
parents: 69629
diff changeset
    86
69634
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    87
    val name_elems: List[String] = explode_name(name)
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    88
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    89
    def name_extends(elems: List[String]): Boolean =
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    90
      name_elems.startsWith(elems) && name_elems != elems
70f1994988d4 more operations;
wenzelm
parents: 69630
diff changeset
    91
69630
aaa0b5f571e8 clarified output;
wenzelm
parents: 69629
diff changeset
    92
    def text: String = uncompressed().text
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
    93
69629
wenzelm
parents: 68924
diff changeset
    94
    def uncompressed(cache: XZ.Cache = XZ.cache()): Bytes =
wenzelm
parents: 68924
diff changeset
    95
    {
wenzelm
parents: 68924
diff changeset
    96
      val (compressed, bytes) = body.join
wenzelm
parents: 68924
diff changeset
    97
      if (compressed) bytes.uncompress(cache = cache) else bytes
wenzelm
parents: 68924
diff changeset
    98
    }
wenzelm
parents: 68924
diff changeset
    99
wenzelm
parents: 68924
diff changeset
   100
    def uncompressed_yxml(cache: XZ.Cache = XZ.cache()): XML.Body =
wenzelm
parents: 68924
diff changeset
   101
      YXML.parse_body(UTF8.decode_permissive(uncompressed(cache = cache)))
wenzelm
parents: 68924
diff changeset
   102
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   103
    def write(db: SQL.Database)
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   104
    {
68167
327bb0f5f768 clarified implicit compression;
wenzelm
parents: 68166
diff changeset
   105
      val (compressed, bytes) = body.join
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   106
      db.using_statement(Data.table.insert())(stmt =>
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   107
      {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   108
        stmt.string(1) = session_name
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   109
        stmt.string(2) = theory_name
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   110
        stmt.string(3) = name
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   111
        stmt.bool(4) = executable
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   112
        stmt.bool(5) = compressed
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   113
        stmt.bytes(6) = bytes
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   114
        stmt.execute()
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   115
      })
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   116
    }
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   117
  }
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   118
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   119
  def make_regex(pattern: String): Regex =
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   120
  {
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   121
    @tailrec def make(result: List[String], depth: Int, chs: List[Char]): Regex =
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   122
      chs match {
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   123
        case '*' :: '*' :: rest => make("[^:]*" :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   124
        case '*' :: rest => make("[^:/]*" :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   125
        case '?' :: rest => make("[^:/]" :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   126
        case '\\' :: c :: rest => make(("\\" + c) :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   127
        case '{' :: rest => make("(" :: result, depth + 1, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   128
        case ',' :: rest if depth > 0 => make("|" :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   129
        case '}' :: rest if depth > 0 => make(")" :: result, depth - 1, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   130
        case c :: rest if ".+()".contains(c) => make(("\\" + c) :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   131
        case c :: rest => make(c.toString :: result, depth, rest)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   132
        case Nil => result.reverse.mkString.r
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   133
      }
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   134
    make(Nil, 0, pattern.toList)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   135
  }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   136
68151
wenzelm
parents: 68116
diff changeset
   137
  def make_matcher(pattern: String): (String, String) => Boolean =
wenzelm
parents: 68116
diff changeset
   138
  {
wenzelm
parents: 68116
diff changeset
   139
    val regex = make_regex(pattern)
wenzelm
parents: 68116
diff changeset
   140
    (theory_name: String, name: String) =>
wenzelm
parents: 68116
diff changeset
   141
      regex.pattern.matcher(compound_name(theory_name, name)).matches
wenzelm
parents: 68116
diff changeset
   142
  }
wenzelm
parents: 68116
diff changeset
   143
68166
021c6fecaf5c tuned -- use XZ.Cache;
wenzelm
parents: 68151
diff changeset
   144
  def make_entry(session_name: String, args: Markup.Export.Args, body: Bytes,
021c6fecaf5c tuned -- use XZ.Cache;
wenzelm
parents: 68151
diff changeset
   145
    cache: XZ.Cache = XZ.cache()): Entry =
68101
0699a0bacc50 store exports within PIDE command state;
wenzelm
parents: 68092
diff changeset
   146
  {
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   147
    Entry(session_name, args.theory_name, args.name, args.executable,
68167
327bb0f5f768 clarified implicit compression;
wenzelm
parents: 68166
diff changeset
   148
      if (args.compress) Future.fork(body.maybe_compress(cache = cache))
327bb0f5f768 clarified implicit compression;
wenzelm
parents: 68166
diff changeset
   149
      else Future.value((false, body)))
68101
0699a0bacc50 store exports within PIDE command state;
wenzelm
parents: 68092
diff changeset
   150
  }
0699a0bacc50 store exports within PIDE command state;
wenzelm
parents: 68092
diff changeset
   151
68202
a99180ad3441 clarified signature;
wenzelm
parents: 68171
diff changeset
   152
  def read_entry(db: SQL.Database, session_name: String, theory_name: String, name: String)
a99180ad3441 clarified signature;
wenzelm
parents: 68171
diff changeset
   153
    : Option[Entry] =
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   154
  {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   155
    val select =
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   156
      Data.table.select(List(Data.executable, Data.compressed, Data.body),
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   157
        Data.where_equal(session_name, theory_name, name))
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   158
    db.using_statement(select)(stmt =>
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   159
    {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   160
      val res = stmt.execute_query()
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   161
      if (res.next()) {
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   162
        val executable = res.bool(Data.executable)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   163
        val compressed = res.bool(Data.compressed)
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   164
        val body = res.bytes(Data.body)
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   165
        Some(Entry(session_name, theory_name, name, executable, Future.value(compressed, body)))
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   166
      }
68202
a99180ad3441 clarified signature;
wenzelm
parents: 68171
diff changeset
   167
      else None
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   168
    })
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   169
  }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   170
68831
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   171
  def read_entry(dir: Path, session_name: String, theory_name: String, name: String): Option[Entry] =
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   172
  {
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   173
    val path = dir + Path.basic(theory_name) + Path.explode(name)
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   174
    if (path.is_file) {
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   175
      val executable = File.is_executable(path)
68831
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   176
      val uncompressed = Bytes.read(path)
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69756
diff changeset
   177
      Some(Entry(session_name, theory_name, name, executable, Future.value((false, uncompressed))))
68831
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   178
    }
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   179
    else None
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   180
  }
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   181
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   182
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   183
  /* database consumer thread */
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   184
68289
c29fc61fb1b1 clarified cache;
wenzelm
parents: 68288
diff changeset
   185
  def consumer(db: SQL.Database, cache: XZ.Cache = XZ.cache()): Consumer = new Consumer(db, cache)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   186
68289
c29fc61fb1b1 clarified cache;
wenzelm
parents: 68288
diff changeset
   187
  class Consumer private[Export](db: SQL.Database, cache: XZ.Cache)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   188
  {
68924
wenzelm
parents: 68832
diff changeset
   189
    private val errors = Synchronized[List[String]](Nil)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   190
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   191
    private val consumer =
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   192
      Consumer_Thread.fork(name = "export")(consume = (arg: (Entry, Boolean)) =>
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   193
        {
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   194
          val (entry, strict) = arg
68103
c5764b8b2a87 more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents: 68102
diff changeset
   195
          entry.body.join
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   196
          db.transaction {
68115
23c6ae3dd3a0 more efficient query;
wenzelm
parents: 68104
diff changeset
   197
            if (read_name(db, entry.session_name, entry.theory_name, entry.name)) {
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   198
              if (strict) {
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   199
                val msg = message("Duplicate export", entry.theory_name, entry.name)
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   200
                errors.change(msg :: _)
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   201
              }
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   202
            }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   203
            else entry.write(db)
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   204
          }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   205
          true
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   206
        })
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   207
68103
c5764b8b2a87 more robust (synchronous) management of Export.Entry: Future.fork happens inside the data structure;
wenzelm
parents: 68102
diff changeset
   208
    def apply(session_name: String, args: Markup.Export.Args, body: Bytes): Unit =
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 69854
diff changeset
   209
      consumer.send(make_entry(session_name, args, body, cache = cache) -> args.strict)
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   210
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   211
    def shutdown(close: Boolean = false): List[String] =
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   212
    {
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   213
      consumer.shutdown()
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   214
      if (close) db.close()
68924
wenzelm
parents: 68832
diff changeset
   215
      errors.value.reverse
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   216
    }
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   217
  }
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   218
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   219
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   220
  /* abstract provider */
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   221
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   222
  object Provider
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   223
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   224
    def database(db: SQL.Database, session_name: String, theory_name: String): Provider =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   225
      new Provider {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   226
        def apply(export_name: String): Option[Entry] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   227
          read_entry(db, session_name, theory_name, export_name)
68832
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   228
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   229
        override def toString: String = db.toString
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   230
      }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   231
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   232
    def snapshot(snapshot: Document.Snapshot): Provider =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   233
      new Provider {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   234
        def apply(export_name: String): Option[Entry] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   235
          snapshot.exports_map.get(export_name)
68832
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   236
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   237
        override def toString: String = snapshot.toString
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   238
      }
68831
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   239
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   240
    def directory(dir: Path, session_name: String, theory_name: String): Provider =
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   241
      new Provider {
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   242
        def apply(export_name: String): Option[Entry] =
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   243
          read_entry(dir, session_name, theory_name, export_name)
68832
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   244
9b9fc9ea9dd1 tuned output;
wenzelm
parents: 68831
diff changeset
   245
        override def toString: String = dir.toString
68831
a6c69599ab99 Export.Provider for "isabelle dump" output_dir;
wenzelm
parents: 68418
diff changeset
   246
      }
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   247
  }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   248
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   249
  trait Provider
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   250
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   251
    def apply(export_name: String): Option[Entry]
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   252
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   253
    def uncompressed_yxml(export_name: String, cache: XZ.Cache = XZ.cache()): XML.Body =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   254
      apply(export_name) match {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   255
        case Some(entry) => entry.uncompressed_yxml(cache = cache)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   256
        case None => Nil
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   257
      }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   258
  }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   259
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68331
diff changeset
   260
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   261
  /* export to file-system */
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   262
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   263
  def export_files(
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   264
    store: Sessions.Store,
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   265
    session_name: String,
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   266
    export_dir: Path,
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   267
    progress: Progress = No_Progress,
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   268
    export_prune: Int = 0,
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   269
    export_list: Boolean = false,
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69789
diff changeset
   270
    export_patterns: List[String] = Nil)
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   271
  {
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   272
    using(store.open_database(session_name))(db =>
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   273
    {
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   274
      db.transaction {
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   275
        val export_names = read_theory_exports(db, session_name)
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   276
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   277
        // list
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   278
        if (export_list) {
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   279
          (for ((theory_name, name) <- export_names) yield compound_name(theory_name, name)).
68291
1e1877cb9b3a clarified output;
wenzelm
parents: 68290
diff changeset
   280
            sorted.foreach(progress.echo(_))
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   281
        }
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   282
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   283
        // export
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   284
        if (export_patterns.nonEmpty) {
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   285
          val exports =
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   286
            (for {
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   287
              export_pattern <- export_patterns.iterator
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   288
              matcher = make_matcher(export_pattern)
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   289
              (theory_name, name) <- export_names if matcher(theory_name, name)
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   290
            } yield (theory_name, name)).toSet
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   291
          for {
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   292
            (theory_name, group) <- exports.toList.groupBy(_._1).toList.sortBy(_._1)
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   293
            name <- group.map(_._2).sorted
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   294
            entry <- read_entry(db, session_name, theory_name, name)
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   295
          } {
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   296
            val elems = theory_name :: space_explode('/', name)
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   297
            val path =
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   298
              if (elems.length < export_prune + 1) {
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   299
                error("Cannot prune path by " + export_prune + " element(s): " + Path.make(elems))
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   300
              }
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   301
              else export_dir + Path.make(elems.drop(export_prune))
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   302
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69789
diff changeset
   303
            progress.echo("export " + path + (if (entry.executable) " (executable)" else ""))
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   304
            Isabelle_System.mkdirs(path.dir)
68289
c29fc61fb1b1 clarified cache;
wenzelm
parents: 68288
diff changeset
   305
            Bytes.write(path, entry.uncompressed(cache = store.xz_cache))
69789
2c3e5e58d93f more thorough File.set_executable, notably for Windows;
wenzelm
parents: 69788
diff changeset
   306
            File.set_executable(path, entry.executable)
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   307
          }
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   308
        }
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   309
      }
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   310
    })
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   311
  }
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   312
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   313
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   314
  /* Isabelle tool wrapper */
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   315
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   316
  val default_export_dir = Path.explode("export")
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   317
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   318
  val isabelle_tool = Isabelle_Tool("export", "retrieve theory exports", args =>
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   319
  {
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   320
    /* arguments */
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   321
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   322
    var export_dir = default_export_dir
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   323
    var dirs: List[Path] = Nil
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   324
    var export_list = false
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   325
    var no_build = false
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   326
    var options = Options.init()
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   327
    var export_prune = 0
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   328
    var export_patterns: List[String] = Nil
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   329
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   330
    val getopts = Getopts("""
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   331
Usage: isabelle export [OPTIONS] SESSION
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   332
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   333
  Options are:
68314
2acbf8129d8b clarified option -O: avoid conflict with build/dump option -D;
wenzelm
parents: 68305
diff changeset
   334
    -O DIR       output directory for exported files (default: """ + default_export_dir + """)
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   335
    -d DIR       include session directory
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   336
    -l           list exports
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   337
    -n           no build of session
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   338
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   339
    -p NUM       prune path of exported files by NUM elements
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   340
    -x PATTERN   extract files matching pattern (e.g. "*:**" for all)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   341
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   342
  List or export theory exports for SESSION: named blobs produced by
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   343
  isabelle build. Option -l or -x is required; option -x may be repeated.
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   344
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   345
  The PATTERN language resembles glob patterns in the shell, with ? and *
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   346
  (both excluding ":" and "/"), ** (excluding ":"), and [abc] or [^abc],
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   347
  and variants {pattern1,pattern2,pattern3}.
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   348
""",
68314
2acbf8129d8b clarified option -O: avoid conflict with build/dump option -D;
wenzelm
parents: 68305
diff changeset
   349
      "O:" -> (arg => export_dir = Path.explode(arg)),
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   350
      "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   351
      "l" -> (_ => export_list = true),
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   352
      "n" -> (_ => no_build = true),
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   353
      "o:" -> (arg => options = options + arg),
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   354
      "p:" -> (arg => export_prune = Value.Int.parse(arg)),
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   355
      "x:" -> (arg => export_patterns ::= arg))
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   356
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   357
    val more_args = getopts(args)
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   358
    val session_name =
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   359
      more_args match {
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   360
        case List(session_name) if export_list || export_patterns.nonEmpty => session_name
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   361
        case _ => getopts.usage()
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   362
      }
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   363
68305
5321218147d3 clarified signature;
wenzelm
parents: 68291
diff changeset
   364
    val progress = new Console_Progress()
5321218147d3 clarified signature;
wenzelm
parents: 68291
diff changeset
   365
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   366
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   367
    /* build */
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   368
68305
5321218147d3 clarified signature;
wenzelm
parents: 68291
diff changeset
   369
    if (!no_build) {
5321218147d3 clarified signature;
wenzelm
parents: 68291
diff changeset
   370
      val rc =
68331
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68314
diff changeset
   371
        progress.interrupt_handler {
69854
cc0b3e177b49 system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents: 69811
diff changeset
   372
          Build.build_logic(options, session_name, progress = progress, dirs = dirs)
68331
7eaaa8f48331 clarified outermost progress.interrupt_handler;
wenzelm
parents: 68314
diff changeset
   373
        }
68305
5321218147d3 clarified signature;
wenzelm
parents: 68291
diff changeset
   374
      if (rc != 0) sys.exit(rc)
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   375
    }
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   376
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   377
68288
d20770229f99 tuned signature;
wenzelm
parents: 68222
diff changeset
   378
    /* export files */
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   379
69854
cc0b3e177b49 system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents: 69811
diff changeset
   380
    val store = Sessions.store(options)
69671
2486792eaf61 support pruning of export names;
wenzelm
parents: 69635
diff changeset
   381
    export_files(store, session_name, export_dir, progress = progress, export_prune = export_prune,
68290
f1f5ccc85b25 support multiple patterns;
wenzelm
parents: 68289
diff changeset
   382
      export_list = export_list, export_patterns = export_patterns)
68116
ac82ee617a75 command-line tool "isabelle export";
wenzelm
parents: 68115
diff changeset
   383
  })
68092
888d35a19866 store exports in session database, with asynchronous / parallel compression;
wenzelm
parents:
diff changeset
   384
}