author | wenzelm |
Thu, 22 Feb 2024 20:37:53 +0100 | |
changeset 79707 | 4ded6d260db0 |
parent 79705 | a6dc0d4ffea2 |
child 79709 | 90fbcdafb34e |
permissions | -rw-r--r-- |
79502 | 1 |
/* Title: Pure/Build/build.scala |
48276 | 2 |
Author: Makarius |
57923 | 3 |
Options: :folding=explicit: |
48276 | 4 |
|
77553 | 5 |
Command-line tools to build and manage Isabelle sessions. |
48276 | 6 |
*/ |
7 |
||
8 |
package isabelle |
|
9 |
||
77553 | 10 |
import scala.collection.mutable |
11 |
import scala.util.matching.Regex |
|
12 |
||
48276 | 13 |
|
75393 | 14 |
object Build { |
77553 | 15 |
/** "isabelle build" **/ |
16 |
||
78232 | 17 |
/* options */ |
18 |
||
19 |
def hostname(options: Options): String = |
|
20 |
Isabelle_System.hostname(options.string("build_hostname")) |
|
21 |
||
22 |
def engine_name(options: Options): String = options.string("build_engine") |
|
23 |
||
24 |
||
25 |
||
78421 | 26 |
/* context */ |
27 |
||
28 |
sealed case class Context( |
|
29 |
store: Store, |
|
79643 | 30 |
deps: isabelle.Sessions.Deps, |
79642 | 31 |
engine: Engine = Engine.Default, |
78421 | 32 |
afp_root: Option[Path] = None, |
33 |
build_hosts: List[Build_Cluster.Host] = Nil, |
|
34 |
ml_platform: String = Isabelle_System.getenv("ML_PLATFORM"), |
|
35 |
hostname: String = Isabelle_System.hostname(), |
|
36 |
numa_shuffling: Boolean = false, |
|
37 |
build_heap: Boolean = false, |
|
38 |
fresh_build: Boolean = false, |
|
39 |
no_build: Boolean = false, |
|
40 |
session_setup: (String, Session) => Unit = (_, _) => (), |
|
41 |
build_uuid: String = UUID.random().toString, |
|
79644 | 42 |
jobs: Int = 0, |
78421 | 43 |
master: Boolean = false |
44 |
) { |
|
45 |
def build_options: Options = store.options |
|
46 |
||
79643 | 47 |
def sessions_structure: isabelle.Sessions.Structure = deps.sessions_structure |
78421 | 48 |
|
79645
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
49 |
def worker: Boolean = jobs > 0 |
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
50 |
|
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
51 |
override def toString: String = |
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
52 |
"Build.Context(build_uuid = " + quote(build_uuid) + |
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
53 |
if_proper(worker, ", worker = true") + |
7a1153c95bf9
clarifier worker vs. master, which may coincide for local build;
wenzelm
parents:
79644
diff
changeset
|
54 |
if_proper(master, ", master = true") + ")" |
78421 | 55 |
} |
56 |
||
57 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
58 |
/* results */ |
48424 | 59 |
|
77311 | 60 |
object Results { |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
61 |
def apply( |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
62 |
context: Context, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
63 |
results: Map[String, Process_Result] = Map.empty, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
64 |
other_rc: Int = Process_Result.RC.ok |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
65 |
): Results = { |
79643 | 66 |
new Results(context.store, context.deps, results, other_rc) |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
67 |
} |
77311 | 68 |
} |
69 |
||
70 |
class Results private( |
|
78178 | 71 |
val store: Store, |
76209 | 72 |
val deps: Sessions.Deps, |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
73 |
results: Map[String, Process_Result], |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
74 |
other_rc: Int |
76198
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
75 |
) { |
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
76 |
def cache: Term.Cache = store.cache |
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
77 |
|
77311 | 78 |
def sessions_ok: List[String] = |
79 |
(for { |
|
80 |
name <- deps.sessions_structure.build_topological_order.iterator |
|
81 |
result <- results.get(name) if result.ok |
|
82 |
} yield name).toList |
|
83 |
||
77250
22016642d6af
clarified data structure: use static info from deps, not dynamic results;
wenzelm
parents:
77246
diff
changeset
|
84 |
def info(name: String): Sessions.Info = deps.sessions_structure(name) |
62403 | 85 |
def sessions: Set[String] = results.keySet |
77253
792dad9cb04f
clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents:
77252
diff
changeset
|
86 |
def cancelled(name: String): Boolean = !results(name).defined |
792dad9cb04f
clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents:
77252
diff
changeset
|
87 |
def apply(name: String): Process_Result = results(name).strict |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
88 |
|
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
89 |
val rc: Int = |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
90 |
Process_Result.RC.merge(other_rc, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
91 |
Process_Result.RC.merge(results.valuesIterator.map(_.strict.rc))) |
74306 | 92 |
def ok: Boolean = rc == Process_Result.RC.ok |
62406 | 93 |
|
78566
a04277e3b313
tuned message: failure may stem from build_cluster init;
wenzelm
parents:
78562
diff
changeset
|
94 |
lazy val unfinished: List[String] = sessions.iterator.filterNot(apply(_).ok).toList.sorted |
76199 | 95 |
|
62406 | 96 |
override def toString: String = rc.toString |
62403 | 97 |
} |
98 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
99 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
100 |
/* engine */ |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
101 |
|
78232 | 102 |
object Engine { |
103 |
lazy val services: List[Engine] = |
|
104 |
Isabelle_System.make_services(classOf[Engine]) |
|
105 |
||
106 |
def apply(name: String): Engine = |
|
107 |
services.find(_.name == name).getOrElse(error("Bad build engine " + quote(name))) |
|
79642 | 108 |
|
109 |
class Default extends Engine("") { override def toString: String = "<default>" } |
|
110 |
object Default extends Default |
|
78232 | 111 |
} |
112 |
||
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
113 |
class Engine(val name: String) extends Isabelle_System.Service { |
79705 | 114 |
engine => |
115 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
116 |
override def toString: String = name |
78232 | 117 |
|
79614 | 118 |
def build_options(options: Options, build_cluster: Boolean = false): Options = { |
78401 | 119 |
val options1 = options + "completion_limit=0" + "editor_tracing_messages=0" |
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79679
diff
changeset
|
120 |
if (build_cluster) options1 + "build_database" else options1 |
78401 | 121 |
} |
78232 | 122 |
|
78412 | 123 |
final def build_store(options: Options, |
79614 | 124 |
build_cluster: Boolean = false, |
78412 | 125 |
cache: Term.Cache = Term.Cache.make() |
126 |
): Store = { |
|
79705 | 127 |
val build_options = engine.build_options(options, build_cluster = build_cluster) |
128 |
val store = Store(build_options, build_cluster = build_cluster, cache = cache) |
|
78412 | 129 |
Isabelle_System.make_directory(store.output_dir + Path.basic("log")) |
130 |
Isabelle_Fonts.init() |
|
131 |
store |
|
132 |
} |
|
133 |
||
78436
5f5f909206bb
clarified signature: more "object-oriented" style;
wenzelm
parents:
78435
diff
changeset
|
134 |
def open_build_process( |
78421 | 135 |
build_context: Context, |
78372 | 136 |
build_progress: Progress, |
137 |
server: SSH.Server |
|
138 |
): Build_Process = new Build_Process(build_context, build_progress, server) |
|
78232 | 139 |
|
78436
5f5f909206bb
clarified signature: more "object-oriented" style;
wenzelm
parents:
78435
diff
changeset
|
140 |
final def run_build_process( |
78421 | 141 |
context: Context, |
78372 | 142 |
progress: Progress, |
143 |
server: SSH.Server |
|
78412 | 144 |
): Results = { |
78232 | 145 |
Isabelle_Thread.uninterruptible { |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
146 |
using(open_build_process(context, progress, server))(_.run()) |
78232 | 147 |
} |
78412 | 148 |
} |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
149 |
} |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
150 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
151 |
|
77558 | 152 |
|
153 |
/* build */ |
|
154 |
||
62641 | 155 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
156 |
options: Options, |
78401 | 157 |
build_hosts: List[Build_Cluster.Host] = Nil, |
71981 | 158 |
selection: Sessions.Selection = Sessions.Selection.empty, |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
159 |
browser_info: Browser_Info.Config = Browser_Info.Config.none, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
160 |
progress: Progress = new Progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
161 |
check_unknown_files: Boolean = false, |
48511
37999ee01156
remove old output heaps, to ensure that result is valid wrt. check_stamps;
wenzelm
parents:
48509
diff
changeset
|
162 |
build_heap: Boolean = false, |
48595 | 163 |
clean_build: Boolean = false, |
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
164 |
afp_root: Option[Path] = None, |
56890 | 165 |
dirs: List[Path] = Nil, |
166 |
select_dirs: List[Path] = Nil, |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66962
diff
changeset
|
167 |
infos: List[Sessions.Info] = Nil, |
64265 | 168 |
numa_shuffling: Boolean = false, |
79616 | 169 |
max_jobs: Option[Int] = None, |
48903 | 170 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
171 |
check_keywords: Set[String] = Set.empty, |
66841 | 172 |
fresh_build: Boolean = false, |
48509 | 173 |
no_build: Boolean = false, |
66745 | 174 |
soft_build: Boolean = false, |
73805
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
175 |
export_files: Boolean = false, |
76927
da13da82f6f9
treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents:
76919
diff
changeset
|
176 |
augment_options: String => List[Options.Spec] = _ => Nil, |
77559
4ad322ee6025
clarified signature: support all arguments of Sessions.store();
wenzelm
parents:
77558
diff
changeset
|
177 |
session_setup: (String, Session) => Unit = (_, _) => (), |
4ad322ee6025
clarified signature: support all arguments of Sessions.store();
wenzelm
parents:
77558
diff
changeset
|
178 |
cache: Term.Cache = Term.Cache.make() |
75393 | 179 |
): Results = { |
79707 | 180 |
val engine = Engine(engine_name(options)) |
181 |
val store = engine.build_store(options, build_cluster = build_hosts.nonEmpty, cache = cache) |
|
77557 | 182 |
val build_options = store.options |
69369
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
183 |
|
78372 | 184 |
using(store.open_server()) { server => |
185 |
using_optional(store.maybe_open_database_server(server = server)) { database_server => |
|
66745 | 186 |
|
78372 | 187 |
|
188 |
/* session selection and dependencies */ |
|
65422 | 189 |
|
78372 | 190 |
val full_sessions = |
78420 | 191 |
Sessions.load_structure(build_options, dirs = AFP.make_dirs(afp_root) ::: dirs, |
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
192 |
select_dirs = select_dirs, infos = infos, augment_options = augment_options) |
78372 | 193 |
val full_sessions_selection = full_sessions.imports_selection(selection) |
73012
238ddf525da4
clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents:
72993
diff
changeset
|
194 |
|
78372 | 195 |
val build_deps = { |
196 |
val deps0 = |
|
79646 | 197 |
Sessions.deps(full_sessions.selection(selection), progress = progress, |
198 |
inlined_files = true, list_files = list_files, check_keywords = check_keywords |
|
199 |
).check_errors |
|
66745 | 200 |
|
78372 | 201 |
if (soft_build && !fresh_build) { |
202 |
val outdated = |
|
203 |
deps0.sessions_structure.build_topological_order.flatMap(name => |
|
204 |
store.try_open_database(name, server = server) match { |
|
205 |
case Some(db) => |
|
206 |
using(db)(store.read_build(_, name)) match { |
|
207 |
case Some(build) if build.ok => |
|
208 |
val session_options = deps0.sessions_structure(name).options |
|
209 |
val session_sources = deps0.sources_shasum(name) |
|
79646 | 210 |
if (Sessions.eq_sources(session_options, build.sources, session_sources)) { |
211 |
None |
|
212 |
} |
|
78372 | 213 |
else Some(name) |
214 |
case _ => Some(name) |
|
215 |
} |
|
216 |
case None => Some(name) |
|
217 |
}) |
|
68204 | 218 |
|
78372 | 219 |
Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)), |
220 |
progress = progress, inlined_files = true).check_errors |
|
221 |
} |
|
222 |
else deps0 |
|
223 |
} |
|
66745 | 224 |
|
225 |
||
78372 | 226 |
/* check unknown files */ |
227 |
||
228 |
if (check_unknown_files) { |
|
229 |
val source_files = |
|
230 |
(for { |
|
231 |
(_, base) <- build_deps.session_bases.iterator |
|
232 |
(path, _) <- base.session_sources.iterator |
|
233 |
} yield path).toList |
|
234 |
Mercurial.check_files(source_files)._2 match { |
|
235 |
case Nil => |
|
236 |
case unknown_files => |
|
79646 | 237 |
progress.echo_warning( |
238 |
"Unknown files (not part of the underlying Mercurial repository):" + |
|
78372 | 239 |
unknown_files.map(File.standard_path).sorted.mkString("\n ", "\n ", "")) |
240 |
} |
|
241 |
} |
|
242 |
||
243 |
||
244 |
/* build process and results */ |
|
245 |
||
246 |
val build_context = |
|
79707 | 247 |
Context(store, build_deps, engine = engine, afp_root = afp_root, |
79639 | 248 |
build_hosts = build_hosts, hostname = hostname(build_options), build_heap = build_heap, |
79644 | 249 |
numa_shuffling = numa_shuffling, fresh_build = fresh_build, |
250 |
no_build = no_build, session_setup = session_setup, |
|
79647 | 251 |
jobs = max_jobs.getOrElse(if (build_hosts.nonEmpty) 0 else 1), master = true) |
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
252 |
|
78372 | 253 |
if (clean_build) { |
254 |
for (name <- full_sessions.imports_descendants(full_sessions_selection)) { |
|
255 |
store.clean_output(database_server, name) match { |
|
256 |
case None => |
|
257 |
case Some(true) => progress.echo("Cleaned " + name) |
|
258 |
case Some(false) => progress.echo(name + " FAILED to clean") |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
||
79707 | 263 |
val results = engine.run_build_process(build_context, progress, server) |
78372 | 264 |
|
265 |
if (export_files) { |
|
266 |
for (name <- full_sessions_selection.iterator if results(name).ok) { |
|
267 |
val info = results.info(name) |
|
268 |
if (info.export_files.nonEmpty) { |
|
269 |
progress.echo("Exporting " + info.name + " ...") |
|
270 |
for ((dir, prune, pats) <- info.export_files) { |
|
271 |
Export.export_files(store, name, info.dir + dir, |
|
272 |
progress = if (progress.verbose) progress else new Progress, |
|
273 |
export_prune = prune, |
|
274 |
export_patterns = pats) |
|
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
val presentation_sessions = |
|
281 |
results.sessions_ok.filter(name => browser_info.enabled(results.info(name))) |
|
282 |
if (presentation_sessions.nonEmpty && !progress.stopped) { |
|
283 |
Browser_Info.build(browser_info, results.store, results.deps, presentation_sessions, |
|
78379 | 284 |
progress = progress, server = server) |
78372 | 285 |
} |
286 |
||
78566
a04277e3b313
tuned message: failure may stem from build_cluster init;
wenzelm
parents:
78562
diff
changeset
|
287 |
if (results.unfinished.nonEmpty && (progress.verbose || !no_build)) { |
78372 | 288 |
progress.echo("Unfinished session(s): " + commas(results.unfinished)) |
289 |
} |
|
290 |
||
291 |
results |
|
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
292 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
293 |
} |
48341 | 294 |
} |
295 |
||
296 |
||
77555 | 297 |
/* build logic image */ |
298 |
||
299 |
def build_logic(options: Options, logic: String, |
|
300 |
progress: Progress = new Progress, |
|
301 |
build_heap: Boolean = false, |
|
302 |
dirs: List[Path] = Nil, |
|
303 |
fresh: Boolean = false, |
|
304 |
strict: Boolean = false |
|
305 |
): Int = { |
|
306 |
val selection = Sessions.Selection.session(logic) |
|
307 |
val rc = |
|
308 |
if (!fresh && build(options, selection = selection, |
|
309 |
build_heap = build_heap, no_build = true, dirs = dirs).ok) Process_Result.RC.ok |
|
310 |
else { |
|
311 |
progress.echo("Build started for Isabelle/" + logic + " ...") |
|
312 |
build(options, selection = selection, progress = progress, |
|
313 |
build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc |
|
314 |
} |
|
315 |
if (strict && rc != Process_Result.RC.ok) error("Failed to build Isabelle/" + logic) else rc |
|
316 |
} |
|
317 |
||
318 |
||
79629 | 319 |
/* Isabelle tool wrappers */ |
48341 | 320 |
|
77553 | 321 |
val isabelle_tool1 = Isabelle_Tool("build", "build and manage Isabelle sessions", |
75394 | 322 |
Scala_Project.here, |
323 |
{ args => |
|
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
324 |
var afp_root: Option[Path] = None |
78405 | 325 |
val base_sessions = new mutable.ListBuffer[String] |
326 |
val select_dirs = new mutable.ListBuffer[Path] |
|
78401 | 327 |
val build_hosts = new mutable.ListBuffer[Build_Cluster.Host] |
75394 | 328 |
var numa_shuffling = false |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
329 |
var browser_info = Browser_Info.Config.none |
75394 | 330 |
var requirements = false |
331 |
var soft_build = false |
|
78405 | 332 |
val exclude_session_groups = new mutable.ListBuffer[String] |
75394 | 333 |
var all_sessions = false |
334 |
var build_heap = false |
|
335 |
var clean_build = false |
|
78405 | 336 |
val dirs = new mutable.ListBuffer[Path] |
75394 | 337 |
var export_files = false |
338 |
var fresh_build = false |
|
78405 | 339 |
val session_groups = new mutable.ListBuffer[String] |
79616 | 340 |
var max_jobs: Option[Int] = None |
75394 | 341 |
var check_keywords: Set[String] = Set.empty |
342 |
var list_files = false |
|
343 |
var no_build = false |
|
77628 | 344 |
var options = Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS) |
75394 | 345 |
var verbose = false |
78405 | 346 |
val exclude_sessions = new mutable.ListBuffer[String] |
62590 | 347 |
|
75394 | 348 |
val getopts = Getopts(""" |
62590 | 349 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
350 |
||
351 |
Options are: |
|
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
352 |
-A ROOT include AFP with given root directory (":" for """ + AFP.BASE.implode + """) |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
353 |
-B NAME include session NAME and all descendants |
62590 | 354 |
-D DIR include session directory and select its sessions |
79615 | 355 |
-H HOSTS additional cluster host specifications of the form |
356 |
NAMES:PARAMETERS (separated by commas) |
|
64265 | 357 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
72648 | 358 |
-P DIR enable HTML/PDF presentation in directory (":" for default) |
71807 | 359 |
-R refer to requirements of selected sessions |
66745 | 360 |
-S soft build: only observe changes of sources, not heap images |
62590 | 361 |
-X NAME exclude sessions from group NAME and all descendants |
362 |
-a select all sessions |
|
363 |
-b build heap images |
|
364 |
-c clean build |
|
365 |
-d DIR include session directory |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
366 |
-e export files from session specification into file-system |
66841 | 367 |
-f fresh build |
62590 | 368 |
-g NAME select session group NAME |
79647 | 369 |
-j INT maximum number of parallel jobs |
370 |
(default: 1 for local build, 0 for build cluster) |
|
62590 | 371 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
372 |
-l list session source files |
|
77554
4465d9dff448
clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents:
77553
diff
changeset
|
373 |
-n no build -- take existing session build databases |
62590 | 374 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
375 |
-v verbose |
|
376 |
-x NAME exclude session NAME and all descendants |
|
377 |
||
77647 | 378 |
Build and manage Isabelle sessions: ML heaps, session databases, documents. |
62596 | 379 |
|
79615 | 380 |
Parameters for cluster host specifications (-H), apart from system options: |
78408
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
381 |
""" + Library.indent_lines(4, Build_Cluster.Host.parameters.print()) + |
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
382 |
""" |
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
383 |
|
77647 | 384 |
Notable system options: see "isabelle options -l -t build" |
385 |
||
386 |
Notable system settings: |
|
78408
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
387 |
""" + Library.indent_lines(4, Build_Log.Settings.show()) + "\n", |
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
388 |
"A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))), |
78405 | 389 |
"B:" -> (arg => base_sessions += arg), |
390 |
"D:" -> (arg => select_dirs += Path.explode(arg)), |
|
78945
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
wenzelm
parents:
78916
diff
changeset
|
391 |
"H:" -> (arg => build_hosts ++= Build_Cluster.Host.parse(Registry.global, arg)), |
75394 | 392 |
"N" -> (_ => numa_shuffling = true), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
393 |
"P:" -> (arg => browser_info = Browser_Info.Config.make(arg)), |
75394 | 394 |
"R" -> (_ => requirements = true), |
395 |
"S" -> (_ => soft_build = true), |
|
78405 | 396 |
"X:" -> (arg => exclude_session_groups += arg), |
75394 | 397 |
"a" -> (_ => all_sessions = true), |
398 |
"b" -> (_ => build_heap = true), |
|
399 |
"c" -> (_ => clean_build = true), |
|
78405 | 400 |
"d:" -> (arg => dirs += Path.explode(arg)), |
75394 | 401 |
"e" -> (_ => export_files = true), |
402 |
"f" -> (_ => fresh_build = true), |
|
78405 | 403 |
"g:" -> (arg => session_groups += arg), |
79616 | 404 |
"j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))), |
75394 | 405 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
406 |
"l" -> (_ => list_files = true), |
|
407 |
"n" -> (_ => no_build = true), |
|
408 |
"o:" -> (arg => options = options + arg), |
|
409 |
"v" -> (_ => verbose = true), |
|
78405 | 410 |
"x:" -> (arg => exclude_sessions += arg)) |
62590 | 411 |
|
75394 | 412 |
val sessions = getopts(args) |
62590 | 413 |
|
75394 | 414 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 415 |
|
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
416 |
progress.echo( |
78895 | 417 |
"Started at " + Build_Log.print_date(progress.start) + |
77719 | 418 |
" (" + Isabelle_System.ml_identifier() + " on " + hostname(options) +")", |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
419 |
verbose = true) |
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
420 |
progress.echo(Build_Log.Settings.show() + "\n", verbose = true) |
62590 | 421 |
|
75394 | 422 |
val results = |
423 |
progress.interrupt_handler { |
|
424 |
build(options, |
|
425 |
selection = Sessions.Selection( |
|
426 |
requirements = requirements, |
|
427 |
all_sessions = all_sessions, |
|
78405 | 428 |
base_sessions = base_sessions.toList, |
429 |
exclude_session_groups = exclude_session_groups.toList, |
|
430 |
exclude_sessions = exclude_sessions.toList, |
|
431 |
session_groups = session_groups.toList, |
|
75394 | 432 |
sessions = sessions), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
433 |
browser_info = browser_info, |
75394 | 434 |
progress = progress, |
435 |
check_unknown_files = Mercurial.is_repository(Path.ISABELLE_HOME), |
|
436 |
build_heap = build_heap, |
|
437 |
clean_build = clean_build, |
|
78437 | 438 |
afp_root = afp_root, |
78405 | 439 |
dirs = dirs.toList, |
440 |
select_dirs = select_dirs.toList, |
|
77477 | 441 |
numa_shuffling = Host.numa_check(progress, numa_shuffling), |
75394 | 442 |
max_jobs = max_jobs, |
443 |
list_files = list_files, |
|
444 |
check_keywords = check_keywords, |
|
445 |
fresh_build = fresh_build, |
|
446 |
no_build = no_build, |
|
447 |
soft_build = soft_build, |
|
78401 | 448 |
export_files = export_files, |
449 |
build_hosts = build_hosts.toList) |
|
75394 | 450 |
} |
77545 | 451 |
val stop_date = Date.now() |
78895 | 452 |
val elapsed_time = stop_date.time - progress.start.time |
75394 | 453 |
|
77545 | 454 |
progress.echo("\nFinished at " + Build_Log.print_date(stop_date), verbose = true) |
62590 | 455 |
|
75394 | 456 |
val total_timing = |
457 |
results.sessions.iterator.map(a => results(a).timing).foldLeft(Timing.zero)(_ + _). |
|
458 |
copy(elapsed = elapsed_time) |
|
459 |
progress.echo(total_timing.message_resources) |
|
62590 | 460 |
|
75394 | 461 |
sys.exit(results.rc) |
462 |
}) |
|
68305 | 463 |
|
464 |
||
77553 | 465 |
|
78562 | 466 |
/** build cluster management **/ |
77557 | 467 |
|
78219 | 468 |
/* identified builds */ |
469 |
||
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
470 |
def read_builds(build_database: Option[SQL.Database]): List[Build_Process.Build] = |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
471 |
build_database match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
472 |
case None => Nil |
78634 | 473 |
case Some(db) => Build_Process.read_builds(db) |
78219 | 474 |
} |
475 |
||
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
476 |
def print_builds(build_database: Option[SQL.Database], builds: List[Build_Process.Build]): String = |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
477 |
{ |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
478 |
val print_database = |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
479 |
build_database match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
480 |
case None => "" |
78634 | 481 |
case Some(db) => " (database " + db + ")" |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
482 |
} |
78640 | 483 |
if (builds.isEmpty) "No build processes" + print_database |
78641 | 484 |
else "Build processes" + print_database + builds.map(build => "\n " + build.print).mkString |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
485 |
} |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
486 |
|
78410 | 487 |
def find_builds( |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
488 |
build_database: Option[SQL.Database], |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
489 |
build_id: String, |
78221 | 490 |
builds: List[Build_Process.Build] |
78410 | 491 |
): Build_Process.Build = { |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
492 |
(build_id, builds.length) match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
493 |
case (UUID(_), _) if builds.exists(_.build_uuid == build_id) => |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
494 |
builds.find(_.build_uuid == build_id).get |
78410 | 495 |
case ("", 1) => builds.head |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
496 |
case ("", 0) => error(print_builds(build_database, builds)) |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
497 |
case _ => |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
498 |
cat_error("Cannot identify build process " + quote(build_id), |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
499 |
print_builds(build_database, builds)) |
78219 | 500 |
} |
78410 | 501 |
} |
78219 | 502 |
|
503 |
||
78562 | 504 |
/* "isabelle build_process" */ |
505 |
||
506 |
def build_process( |
|
507 |
options: Options, |
|
79676
0cac7e3634d0
more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents:
79647
diff
changeset
|
508 |
build_cluster: Boolean = false, |
78562 | 509 |
list_builds: Boolean = false, |
78636 | 510 |
remove_builds: Boolean = false, |
511 |
force: Boolean = false, |
|
78562 | 512 |
progress: Progress = new Progress |
513 |
): Unit = { |
|
79707 | 514 |
val engine = Engine(engine_name(options)) |
515 |
val store = engine.build_store(options, build_cluster = build_cluster) |
|
78562 | 516 |
|
517 |
using(store.open_server()) { server => |
|
518 |
using_optional(store.maybe_open_build_database(server = server)) { build_database => |
|
78636 | 519 |
def print(builds: List[Build_Process.Build]): Unit = |
520 |
if (list_builds) progress.echo(print_builds(build_database, builds)) |
|
78562 | 521 |
|
78636 | 522 |
build_database match { |
523 |
case None => print(Nil) |
|
524 |
case Some(db) => |
|
525 |
Build_Process.private_data.transaction_lock(db, create = true, label = "build_process") { |
|
526 |
val builds = Build_Process.private_data.read_builds(db) |
|
527 |
val remove = |
|
528 |
if (!remove_builds) Nil |
|
529 |
else if (force) builds.map(_.build_uuid) |
|
530 |
else builds.flatMap(build => if (build.active) None else Some(build.build_uuid)) |
|
531 |
||
532 |
print(builds) |
|
533 |
if (remove.nonEmpty) { |
|
534 |
if (remove_builds) { |
|
535 |
progress.echo("Removing " + commas(remove) + " ...") |
|
536 |
Build_Process.private_data.remove_builds(db, remove) |
|
537 |
print(Build_Process.private_data.read_builds(db)) |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
} |
|
78562 | 542 |
} |
543 |
} |
|
544 |
} |
|
545 |
||
546 |
val isabelle_tool2 = Isabelle_Tool("build_process", "manage session build process", |
|
547 |
Scala_Project.here, |
|
548 |
{ args => |
|
79676
0cac7e3634d0
more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents:
79647
diff
changeset
|
549 |
var build_cluster = false |
78636 | 550 |
var force = false |
78562 | 551 |
var list_builds = false |
552 |
var options = |
|
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79679
diff
changeset
|
553 |
Options.init(specs = |
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79679
diff
changeset
|
554 |
Options.Spec.ISABELLE_BUILD_OPTIONS ::: List(Options.Spec.make("build_database"))) |
78636 | 555 |
var remove_builds = false |
78562 | 556 |
|
557 |
val getopts = Getopts(""" |
|
558 |
Usage: isabelle build_process [OPTIONS] |
|
559 |
||
560 |
Options are: |
|
79676
0cac7e3634d0
more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents:
79647
diff
changeset
|
561 |
-C build cluster mode (database server) |
78636 | 562 |
-f extra force for option -r |
78562 | 563 |
-l list build processes |
564 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
78636 | 565 |
-r remove data from build processes: inactive processes (default) |
566 |
or all processes (option -f) |
|
79700 | 567 |
|
568 |
Manage Isabelle build process, notably distributed build cluster (option -C). |
|
78562 | 569 |
""", |
79679
ba2c43592f35
proper treatment of "isabelle build_process -C" (amending 0cac7e3634d0);
wenzelm
parents:
79676
diff
changeset
|
570 |
"C" -> (_ => build_cluster = true), |
78636 | 571 |
"f" -> (_ => force = true), |
78562 | 572 |
"l" -> (_ => list_builds = true), |
78636 | 573 |
"o:" -> (arg => options = options + arg), |
574 |
"r" -> (_ => remove_builds = true)) |
|
78562 | 575 |
|
576 |
val more_args = getopts(args) |
|
577 |
if (more_args.nonEmpty) getopts.usage() |
|
578 |
||
579 |
val progress = new Console_Progress() |
|
580 |
||
79676
0cac7e3634d0
more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents:
79647
diff
changeset
|
581 |
build_process(options, build_cluster = build_cluster, list_builds = list_builds, |
0cac7e3634d0
more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents:
79647
diff
changeset
|
582 |
remove_builds = remove_builds, force = force, progress = progress) |
78562 | 583 |
}) |
584 |
||
585 |
||
586 |
||
587 |
/* "isabelle build_worker" */ |
|
77557 | 588 |
|
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
589 |
def build_worker_command( |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
590 |
host: Build_Cluster.Host, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
591 |
ssh: SSH.System = SSH.Local, |
78558 | 592 |
build_options: List[Options.Spec] = Nil, |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
593 |
build_id: String = "", |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
594 |
isabelle_home: Path = Path.current, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
595 |
afp_root: Option[Path] = None, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
596 |
dirs: List[Path] = Nil, |
78637 | 597 |
quiet: Boolean = false, |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
598 |
verbose: Boolean = false |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
599 |
): String = { |
78916 | 600 |
val options = build_options ::: Options.Spec.eq("build_hostname", host.name) :: host.options |
79624 | 601 |
ssh.bash_path(Isabelle_Tool.exe(isabelle_home)) + " build_worker" + |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
602 |
if_proper(build_id, " -B " + Bash.string(build_id)) + |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
603 |
if_proper(afp_root, " -A " + ssh.bash_path(afp_root.get)) + |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
604 |
dirs.map(dir => " -d " + ssh.bash_path(dir)).mkString + |
78560 | 605 |
if_proper(host.numa, " -N") + " -j" + host.jobs + |
78915
90756ad4d8d7
more accurate treatment of surrounding whitespace;
wenzelm
parents:
78908
diff
changeset
|
606 |
Options.Spec.bash_strings(options, bg = true) + |
78637 | 607 |
if_proper(quiet, " -q") + |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
608 |
if_proper(verbose, " -v") |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
609 |
} |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
610 |
|
77557 | 611 |
def build_worker( |
612 |
options: Options, |
|
78410 | 613 |
build_id: String = "", |
77557 | 614 |
progress: Progress = new Progress, |
78420 | 615 |
afp_root: Option[Path] = None, |
77557 | 616 |
dirs: List[Path] = Nil, |
617 |
numa_shuffling: Boolean = false, |
|
79616 | 618 |
max_jobs: Option[Int] = None |
78568 | 619 |
): Results = { |
79707 | 620 |
val engine = Engine(engine_name(options)) |
621 |
val store = engine.build_store(options, build_cluster = true) |
|
77557 | 622 |
val build_options = store.options |
623 |
||
78372 | 624 |
using(store.open_server()) { server => |
625 |
using_optional(store.maybe_open_build_database(server = server)) { build_database => |
|
626 |
val builds = read_builds(build_database) |
|
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
627 |
|
78634 | 628 |
val build_master = find_builds(build_database, build_id, builds.filter(_.active)) |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
629 |
|
78562 | 630 |
val sessions_structure = |
631 |
Sessions.load_structure(build_options, dirs = AFP.make_dirs(afp_root) ::: dirs). |
|
632 |
selection(Sessions.Selection(sessions = build_master.sessions)) |
|
78219 | 633 |
|
78562 | 634 |
val build_deps = |
635 |
Sessions.deps(sessions_structure, progress = progress, inlined_files = true).check_errors |
|
78219 | 636 |
|
78562 | 637 |
val build_context = |
79707 | 638 |
Context(store, build_deps, engine = engine, afp_root = afp_root, |
78562 | 639 |
hostname = hostname(build_options), numa_shuffling = numa_shuffling, |
79644 | 640 |
build_uuid = build_master.build_uuid, jobs = max_jobs.getOrElse(1)) |
78219 | 641 |
|
79707 | 642 |
engine.run_build_process(build_context, progress, server) |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
643 |
} |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
644 |
} |
77557 | 645 |
} |
646 |
||
78562 | 647 |
val isabelle_tool3 = Isabelle_Tool("build_worker", "start worker for session build process", |
77557 | 648 |
Scala_Project.here, |
649 |
{ args => |
|
78420 | 650 |
var afp_root: Option[Path] = None |
78219 | 651 |
var build_id = "" |
77557 | 652 |
var numa_shuffling = false |
78405 | 653 |
val dirs = new mutable.ListBuffer[Path] |
79616 | 654 |
var max_jobs: Option[Int] = None |
78219 | 655 |
var options = |
79682
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79679
diff
changeset
|
656 |
Options.init(specs = |
1fa1b32b0379
build local log_db, with store/restore via optional database server;
wenzelm
parents:
79679
diff
changeset
|
657 |
Options.Spec.ISABELLE_BUILD_OPTIONS ::: List(Options.Spec.make("build_database"))) |
78637 | 658 |
var quiet = false |
77557 | 659 |
var verbose = false |
660 |
||
661 |
val getopts = Getopts(""" |
|
78219 | 662 |
Usage: isabelle build_worker [OPTIONS] |
77557 | 663 |
|
664 |
Options are: |
|
78420 | 665 |
-A ROOT include AFP with given root directory (":" for """ + AFP.BASE.implode + """) |
78411 | 666 |
-B UUID existing UUID for build process (default: from database) |
77557 | 667 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
668 |
-d DIR include session directory |
|
669 |
-j INT maximum number of parallel jobs (default 1) |
|
670 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
78637 | 671 |
-q quiet mode: no progress |
77557 | 672 |
-v verbose |
77647 | 673 |
""", |
78420 | 674 |
"A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))), |
78410 | 675 |
"B:" -> (arg => build_id = arg), |
77557 | 676 |
"N" -> (_ => numa_shuffling = true), |
78405 | 677 |
"d:" -> (arg => dirs += Path.explode(arg)), |
79616 | 678 |
"j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))), |
77557 | 679 |
"o:" -> (arg => options = options + arg), |
78637 | 680 |
"q" -> (_ => quiet = true), |
77557 | 681 |
"v" -> (_ => verbose = true)) |
682 |
||
683 |
val more_args = getopts(args) |
|
684 |
if (more_args.nonEmpty) getopts.usage() |
|
685 |
||
78637 | 686 |
val progress = |
687 |
if (quiet && verbose) new Progress { override def verbose: Boolean = true } |
|
688 |
else if (quiet) new Progress |
|
689 |
else new Console_Progress(verbose = verbose) |
|
77557 | 690 |
|
78568 | 691 |
val results = |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
692 |
progress.interrupt_handler { |
78411 | 693 |
build_worker(options, |
694 |
build_id = build_id, |
|
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
695 |
progress = progress, |
78420 | 696 |
afp_root = afp_root, |
78405 | 697 |
dirs = dirs.toList, |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
698 |
numa_shuffling = Host.numa_check(progress, numa_shuffling), |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
699 |
max_jobs = max_jobs) |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
700 |
} |
77557 | 701 |
|
78568 | 702 |
if (!results.ok) sys.exit(results.rc) |
77557 | 703 |
}) |
704 |
||
705 |
||
706 |
||
77563 | 707 |
/** "isabelle build_log" **/ |
77553 | 708 |
|
709 |
/* theory markup/messages from session database */ |
|
710 |
||
711 |
def read_theory( |
|
712 |
theory_context: Export.Theory_Context, |
|
713 |
unicode_symbols: Boolean = false |
|
714 |
): Option[Document.Snapshot] = { |
|
715 |
def decode_bytes(bytes: Bytes): String = |
|
716 |
Symbol.output(unicode_symbols, UTF8.decode_permissive(bytes)) |
|
717 |
||
718 |
def read(name: String): Export.Entry = theory_context(name, permissive = true) |
|
719 |
||
720 |
def read_xml(name: String): XML.Body = |
|
721 |
YXML.parse_body(decode_bytes(read(name).bytes), cache = theory_context.cache) |
|
722 |
||
78178 | 723 |
def read_source_file(name: String): Store.Source_File = |
77553 | 724 |
theory_context.session_context.source_file(name) |
725 |
||
726 |
for { |
|
727 |
id <- theory_context.document_id() |
|
728 |
(thy_file, blobs_files) <- theory_context.files(permissive = true) |
|
729 |
} |
|
730 |
yield { |
|
731 |
val master_dir = |
|
732 |
Path.explode(Url.strip_base_name(thy_file).getOrElse( |
|
733 |
error("Cannot determine theory master directory: " + quote(thy_file)))) |
|
734 |
||
735 |
val blobs = |
|
736 |
blobs_files.map { name => |
|
737 |
val path = Path.explode(name) |
|
738 |
val src_path = File.relative_path(master_dir, path).getOrElse(path) |
|
739 |
||
740 |
val file = read_source_file(name) |
|
741 |
val bytes = file.bytes |
|
742 |
val text = decode_bytes(bytes) |
|
743 |
val chunk = Symbol.Text_Chunk(text) |
|
744 |
||
745 |
Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) -> |
|
746 |
Document.Blobs.Item(bytes, text, chunk, changed = false) |
|
747 |
} |
|
748 |
||
749 |
val thy_source = decode_bytes(read_source_file(thy_file).bytes) |
|
750 |
val thy_xml = read_xml(Export.MARKUP) |
|
751 |
val blobs_xml = |
|
752 |
for (i <- (1 to blobs.length).toList) |
|
753 |
yield read_xml(Export.MARKUP + i) |
|
754 |
||
755 |
val markups_index = Command.Markup_Index.make(blobs.map(_._1)) |
|
756 |
val markups = |
|
757 |
Command.Markups.make( |
|
758 |
for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml)) |
|
759 |
yield index -> Markup_Tree.from_XML(xml)) |
|
760 |
||
761 |
val results = |
|
762 |
Command.Results.make( |
|
78592 | 763 |
for (case elem@XML.Elem(Markup(_, Markup.Serial(i)), _) <- read_xml(Export.MESSAGES)) |
77553 | 764 |
yield i -> elem) |
765 |
||
766 |
val command = |
|
767 |
Command.unparsed(thy_source, theory = true, id = id, |
|
768 |
node_name = Document.Node.Name(thy_file, theory = theory_context.theory), |
|
769 |
blobs_info = Command.Blobs_Info.make(blobs), |
|
770 |
markups = markups, results = results) |
|
771 |
||
772 |
val doc_blobs = Document.Blobs.make(blobs) |
|
773 |
||
774 |
Document.State.init.snippet(command, doc_blobs) |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
||
779 |
/* print messages */ |
|
780 |
||
781 |
def print_log( |
|
782 |
options: Options, |
|
783 |
sessions: List[String], |
|
784 |
theories: List[String] = Nil, |
|
785 |
message_head: List[Regex] = Nil, |
|
786 |
message_body: List[Regex] = Nil, |
|
787 |
progress: Progress = new Progress, |
|
788 |
margin: Double = Pretty.default_margin, |
|
789 |
breakgain: Double = Pretty.default_breakgain, |
|
790 |
metric: Pretty.Metric = Symbol.Metric, |
|
791 |
unicode_symbols: Boolean = false |
|
792 |
): Unit = { |
|
78178 | 793 |
val store = Store(options) |
77553 | 794 |
val session = new Session(options, Resources.bootstrap) |
795 |
||
796 |
def check(filter: List[Regex], make_string: => String): Boolean = |
|
797 |
filter.isEmpty || { |
|
798 |
val s = Output.clean_yxml(make_string) |
|
799 |
filter.forall(r => r.findFirstIn(Output.clean_yxml(s)).nonEmpty) |
|
800 |
} |
|
801 |
||
802 |
def print(session_name: String): Unit = { |
|
803 |
using(Export.open_session_context0(store, session_name)) { session_context => |
|
804 |
val result = |
|
805 |
for { |
|
806 |
db <- session_context.session_db() |
|
807 |
theories = store.read_theories(db, session_name) |
|
808 |
errors = store.read_errors(db, session_name) |
|
809 |
info <- store.read_build(db, session_name) |
|
810 |
} yield (theories, errors, info.return_code) |
|
811 |
result match { |
|
812 |
case None => store.error_database(session_name) |
|
813 |
case Some((used_theories, errors, rc)) => |
|
814 |
theories.filterNot(used_theories.toSet) match { |
|
815 |
case Nil => |
|
816 |
case bad => error("Unknown theories " + commas_quote(bad)) |
|
817 |
} |
|
818 |
val print_theories = |
|
819 |
if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet) |
|
820 |
||
821 |
for (thy <- print_theories) { |
|
822 |
val thy_heading = "\nTheory " + quote(thy) + " (in " + session_name + ")" + ":" |
|
823 |
||
78280 | 824 |
Build.read_theory(session_context.theory(thy), unicode_symbols = unicode_symbols) match { |
77553 | 825 |
case None => progress.echo(thy_heading + " MISSING") |
826 |
case Some(snapshot) => |
|
827 |
val rendering = new Rendering(snapshot, options, session) |
|
828 |
val messages = |
|
829 |
rendering.text_messages(Text.Range.full) |
|
830 |
.filter(message => progress.verbose || Protocol.is_exported(message.info)) |
|
831 |
if (messages.nonEmpty) { |
|
832 |
val line_document = Line.Document(snapshot.node.source) |
|
833 |
val buffer = new mutable.ListBuffer[String] |
|
834 |
for (Text.Info(range, elem) <- messages) { |
|
835 |
val line = line_document.position(range.start).line1 |
|
836 |
val pos = Position.Line_File(line, snapshot.node_name.node) |
|
837 |
def message_text: String = |
|
838 |
Protocol.message_text(elem, heading = true, pos = pos, |
|
839 |
margin = margin, breakgain = breakgain, metric = metric) |
|
840 |
val ok = |
|
841 |
check(message_head, Protocol.message_heading(elem, pos)) && |
|
842 |
check(message_body, XML.content(Pretty.unformatted(List(elem)))) |
|
843 |
if (ok) buffer += message_text |
|
844 |
} |
|
845 |
if (buffer.nonEmpty) { |
|
846 |
progress.echo(thy_heading) |
|
847 |
buffer.foreach(progress.echo(_)) |
|
848 |
} |
|
849 |
} |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
if (errors.nonEmpty) { |
|
854 |
val msg = Symbol.output(unicode_symbols, cat_lines(errors)) |
|
855 |
progress.echo("\nBuild errors:\n" + Output.error_message_text(msg)) |
|
856 |
} |
|
857 |
if (rc != Process_Result.RC.ok) { |
|
858 |
progress.echo("\n" + Process_Result.RC.print_long(rc)) |
|
859 |
} |
|
860 |
} |
|
861 |
} |
|
862 |
} |
|
863 |
||
864 |
val errors = new mutable.ListBuffer[String] |
|
865 |
for (session_name <- sessions) { |
|
78705
fde0b195cb7d
clarified signature: avoid association with potentially dangerous Exn.capture;
wenzelm
parents:
78643
diff
changeset
|
866 |
Exn.result(print(session_name)) match { |
77553 | 867 |
case Exn.Res(_) => |
868 |
case Exn.Exn(exn) => errors += Exn.message(exn) |
|
869 |
} |
|
870 |
} |
|
871 |
if (errors.nonEmpty) error(cat_lines(errors.toList)) |
|
872 |
} |
|
873 |
||
874 |
||
79629 | 875 |
/* Isabelle tool wrapper */ |
77553 | 876 |
|
78562 | 877 |
val isabelle_tool4 = Isabelle_Tool("build_log", "print messages from session build database", |
77553 | 878 |
Scala_Project.here, |
879 |
{ args => |
|
880 |
/* arguments */ |
|
881 |
||
78405 | 882 |
val message_head = new mutable.ListBuffer[Regex] |
883 |
val message_body = new mutable.ListBuffer[Regex] |
|
77553 | 884 |
var unicode_symbols = false |
78405 | 885 |
val theories = new mutable.ListBuffer[String] |
77553 | 886 |
var margin = Pretty.default_margin |
887 |
var options = Options.init() |
|
888 |
var verbose = false |
|
889 |
||
890 |
val getopts = Getopts(""" |
|
77563 | 891 |
Usage: isabelle build_log [OPTIONS] [SESSIONS ...] |
77553 | 892 |
|
893 |
Options are: |
|
894 |
-H REGEX filter messages by matching against head |
|
895 |
-M REGEX filter messages by matching against body |
|
896 |
-T NAME restrict to given theories (multiple options possible) |
|
897 |
-U output Unicode symbols |
|
898 |
-m MARGIN margin for pretty printing (default: """ + margin + """) |
|
899 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
900 |
-v print all messages, including information etc. |
|
901 |
||
77554
4465d9dff448
clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents:
77553
diff
changeset
|
902 |
Print messages from the session build database of the given sessions, |
4465d9dff448
clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents:
77553
diff
changeset
|
903 |
without any checks against current sources nor session structure: results |
4465d9dff448
clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents:
77553
diff
changeset
|
904 |
from old sessions or failed builds can be printed as well. |
77553 | 905 |
|
906 |
Multiple options -H and -M are conjunctive: all given patterns need to |
|
907 |
match. Patterns match any substring, but ^ or $ may be used to match the |
|
908 |
start or end explicitly. |
|
909 |
""", |
|
78405 | 910 |
"H:" -> (arg => message_head += arg.r), |
911 |
"M:" -> (arg => message_body += arg.r), |
|
912 |
"T:" -> (arg => theories += arg), |
|
77553 | 913 |
"U" -> (_ => unicode_symbols = true), |
914 |
"m:" -> (arg => margin = Value.Double.parse(arg)), |
|
915 |
"o:" -> (arg => options = options + arg), |
|
916 |
"v" -> (_ => verbose = true)) |
|
917 |
||
918 |
val sessions = getopts(args) |
|
919 |
||
920 |
val progress = new Console_Progress(verbose = verbose) |
|
921 |
||
922 |
if (sessions.isEmpty) progress.echo_warning("No sessions to print") |
|
923 |
else { |
|
78405 | 924 |
print_log(options, sessions, theories = theories.toList, message_head = message_head.toList, |
925 |
message_body = message_body.toList, margin = margin, progress = progress, |
|
77553 | 926 |
unicode_symbols = unicode_symbols) |
927 |
} |
|
928 |
}) |
|
48276 | 929 |
} |