author | wenzelm |
Thu, 19 Jul 2012 12:37:08 +0200 | |
changeset 48347 | 8bb27ab9e841 |
parent 48346 | e2382bede914 |
child 48349 | a78e5d399599 |
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 |
||
48335 | 10 |
import java.io.File |
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 |
|
20 |
type Options = List[(String, Option[String])] |
|
21 |
||
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
22 |
case class Session_Info( |
48334 | 23 |
dir: Path, |
24 |
name: String, |
|
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
25 |
parent: Option[String], |
48334 | 26 |
description: String, |
27 |
options: Options, |
|
28 |
theories: List[(Options, String)], |
|
29 |
files: List[String]) |
|
30 |
||
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
31 |
|
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
32 |
/* parsing */ |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
33 |
|
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
34 |
val ROOT_NAME = "ROOT" |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
35 |
|
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
36 |
private case class Session_Entry( |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
37 |
name: String, |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
38 |
reset: Boolean, |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
39 |
path: Option[String], |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
40 |
parent: Option[String], |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
41 |
description: String, |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
42 |
options: Options, |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
43 |
theories: List[(Options, List[String])], |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
44 |
files: List[String]) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
45 |
|
48334 | 46 |
private object Parser extends Parse.Parser |
47 |
{ |
|
48 |
val SESSION = "session" |
|
49 |
val IN = "in" |
|
50 |
val DESCRIPTION = "description" |
|
51 |
val OPTIONS = "options" |
|
52 |
val THEORIES = "theories" |
|
53 |
val FILES = "files" |
|
54 |
||
55 |
val syntax = |
|
48336 | 56 |
Outer_Syntax.empty + "!" + "(" + ")" + "+" + "," + "=" + "[" + "]" + |
57 |
SESSION + IN + DESCRIPTION + OPTIONS + THEORIES + FILES |
|
48334 | 58 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
59 |
val session_entry: Parser[Session_Entry] = |
48334 | 60 |
{ |
61 |
val session_name = atom("session name", _.is_name) |
|
62 |
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
|
63 |
|
48334 | 64 |
val option = |
65 |
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
|
66 |
val options = keyword("[") ~> repsep(option, keyword(",")) <~ keyword("]") |
48334 | 67 |
|
68 |
val theories = |
|
69 |
keyword(THEORIES) ~! ((options | success(Nil)) ~ rep1(theory_name)) ^^ |
|
70 |
{ case _ ~ (x ~ y) => (x, y) } |
|
71 |
||
72 |
((keyword(SESSION) ~! session_name) ^^ { case _ ~ x => x }) ~ |
|
48336 | 73 |
(keyword("!") ^^^ true | success(false)) ~ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
74 |
(opt(keyword(IN) ~! string ^^ { case _ ~ x => x })) ~ |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
75 |
(keyword("=") ~> opt(session_name <~ keyword("+"))) ~ |
48334 | 76 |
(keyword(DESCRIPTION) ~! text ^^ { case _ ~ x => x } | success("")) ~ |
77 |
(keyword(OPTIONS) ~! options ^^ { case _ ~ x => x } | success(Nil)) ~ |
|
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
78 |
rep(theories) ~ |
48336 | 79 |
(keyword(FILES) ~! rep1(path) ^^ { case _ ~ x => x } | success(Nil)) ^^ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
80 |
{ case a ~ b ~ c ~ d ~ e ~ f ~ g ~ h => Session_Entry(a, b, c, d, e, f, g, h) } |
48334 | 81 |
} |
82 |
||
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
83 |
def parse_entries(root: File): List[Session_Entry] = |
48334 | 84 |
{ |
48335 | 85 |
val toks = syntax.scan(Standard_System.read_file(root)) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
86 |
parse_all(rep(session_entry), Token.reader(toks, root.toString)) match { |
48334 | 87 |
case Success(result, _) => result |
88 |
case bad => error(bad.toString) |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
92 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
93 |
|
48341 | 94 |
/* find sessions */ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
95 |
|
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
96 |
def find_sessions(more_dirs: List[Path]): List[Session_Info] = |
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
97 |
{ |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
98 |
val infos = new mutable.ListBuffer[Session_Info] |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
99 |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
100 |
for { |
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
101 |
(dir, strict) <- Isabelle_System.components().map((_, false)) ++ more_dirs.map((_, true)) |
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
102 |
root = Isabelle_System.platform_file(dir + Path.basic(ROOT_NAME)) |
48340
6f4fc030882a
allow explicit specification of additional session directories;
wenzelm
parents:
48339
diff
changeset
|
103 |
_ = (strict && !root.isFile && error("Bad session root file: " + quote(root.toString))) |
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
104 |
if root.isFile |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
105 |
entry <- Parser.parse_entries(root) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
106 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
107 |
{ |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
108 |
try { |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
109 |
if (entry.name == "") error("Bad session name") |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
110 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
111 |
val full_name = |
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
112 |
if (entry.name == "RAW" || entry.name == "Pure") { |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
113 |
if (entry.parent.isDefined) error("Illegal parent session") |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
114 |
else entry.name |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
115 |
} |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
116 |
else |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
117 |
entry.parent match { |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
118 |
case None => error("Missing parent session") |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
119 |
case Some(parent) => |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
120 |
val parent_info = |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
121 |
infos.find(_.name == parent) getOrElse |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
122 |
error("Undefined parent session: " + quote(parent)) |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
123 |
if (entry.reset) entry.name |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
124 |
else parent_info.name + "-" + entry.name |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
125 |
} |
48339 | 126 |
|
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
127 |
val path = |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
128 |
entry.path match { |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
129 |
case Some(p) => Path.explode(p) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
130 |
case None => Path.basic(entry.name) |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
131 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
132 |
val thys = entry.theories.map({ case (x, ys) => ys.map(y => (x, y)) }).flatten |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
133 |
val info = |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
134 |
Session_Info(dir + path, full_name, entry.parent, entry.description, |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
135 |
entry.options, thys, entry.files) |
48339 | 136 |
|
48347
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
137 |
if (infos.exists(_.name == full_name)) |
8bb27ab9e841
more explicit treatment of initial Pure sessions;
wenzelm
parents:
48346
diff
changeset
|
138 |
error("Duplicate session: " + quote(full_name)) |
48337
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
139 |
infos += info |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
140 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
141 |
catch { |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
142 |
case ERROR(msg) => |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
143 |
error(msg + "\nThe error(s) above occurred in session entry " + |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
144 |
quote(entry.name) + " (file " + quote(root.toString) + ")") |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
145 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
146 |
} |
9c7f8e5805b4
cumulate semantic Session_Info, based on syntactic Session_Entry;
wenzelm
parents:
48336
diff
changeset
|
147 |
infos.toList |
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
148 |
} |
48341 | 149 |
|
150 |
||
151 |
||
152 |
/** build **/ |
|
153 |
||
154 |
def build(all_sessions: Boolean, build_images: Boolean, list_only: Boolean, |
|
155 |
more_dirs: List[Path], options: List[String], sessions: List[String]): Int = |
|
156 |
{ |
|
157 |
println("more_dirs = " + more_dirs.toString) |
|
158 |
println("options = " + options.toString) |
|
159 |
println("sessions = " + sessions.toString) |
|
160 |
||
161 |
find_sessions(more_dirs) foreach println |
|
162 |
||
163 |
0 |
|
164 |
} |
|
165 |
||
166 |
||
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
167 |
/* command line entry point */ |
48341 | 168 |
|
169 |
def main(args: Array[String]) |
|
170 |
{ |
|
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
171 |
Command_Line.tool { |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
172 |
args.toList match { |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
173 |
case |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
174 |
Properties.Value.Boolean(all_sessions) :: |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
175 |
Properties.Value.Boolean(build_images) :: |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
176 |
Properties.Value.Boolean(list_only) :: |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
177 |
Command_Line.Chunks(more_dirs, options, sessions) => |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
178 |
build(all_sessions, build_images, list_only, |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
179 |
more_dirs.map(Path.explode), options, sessions) |
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
180 |
case _ => error("Bad arguments:\n" + cat_lines(args)) |
48341 | 181 |
} |
48346
e2382bede914
more general support for Isabelle/Scala command line tools;
wenzelm
parents:
48344
diff
changeset
|
182 |
} |
48341 | 183 |
} |
48276 | 184 |
} |
185 |