src/Pure/Thy/sessions.scala
author wenzelm
Tue Apr 05 14:58:24 2016 +0200 (2016-04-05 ago)
changeset 62864 2d5959cf3c1a
parent 62769 146945b9e83c
child 62883 b04e9fe29223
permissions -rw-r--r--
tuned;
wenzelm@62631
     1
/*  Title:      Pure/Thy/sessions.scala
wenzelm@62631
     2
    Author:     Makarius
wenzelm@62631
     3
wenzelm@62631
     4
Session information.
wenzelm@62631
     5
*/
wenzelm@62631
     6
wenzelm@62631
     7
package isabelle
wenzelm@62631
     8
wenzelm@62704
     9
import java.nio.ByteBuffer
wenzelm@62704
    10
import java.nio.channels.FileChannel
wenzelm@62704
    11
import java.nio.file.StandardOpenOption
wenzelm@62631
    12
wenzelm@62631
    13
import scala.collection.SortedSet
wenzelm@62631
    14
import scala.collection.mutable
wenzelm@62631
    15
wenzelm@62631
    16
wenzelm@62631
    17
object Sessions
wenzelm@62631
    18
{
wenzelm@62631
    19
  /* info */
wenzelm@62631
    20
wenzelm@62631
    21
  def is_pure(name: String): Boolean = name == "Pure"
wenzelm@62631
    22
wenzelm@62631
    23
  sealed case class Info(
wenzelm@62631
    24
    chapter: String,
wenzelm@62631
    25
    select: Boolean,
wenzelm@62631
    26
    pos: Position.T,
wenzelm@62631
    27
    groups: List[String],
wenzelm@62631
    28
    dir: Path,
wenzelm@62631
    29
    parent: Option[String],
wenzelm@62631
    30
    description: String,
wenzelm@62631
    31
    options: Options,
wenzelm@62631
    32
    theories: List[(Boolean, Options, List[Path])],
wenzelm@62631
    33
    files: List[Path],
wenzelm@62631
    34
    document_files: List[(Path, Path)],
wenzelm@62631
    35
    meta_digest: SHA1.Digest)
wenzelm@62631
    36
  {
wenzelm@62631
    37
    def timeout: Time = Time.seconds(options.real("timeout") * options.real("timeout_scale"))
wenzelm@62631
    38
  }
wenzelm@62631
    39
wenzelm@62631
    40
wenzelm@62631
    41
  /* session tree */
wenzelm@62631
    42
wenzelm@62631
    43
  object Tree
wenzelm@62631
    44
  {
wenzelm@62631
    45
    def apply(infos: Seq[(String, Info)]): Tree =
wenzelm@62631
    46
    {
wenzelm@62631
    47
      val graph1 =
wenzelm@62631
    48
        (Graph.string[Info] /: infos) {
wenzelm@62631
    49
          case (graph, (name, info)) =>
wenzelm@62631
    50
            if (graph.defined(name))
wenzelm@62631
    51
              error("Duplicate session " + quote(name) + Position.here(info.pos) +
wenzelm@62631
    52
                Position.here(graph.get_node(name).pos))
wenzelm@62631
    53
            else graph.new_node(name, info)
wenzelm@62631
    54
        }
wenzelm@62631
    55
      val graph2 =
wenzelm@62631
    56
        (graph1 /: graph1.iterator) {
wenzelm@62631
    57
          case (graph, (name, (info, _))) =>
wenzelm@62631
    58
            info.parent match {
wenzelm@62631
    59
              case None => graph
wenzelm@62631
    60
              case Some(parent) =>
wenzelm@62631
    61
                if (!graph.defined(parent))
wenzelm@62631
    62
                  error("Bad parent session " + quote(parent) + " for " +
wenzelm@62631
    63
                    quote(name) + Position.here(info.pos))
wenzelm@62631
    64
wenzelm@62631
    65
                try { graph.add_edge_acyclic(parent, name) }
wenzelm@62631
    66
                catch {
wenzelm@62631
    67
                  case exn: Graph.Cycles[_] =>
wenzelm@62631
    68
                    error(cat_lines(exn.cycles.map(cycle =>
wenzelm@62631
    69
                      "Cyclic session dependency of " +
wenzelm@62631
    70
                        cycle.map(c => quote(c.toString)).mkString(" via "))) +
wenzelm@62631
    71
                          Position.here(info.pos))
wenzelm@62631
    72
                }
wenzelm@62631
    73
            }
wenzelm@62631
    74
        }
wenzelm@62631
    75
      new Tree(graph2)
wenzelm@62631
    76
    }
wenzelm@62631
    77
  }
wenzelm@62631
    78
wenzelm@62631
    79
  final class Tree private(val graph: Graph[String, Info])
wenzelm@62631
    80
    extends PartialFunction[String, Info]
wenzelm@62631
    81
  {
wenzelm@62631
    82
    def apply(name: String): Info = graph.get_node(name)
wenzelm@62631
    83
    def isDefinedAt(name: String): Boolean = graph.defined(name)
wenzelm@62631
    84
wenzelm@62631
    85
    def selection(
wenzelm@62631
    86
      requirements: Boolean = false,
wenzelm@62631
    87
      all_sessions: Boolean = false,
wenzelm@62631
    88
      exclude_session_groups: List[String] = Nil,
wenzelm@62631
    89
      exclude_sessions: List[String] = Nil,
wenzelm@62631
    90
      session_groups: List[String] = Nil,
wenzelm@62631
    91
      sessions: List[String] = Nil): (List[String], Tree) =
wenzelm@62631
    92
    {
wenzelm@62631
    93
      val bad_sessions =
wenzelm@62631
    94
        SortedSet((exclude_sessions ::: sessions).filterNot(isDefinedAt(_)): _*).toList
wenzelm@62631
    95
      if (bad_sessions.nonEmpty) error("Undefined session(s): " + commas_quote(bad_sessions))
wenzelm@62631
    96
wenzelm@62631
    97
      val excluded =
wenzelm@62631
    98
      {
wenzelm@62631
    99
        val exclude_group = exclude_session_groups.toSet
wenzelm@62631
   100
        val exclude_group_sessions =
wenzelm@62631
   101
          (for {
wenzelm@62631
   102
            (name, (info, _)) <- graph.iterator
wenzelm@62631
   103
            if apply(name).groups.exists(exclude_group)
wenzelm@62631
   104
          } yield name).toList
wenzelm@62631
   105
        graph.all_succs(exclude_group_sessions ::: exclude_sessions).toSet
wenzelm@62631
   106
      }
wenzelm@62631
   107
wenzelm@62631
   108
      val pre_selected =
wenzelm@62631
   109
      {
wenzelm@62631
   110
        if (all_sessions) graph.keys
wenzelm@62631
   111
        else {
wenzelm@62631
   112
          val select_group = session_groups.toSet
wenzelm@62631
   113
          val select = sessions.toSet
wenzelm@62631
   114
          (for {
wenzelm@62631
   115
            (name, (info, _)) <- graph.iterator
wenzelm@62631
   116
            if info.select || select(name) || apply(name).groups.exists(select_group)
wenzelm@62631
   117
          } yield name).toList
wenzelm@62631
   118
        }
wenzelm@62631
   119
      }.filterNot(excluded)
wenzelm@62631
   120
wenzelm@62631
   121
      val selected =
wenzelm@62631
   122
        if (requirements) (graph.all_preds(pre_selected).toSet -- pre_selected).toList
wenzelm@62631
   123
        else pre_selected
wenzelm@62631
   124
wenzelm@62631
   125
      val graph1 = graph.restrict(graph.all_preds(selected).toSet)
wenzelm@62631
   126
      (selected, new Tree(graph1))
wenzelm@62631
   127
    }
wenzelm@62631
   128
wenzelm@62631
   129
    def ancestors(name: String): List[String] =
wenzelm@62631
   130
      graph.all_preds(List(name)).tail.reverse
wenzelm@62631
   131
wenzelm@62631
   132
    def topological_order: List[(String, Info)] =
wenzelm@62631
   133
      graph.topological_order.map(name => (name, apply(name)))
wenzelm@62631
   134
wenzelm@62631
   135
    override def toString: String = graph.keys_iterator.mkString("Sessions.Tree(", ", ", ")")
wenzelm@62631
   136
  }
wenzelm@62631
   137
wenzelm@62631
   138
wenzelm@62631
   139
  /* parser */
wenzelm@62631
   140
wenzelm@62864
   141
  val ROOT = Path.explode("ROOT")
wenzelm@62864
   142
  val ROOTS = Path.explode("ROOTS")
wenzelm@62864
   143
wenzelm@62631
   144
  private val CHAPTER = "chapter"
wenzelm@62631
   145
  private val SESSION = "session"
wenzelm@62631
   146
  private val IN = "in"
wenzelm@62631
   147
  private val DESCRIPTION = "description"
wenzelm@62631
   148
  private val OPTIONS = "options"
wenzelm@62631
   149
  private val GLOBAL_THEORIES = "global_theories"
wenzelm@62631
   150
  private val THEORIES = "theories"
wenzelm@62631
   151
  private val FILES = "files"
wenzelm@62631
   152
  private val DOCUMENT_FILES = "document_files"
wenzelm@62631
   153
wenzelm@62631
   154
  lazy val root_syntax =
wenzelm@62631
   155
    Outer_Syntax.init() + "(" + ")" + "+" + "," + "=" + "[" + "]" +
wenzelm@62631
   156
      (CHAPTER, Keyword.THY_DECL) + (SESSION, Keyword.THY_DECL) +
wenzelm@62631
   157
      IN + DESCRIPTION + OPTIONS + GLOBAL_THEORIES + THEORIES + FILES + DOCUMENT_FILES
wenzelm@62631
   158
wenzelm@62864
   159
  private object Parser extends Parse.Parser
wenzelm@62631
   160
  {
wenzelm@62631
   161
    private abstract class Entry
wenzelm@62631
   162
    private sealed case class Chapter(name: String) extends Entry
wenzelm@62631
   163
    private sealed case class Session_Entry(
wenzelm@62631
   164
      pos: Position.T,
wenzelm@62631
   165
      name: String,
wenzelm@62631
   166
      groups: List[String],
wenzelm@62631
   167
      path: String,
wenzelm@62631
   168
      parent: Option[String],
wenzelm@62631
   169
      description: String,
wenzelm@62631
   170
      options: List[Options.Spec],
wenzelm@62631
   171
      theories: List[(Boolean, List[Options.Spec], List[String])],
wenzelm@62631
   172
      files: List[String],
wenzelm@62631
   173
      document_files: List[(String, String)]) extends Entry
wenzelm@62631
   174
wenzelm@62631
   175
    private val chapter: Parser[Chapter] =
wenzelm@62631
   176
    {
wenzelm@62631
   177
      val chapter_name = atom("chapter name", _.is_name)
wenzelm@62631
   178
wenzelm@62631
   179
      command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) }
wenzelm@62631
   180
    }
wenzelm@62631
   181
wenzelm@62631
   182
    private val session_entry: Parser[Session_Entry] =
wenzelm@62631
   183
    {
wenzelm@62631
   184
      val session_name = atom("session name", _.is_name)
wenzelm@62631
   185
wenzelm@62631
   186
      val option =
wenzelm@62631
   187
        name ~ opt($$$("=") ~! name ^^ { case _ ~ x => x }) ^^ { case x ~ y => (x, y) }
wenzelm@62631
   188
      val options = $$$("[") ~> rep1sep(option, $$$(",")) <~ $$$("]")
wenzelm@62631
   189
wenzelm@62631
   190
      val theories =
wenzelm@62631
   191
        ($$$(GLOBAL_THEORIES) | $$$(THEORIES)) ~!
wenzelm@62631
   192
          ((options | success(Nil)) ~ rep(theory_xname)) ^^
wenzelm@62631
   193
          { case x ~ (y ~ z) => (x == GLOBAL_THEORIES, y, z) }
wenzelm@62631
   194
wenzelm@62631
   195
      val document_files =
wenzelm@62631
   196
        $$$(DOCUMENT_FILES) ~!
wenzelm@62631
   197
          (($$$("(") ~! ($$$(IN) ~! (path ~ $$$(")"))) ^^
wenzelm@62631
   198
              { case _ ~ (_ ~ (x ~ _)) => x } | success("document")) ~
wenzelm@62631
   199
            rep1(path)) ^^ { case _ ~ (x ~ y) => y.map((x, _)) }
wenzelm@62631
   200
wenzelm@62631
   201
      command(SESSION) ~!
wenzelm@62631
   202
        (position(session_name) ~
wenzelm@62631
   203
          (($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~
wenzelm@62631
   204
          (($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~
wenzelm@62631
   205
          ($$$("=") ~!
wenzelm@62631
   206
            (opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~
wenzelm@62631
   207
              (($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~
wenzelm@62631
   208
              (($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~
wenzelm@62631
   209
              rep1(theories) ~
wenzelm@62631
   210
              (($$$(FILES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil)) ~
wenzelm@62631
   211
              (rep(document_files) ^^ (x => x.flatten))))) ^^
wenzelm@62631
   212
        { case _ ~ ((a, pos) ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h ~ i))) =>
wenzelm@62631
   213
            Session_Entry(pos, a, b, c, d, e, f, g, h, i) }
wenzelm@62631
   214
    }
wenzelm@62631
   215
wenzelm@62631
   216
    def parse(options: Options, select: Boolean, dir: Path): List[(String, Info)] =
wenzelm@62631
   217
    {
wenzelm@62631
   218
      def make_info(entry_chapter: String, entry: Session_Entry): (String, Info) =
wenzelm@62631
   219
      {
wenzelm@62631
   220
        try {
wenzelm@62631
   221
          val name = entry.name
wenzelm@62631
   222
wenzelm@62631
   223
          if (name == "") error("Bad session name")
wenzelm@62631
   224
          if (is_pure(name) && entry.parent.isDefined) error("Illegal parent session")
wenzelm@62631
   225
          if (!is_pure(name) && !entry.parent.isDefined) error("Missing parent session")
wenzelm@62631
   226
wenzelm@62631
   227
          val session_options = options ++ entry.options
wenzelm@62631
   228
wenzelm@62631
   229
          val theories =
wenzelm@62631
   230
            entry.theories.map({ case (global, opts, thys) =>
wenzelm@62631
   231
              (global, session_options ++ opts, thys.map(Path.explode(_))) })
wenzelm@62631
   232
          val files = entry.files.map(Path.explode(_))
wenzelm@62631
   233
          val document_files =
wenzelm@62631
   234
            entry.document_files.map({ case (s1, s2) => (Path.explode(s1), Path.explode(s2)) })
wenzelm@62631
   235
wenzelm@62631
   236
          val meta_digest =
wenzelm@62631
   237
            SHA1.digest((entry_chapter, name, entry.parent, entry.options,
wenzelm@62631
   238
              entry.theories, entry.files, entry.document_files).toString)
wenzelm@62631
   239
wenzelm@62631
   240
          val info =
wenzelm@62631
   241
            Info(entry_chapter, select, entry.pos, entry.groups, dir + Path.explode(entry.path),
wenzelm@62631
   242
              entry.parent, entry.description, session_options, theories, files,
wenzelm@62631
   243
              document_files, meta_digest)
wenzelm@62631
   244
wenzelm@62631
   245
          (name, info)
wenzelm@62631
   246
        }
wenzelm@62631
   247
        catch {
wenzelm@62631
   248
          case ERROR(msg) =>
wenzelm@62631
   249
            error(msg + "\nThe error(s) above occurred in session entry " +
wenzelm@62631
   250
              quote(entry.name) + Position.here(entry.pos))
wenzelm@62631
   251
        }
wenzelm@62631
   252
      }
wenzelm@62631
   253
wenzelm@62631
   254
      val root = dir + ROOT
wenzelm@62631
   255
      if (root.is_file) {
wenzelm@62631
   256
        val toks = Token.explode(root_syntax.keywords, File.read(root))
wenzelm@62631
   257
        val start = Token.Pos.file(root.implode)
wenzelm@62631
   258
wenzelm@62631
   259
        parse_all(rep(chapter | session_entry), Token.reader(toks, start)) match {
wenzelm@62631
   260
          case Success(result, _) =>
wenzelm@62631
   261
            var entry_chapter = "Unsorted"
wenzelm@62631
   262
            val infos = new mutable.ListBuffer[(String, Info)]
wenzelm@62631
   263
            result.foreach {
wenzelm@62631
   264
              case Chapter(name) => entry_chapter = name
wenzelm@62631
   265
              case entry: Session_Entry => infos += make_info(entry_chapter, entry)
wenzelm@62631
   266
            }
wenzelm@62631
   267
            infos.toList
wenzelm@62631
   268
          case bad => error(bad.toString)
wenzelm@62631
   269
        }
wenzelm@62631
   270
      }
wenzelm@62631
   271
      else Nil
wenzelm@62631
   272
    }
wenzelm@62631
   273
  }
wenzelm@62631
   274
wenzelm@62631
   275
wenzelm@62635
   276
  /* load sessions from certain directories */
wenzelm@62631
   277
wenzelm@62631
   278
  private def is_session_dir(dir: Path): Boolean =
wenzelm@62631
   279
    (dir + ROOT).is_file || (dir + ROOTS).is_file
wenzelm@62631
   280
wenzelm@62631
   281
  private def check_session_dir(dir: Path): Path =
wenzelm@62631
   282
    if (is_session_dir(dir)) dir
wenzelm@62631
   283
    else error("Bad session root directory: " + dir.toString)
wenzelm@62631
   284
wenzelm@62635
   285
  def load(options: Options, dirs: List[Path] = Nil, select_dirs: List[Path] = Nil): Tree =
wenzelm@62631
   286
  {
wenzelm@62635
   287
    def load_dir(select: Boolean, dir: Path): List[(String, Info)] =
wenzelm@62635
   288
      load_root(select, dir) ::: load_roots(select, dir)
wenzelm@62631
   289
wenzelm@62635
   290
    def load_root(select: Boolean, dir: Path): List[(String, Info)] =
wenzelm@62631
   291
      Parser.parse(options, select, dir)
wenzelm@62631
   292
wenzelm@62635
   293
    def load_roots(select: Boolean, dir: Path): List[(String, Info)] =
wenzelm@62631
   294
    {
wenzelm@62631
   295
      val roots = dir + ROOTS
wenzelm@62631
   296
      if (roots.is_file) {
wenzelm@62631
   297
        for {
wenzelm@62631
   298
          line <- split_lines(File.read(roots))
wenzelm@62631
   299
          if !(line == "" || line.startsWith("#"))
wenzelm@62631
   300
          dir1 =
wenzelm@62631
   301
            try { check_session_dir(dir + Path.explode(line)) }
wenzelm@62631
   302
            catch {
wenzelm@62631
   303
              case ERROR(msg) =>
wenzelm@62631
   304
                error(msg + "\nThe error(s) above occurred in session catalog " + roots.toString)
wenzelm@62631
   305
            }
wenzelm@62635
   306
          info <- load_dir(select, dir1)
wenzelm@62631
   307
        } yield info
wenzelm@62631
   308
      }
wenzelm@62631
   309
      else Nil
wenzelm@62631
   310
    }
wenzelm@62631
   311
wenzelm@62631
   312
    val default_dirs = Isabelle_System.components().filter(is_session_dir(_))
wenzelm@62631
   313
    dirs.foreach(check_session_dir(_))
wenzelm@62631
   314
    select_dirs.foreach(check_session_dir(_))
wenzelm@62631
   315
wenzelm@62631
   316
    Tree(
wenzelm@62631
   317
      for {
wenzelm@62631
   318
        (select, dir) <- (default_dirs ::: dirs).map((false, _)) ::: select_dirs.map((true, _))
wenzelm@62635
   319
        info <- load_dir(select, dir)
wenzelm@62631
   320
      } yield info)
wenzelm@62631
   321
  }
wenzelm@62632
   322
wenzelm@62632
   323
wenzelm@62637
   324
wenzelm@62704
   325
  /** heap file with SHA1 digest **/
wenzelm@62704
   326
wenzelm@62704
   327
  private val sha1_prefix = "SHA1:"
wenzelm@62704
   328
wenzelm@62704
   329
  def read_heap_digest(heap: Path): Option[String] =
wenzelm@62704
   330
  {
wenzelm@62704
   331
    if (heap.is_file) {
wenzelm@62704
   332
      val file = FileChannel.open(heap.file.toPath, StandardOpenOption.READ)
wenzelm@62704
   333
      try {
wenzelm@62704
   334
        val len = file.size
wenzelm@62704
   335
        val n = sha1_prefix.length + SHA1.digest_length
wenzelm@62704
   336
        if (len >= n) {
wenzelm@62704
   337
          file.position(len - n)
wenzelm@62704
   338
wenzelm@62704
   339
          val buf = ByteBuffer.allocate(n)
wenzelm@62704
   340
          var i = 0
wenzelm@62704
   341
          var m = 0
wenzelm@62704
   342
          do {
wenzelm@62704
   343
            m = file.read(buf)
wenzelm@62704
   344
            if (m != -1) i += m
wenzelm@62704
   345
          }
wenzelm@62704
   346
          while (m != -1 && n > i)
wenzelm@62704
   347
wenzelm@62704
   348
          if (i == n) {
wenzelm@62704
   349
            val prefix = new String(buf.array(), 0, sha1_prefix.length, UTF8.charset)
wenzelm@62704
   350
            val s = new String(buf.array(), sha1_prefix.length, SHA1.digest_length, UTF8.charset)
wenzelm@62704
   351
            if (prefix == sha1_prefix) Some(s) else None
wenzelm@62704
   352
          }
wenzelm@62704
   353
          else None
wenzelm@62704
   354
        }
wenzelm@62704
   355
        else None
wenzelm@62704
   356
      }
wenzelm@62704
   357
      finally { file.close }
wenzelm@62704
   358
    }
wenzelm@62704
   359
    else None
wenzelm@62704
   360
  }
wenzelm@62704
   361
wenzelm@62704
   362
  def write_heap_digest(heap: Path): String =
wenzelm@62704
   363
    read_heap_digest(heap) match {
wenzelm@62704
   364
      case None =>
wenzelm@62704
   365
        val s = SHA1.digest(heap).rep
wenzelm@62704
   366
        File.append(heap, sha1_prefix + s)
wenzelm@62704
   367
        s
wenzelm@62704
   368
      case Some(s) => s
wenzelm@62704
   369
    }
wenzelm@62704
   370
wenzelm@62704
   371
wenzelm@62704
   372
wenzelm@62637
   373
  /** persistent store **/
wenzelm@62632
   374
wenzelm@62632
   375
  def log(name: String): Path = Path.basic("log") + Path.basic(name)
wenzelm@62632
   376
  def log_gz(name: String): Path = log(name).ext("gz")
wenzelm@62632
   377
wenzelm@62632
   378
  def store(system_mode: Boolean = false): Store = new Store(system_mode)
wenzelm@62632
   379
wenzelm@62632
   380
  class Store private [Sessions](system_mode: Boolean)
wenzelm@62632
   381
  {
wenzelm@62637
   382
    /* output */
wenzelm@62632
   383
wenzelm@62632
   384
    val browser_info: Path =
wenzelm@62632
   385
      if (system_mode) Path.explode("~~/browser_info")
wenzelm@62632
   386
      else Path.explode("$ISABELLE_BROWSER_INFO")
wenzelm@62632
   387
wenzelm@62637
   388
    val output_dir: Path =
wenzelm@62637
   389
      if (system_mode) Path.explode("~~/heaps/$ML_IDENTIFIER")
wenzelm@62637
   390
      else Path.explode("$ISABELLE_OUTPUT")
wenzelm@62637
   391
wenzelm@62637
   392
    def prepare_output() { Isabelle_System.mkdirs(output_dir + Path.basic("log")) }
wenzelm@62637
   393
wenzelm@62637
   394
wenzelm@62637
   395
    /* input */
wenzelm@62637
   396
wenzelm@62637
   397
    private val input_dirs =
wenzelm@62632
   398
      if (system_mode) List(output_dir)
wenzelm@62633
   399
      else {
wenzelm@62633
   400
        val ml_ident = Path.explode("$ML_IDENTIFIER").expand
wenzelm@62633
   401
        output_dir :: Path.split(Isabelle_System.getenv_strict("ISABELLE_PATH")).map(_ + ml_ident)
wenzelm@62633
   402
      }
wenzelm@62632
   403
wenzelm@62636
   404
    def find(name: String): Option[(Path, Option[String])] =
wenzelm@62632
   405
      input_dirs.find(dir => (dir + log_gz(name)).is_file).map(dir =>
wenzelm@62704
   406
        (dir + log_gz(name), read_heap_digest(dir + Path.basic(name))))
wenzelm@62632
   407
wenzelm@62633
   408
    def find_log(name: String): Option[Path] =
wenzelm@62633
   409
      input_dirs.map(_ + log(name)).find(_.is_file)
wenzelm@62633
   410
wenzelm@62633
   411
    def find_log_gz(name: String): Option[Path] =
wenzelm@62633
   412
      input_dirs.map(_ + log_gz(name)).find(_.is_file)
wenzelm@62632
   413
wenzelm@62637
   414
    def find_heap(name: String): Option[Path] =
wenzelm@62637
   415
      input_dirs.map(_ + Path.basic(name)).find(_.is_file)
wenzelm@62637
   416
wenzelm@62637
   417
    def heap(name: String): Path =
wenzelm@62637
   418
      find_heap(name) getOrElse
wenzelm@62637
   419
        error("Unknown logic " + quote(name) + " -- no heap file found in:\n" +
wenzelm@62769
   420
          cat_lines(input_dirs.map(dir => "  " + dir.expand.implode)))
wenzelm@62632
   421
  }
wenzelm@62631
   422
}