src/Pure/System/build_dialog.scala
author wenzelm
Wed, 05 Dec 2012 18:07:32 +0100
changeset 50372 11c96cac860d
parent 50371 9b6f5f758c31
child 50374 1a7cae0711d2
permissions -rw-r--r--
tuned message;
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 {
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    23
        case
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    24
          Properties.Value.Boolean(system_mode) ::
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    25
          session :: include_dirs =>
50370
d5dbb63df0c7 check for existing image (even if outdated);
wenzelm
parents: 50369
diff changeset
    26
            val top = build_dialog(system_mode, include_dirs.map(Path.explode), session)
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    27
            top.pack()
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    28
            top.visible = true
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    29
        case _ => error("Bad arguments:\n" + cat_lines(args))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    30
      }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    31
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    32
    catch {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    33
      case exn: Throwable =>
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    34
        Library.error_dialog(null, "Isabelle build failure",
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    35
          Library.scrollable_text(Exn.message(exn)))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    36
        sys.exit(2)
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
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    40
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    41
  def build_dialog(
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    42
    system_mode: Boolean,
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    43
    include_dirs: List[Path],
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    44
    session: String): MainFrame = new MainFrame
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    45
  {
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    46
    title = "Isabelle build"
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    47
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
    /* GUI state */
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    50
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    51
    private var is_stopped = false
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    52
    private var return_code = 0
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    53
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    54
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    55
    /* text */
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    56
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    57
    val text = new TextArea {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    58
      editable = false
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    59
      columns = 40
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    60
      rows = 10
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    61
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    62
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    63
    val progress = new Build.Progress
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    64
    {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    65
      override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    66
      override def stopped: Boolean =
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    67
        Swing_Thread.now { val b = is_stopped; is_stopped = false; b  }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    68
    }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    69
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    70
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    71
    /* actions */
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    72
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    73
    val cancel = new Button("Cancel") {
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    74
      reactions += { case ButtonClicked(_) => is_stopped = true }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    75
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    76
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    77
    val actions = new FlowPanel(FlowPanel.Alignment.Center)(cancel)
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    78
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    79
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    80
    /* layout panel */
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    81
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    82
    val layout_panel = new BorderPanel
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    83
    layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    84
    layout_panel.layout(actions) = BorderPanel.Position.South
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    85
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    86
    contents = layout_panel
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    87
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    88
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    89
    /* main build */
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    90
50372
11c96cac860d tuned message;
wenzelm
parents: 50371
diff changeset
    91
    progress.echo("Build started for Isabelle/" + session + " ...")
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    92
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    93
    default_thread_pool.submit(() => {
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    94
      val (out, rc) =
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    95
        try {
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    96
          ("",
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    97
            Build.build(progress, build_heap = true,
50370
d5dbb63df0c7 check for existing image (even if outdated);
wenzelm
parents: 50369
diff changeset
    98
              system_mode = system_mode, sessions = List(session)))
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    99
        }
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   100
        catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
50371
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   101
      if (rc == 0) {
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   102
        progress.echo("OK\n")
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   103
        Thread.sleep(1000)
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   104
      }
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   105
      else
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   106
        Swing_Thread.now {
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   107
          Library.error_dialog(this.peer, "Isabelle build failure",
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   108
            Library.scrollable_text(out + "Return code: " + rc + "\n"))
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   109
        }
50371
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   110
      sys.exit(rc)
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
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
}
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   114