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