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