src/Pure/System/build_dialog.scala
author wenzelm
Wed, 05 Dec 2012 16:33:02 +0100
changeset 50368 e6c0720e4cef
parent 50365 82f5aea343e7
child 50369 622002c702ad
permissions -rw-r--r--
basic interaction with build process;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/build_dialog.scala
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     3
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     4
Dialog for session build process.
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     5
*/
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     6
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     7
package isabelle
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     8
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     9
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    10
import scala.swing.{ScrollPane, Button, CheckBox, FlowPanel,
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    11
  BorderPanel, MainFrame, TextArea, SwingApplication}
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    12
import scala.swing.event.ButtonClicked
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    13
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    14
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    15
object Build_Dialog extends SwingApplication
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    16
{
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    17
  def startup(args: Array[String]) =
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    18
  {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    19
    Platform.init_laf()
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    20
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    21
    try {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    22
      args.toList match {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    23
        case Command_Line.Chunks(include_dirs, List(session)) =>
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    24
          val top = build_dialog(include_dirs.map(Path.explode), session)
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    25
          top.pack()
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    26
          top.visible = true
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    27
        case _ => error("Bad arguments:\n" + cat_lines(args))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    28
      }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    29
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    30
    catch {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    31
      case exn: Throwable =>
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    32
        Library.error_dialog(null, "Isabelle build failure",
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    33
          Library.scrollable_text(Exn.message(exn)))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    34
        sys.exit(2)
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    35
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    36
  }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    37
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    38
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    39
  def build_dialog(include_dirs: List[Path], session: String): MainFrame = new MainFrame
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    40
  {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    41
    title = "Isabelle session build"
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    42
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    43
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    44
    /* GUI state */
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    45
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    46
    private var clean_build = false
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    47
    private var system_mode = false
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    48
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    49
    private var is_started = false
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    50
    private var is_stopped = false
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    51
    private var return_code = 0
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    52
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    53
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    54
    /* controls */
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    55
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    56
    private val _clean_build = new CheckBox("Clean build") {
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    57
      reactions += { case ButtonClicked(_) => clean_build = this.selected }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    58
    }
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    59
    _clean_build.selected = clean_build
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    60
    _clean_build.tooltip = "Delete outdated session images"
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    61
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    62
    private val _system_mode = new CheckBox("System build") {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    63
      reactions += { case ButtonClicked(_) => system_mode = this.selected }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    64
    }
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    65
    _system_mode.selected = system_mode
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    66
    _system_mode.tooltip = "Produce output in $ISABELLE_HOME instead of $ISABELLE_HOME_USER"
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    67
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    68
    val controls = new FlowPanel(FlowPanel.Alignment.Right)(_clean_build, _system_mode)
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    69
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    70
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    71
    /* text */
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    72
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    73
    val text = new TextArea {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    74
      editable = false
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    75
      columns = 80
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    76
      rows = 15
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    77
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    78
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    79
    val progress = new Build.Progress
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    80
    {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    81
      override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    82
      override def stopped: Boolean =
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    83
        Swing_Thread.now { val b = is_stopped; is_stopped = false; b  }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    84
    }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    85
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    86
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    87
    /* actions */
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    88
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    89
    val start = new Button("Start") {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    90
      reactions += { case ButtonClicked(_) =>
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    91
        if (!is_started) {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    92
          progress.echo("Build started ...")
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    93
          is_started = true
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    94
          default_thread_pool.submit(() => {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    95
            val (out, rc) =
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    96
              try {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    97
                ("",
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    98
                  Build.build(progress, build_heap = true, verbose = true,
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    99
                    clean_build = clean_build, system_mode = system_mode, sessions = List(session)))
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   100
              }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   101
              catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   102
            Swing_Thread.now {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   103
              if (rc != 0) {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   104
                progress.echo(out + "Return code: " + rc + "\n")
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   105
                return_code = rc
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   106
              }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   107
              is_started = false
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   108
            }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   109
          })
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   110
        }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   111
      }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   112
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   113
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   114
    val stop = new Button("Stop") {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   115
      reactions += { case ButtonClicked(_) =>
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   116
        progress.echo("Build stopped ...")
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   117
        is_stopped = true
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   118
      }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   119
    }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   120
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   121
    val exit = new Button("Exit") {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   122
      reactions += { case ButtonClicked(_) => sys.exit(return_code) }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   123
    }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   124
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   125
    val actions = new FlowPanel(FlowPanel.Alignment.Center)(start, stop, exit)
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   126
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   127
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   128
    /* layout panel */
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   129
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   130
    val layout_panel = new BorderPanel
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   131
    layout_panel.layout(controls) = BorderPanel.Position.North
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   132
    layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   133
    layout_panel.layout(actions) = BorderPanel.Position.South
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   134
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   135
    contents = layout_panel
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   136
  }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   137
}
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   138