author | wenzelm |
Tue, 24 Jul 2012 20:41:50 +0200 | |
changeset 48482 | 45137257399a |
parent 48478 | 146090de0474 |
child 48484 | 70898d016538 |
permissions | -rw-r--r-- |
48276 | 1 |
/* Title: Pure/System/build.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build and manage Isabelle sessions. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
48409 | 10 |
import java.io.{File => JFile} |
48335 | 11 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
12 |
import scala.collection.mutable |
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
13 |
import scala.annotation.tailrec |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
14 |
|
48335 | 15 |
|
48276 | 16 |
object Build |
17 |
{ |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
18 |
/** session information **/ |
48334 | 19 |
|
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
20 |
object Session |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
21 |
{ |
48421 | 22 |
/* Key */ |
23 |
||
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
24 |
object Key |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
25 |
{ |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
26 |
object Ordering extends scala.math.Ordering[Key] |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
27 |
{ |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
28 |
def compare(key1: Key, key2: Key): Int = |
48350
09bf3b73e446
clarified topological ordering: preserve order of adjacency via reverse fold;
wenzelm
parents:
48349
diff
changeset
|
29 |
key1.order compare key2.order match { |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
30 |
case 0 => key1.name compare key2.name |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
31 |
case ord => ord |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
32 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
33 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
34 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
35 |
|
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
36 |
sealed case class Key(name: String, order: Int) |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
37 |
{ |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
38 |
override def toString: String = name |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
39 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
40 |
|
48421 | 41 |
|
42 |
/* Info */ |
|
43 |
||
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
44 |
sealed case class Info( |
48457 | 45 |
base_name: String, |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
46 |
dir: Path, |
48418 | 47 |
parent: Option[String], |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
48 |
parent_base_name: Option[String], |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
49 |
description: String, |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
50 |
options: Options, |
48421 | 51 |
theories: List[(Options, List[Path])], |
52 |
files: List[Path], |
|
48424 | 53 |
digest: SHA1.Digest) |
48421 | 54 |
|
55 |
||
56 |
/* Queue */ |
|
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
57 |
|
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
58 |
object Queue |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
59 |
{ |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
60 |
val empty: Queue = new Queue() |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
61 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
62 |
|
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
63 |
final class Queue private( |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
64 |
keys: Map[String, Key] = Map.empty, |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
65 |
graph: Graph[Key, Info] = Graph.empty(Key.Ordering)) |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
66 |
{ |
48425 | 67 |
def is_empty: Boolean = graph.is_empty |
68 |
||
69 |
def apply(name: String): Info = graph.get_node(keys(name)) |
|
48351 | 70 |
def defined(name: String): Boolean = keys.isDefinedAt(name) |
48419 | 71 |
def is_inner(name: String): Boolean = !graph.is_maximal(keys(name)) |
72 |
||
48418 | 73 |
def + (key: Key, info: Info): Queue = |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
74 |
{ |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
75 |
val keys1 = |
48351 | 76 |
if (defined(key.name)) error("Duplicate session: " + quote(key.name)) |
77 |
else keys + (key.name -> key) |
|
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
78 |
|
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
79 |
val graph1 = |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
80 |
try { |
48418 | 81 |
graph.new_node(key, info).add_deps_acyclic(key, info.parent.toList.map(keys(_))) |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
82 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
83 |
catch { |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
84 |
case exn: Graph.Cycles[_] => |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
85 |
error(cat_lines(exn.cycles.map(cycle => |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
86 |
"Cyclic session dependency of " + |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
87 |
cycle.map(key => quote(key.toString)).mkString(" via ")))) |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
88 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
89 |
new Queue(keys1, graph1) |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
90 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
91 |
|
48425 | 92 |
def - (name: String): Queue = new Queue(keys - name, graph.del_node(keys(name))) |
93 |
||
48363 | 94 |
def required(names: List[String]): Queue = |
95 |
{ |
|
96 |
val req = graph.all_preds(names.map(keys(_))).map(_.name).toSet |
|
97 |
val keys1 = keys -- keys.keySet.filter(name => !req(name)) |
|
98 |
val graph1 = graph.restrict(key => keys1.isDefinedAt(key.name)) |
|
99 |
new Queue(keys1, graph1) |
|
100 |
} |
|
101 |
||
48425 | 102 |
def dequeue(skip: String => Boolean): Option[(String, Info)] = |
103 |
{ |
|
104 |
val it = graph.entries.dropWhile( |
|
105 |
{ case (key, (_, (deps, _))) => !deps.isEmpty || skip(key.name) }) |
|
106 |
if (it.hasNext) { val (key, (info, _)) = it.next; Some((key.name, info)) } |
|
107 |
else None |
|
108 |
} |
|
109 |
||
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
110 |
def topological_order: List[(String, Info)] = |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
111 |
graph.topological_order.map(key => (key.name, graph.get_node(key))) |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
112 |
} |
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
113 |
} |
48334 | 114 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
115 |
|
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
116 |
/* parsing */ |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
117 |
|
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
118 |
private case class Session_Entry( |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
119 |
name: String, |
48462
424fd5364f15
clarified "this_name" vs. former "reset" feature -- imitate the latter by loading other session sources directly;
wenzelm
parents:
48459
diff
changeset
|
120 |
this_name: Boolean, |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
121 |
order: Int, |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
122 |
path: Option[String], |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
123 |
parent: Option[String], |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
124 |
description: String, |
48421 | 125 |
options: List[Options.Spec], |
126 |
theories: List[(List[Options.Spec], List[String])], |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
127 |
files: List[String]) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
128 |
|
48334 | 129 |
private object Parser extends Parse.Parser |
130 |
{ |
|
131 |
val SESSION = "session" |
|
132 |
val IN = "in" |
|
133 |
val DESCRIPTION = "description" |
|
134 |
val OPTIONS = "options" |
|
135 |
val THEORIES = "theories" |
|
136 |
val FILES = "files" |
|
137 |
||
138 |
val syntax = |
|
48336 | 139 |
Outer_Syntax.empty + "!" + "(" + ")" + "+" + "," + "=" + "[" + "]" + |
140 |
SESSION + IN + DESCRIPTION + OPTIONS + THEORIES + FILES |
|
48334 | 141 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
142 |
val session_entry: Parser[Session_Entry] = |
48334 | 143 |
{ |
144 |
val session_name = atom("session name", _.is_name) |
|
145 |
val theory_name = atom("theory name", _.is_name) |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
146 |
|
48334 | 147 |
val option = |
148 |
name ~ opt(keyword("=") ~! name ^^ { case _ ~ x => x }) ^^ { case x ~ y => (x, y) } |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
149 |
val options = keyword("[") ~> repsep(option, keyword(",")) <~ keyword("]") |
48334 | 150 |
|
151 |
val theories = |
|
152 |
keyword(THEORIES) ~! ((options | success(Nil)) ~ rep1(theory_name)) ^^ |
|
153 |
{ case _ ~ (x ~ y) => (x, y) } |
|
154 |
||
155 |
((keyword(SESSION) ~! session_name) ^^ { case _ ~ x => x }) ~ |
|
48336 | 156 |
(keyword("!") ^^^ true | success(false)) ~ |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
157 |
(keyword("(") ~! (nat <~ keyword(")")) ^^ { case _ ~ x => x } | success(Integer.MAX_VALUE)) ~ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
158 |
(opt(keyword(IN) ~! string ^^ { case _ ~ x => x })) ~ |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
159 |
(keyword("=") ~> opt(session_name <~ keyword("+"))) ~ |
48334 | 160 |
(keyword(DESCRIPTION) ~! text ^^ { case _ ~ x => x } | success("")) ~ |
161 |
(keyword(OPTIONS) ~! options ^^ { case _ ~ x => x } | success(Nil)) ~ |
|
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
162 |
rep(theories) ~ |
48336 | 163 |
(keyword(FILES) ~! rep1(path) ^^ { case _ ~ x => x } | success(Nil)) ^^ |
48349
a78e5d399599
support Session.Queue with ordering and dependencies;
wenzelm
parents:
48347
diff
changeset
|
164 |
{ case a ~ b ~ c ~ d ~ e ~ f ~ g ~ h ~ i => Session_Entry(a, b, c, d, e, f, g, h, i) } |
48334 | 165 |
} |
166 |
||
48409 | 167 |
def parse_entries(root: JFile): List[Session_Entry] = |
48334 | 168 |
{ |
48411
5b3440850d36
more abstract file system operations in Scala, corresponding to ML version;
wenzelm
parents:
48409
diff
changeset
|
169 |
val toks = syntax.scan(File.read(root)) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
170 |
parse_all(rep(session_entry), Token.reader(toks, root.toString)) match { |
48334 | 171 |
case Success(result, _) => result |
172 |
case bad => error(bad.toString) |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
176 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
177 |
|
48341 | 178 |
/* find sessions */ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
179 |
|
48361 | 180 |
private val ROOT = Path.explode("ROOT") |
181 |
private val SESSIONS = Path.explode("etc/sessions") |
|
182 |
||
48364 | 183 |
private def is_pure(name: String): Boolean = name == "RAW" || name == "Pure" |
184 |
||
48421 | 185 |
private def sessions_root(options: Options, dir: Path, root: JFile, queue: Session.Queue) |
186 |
: Session.Queue = |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
187 |
{ |
48361 | 188 |
(queue /: Parser.parse_entries(root))((queue1, entry) => |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
189 |
try { |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
190 |
if (entry.name == "") error("Bad session name") |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
191 |
|
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
192 |
val (full_name, parent_base_name) = |
48364 | 193 |
if (is_pure(entry.name)) { |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
194 |
if (entry.parent.isDefined) error("Illegal parent session") |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
195 |
else (entry.name, None: Option[String]) |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
196 |
} |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
197 |
else |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
198 |
entry.parent match { |
48361 | 199 |
case Some(parent_name) if queue1.defined(parent_name) => |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
200 |
val full_name = |
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
201 |
if (entry.this_name) entry.name |
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
202 |
else parent_name + "-" + entry.name |
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
203 |
val parent_base_name = Some(queue1(parent_name).base_name) |
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
204 |
(full_name, parent_base_name) |
48351 | 205 |
case _ => error("Bad parent session") |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
206 |
} |
48339 | 207 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
208 |
val path = |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
209 |
entry.path match { |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
210 |
case Some(p) => Path.explode(p) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
211 |
case None => Path.basic(entry.name) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
212 |
} |
48339 | 213 |
|
48351 | 214 |
val key = Session.Key(full_name, entry.order) |
48421 | 215 |
|
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
216 |
val session_options = options ++ entry.options |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
217 |
|
48421 | 218 |
val theories = |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
219 |
entry.theories.map({ case (opts, thys) => |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
220 |
(session_options ++ opts, thys.map(Path.explode(_))) }) |
48421 | 221 |
val files = entry.files.map(Path.explode(_)) |
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
222 |
val digest = SHA1.digest((full_name, entry.parent, entry.options, entry.theories).toString) |
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
223 |
|
48418 | 224 |
val info = |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
225 |
Session.Info(entry.name, dir + path, entry.parent, parent_base_name, |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
226 |
entry.description, session_options, theories, files, digest) |
48351 | 227 |
|
48418 | 228 |
queue1 + (key, info) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
229 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
230 |
catch { |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
231 |
case ERROR(msg) => |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
232 |
error(msg + "\nThe error(s) above occurred in session entry " + |
48370 | 233 |
quote(entry.name) + Position.str_of(Position.file(root))) |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
234 |
}) |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
235 |
} |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
236 |
|
48421 | 237 |
private def sessions_dir(options: Options, strict: Boolean, dir: Path, queue: Session.Queue) |
238 |
: Session.Queue = |
|
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
239 |
{ |
48373 | 240 |
val root = (dir + ROOT).file |
48421 | 241 |
if (root.isFile) sessions_root(options, dir, root, queue) |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
242 |
else if (strict) error("Bad session root file: " + quote(root.toString)) |
48361 | 243 |
else queue |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
244 |
} |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
245 |
|
48421 | 246 |
private def sessions_catalog(options: Options, dir: Path, catalog: JFile, queue: Session.Queue) |
247 |
: Session.Queue = |
|
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
248 |
{ |
48354 | 249 |
val dirs = |
48411
5b3440850d36
more abstract file system operations in Scala, corresponding to ML version;
wenzelm
parents:
48409
diff
changeset
|
250 |
split_lines(File.read(catalog)).filterNot(line => line == "" || line.startsWith("#")) |
48361 | 251 |
(queue /: dirs)((queue1, dir1) => |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
252 |
try { |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
253 |
val dir2 = dir + Path.explode(dir1) |
48421 | 254 |
if (dir2.file.isDirectory) sessions_dir(options, true, dir2, queue1) |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
255 |
else error("Bad session directory: " + dir2.toString) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
256 |
} |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
257 |
catch { |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
258 |
case ERROR(msg) => |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
259 |
error(msg + "\nThe error(s) above occurred in session catalog " + quote(catalog.toString)) |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
260 |
}) |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
261 |
} |
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
262 |
|
48421 | 263 |
def find_sessions(options: Options, all_sessions: Boolean, sessions: List[String], |
48419 | 264 |
more_dirs: List[Path]): Session.Queue = |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
265 |
{ |
48361 | 266 |
var queue = Session.Queue.empty |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
267 |
|
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
268 |
for (dir <- Isabelle_System.components()) { |
48421 | 269 |
queue = sessions_dir(options, false, dir, queue) |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
270 |
|
48373 | 271 |
val catalog = (dir + SESSIONS).file |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
272 |
if (catalog.isFile) |
48421 | 273 |
queue = sessions_catalog(options, dir, catalog, queue) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
274 |
} |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
275 |
|
48421 | 276 |
for (dir <- more_dirs) queue = sessions_dir(options, true, dir, queue) |
48352
7fbf98ee265f
include COMPONENT/etc/sessions as catalog for more directories, for improved scalability with hundreds of entries (notably AFP);
wenzelm
parents:
48351
diff
changeset
|
277 |
|
48419 | 278 |
sessions.filter(name => !queue.defined(name)) match { |
279 |
case Nil => |
|
280 |
case bad => error("Undefined session(s): " + commas_quote(bad)) |
|
281 |
} |
|
282 |
||
283 |
if (all_sessions) queue else queue.required(sessions) |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
284 |
} |
48341 | 285 |
|
286 |
||
48424 | 287 |
|
288 |
/** build **/ |
|
289 |
||
48478 | 290 |
private def echo(msg: String) { java.lang.System.out.println(msg) } |
291 |
private def sleep(): Unit = Thread.sleep(500) |
|
292 |
||
293 |
||
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
294 |
/* dependencies */ |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
295 |
|
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
296 |
sealed case class Node( |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
297 |
loaded_theories: Set[String], |
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
298 |
sources: List[(Path, SHA1.Digest)]) |
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
299 |
|
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
300 |
sealed case class Deps(deps: Map[String, Node]) |
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
301 |
{ |
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
302 |
def sources(name: String): List[(Path, SHA1.Digest)] = deps(name).sources |
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
303 |
} |
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
304 |
|
48478 | 305 |
def dependencies(verbose: Boolean, queue: Session.Queue): Deps = |
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
306 |
Deps((Map.empty[String, Node] /: queue.topological_order)( |
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
307 |
{ case (deps, (name, info)) => |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
308 |
val preloaded = |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
309 |
info.parent match { |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
310 |
case None => Set.empty[String] |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
311 |
case Some(parent) => deps(parent).loaded_theories |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
312 |
} |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
313 |
val thy_info = new Thy_Info(new Thy_Load(preloaded)) |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
314 |
|
48478 | 315 |
if (verbose) echo("Checking " + name) |
316 |
||
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
317 |
val thy_deps = |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
318 |
thy_info.dependencies( |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
319 |
info.theories.map(_._2).flatten. |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
320 |
map(thy => Document.Node.Name(info.dir + Thy_Load.thy_path(thy)))) |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
321 |
|
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
322 |
val loaded_theories = preloaded ++ thy_deps.map(_._1.theory) |
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
323 |
|
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
324 |
val all_files = |
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
325 |
thy_deps.map({ case (n, h) => |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
326 |
val thy = Path.explode(n.node).expand |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
327 |
val uses = |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
328 |
h match { |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
329 |
case Exn.Res(d) => |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
330 |
d.uses.map(p => (Path.explode(n.dir) + Path.explode(p._1)).expand) |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
331 |
case _ => Nil |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
332 |
} |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
333 |
thy :: uses |
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
334 |
}).flatten ::: info.files.map(file => info.dir + file) |
48478 | 335 |
val sources = all_files.map(p => (p, SHA1.digest(p))) |
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
336 |
|
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
337 |
deps + (name -> Node(loaded_theories, sources)) |
48423
0ccf143a2a69
maintain set of source digests, including relevant parts of session entry;
wenzelm
parents:
48422
diff
changeset
|
338 |
})) |
48422
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
339 |
|
9613780a805b
determine source dependencies, relatively to preloaded theories;
wenzelm
parents:
48421
diff
changeset
|
340 |
|
48424 | 341 |
/* jobs */ |
48341 | 342 |
|
48424 | 343 |
private class Job(cwd: JFile, env: Map[String, String], script: String, args: String) |
48364 | 344 |
{ |
48418 | 345 |
private val args_file = File.tmp_file("args") |
346 |
private val env1 = env + ("ARGS_FILE" -> Isabelle_System.posix_path(args_file.getPath)) |
|
347 |
File.write(args_file, args) |
|
348 |
||
48424 | 349 |
private val (thread, result) = |
350 |
Simple_Thread.future("build") { Isabelle_System.bash_env(cwd, env1, script) } |
|
48418 | 351 |
|
352 |
def terminate: Unit = thread.interrupt |
|
353 |
def is_finished: Boolean = result.is_finished |
|
48425 | 354 |
def join: (String, String, Int) = { val res = result.join; args_file.delete; res } |
48418 | 355 |
} |
356 |
||
48457 | 357 |
private def start_job(name: String, info: Session.Info, output: Option[String], |
48459
375e45df6fdf
timing is command line options, not system option;
wenzelm
parents:
48457
diff
changeset
|
358 |
options: Options, timing: Boolean, verbose: Boolean, browser_info: Path): Job = |
48418 | 359 |
{ |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
360 |
// global browser info dir |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
361 |
if (options.bool("browser_info") && !(browser_info + Path.explode("index.html")).file.isFile) |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
362 |
{ |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
363 |
browser_info.file.mkdirs() |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
364 |
File.copy(Path.explode("~~/lib/logo/isabelle.gif"), |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
365 |
browser_info + Path.explode("isabelle.gif")) |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
366 |
File.write(browser_info + Path.explode("index.html"), |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
367 |
File.read(Path.explode("~~/lib/html/library_index_header.template")) + |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
368 |
File.read(Path.explode("~~/lib/html/library_index_content.template")) + |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
369 |
File.read(Path.explode("~~/lib/html/library_index_footer.template"))) |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
370 |
} |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
371 |
|
48418 | 372 |
val parent = info.parent.getOrElse("") |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
373 |
val parent_base_name = info.parent_base_name.getOrElse("") |
48418 | 374 |
|
48373 | 375 |
val cwd = info.dir.file |
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
376 |
val env = Map("INPUT" -> parent, "TARGET" -> name, "OUTPUT" -> output.getOrElse("")) |
48364 | 377 |
val script = |
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
378 |
if (is_pure(name)) "./build " + name + " \"$OUTPUT\"" |
48418 | 379 |
else { |
380 |
""" |
|
381 |
. "$ISABELLE_HOME/lib/scripts/timestart.bash" |
|
382 |
""" + |
|
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
383 |
(if (output.isDefined) |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
384 |
""" "$ISABELLE_PROCESS" -e "Build.build \"$ARGS_FILE\";" -q -w "$INPUT" "$OUTPUT" """ |
48418 | 385 |
else |
386 |
""" "$ISABELLE_PROCESS" -e "Build.build \"$ARGS_FILE\";" -r -q "$INPUT" """) + |
|
387 |
""" |
|
388 |
RC="$?" |
|
389 |
||
390 |
. "$ISABELLE_HOME/lib/scripts/timestop.bash" |
|
391 |
||
392 |
if [ "$RC" -eq 0 ]; then |
|
393 |
echo "Finished $TARGET ($TIMES_REPORT)" >&2 |
|
394 |
fi |
|
395 |
||
396 |
exit "$RC" |
|
397 |
""" |
|
398 |
} |
|
399 |
val args_xml = |
|
400 |
{ |
|
401 |
import XML.Encode._ |
|
48459
375e45df6fdf
timing is command line options, not system option;
wenzelm
parents:
48457
diff
changeset
|
402 |
pair(bool, pair(Options.encode, pair(bool, pair(bool, pair(Path.encode, pair(string, |
375e45df6fdf
timing is command line options, not system option;
wenzelm
parents:
48457
diff
changeset
|
403 |
pair(string, pair(string, list(pair(Options.encode, list(Path.encode)))))))))))( |
48482
45137257399a
pass parent_base_name, which is required for Session.init sanity check;
wenzelm
parents:
48478
diff
changeset
|
404 |
(output.isDefined, (options, (timing, (verbose, (browser_info, (parent_base_name, |
48459
375e45df6fdf
timing is command line options, not system option;
wenzelm
parents:
48457
diff
changeset
|
405 |
(name, (info.base_name, info.theories))))))))) |
48418 | 406 |
} |
48424 | 407 |
new Job(cwd, env, script, YXML.string_of_body(args_xml)) |
48364 | 408 |
} |
409 |
||
48424 | 410 |
|
48425 | 411 |
/* build */ |
48424 | 412 |
|
48425 | 413 |
def build(all_sessions: Boolean, build_images: Boolean, max_jobs: Int, |
48469 | 414 |
no_build: Boolean, system_mode: Boolean, timing: Boolean, verbose: Boolean, |
48419 | 415 |
more_dirs: List[Path], more_options: List[String], sessions: List[String]): Int = |
48341 | 416 |
{ |
48419 | 417 |
val options = (Options.init() /: more_options)(_.define_simple(_)) |
48421 | 418 |
val queue = find_sessions(options, all_sessions, sessions, more_dirs) |
48478 | 419 |
val deps = dependencies(verbose, queue) |
48368 | 420 |
|
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
421 |
val (output_dir, browser_info) = |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
422 |
if (system_mode) (Path.explode("~~/heaps/$ML_IDENTIFIER"), Path.explode("~~/browser_info")) |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
423 |
else (Path.explode("$ISABELLE_OUTPUT"), Path.explode("$ISABELLE_BROWSER_INFO")) |
48363 | 424 |
|
48373 | 425 |
// prepare log dir |
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
426 |
val log_dir = output_dir + Path.explode("log") |
48373 | 427 |
log_dir.file.mkdirs() |
428 |
||
48425 | 429 |
// scheduler loop |
430 |
@tailrec def loop( |
|
431 |
pending: Session.Queue, |
|
432 |
running: Map[String, Job], |
|
433 |
results: Map[String, Int]): Map[String, Int] = |
|
434 |
{ |
|
435 |
if (pending.is_empty) results |
|
436 |
else if (running.exists({ case (_, job) => job.is_finished })) { |
|
437 |
val (name, job) = running.find({ case (_, job) => job.is_finished }).get |
|
48424 | 438 |
|
48425 | 439 |
val (out, err, rc) = job.join |
440 |
echo(Library.trim_line(err)) |
|
48373 | 441 |
|
48425 | 442 |
val log = log_dir + Path.basic(name) |
443 |
if (rc == 0) { |
|
444 |
val sources = |
|
445 |
(queue(name).digest :: deps.sources(name).map(_._2)).map(_.toString).sorted |
|
446 |
.mkString("sources: ", " ", "\n") |
|
447 |
File.write_zip(log.ext("gz"), sources + out) |
|
448 |
} |
|
449 |
else { |
|
450 |
File.write(log, out) |
|
451 |
echo(name + " FAILED") |
|
452 |
echo("(see also " + log.file + ")") |
|
453 |
val lines = split_lines(out) |
|
454 |
val tail = lines.drop(lines.length - 20 max 0) |
|
455 |
echo("\n" + cat_lines(tail)) |
|
456 |
} |
|
457 |
loop(pending - name, running - name, results + (name -> rc)) |
|
458 |
} |
|
459 |
else if (running.size < (max_jobs max 1)) { |
|
460 |
pending.dequeue(running.isDefinedAt(_)) match { |
|
461 |
case Some((name, info)) => |
|
48471 | 462 |
if (no_build) { |
48425 | 463 |
loop(pending - name, running, results + (name -> 0)) |
464 |
} |
|
465 |
else if (info.parent.map(results(_)).forall(_ == 0)) { |
|
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
466 |
val output = |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
467 |
if (build_images || queue.is_inner(name)) |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
468 |
Some(Isabelle_System.standard_path(output_dir + Path.basic(name))) |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
469 |
else None |
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
470 |
echo((if (output.isDefined) "Building " else "Running ") + name + " ...") |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48462
diff
changeset
|
471 |
val job = start_job(name, info, output, info.options, timing, verbose, browser_info) |
48425 | 472 |
loop(pending, running + (name -> job), results) |
473 |
} |
|
474 |
else { |
|
475 |
echo(name + " CANCELLED") |
|
476 |
loop(pending - name, running, results + (name -> 1)) |
|
477 |
} |
|
478 |
case None => sleep(); loop(pending, running, results) |
|
48373 | 479 |
} |
480 |
} |
|
48425 | 481 |
else { sleep(); loop(pending, running, results) } |
482 |
} |
|
483 |
||
48473 | 484 |
val results = loop(queue, Map.empty, Map.empty) |
485 |
val rc = (0 /: results)({ case (rc1, (_, rc2)) => rc1 max rc2 }) |
|
486 |
if (rc != 0) { |
|
487 |
val unfinished = (for ((name, r) <- results.iterator if r != 0) yield name).toList.sorted |
|
488 |
echo("Unfinished session(s): " + commas(unfinished)) |
|
489 |
} |
|
490 |
rc |
|
48341 | 491 |
} |
492 |
||
493 |
||
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
494 |
/* command line entry point */ |
48341 | 495 |
|
496 |
def main(args: Array[String]) |
|
497 |
{ |
|
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
498 |
Command_Line.tool { |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
499 |
args.toList match { |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
500 |
case |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
501 |
Properties.Value.Boolean(all_sessions) :: |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
502 |
Properties.Value.Boolean(build_images) :: |
48425 | 503 |
Properties.Value.Int(max_jobs) :: |
48469 | 504 |
Properties.Value.Boolean(no_build) :: |
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
505 |
Properties.Value.Boolean(system_mode) :: |
48459
375e45df6fdf
timing is command line options, not system option;
wenzelm
parents:
48457
diff
changeset
|
506 |
Properties.Value.Boolean(timing) :: |
48425 | 507 |
Properties.Value.Boolean(verbose) :: |
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
508 |
Command_Line.Chunks(more_dirs, options, sessions) => |
48469 | 509 |
build(all_sessions, build_images, max_jobs, no_build, system_mode, timing, |
48447
ef600ce4559c
added system build mode: produce output in ISABELLE_HOME;
wenzelm
parents:
48425
diff
changeset
|
510 |
verbose, more_dirs.map(Path.explode), options, sessions) |
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
511 |
case _ => error("Bad arguments:\n" + cat_lines(args)) |
48341 | 512 |
} |
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
513 |
} |
48341 | 514 |
} |
48276 | 515 |
} |
516 |