author | wenzelm |
Wed, 18 Jul 2012 14:07:31 +0200 | |
changeset 48335 | 2f923e994056 |
parent 48334 | 8dff9933e72a |
child 48336 | 3c55bfad22eb |
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 |
||
12 |
||
48276 | 13 |
object Build |
14 |
{ |
|
15 |
/* command line entry point */ |
|
16 |
||
17 |
private object Bool |
|
18 |
{ |
|
19 |
def unapply(s: String): Option[Boolean] = |
|
20 |
s match { |
|
21 |
case "true" => Some(true) |
|
22 |
case "false" => Some(false) |
|
23 |
case _ => None |
|
24 |
} |
|
25 |
} |
|
26 |
||
27 |
def main(args: Array[String]) |
|
28 |
{ |
|
48335 | 29 |
def bad_args(): Nothing = error("Bad arguments: " + args.toString) |
48276 | 30 |
|
48335 | 31 |
val rc = |
32 |
try { |
|
33 |
args.toList match { |
|
34 |
case Bool(all_sessions) :: Bool(build_images) :: Bool(list_only) :: rest => |
|
35 |
rest.indexWhere(_ == "\n") match { |
|
36 |
case -1 => bad_args() |
|
37 |
case i => |
|
38 |
val (options, rest1) = rest.splitAt(i) |
|
39 |
val sessions = rest1.tail |
|
40 |
build(all_sessions, build_images, list_only, options, sessions) |
|
41 |
} |
|
42 |
case _ => bad_args() |
|
48276 | 43 |
} |
48335 | 44 |
} |
45 |
catch { |
|
46 |
case exn: Throwable => java.lang.System.err.println(Exn.message(exn)); 2 |
|
47 |
} |
|
48 |
||
49 |
sys.exit(rc) |
|
48276 | 50 |
} |
51 |
||
52 |
||
53 |
/* build */ |
|
54 |
||
55 |
def build(all_sessions: Boolean, build_images: Boolean, list_only: Boolean, |
|
56 |
options: List[String], sessions: List[String]): Int = |
|
57 |
{ |
|
58 |
println("options = " + options.toString) |
|
59 |
println("sessions = " + sessions.toString) |
|
60 |
||
48335 | 61 |
find_sessions() foreach println |
62 |
||
63 |
0 |
|
48276 | 64 |
} |
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
65 |
|
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
66 |
|
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
67 |
/* session information */ |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
68 |
|
48334 | 69 |
val ROOT_NAME = "ROOT" |
70 |
||
71 |
type Options = List[(String, Option[String])] |
|
72 |
||
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
73 |
case class Session_Info( |
48334 | 74 |
dir: Path, |
75 |
name: String, |
|
76 |
path: String, |
|
77 |
parent: String, |
|
78 |
alt_name: Option[String], |
|
79 |
description: String, |
|
80 |
options: Options, |
|
81 |
theories: List[(Options, String)], |
|
82 |
files: List[String]) |
|
83 |
||
84 |
private object Parser extends Parse.Parser |
|
85 |
{ |
|
86 |
val SESSION = "session" |
|
87 |
val IN = "in" |
|
88 |
val NAME = "name" |
|
89 |
val DESCRIPTION = "description" |
|
90 |
val OPTIONS = "options" |
|
91 |
val THEORIES = "theories" |
|
92 |
val FILES = "files" |
|
93 |
||
94 |
val syntax = |
|
95 |
Outer_Syntax.empty + "(" + ")" + "+" + "," + "=" + "[" + "]" + |
|
96 |
SESSION + IN + NAME + DESCRIPTION + OPTIONS + THEORIES + FILES |
|
97 |
||
48335 | 98 |
def session_info(dir: Path): Parser[Session_Info] = |
48334 | 99 |
{ |
100 |
val session_name = atom("session name", _.is_name) |
|
101 |
val theory_name = atom("theory name", _.is_name) |
|
102 |
val file_name = atom("file name", _.is_name) |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
103 |
|
48334 | 104 |
val option = |
105 |
name ~ opt(keyword("=") ~! name ^^ { case _ ~ x => x }) ^^ { case x ~ y => (x, y) } |
|
106 |
val options: Parser[Options] = |
|
107 |
keyword("[") ~> repsep(option, keyword(",")) <~ keyword("]") |
|
108 |
||
109 |
val theories = |
|
110 |
keyword(THEORIES) ~! ((options | success(Nil)) ~ rep1(theory_name)) ^^ |
|
111 |
{ case _ ~ (x ~ y) => (x, y) } |
|
112 |
||
113 |
((keyword(SESSION) ~! session_name) ^^ { case _ ~ x => x }) ~ |
|
114 |
(opt(keyword(IN) ~! string ^^ { case _ ~ x => x })) ~ |
|
115 |
(keyword("=") ~> session_name <~ keyword("+")) ~ |
|
116 |
(opt(keyword(NAME) ~! session_name ^^ { case _ ~ x => x })) ~ |
|
117 |
(keyword(DESCRIPTION) ~! text ^^ { case _ ~ x => x } | success("")) ~ |
|
118 |
(keyword(OPTIONS) ~! options ^^ { case _ ~ x => x } | success(Nil)) ~ |
|
119 |
rep(theories) ~ |
|
120 |
(keyword(FILES) ~! rep1(file_name) ^^ { case _ ~ x => x } | success(Nil)) ^^ |
|
121 |
{ case a ~ b ~ c ~ d ~ e ~ f ~ g ~ h => |
|
48335 | 122 |
Session_Info(dir, a, b getOrElse a, c, d, e, f, |
48334 | 123 |
g.map({ case (x, ys) => ys.map(y => (x, y)) }).flatten, h) } |
124 |
} |
|
125 |
||
48335 | 126 |
def parse_entries(dir: Path, root: File): List[Session_Info] = |
48334 | 127 |
{ |
48335 | 128 |
val toks = syntax.scan(Standard_System.read_file(root)) |
129 |
parse_all(rep(session_info(dir)), Token.reader(toks, root.toString)) match { |
|
48334 | 130 |
case Success(result, _) => result |
131 |
case bad => error(bad.toString) |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
135 |
|
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
136 |
def find_sessions(): List[Session_Info] = |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
137 |
{ |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
138 |
for { |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
139 |
dir <- Isabelle_System.components() |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
140 |
root = Isabelle_System.platform_file(dir + Path.basic(ROOT_NAME)) |
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
141 |
if root.isFile |
48335 | 142 |
entry <- Parser.parse_entries(dir, root) |
143 |
} yield entry |
|
48280
7d86239986c2
basic support for session ROOT files, with examples for FOL and ZF;
wenzelm
parents:
48276
diff
changeset
|
144 |
} |
48276 | 145 |
} |
146 |