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