author | wenzelm |
Wed, 05 Oct 2016 10:43:52 +0200 | |
changeset 64046 | 5a6a7401c48b |
parent 64044 | deb4a786e6f9 |
child 64047 | 1013cf043274 |
permissions | -rw-r--r-- |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Tools/build_history.scala |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
3 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
4 |
Build other history versions. |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
6 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
8 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
9 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
10 |
import java.io.{File => JFile} |
64025 | 11 |
import java.util.Calendar |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
12 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
13 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
14 |
object Build_History |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
15 |
{ |
64025 | 16 |
/* build_history */ |
17 |
||
18 |
private val default_rev = "tip" |
|
64030 | 19 |
private val default_threads = 1 |
64034 | 20 |
private val default_heap = 1000 |
64025 | 21 |
private val default_isabelle_identifier = "build_history" |
22 |
||
23 |
def build_history( |
|
64038 | 24 |
progress: Progress, |
64025 | 25 |
hg: Mercurial.Repository, |
26 |
rev: String = default_rev, |
|
27 |
isabelle_identifier: String = default_isabelle_identifier, |
|
28 |
components_base: String = "", |
|
64026 | 29 |
fresh: Boolean = false, |
64025 | 30 |
nonfree: Boolean = false, |
64030 | 31 |
threads: Int = default_threads, |
32 |
arch_64: Boolean = false, |
|
33 |
heap: Int = default_heap, |
|
64036 | 34 |
max_heap: Option[Int] = None, |
64030 | 35 |
more_settings: List[String] = Nil, |
64026 | 36 |
verbose: Boolean = false, |
37 |
build_args: List[String] = Nil): Process_Result = |
|
64025 | 38 |
{ |
64038 | 39 |
/* output */ |
40 |
||
41 |
def output(msg: String) { progress.echo(msg) } |
|
42 |
def output_if(b: Boolean, msg: String) { if (b) output(msg) } |
|
43 |
||
44 |
||
64031 | 45 |
/* sanity checks */ |
46 |
||
64046 | 47 |
if (File.eq(Path.explode("~~").file, hg.root.file)) |
48 |
error("Repository coincides with ISABELLE_HOME=" + Path.explode("~~").expand) |
|
49 |
||
64030 | 50 |
if (threads < 1) error("Bad threads value < 1: " + threads) |
64036 | 51 |
|
64030 | 52 |
if (heap < 100) error("Bad heap value < 100: " + heap) |
53 |
||
64036 | 54 |
if (max_heap.isDefined && max_heap.get < heap) |
55 |
error("Bad max_heap value < heap: " + max_heap.get) |
|
56 |
||
64031 | 57 |
System.getenv("ISABELLE_SETTINGS_PRESENT") match { |
58 |
case null | "" => |
|
59 |
case _ => error("Cannot run build_history within existing Isabelle settings environment") |
|
60 |
} |
|
61 |
||
62 |
||
63 |
/* purge repository */ |
|
64 |
||
64025 | 65 |
hg.update(rev = rev, clean = true) |
64038 | 66 |
output_if(verbose, hg.log(rev, options = "-l1")) |
64025 | 67 |
|
64031 | 68 |
|
69 |
/* invoke isabelle tools */ |
|
70 |
||
64038 | 71 |
def bash(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result = |
64025 | 72 |
Isabelle_System.bash("env ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + |
64038 | 73 |
" " + script, cwd = hg.root.file, env = null, redirect = redirect, |
74 |
progress_stdout = output_if(echo, _), progress_stderr = output_if(echo, _)) |
|
64025 | 75 |
|
64038 | 76 |
def isabelle(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result = |
77 |
bash("bin/isabelle " + cmdline, redirect, echo) |
|
64037 | 78 |
|
64038 | 79 |
val isabelle_home_user = Path.explode(isabelle("getenv -b ISABELLE_HOME_USER").check.out) |
64025 | 80 |
|
81 |
||
64030 | 82 |
/* reset settings */ |
83 |
||
64038 | 84 |
val etc_settings = isabelle_home_user + Path.explode("etc/settings") |
64030 | 85 |
|
86 |
if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle")) |
|
87 |
error("Cannot proceed with existing user settings file: " + etc_settings) |
|
88 |
||
89 |
Isabelle_System.mkdirs(etc_settings.dir) |
|
64025 | 90 |
|
64030 | 91 |
File.write(etc_settings, |
92 |
"# generated by Isabelle " + Calendar.getInstance.getTime + "\n" + |
|
93 |
"#-*- shell-script -*- :mode=shellscript:\n") |
|
94 |
||
95 |
||
64032 | 96 |
/* initial settings */ |
64030 | 97 |
|
98 |
val component_settings = |
|
64025 | 99 |
{ |
100 |
val components_base_path = |
|
101 |
if (components_base == "") isabelle_home_user.dir + Path.explode("contrib") |
|
102 |
else Path.explode(components_base).expand |
|
103 |
||
104 |
val catalogs = |
|
105 |
if (nonfree) List("main", "optional", "nonfree") else List("main", "optional") |
|
106 |
||
64030 | 107 |
catalogs.map(catalog => |
108 |
"init_components " + File.bash_path(components_base_path) + |
|
109 |
" \"$ISABELLE_HOME/Admin/components/" + catalog + "\"") |
|
110 |
} |
|
111 |
||
112 |
File.append(etc_settings, "\n" + Library.terminate_lines(component_settings)) |
|
113 |
||
114 |
||
64043 | 115 |
isabelle("components -a", redirect = true, echo = verbose).check |
116 |
||
117 |
||
64032 | 118 |
/* augmented settings */ |
64030 | 119 |
|
120 |
val ml_settings = |
|
121 |
{ |
|
122 |
val windows_32 = "x86-windows" |
|
123 |
val windows_64 = "x86_64-windows" |
|
124 |
val platform_32 = isabelle("getenv -b ISABELLE_PLATFORM32").check.out |
|
125 |
val platform_64 = isabelle("getenv -b ISABELLE_PLATFORM64").check.out |
|
126 |
val platform_family = isabelle("getenv -b ISABELLE_PLATFORM_FAMILY").check.out |
|
127 |
||
64040 | 128 |
val polyml_home = |
129 |
try { Path.explode(isabelle("getenv -b ML_HOME").check.out).dir } |
|
130 |
catch { case ERROR(msg) => error("Bad ML_HOME: " + msg) } |
|
131 |
||
64030 | 132 |
def ml_home(platform: String): Path = polyml_home + Path.explode(platform) |
133 |
||
134 |
def err(platform: String): Nothing = |
|
135 |
error("Platform " + platform + " unavailable on this machine") |
|
64025 | 136 |
|
64030 | 137 |
def check_dir(platform: String): Boolean = |
138 |
platform != "" && ml_home(platform).is_dir |
|
139 |
||
140 |
val ml_platform = |
|
141 |
if (Platform.is_windows && arch_64) { |
|
142 |
if (check_dir(windows_64)) windows_64 else err(windows_64) |
|
143 |
} |
|
144 |
else if (Platform.is_windows && !arch_64) { |
|
145 |
if (check_dir(windows_32)) windows_32 |
|
146 |
else platform_32 // x86-cygwin |
|
147 |
} |
|
148 |
else { |
|
149 |
val (platform, platform_name) = |
|
150 |
if (arch_64) (platform_64, "x86_64-" + platform_family) |
|
151 |
else (platform_32, "x86-" + platform_family) |
|
152 |
if (check_dir(platform)) platform else err(platform_name) |
|
153 |
} |
|
154 |
||
155 |
val ml_options = |
|
64036 | 156 |
"--minheap " + heap + (if (max_heap.isDefined) " --maxheap " + max_heap.get else "") + |
157 |
" --gcthreads " + threads + |
|
64030 | 158 |
(if (ml_platform.endsWith("-windows")) " --codepage utf8" else "") |
159 |
||
160 |
List( |
|
161 |
"ML_HOME=" + File.bash_path(ml_home(ml_platform)), |
|
162 |
"ML_PLATFORM=" + quote(ml_platform), |
|
163 |
"ML_OPTIONS=" + quote(ml_options)) |
|
64025 | 164 |
} |
165 |
||
64030 | 166 |
val thread_settings = |
167 |
List( |
|
168 |
"ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"", |
|
169 |
"ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"") |
|
170 |
||
171 |
File.append(etc_settings, "\n" + |
|
172 |
cat_lines(List(ml_settings, thread_settings).map(Library.terminate_lines(_)))) |
|
173 |
||
174 |
if (more_settings.nonEmpty) |
|
175 |
File.append(etc_settings, "\n" + Library.terminate_lines(more_settings)) |
|
64025 | 176 |
|
64032 | 177 |
|
64043 | 178 |
isabelle("components -a", redirect = true, echo = verbose).check |
179 |
||
180 |
||
64032 | 181 |
/* build */ |
182 |
||
64044 | 183 |
bash("env PATH=\"" + File.bash_path(Path.explode("~~/lib/dummy_stty").expand) + ":$PATH\" " + |
184 |
"bin/isabelle jedit -b" + (if (fresh) " -f" else ""), redirect = true, echo = verbose).check |
|
64025 | 185 |
|
64038 | 186 |
isabelle("build " + File.bash_args(build_args), redirect = true, echo = verbose) |
64025 | 187 |
} |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
188 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
189 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
190 |
/* command line entry point */ |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
191 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
192 |
def main(args: Array[String]) |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
193 |
{ |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
194 |
Command_Line.tool0 { |
64025 | 195 |
var components_base = "" |
64030 | 196 |
var heap: Option[Int] = None |
64036 | 197 |
var max_heap: Option[Int] = None |
64030 | 198 |
var threads = default_threads |
64025 | 199 |
var isabelle_identifier = default_isabelle_identifier |
64030 | 200 |
var more_settings: List[String] = Nil |
64026 | 201 |
var fresh = false |
64030 | 202 |
var arch_64 = false |
64025 | 203 |
var nonfree = false |
204 |
var rev = default_rev |
|
205 |
var verbose = false |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
206 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
207 |
val getopts = Getopts(""" |
64026 | 208 |
Usage: isabelle build_history [OPTIONS] REPOSITORY [ARGS ...] |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
209 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
210 |
Options are: |
64025 | 211 |
-C DIR base directory for Isabelle components (default: $ISABELLE_HOME_USER/../contrib) |
64036 | 212 |
-H SIZE minimal ML heap in MB (default: """ + default_heap + """ for x86, """ + default_heap * 2 + """ for x86_64) |
64030 | 213 |
-M THREADS number of threads for Poly/ML RTS and Isabelle/ML (default: """ + default_threads + """) |
64025 | 214 |
-N NAME alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """) |
64036 | 215 |
-U SIZE maximal ML heap in MB (default: unbounded) |
64030 | 216 |
-e TEXT additional text for generated etc/settings |
64026 | 217 |
-f fresh build of Isabelle/Scala components (recommended) |
64030 | 218 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64025 | 219 |
-n include nonfree components |
64026 | 220 |
-r REV update to revision (default: """ + default_rev + """) |
64025 | 221 |
-v verbose |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
222 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
223 |
Build Isabelle sessions from the history of another REPOSITORY clone, |
64026 | 224 |
passing ARGS directly to its isabelle build tool. |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
225 |
""", |
64025 | 226 |
"C:" -> (arg => components_base = arg), |
64030 | 227 |
"H:" -> (arg => heap = Some(Value.Int.parse(arg))), |
228 |
"M:" -> (arg => threads = Value.Int.parse(arg)), |
|
64025 | 229 |
"N:" -> (arg => isabelle_identifier = arg), |
64036 | 230 |
"U:" -> (arg => max_heap = Some(Value.Int.parse(arg))), |
64030 | 231 |
"e:" -> (arg => more_settings = more_settings ::: List(arg)), |
64026 | 232 |
"f" -> (_ => fresh = true), |
64030 | 233 |
"m:" -> |
234 |
{ |
|
235 |
case "32" | "x86" => arch_64 = false |
|
236 |
case "64" | "x86_64" => arch_64 = true |
|
237 |
case bad => error("Bad processor architecture: " + quote(bad)) |
|
238 |
}, |
|
64025 | 239 |
"n" -> (_ => nonfree = true), |
240 |
"r:" -> (arg => rev = arg), |
|
241 |
"v" -> (_ => verbose = true)) |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
242 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
243 |
val more_args = getopts(args) |
64026 | 244 |
val (root, build_args) = |
245 |
more_args match { |
|
246 |
case root :: build_args => (root, build_args) |
|
247 |
case _ => getopts.usage() |
|
248 |
} |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
249 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
250 |
using(Mercurial.open_repository(Path.explode(root)))(hg => |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
251 |
{ |
64038 | 252 |
val progress = new Console_Progress(false) |
64026 | 253 |
val res = |
64038 | 254 |
build_history(progress, hg, rev = rev, isabelle_identifier = isabelle_identifier, |
64026 | 255 |
components_base = components_base, fresh = fresh, nonfree = nonfree, |
64030 | 256 |
threads = threads, arch_64 = arch_64, |
257 |
heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap), |
|
64036 | 258 |
max_heap = max_heap, more_settings = more_settings, verbose = verbose, |
259 |
build_args = build_args) |
|
64026 | 260 |
if (!res.ok) sys.exit(res.rc) |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
261 |
}) |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
262 |
} |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
263 |
} |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
264 |
} |