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(clean_build) ::
|
|
25 |
Properties.Value.Boolean(system_mode) ::
|
|
26 |
session :: include_dirs =>
|
|
27 |
val top =
|
|
28 |
build_dialog(clean_build, system_mode, include_dirs.map(Path.explode), session)
|
|
29 |
top.pack()
|
|
30 |
top.visible = true
|
50365
|
31 |
case _ => error("Bad arguments:\n" + cat_lines(args))
|
|
32 |
}
|
|
33 |
}
|
|
34 |
catch {
|
|
35 |
case exn: Throwable =>
|
|
36 |
Library.error_dialog(null, "Isabelle build failure",
|
|
37 |
Library.scrollable_text(Exn.message(exn)))
|
|
38 |
sys.exit(2)
|
|
39 |
}
|
|
40 |
}
|
|
41 |
|
|
42 |
|
50369
|
43 |
def build_dialog(
|
|
44 |
clean_build: Boolean,
|
|
45 |
system_mode: Boolean,
|
|
46 |
include_dirs: List[Path],
|
|
47 |
session: String): MainFrame = new MainFrame
|
50365
|
48 |
{
|
50369
|
49 |
title = "Isabelle build"
|
50365
|
50 |
|
|
51 |
|
50368
|
52 |
/* GUI state */
|
50365
|
53 |
|
50368
|
54 |
private var is_stopped = false
|
|
55 |
private var return_code = 0
|
|
56 |
|
|
57 |
|
50365
|
58 |
/* text */
|
|
59 |
|
|
60 |
val text = new TextArea {
|
|
61 |
editable = false
|
50369
|
62 |
columns = 40
|
|
63 |
rows = 10
|
50365
|
64 |
}
|
|
65 |
|
50368
|
66 |
val progress = new Build.Progress
|
|
67 |
{
|
|
68 |
override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") }
|
|
69 |
override def stopped: Boolean =
|
|
70 |
Swing_Thread.now { val b = is_stopped; is_stopped = false; b }
|
|
71 |
}
|
|
72 |
|
50365
|
73 |
|
|
74 |
/* actions */
|
|
75 |
|
50369
|
76 |
val cancel = new Button("Cancel") {
|
|
77 |
reactions += { case ButtonClicked(_) => is_stopped = true }
|
50365
|
78 |
}
|
|
79 |
|
50369
|
80 |
val actions = new FlowPanel(FlowPanel.Alignment.Center)(cancel)
|
50368
|
81 |
|
|
82 |
|
|
83 |
/* layout panel */
|
|
84 |
|
|
85 |
val layout_panel = new BorderPanel
|
|
86 |
layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
|
|
87 |
layout_panel.layout(actions) = BorderPanel.Position.South
|
|
88 |
|
|
89 |
contents = layout_panel
|
50369
|
90 |
|
|
91 |
|
|
92 |
/* main build */
|
|
93 |
|
|
94 |
progress.echo("Build started ...")
|
|
95 |
|
|
96 |
default_thread_pool.submit(() => {
|
|
97 |
val (out, rc) =
|
|
98 |
try {
|
|
99 |
("",
|
|
100 |
Build.build(progress, build_heap = true,
|
|
101 |
clean_build = clean_build, system_mode = system_mode, sessions = List(session)))
|
|
102 |
}
|
|
103 |
catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
|
|
104 |
Swing_Thread.now {
|
|
105 |
if (rc != 0) {
|
|
106 |
Library.error_dialog(this.peer, "Isabelle build failure",
|
|
107 |
Library.scrollable_text(out + "Return code: " + rc + "\n"))
|
|
108 |
}
|
|
109 |
sys.exit(rc)
|
|
110 |
}
|
|
111 |
})
|
50365
|
112 |
}
|
|
113 |
}
|
|
114 |
|