author | wenzelm |
Tue, 04 Oct 2016 14:32:44 +0200 | |
changeset 64034 | 51bf28aa18a5 |
parent 64032 | 46c1ffc78d73 |
child 64036 | a14fe26c0144 |
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( |
|
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 |
||
64032 | 78 |
/* initial settings */ |
64030 | 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 |
||
64032 | 97 |
/* augmented settings */ |
64030 | 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 |
||
64030 | 141 |
val thread_settings = |
142 |
List( |
|
143 |
"ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"", |
|
144 |
"ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"") |
|
145 |
||
146 |
File.append(etc_settings, "\n" + |
|
147 |
cat_lines(List(ml_settings, thread_settings).map(Library.terminate_lines(_)))) |
|
148 |
||
149 |
if (more_settings.nonEmpty) |
|
150 |
File.append(etc_settings, "\n" + Library.terminate_lines(more_settings)) |
|
64025 | 151 |
|
64032 | 152 |
|
153 |
/* build */ |
|
154 |
||
64025 | 155 |
isabelle("components -a").check.print_if(verbose) |
64026 | 156 |
isabelle("jedit -b" + (if (fresh) " -f" else "")).check.print_if(verbose) |
64025 | 157 |
|
64026 | 158 |
isabelle("build " + File.bash_args(build_args)) |
64025 | 159 |
} |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
160 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
161 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
162 |
/* command line entry point */ |
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 |
def main(args: Array[String]) |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
165 |
{ |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
166 |
Command_Line.tool0 { |
64026 | 167 |
var allow = false |
64025 | 168 |
var components_base = "" |
64030 | 169 |
var heap: Option[Int] = None |
170 |
var threads = default_threads |
|
64025 | 171 |
var isabelle_identifier = default_isabelle_identifier |
64030 | 172 |
var more_settings: List[String] = Nil |
64026 | 173 |
var fresh = false |
64030 | 174 |
var arch_64 = false |
64025 | 175 |
var nonfree = false |
176 |
var rev = default_rev |
|
177 |
var verbose = false |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
178 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
179 |
val getopts = Getopts(""" |
64026 | 180 |
Usage: isabelle build_history [OPTIONS] REPOSITORY [ARGS ...] |
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 |
Options are: |
64030 | 183 |
-A allow irreversible cleanup of REPOSITORY clone (required) |
64025 | 184 |
-C DIR base directory for Isabelle components (default: $ISABELLE_HOME_USER/../contrib) |
64030 | 185 |
-H HEAP minimal ML heap in MB (default: """ + default_heap + """ for x86, """ + default_heap * 2 + """ for x86_64) |
186 |
-M THREADS number of threads for Poly/ML RTS and Isabelle/ML (default: """ + default_threads + """) |
|
64025 | 187 |
-N NAME alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """) |
64030 | 188 |
-e TEXT additional text for generated etc/settings |
64026 | 189 |
-f fresh build of Isabelle/Scala components (recommended) |
64030 | 190 |
-m ARCH processor architecture (32=x86, 64=x86_64, default: x86) |
64025 | 191 |
-n include nonfree components |
64026 | 192 |
-r REV update to revision (default: """ + default_rev + """) |
64025 | 193 |
-v verbose |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
194 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
195 |
Build Isabelle sessions from the history of another REPOSITORY clone, |
64026 | 196 |
passing ARGS directly to its isabelle build tool. |
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
197 |
""", |
64026 | 198 |
"A" -> (_ => allow = true), |
64025 | 199 |
"C:" -> (arg => components_base = arg), |
64030 | 200 |
"H:" -> (arg => heap = Some(Value.Int.parse(arg))), |
201 |
"M:" -> (arg => threads = Value.Int.parse(arg)), |
|
64025 | 202 |
"N:" -> (arg => isabelle_identifier = arg), |
64030 | 203 |
"e:" -> (arg => more_settings = more_settings ::: List(arg)), |
64026 | 204 |
"f" -> (_ => fresh = true), |
64030 | 205 |
"m:" -> |
206 |
{ |
|
207 |
case "32" | "x86" => arch_64 = false |
|
208 |
case "64" | "x86_64" => arch_64 = true |
|
209 |
case bad => error("Bad processor architecture: " + quote(bad)) |
|
210 |
}, |
|
64025 | 211 |
"n" -> (_ => nonfree = true), |
212 |
"r:" -> (arg => rev = arg), |
|
213 |
"v" -> (_ => verbose = true)) |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
214 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
215 |
val more_args = getopts(args) |
64026 | 216 |
val (root, build_args) = |
217 |
more_args match { |
|
218 |
case root :: build_args => (root, build_args) |
|
219 |
case _ => getopts.usage() |
|
220 |
} |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
221 |
|
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
222 |
using(Mercurial.open_repository(Path.explode(root)))(hg => |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
223 |
{ |
64026 | 224 |
if (!allow) |
225 |
error("Repository " + hg + " will be cleaned thoroughly!\n" + |
|
226 |
"Provide option -A to allow this explicitly.") |
|
64021
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
227 |
|
64026 | 228 |
val res = |
229 |
build_history(hg, rev = rev, isabelle_identifier = isabelle_identifier, |
|
230 |
components_base = components_base, fresh = fresh, nonfree = nonfree, |
|
64030 | 231 |
threads = threads, arch_64 = arch_64, |
232 |
heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap), |
|
233 |
more_settings = more_settings, verbose = verbose, build_args = build_args) |
|
64026 | 234 |
res.print |
235 |
if (!res.ok) sys.exit(res.rc) |
|
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 |
} |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
238 |
} |
1e23caac8757
basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff
changeset
|
239 |
} |