src/Pure/System/bash.scala
changeset 74212 a1ccecae6a57
parent 74158 1cb0ad6f9a2d
child 74273 0a4cdf0036a0
equal deleted inserted replaced
74211:2ee03f7abd8d 74212:a1ccecae6a57
    44     ss.iterator.map(Bash.string).mkString(" ")
    44     ss.iterator.map(Bash.string).mkString(" ")
    45 
    45 
    46 
    46 
    47   /* process and result */
    47   /* process and result */
    48 
    48 
       
    49   private def make_description(description: String): String =
       
    50     proper_string(description) getOrElse "bash_process"
       
    51 
    49   type Watchdog = (Time, Process => Boolean)
    52   type Watchdog = (Time, Process => Boolean)
    50 
    53 
    51   def process(script: String,
    54   def process(script: String,
       
    55       description: String = "",
    52       cwd: JFile = null,
    56       cwd: JFile = null,
    53       env: JMap[String, String] = Isabelle_System.settings(),
    57       env: JMap[String, String] = Isabelle_System.settings(),
    54       redirect: Boolean = false,
    58       redirect: Boolean = false,
    55       cleanup: () => Unit = () => ()): Process =
    59       cleanup: () => Unit = () => ()): Process =
    56     new Process(script, cwd, env, redirect, cleanup)
    60     new Process(script, description, cwd, env, redirect, cleanup)
    57 
    61 
    58   class Process private[Bash](
    62   class Process private[Bash](
    59       script: String,
    63       script: String,
       
    64       description: String,
    60       cwd: JFile,
    65       cwd: JFile,
    61       env: JMap[String, String],
    66       env: JMap[String, String],
    62       redirect: Boolean,
    67       redirect: Boolean,
    63       cleanup: () => Unit)
    68       cleanup: () => Unit)
    64   {
    69   {
       
    70     override def toString: String = make_description(description)
       
    71 
    65     private val timing_file = Isabelle_System.tmp_file("bash_timing")
    72     private val timing_file = Isabelle_System.tmp_file("bash_timing")
    66     private val timing = Synchronized[Option[Timing]](None)
    73     private val timing = Synchronized[Option[Timing]](None)
    67     def get_timing: Timing = timing.value getOrElse Timing.zero
    74     def get_timing: Timing = timing.value getOrElse Timing.zero
    68 
    75 
    69     private val winpid_file: Option[JFile] =
    76     private val winpid_file: Option[JFile] =
   301 
   308 
   302         case Some(List(Server.RUN, script, input, cwd, putenv,
   309         case Some(List(Server.RUN, script, input, cwd, putenv,
   303             Value.Boolean(redirect), Value.Seconds(timeout), description)) =>
   310             Value.Boolean(redirect), Value.Seconds(timeout), description)) =>
   304           val uuid = UUID.random()
   311           val uuid = UUID.random()
   305 
   312 
   306           val descr = proper_string(description) getOrElse "bash_process"
   313           val descr = make_description(description)
   307           if (debugging) {
   314           if (debugging) {
   308             Output.writeln(
   315             Output.writeln(
   309               "start " + quote(descr) + " (uuid=" + uuid + ", timeout=" + timeout.seconds + ")")
   316               "start " + quote(descr) + " (uuid=" + uuid + ", timeout=" + timeout.seconds + ")")
   310           }
   317           }
   311 
   318 
   312           Exn.capture {
   319           Exn.capture {
   313             Bash.process(script,
   320             Bash.process(script,
       
   321               description = description,
   314               cwd =
   322               cwd =
   315                 XML.Decode.option(XML.Decode.string)(YXML.parse_body(cwd)) match {
   323                 XML.Decode.option(XML.Decode.string)(YXML.parse_body(cwd)) match {
   316                   case None => null
   324                   case None => null
   317                   case Some(s) => Path.explode(s).file
   325                   case Some(s) => Path.explode(s).file
   318                 },
   326                 },