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