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 {
|
50369
|
23 |
case
|
|
24 |
Properties.Value.Boolean(system_mode) ::
|
|
25 |
session :: include_dirs =>
|
50370
|
26 |
val top = build_dialog(system_mode, include_dirs.map(Path.explode), session)
|
50369
|
27 |
top.pack()
|
|
28 |
top.visible = true
|
50365
|
29 |
case _ => error("Bad arguments:\n" + cat_lines(args))
|
|
30 |
}
|
|
31 |
}
|
|
32 |
catch {
|
|
33 |
case exn: Throwable =>
|
|
34 |
Library.error_dialog(null, "Isabelle build failure",
|
|
35 |
Library.scrollable_text(Exn.message(exn)))
|
|
36 |
sys.exit(2)
|
|
37 |
}
|
|
38 |
}
|
|
39 |
|
|
40 |
|
50369
|
41 |
def build_dialog(
|
|
42 |
system_mode: Boolean,
|
|
43 |
include_dirs: List[Path],
|
|
44 |
session: String): MainFrame = new MainFrame
|
50365
|
45 |
{
|
50369
|
46 |
title = "Isabelle build"
|
50365
|
47 |
|
|
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 |
|
|
71 |
/* actions */
|
|
72 |
|
50369
|
73 |
val cancel = new Button("Cancel") {
|
|
74 |
reactions += { case ButtonClicked(_) => is_stopped = true }
|
50365
|
75 |
}
|
|
76 |
|
50369
|
77 |
val actions = new FlowPanel(FlowPanel.Alignment.Center)(cancel)
|
50368
|
78 |
|
|
79 |
|
|
80 |
/* layout panel */
|
|
81 |
|
|
82 |
val layout_panel = new BorderPanel
|
|
83 |
layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
|
|
84 |
layout_panel.layout(actions) = BorderPanel.Position.South
|
|
85 |
|
|
86 |
contents = layout_panel
|
50369
|
87 |
|
|
88 |
|
|
89 |
/* main build */
|
|
90 |
|
50372
|
91 |
progress.echo("Build started for Isabelle/" + session + " ...")
|
50369
|
92 |
|
|
93 |
default_thread_pool.submit(() => {
|
|
94 |
val (out, rc) =
|
|
95 |
try {
|
|
96 |
("",
|
|
97 |
Build.build(progress, build_heap = true,
|
50370
|
98 |
system_mode = system_mode, sessions = List(session)))
|
50369
|
99 |
}
|
|
100 |
catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
|
50371
|
101 |
if (rc == 0) {
|
|
102 |
progress.echo("OK\n")
|
|
103 |
Thread.sleep(1000)
|
|
104 |
}
|
|
105 |
else
|
|
106 |
Swing_Thread.now {
|
50369
|
107 |
Library.error_dialog(this.peer, "Isabelle build failure",
|
|
108 |
Library.scrollable_text(out + "Return code: " + rc + "\n"))
|
|
109 |
}
|
50371
|
110 |
sys.exit(rc)
|
50369
|
111 |
})
|
50365
|
112 |
}
|
|
113 |
}
|
|
114 |
|