50365
|
1 |
/* Title: Pure/System/build_dialog.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Dialog for session build process.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
50377
|
10 |
import java.awt.{GraphicsEnvironment, Point}
|
50365
|
11 |
import scala.swing.{ScrollPane, Button, CheckBox, FlowPanel,
|
|
12 |
BorderPanel, MainFrame, TextArea, SwingApplication}
|
|
13 |
import scala.swing.event.ButtonClicked
|
|
14 |
|
|
15 |
|
|
16 |
object Build_Dialog extends SwingApplication
|
|
17 |
{
|
|
18 |
def startup(args: Array[String]) =
|
|
19 |
{
|
|
20 |
Platform.init_laf()
|
|
21 |
|
|
22 |
try {
|
|
23 |
args.toList match {
|
50369
|
24 |
case
|
|
25 |
Properties.Value.Boolean(system_mode) ::
|
|
26 |
session :: include_dirs =>
|
50377
|
27 |
val center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint()
|
50370
|
28 |
val top = build_dialog(system_mode, include_dirs.map(Path.explode), session)
|
50369
|
29 |
top.pack()
|
50377
|
30 |
top.location = new Point(center.x - top.size.width / 2, center.y - top.size.height / 2)
|
50369
|
31 |
top.visible = true
|
50365
|
32 |
case _ => error("Bad arguments:\n" + cat_lines(args))
|
|
33 |
}
|
|
34 |
}
|
|
35 |
catch {
|
|
36 |
case exn: Throwable =>
|
|
37 |
Library.error_dialog(null, "Isabelle build failure",
|
|
38 |
Library.scrollable_text(Exn.message(exn)))
|
|
39 |
sys.exit(2)
|
|
40 |
}
|
|
41 |
}
|
|
42 |
|
|
43 |
|
50369
|
44 |
def build_dialog(
|
|
45 |
system_mode: Boolean,
|
|
46 |
include_dirs: List[Path],
|
|
47 |
session: String): MainFrame = new MainFrame
|
50365
|
48 |
{
|
50368
|
49 |
/* GUI state */
|
50365
|
50 |
|
50368
|
51 |
private var is_stopped = false
|
|
52 |
private var return_code = 0
|
|
53 |
|
|
54 |
|
50365
|
55 |
/* text */
|
|
56 |
|
|
57 |
val text = new TextArea {
|
|
58 |
editable = false
|
50369
|
59 |
columns = 40
|
|
60 |
rows = 10
|
50365
|
61 |
}
|
|
62 |
|
50368
|
63 |
val progress = new Build.Progress
|
|
64 |
{
|
|
65 |
override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") }
|
|
66 |
override def stopped: Boolean =
|
|
67 |
Swing_Thread.now { val b = is_stopped; is_stopped = false; b }
|
|
68 |
}
|
|
69 |
|
50365
|
70 |
|
50376
|
71 |
/* action button */
|
50365
|
72 |
|
50376
|
73 |
var button_action: () => Unit = (() => is_stopped = true)
|
|
74 |
val button = new Button("Cancel") {
|
|
75 |
reactions += { case ButtonClicked(_) => button_action() }
|
|
76 |
}
|
|
77 |
def button_exit(rc: Int)
|
|
78 |
{
|
|
79 |
button.text = if (rc == 0) "OK" else "Exit"
|
|
80 |
button_action = (() => sys.exit(rc))
|
50365
|
81 |
}
|
|
82 |
|
50376
|
83 |
val action_panel = new FlowPanel(FlowPanel.Alignment.Center)(button)
|
50368
|
84 |
|
|
85 |
|
|
86 |
/* layout panel */
|
|
87 |
|
|
88 |
val layout_panel = new BorderPanel
|
|
89 |
layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
|
50376
|
90 |
layout_panel.layout(action_panel) = BorderPanel.Position.South
|
50368
|
91 |
|
|
92 |
contents = layout_panel
|
50369
|
93 |
|
|
94 |
|
|
95 |
/* main build */
|
|
96 |
|
50374
|
97 |
title = "Isabelle build (" + Isabelle_System.getenv("ML_IDENTIFIER") + ")"
|
50372
|
98 |
progress.echo("Build started for Isabelle/" + session + " ...")
|
50369
|
99 |
|
|
100 |
default_thread_pool.submit(() => {
|
|
101 |
val (out, rc) =
|
|
102 |
try {
|
|
103 |
("",
|
|
104 |
Build.build(progress, build_heap = true,
|
50370
|
105 |
system_mode = system_mode, sessions = List(session)))
|
50369
|
106 |
}
|
|
107 |
catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
|
50376
|
108 |
Swing_Thread.now {
|
|
109 |
progress.echo(out + (if (rc == 0) "OK\n" else "Return code: " + rc + "\n"))
|
|
110 |
button_exit(rc)
|
50371
|
111 |
}
|
50369
|
112 |
})
|
50365
|
113 |
}
|
|
114 |
}
|
|
115 |
|