src/Pure/System/process_result.scala
author wenzelm
Mon, 07 Mar 2016 20:44:47 +0100
changeset 62548 f8ebb715e06d
parent 62492 0e53fade87fe
child 62553 d2e0d626fb96
permissions -rw-r--r--
clarified treatment of DEL; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/process_result.scala
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     3
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     4
Result of system process.
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     6
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
     8
62401
15a2533f1f0a more informative Process_Result;
wenzelm
parents: 62400
diff changeset
     9
final case class Process_Result(
62402
bff56eae3ec5 more informative Build.build_results;
wenzelm
parents: 62401
diff changeset
    10
  rc: Int,
bff56eae3ec5 more informative Build.build_results;
wenzelm
parents: 62401
diff changeset
    11
  out_lines: List[String] = Nil,
bff56eae3ec5 more informative Build.build_results;
wenzelm
parents: 62401
diff changeset
    12
  err_lines: List[String] = Nil,
bff56eae3ec5 more informative Build.build_results;
wenzelm
parents: 62401
diff changeset
    13
  timeout: Option[Time] = None)
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    14
{
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    15
  def out: String = cat_lines(out_lines)
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    16
  def err: String = cat_lines(err_lines)
62405
d653532762e4 proper return code for timeout (amending f868f12f9419);
wenzelm
parents: 62404
diff changeset
    17
  def error(s: String): Process_Result = copy(err_lines = err_lines ::: List(s))
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    18
62405
d653532762e4 proper return code for timeout (amending f868f12f9419);
wenzelm
parents: 62404
diff changeset
    19
  def set_timeout(t: Time): Process_Result = copy(rc = 1, timeout = Some(t))
62401
15a2533f1f0a more informative Process_Result;
wenzelm
parents: 62400
diff changeset
    20
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    21
  def ok: Boolean = rc == 0
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    22
  def interrupted: Boolean = rc == Exn.Interrupt.return_code
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    23
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    24
  def check: Process_Result =
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    25
    if (ok) this
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    26
    else if (interrupted) throw Exn.Interrupt()
62492
0e53fade87fe clarified modules;
wenzelm
parents: 62405
diff changeset
    27
    else Exn.error(err)
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    28
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    29
  def print: Process_Result =
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    30
  {
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    31
    Output.warning(Library.trim_line(err))
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    32
    Output.writeln(Library.trim_line(out))
62404
13a0f537e232 retain tail out_lines as printed, but not the whole log content;
wenzelm
parents: 62402
diff changeset
    33
    copy(out_lines = Nil, err_lines = Nil)
62400
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    34
  }
833af0d6d469 clarified modules;
wenzelm
parents:
diff changeset
    35
}