src/Pure/PIDE/batch_session.scala
author wenzelm
Wed Apr 01 15:41:08 2015 +0200 (2015-04-01)
changeset 59891 9ce697050455
parent 59720 f893472fff31
child 59892 2a616319c171
permissions -rw-r--r--
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm@59720
     1
/*  Title:      Pure/PIDE/batch_session.scala
wenzelm@59362
     2
    Author:     Makarius
wenzelm@59362
     3
wenzelm@59362
     4
PIDE session in batch mode.
wenzelm@59362
     5
*/
wenzelm@59362
     6
wenzelm@59362
     7
package isabelle
wenzelm@59362
     8
wenzelm@59362
     9
wenzelm@59362
    10
import isabelle._
wenzelm@59362
    11
wenzelm@59362
    12
wenzelm@59362
    13
object Batch_Session
wenzelm@59362
    14
{
wenzelm@59362
    15
  def batch_session(
wenzelm@59362
    16
    options: Options,
wenzelm@59362
    17
    verbose: Boolean = false,
wenzelm@59362
    18
    dirs: List[Path] = Nil,
wenzelm@59369
    19
    session: String): Batch_Session =
wenzelm@59362
    20
  {
wenzelm@59362
    21
    val (_, session_tree) =
wenzelm@59362
    22
      Build.find_sessions(options, dirs).selection(false, false, Nil, List(session))
wenzelm@59362
    23
    val session_info = session_tree(session)
wenzelm@59362
    24
    val parent_session =
wenzelm@59362
    25
      session_info.parent getOrElse error("No parent session for " + quote(session))
wenzelm@59362
    26
wenzelm@59362
    27
    if (Build.build(options, new Build.Console_Progress(verbose),
wenzelm@59362
    28
        verbose = verbose, build_heap = true,
wenzelm@59362
    29
        dirs = dirs, sessions = List(parent_session)) != 0)
wenzelm@59362
    30
      new RuntimeException
wenzelm@59362
    31
wenzelm@59891
    32
    val deps = Build.dependencies(verbose = verbose, tree = session_tree)
wenzelm@59362
    33
    val resources =
wenzelm@59362
    34
    {
wenzelm@59362
    35
      val content = deps(parent_session)
wenzelm@59362
    36
      new Resources(content.loaded_theories, content.known_theories, content.syntax)
wenzelm@59362
    37
    }
wenzelm@59362
    38
wenzelm@59362
    39
    val progress = new Build.Console_Progress(verbose)
wenzelm@59366
    40
wenzelm@59362
    41
    val prover_session = new Session(resources)
wenzelm@59369
    42
    val batch_session = new Batch_Session(prover_session)
wenzelm@59362
    43
wenzelm@59367
    44
    val handler = new Build.Handler(progress, session)
wenzelm@59367
    45
wenzelm@59362
    46
    prover_session.phase_changed +=
wenzelm@59362
    47
      Session.Consumer[Session.Phase](getClass.getName) {
wenzelm@59362
    48
        case Session.Ready =>
wenzelm@59367
    49
          prover_session.add_protocol_handler(handler)
wenzelm@59362
    50
          val master_dir = session_info.dir
wenzelm@59364
    51
          val theories = session_info.theories.map({ case (_, opts, thys) => (opts, thys) })
wenzelm@59369
    52
          batch_session.build_theories_result =
wenzelm@59366
    53
            Some(Build.build_theories(prover_session, master_dir, theories))
wenzelm@59362
    54
        case Session.Inactive | Session.Failed =>
wenzelm@59369
    55
          batch_session.session_result.fulfill_result(Exn.Exn(ERROR("Prover process terminated")))
wenzelm@59362
    56
        case Session.Shutdown =>
wenzelm@59369
    57
          batch_session.session_result.fulfill(())
wenzelm@59362
    58
        case _ =>
wenzelm@59362
    59
      }
wenzelm@59362
    60
wenzelm@59362
    61
    prover_session.start("Isabelle", List("-r", "-q", parent_session))
wenzelm@59362
    62
wenzelm@59369
    63
    batch_session
wenzelm@59362
    64
  }
wenzelm@59362
    65
}
wenzelm@59362
    66
wenzelm@59369
    67
class Batch_Session private(val session: Session)
wenzelm@59369
    68
{
wenzelm@59369
    69
  val session_result = Future.promise[Unit]
wenzelm@59369
    70
  @volatile var build_theories_result: Option[Promise[XML.Body]] = None
wenzelm@59369
    71
}
wenzelm@59369
    72