author | wenzelm |
Thu, 15 Feb 2024 13:00:56 +0100 | |
changeset 79622 | e413c94b192a |
parent 79621 | 7697037f1e24 |
child 79624 | 8e97d1fcbbc2 |
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, |
|
78435
a623cb346b4a
more flexible Build.Engine.process_options: e.g. to manipulate "process_policy" for ML process;
wenzelm
parents:
78421
diff
changeset
|
30 |
engine: Engine, |
78421 | 31 |
build_deps: isabelle.Sessions.Deps, |
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, |
|
79616 | 38 |
max_jobs: Option[Int] = None, |
78421 | 39 |
fresh_build: Boolean = false, |
40 |
no_build: Boolean = false, |
|
41 |
session_setup: (String, Session) => Unit = (_, _) => (), |
|
42 |
build_uuid: String = UUID.random().toString, |
|
43 |
master: Boolean = false |
|
44 |
) { |
|
45 |
override def toString: String = |
|
46 |
"Build.Context(build_uuid = " + quote(build_uuid) + if_proper(master, ", master = true") + ")" |
|
47 |
||
48 |
def build_options: Options = store.options |
|
49 |
||
50 |
def sessions_structure: isabelle.Sessions.Structure = build_deps.sessions_structure |
|
51 |
||
79616 | 52 |
def jobs: Int = max_jobs.getOrElse(1) |
53 |
def worker_active: Boolean = jobs > 0 |
|
78421 | 54 |
} |
55 |
||
56 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
57 |
/* results */ |
48424 | 58 |
|
77311 | 59 |
object Results { |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
60 |
def apply( |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
61 |
context: Context, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
62 |
results: Map[String, Process_Result] = Map.empty, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
63 |
other_rc: Int = Process_Result.RC.ok |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
64 |
): Results = { |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
65 |
new Results(context.store, context.build_deps, results, other_rc) |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
66 |
} |
77311 | 67 |
} |
68 |
||
69 |
class Results private( |
|
78178 | 70 |
val store: Store, |
76209 | 71 |
val deps: Sessions.Deps, |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
72 |
results: Map[String, Process_Result], |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
73 |
other_rc: Int |
76198
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
74 |
) { |
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
75 |
def cache: Term.Cache = store.cache |
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
76 |
|
77311 | 77 |
def sessions_ok: List[String] = |
78 |
(for { |
|
79 |
name <- deps.sessions_structure.build_topological_order.iterator |
|
80 |
result <- results.get(name) if result.ok |
|
81 |
} yield name).toList |
|
82 |
||
77250
22016642d6af
clarified data structure: use static info from deps, not dynamic results;
wenzelm
parents:
77246
diff
changeset
|
83 |
def info(name: String): Sessions.Info = deps.sessions_structure(name) |
62403 | 84 |
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
|
85 |
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
|
86 |
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
|
87 |
|
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
88 |
val rc: Int = |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
89 |
Process_Result.RC.merge(other_rc, |
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
90 |
Process_Result.RC.merge(results.valuesIterator.map(_.strict.rc))) |
74306 | 91 |
def ok: Boolean = rc == Process_Result.RC.ok |
62406 | 92 |
|
78566
a04277e3b313
tuned message: failure may stem from build_cluster init;
wenzelm
parents:
78562
diff
changeset
|
93 |
lazy val unfinished: List[String] = sessions.iterator.filterNot(apply(_).ok).toList.sorted |
76199 | 94 |
|
62406 | 95 |
override def toString: String = rc.toString |
62403 | 96 |
} |
97 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
98 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
99 |
/* engine */ |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
100 |
|
78232 | 101 |
object Engine { |
102 |
lazy val services: List[Engine] = |
|
103 |
Isabelle_System.make_services(classOf[Engine]) |
|
104 |
||
105 |
def apply(name: String): Engine = |
|
106 |
services.find(_.name == name).getOrElse(error("Bad build engine " + quote(name))) |
|
107 |
} |
|
108 |
||
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
109 |
class Engine(val name: String) extends Isabelle_System.Service { |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
110 |
override def toString: String = name |
78232 | 111 |
|
79614 | 112 |
def build_options(options: Options, build_cluster: Boolean = false): Options = { |
78401 | 113 |
val options1 = options + "completion_limit=0" + "editor_tracing_messages=0" |
79622 | 114 |
if (build_cluster) options1 + "build_database_server" + "build_database" else options1 |
78401 | 115 |
} |
78232 | 116 |
|
78412 | 117 |
final def build_store(options: Options, |
79614 | 118 |
build_cluster: Boolean = false, |
78412 | 119 |
cache: Term.Cache = Term.Cache.make() |
120 |
): Store = { |
|
79614 | 121 |
val store = Store(build_options(options, build_cluster = build_cluster), cache = cache) |
78412 | 122 |
Isabelle_System.make_directory(store.output_dir + Path.basic("log")) |
123 |
Isabelle_Fonts.init() |
|
124 |
store |
|
125 |
} |
|
126 |
||
78436
5f5f909206bb
clarified signature: more "object-oriented" style;
wenzelm
parents:
78435
diff
changeset
|
127 |
def open_build_process( |
78421 | 128 |
build_context: Context, |
78372 | 129 |
build_progress: Progress, |
130 |
server: SSH.Server |
|
131 |
): Build_Process = new Build_Process(build_context, build_progress, server) |
|
78232 | 132 |
|
78436
5f5f909206bb
clarified signature: more "object-oriented" style;
wenzelm
parents:
78435
diff
changeset
|
133 |
final def run_build_process( |
78421 | 134 |
context: Context, |
78372 | 135 |
progress: Progress, |
136 |
server: SSH.Server |
|
78412 | 137 |
): Results = { |
78232 | 138 |
Isabelle_Thread.uninterruptible { |
78440
126a12483c67
support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents:
78437
diff
changeset
|
139 |
using(open_build_process(context, progress, server))(_.run()) |
78232 | 140 |
} |
78412 | 141 |
} |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
142 |
} |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
143 |
|
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
144 |
class Default_Engine extends Engine("") { override def toString: String = "<default>" } |
79621
7697037f1e24
prefer static object, while class is required for "services" (see 47eb96592aa2);
wenzelm
parents:
79616
diff
changeset
|
145 |
object Default_Engine extends Default_Engine |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
146 |
|
77558 | 147 |
|
148 |
/* build */ |
|
149 |
||
62641 | 150 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
151 |
options: Options, |
78401 | 152 |
build_hosts: List[Build_Cluster.Host] = Nil, |
71981 | 153 |
selection: Sessions.Selection = Sessions.Selection.empty, |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
154 |
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
|
155 |
progress: Progress = new Progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
156 |
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
|
157 |
build_heap: Boolean = false, |
48595 | 158 |
clean_build: Boolean = false, |
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
159 |
afp_root: Option[Path] = None, |
56890 | 160 |
dirs: List[Path] = Nil, |
161 |
select_dirs: List[Path] = Nil, |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66962
diff
changeset
|
162 |
infos: List[Sessions.Info] = Nil, |
64265 | 163 |
numa_shuffling: Boolean = false, |
79616 | 164 |
max_jobs: Option[Int] = None, |
48903 | 165 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
166 |
check_keywords: Set[String] = Set.empty, |
66841 | 167 |
fresh_build: Boolean = false, |
48509 | 168 |
no_build: Boolean = false, |
66745 | 169 |
soft_build: Boolean = false, |
73805
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
170 |
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
|
171 |
augment_options: String => List[Options.Spec] = _ => Nil, |
77559
4ad322ee6025
clarified signature: support all arguments of Sessions.store();
wenzelm
parents:
77558
diff
changeset
|
172 |
session_setup: (String, Session) => Unit = (_, _) => (), |
4ad322ee6025
clarified signature: support all arguments of Sessions.store();
wenzelm
parents:
77558
diff
changeset
|
173 |
cache: Term.Cache = Term.Cache.make() |
75393 | 174 |
): Results = { |
78232 | 175 |
val build_engine = Engine(engine_name(options)) |
176 |
||
79614 | 177 |
val store = |
178 |
build_engine.build_store(options, build_cluster = build_hosts.nonEmpty, cache = cache) |
|
77557 | 179 |
val build_options = store.options |
69369
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
180 |
|
78372 | 181 |
using(store.open_server()) { server => |
182 |
using_optional(store.maybe_open_database_server(server = server)) { database_server => |
|
66745 | 183 |
|
78372 | 184 |
|
185 |
/* session selection and dependencies */ |
|
65422 | 186 |
|
78372 | 187 |
val full_sessions = |
78420 | 188 |
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
|
189 |
select_dirs = select_dirs, infos = infos, augment_options = augment_options) |
78372 | 190 |
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
|
191 |
|
78372 | 192 |
val build_deps = { |
193 |
val deps0 = |
|
194 |
Sessions.deps(full_sessions.selection(selection), progress = progress, inlined_files = true, |
|
195 |
list_files = list_files, check_keywords = check_keywords).check_errors |
|
66745 | 196 |
|
78372 | 197 |
if (soft_build && !fresh_build) { |
198 |
val outdated = |
|
199 |
deps0.sessions_structure.build_topological_order.flatMap(name => |
|
200 |
store.try_open_database(name, server = server) match { |
|
201 |
case Some(db) => |
|
202 |
using(db)(store.read_build(_, name)) match { |
|
203 |
case Some(build) if build.ok => |
|
204 |
val session_options = deps0.sessions_structure(name).options |
|
205 |
val session_sources = deps0.sources_shasum(name) |
|
206 |
if (Sessions.eq_sources(session_options, build.sources, session_sources)) None |
|
207 |
else Some(name) |
|
208 |
case _ => Some(name) |
|
209 |
} |
|
210 |
case None => Some(name) |
|
211 |
}) |
|
68204 | 212 |
|
78372 | 213 |
Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)), |
214 |
progress = progress, inlined_files = true).check_errors |
|
215 |
} |
|
216 |
else deps0 |
|
217 |
} |
|
66745 | 218 |
|
219 |
||
78372 | 220 |
/* check unknown files */ |
221 |
||
222 |
if (check_unknown_files) { |
|
223 |
val source_files = |
|
224 |
(for { |
|
225 |
(_, base) <- build_deps.session_bases.iterator |
|
226 |
(path, _) <- base.session_sources.iterator |
|
227 |
} yield path).toList |
|
228 |
Mercurial.check_files(source_files)._2 match { |
|
229 |
case Nil => |
|
230 |
case unknown_files => |
|
231 |
progress.echo_warning("Unknown files (not part of the underlying Mercurial repository):" + |
|
232 |
unknown_files.map(File.standard_path).sorted.mkString("\n ", "\n ", "")) |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
||
237 |
/* build process and results */ |
|
238 |
||
239 |
val build_context = |
|
78435
a623cb346b4a
more flexible Build.Engine.process_options: e.g. to manipulate "process_policy" for ML process;
wenzelm
parents:
78421
diff
changeset
|
240 |
Context(store, build_engine, build_deps, afp_root = afp_root, build_hosts = build_hosts, |
78401 | 241 |
hostname = hostname(build_options), build_heap = build_heap, |
242 |
numa_shuffling = numa_shuffling, max_jobs = max_jobs, fresh_build = fresh_build, |
|
243 |
no_build = no_build, session_setup = session_setup, master = true) |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
244 |
|
78372 | 245 |
if (clean_build) { |
246 |
for (name <- full_sessions.imports_descendants(full_sessions_selection)) { |
|
247 |
store.clean_output(database_server, name) match { |
|
248 |
case None => |
|
249 |
case Some(true) => progress.echo("Cleaned " + name) |
|
250 |
case Some(false) => progress.echo(name + " FAILED to clean") |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
||
78436
5f5f909206bb
clarified signature: more "object-oriented" style;
wenzelm
parents:
78435
diff
changeset
|
255 |
val results = build_engine.run_build_process(build_context, progress, server) |
78372 | 256 |
|
257 |
if (export_files) { |
|
258 |
for (name <- full_sessions_selection.iterator if results(name).ok) { |
|
259 |
val info = results.info(name) |
|
260 |
if (info.export_files.nonEmpty) { |
|
261 |
progress.echo("Exporting " + info.name + " ...") |
|
262 |
for ((dir, prune, pats) <- info.export_files) { |
|
263 |
Export.export_files(store, name, info.dir + dir, |
|
264 |
progress = if (progress.verbose) progress else new Progress, |
|
265 |
export_prune = prune, |
|
266 |
export_patterns = pats) |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
||
272 |
val presentation_sessions = |
|
273 |
results.sessions_ok.filter(name => browser_info.enabled(results.info(name))) |
|
274 |
if (presentation_sessions.nonEmpty && !progress.stopped) { |
|
275 |
Browser_Info.build(browser_info, results.store, results.deps, presentation_sessions, |
|
78379 | 276 |
progress = progress, server = server) |
78372 | 277 |
} |
278 |
||
78566
a04277e3b313
tuned message: failure may stem from build_cluster init;
wenzelm
parents:
78562
diff
changeset
|
279 |
if (results.unfinished.nonEmpty && (progress.verbose || !no_build)) { |
78372 | 280 |
progress.echo("Unfinished session(s): " + commas(results.unfinished)) |
281 |
} |
|
282 |
||
283 |
results |
|
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
284 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
285 |
} |
48341 | 286 |
} |
287 |
||
288 |
||
77555 | 289 |
/* build logic image */ |
290 |
||
291 |
def build_logic(options: Options, logic: String, |
|
292 |
progress: Progress = new Progress, |
|
293 |
build_heap: Boolean = false, |
|
294 |
dirs: List[Path] = Nil, |
|
295 |
fresh: Boolean = false, |
|
296 |
strict: Boolean = false |
|
297 |
): Int = { |
|
298 |
val selection = Sessions.Selection.session(logic) |
|
299 |
val rc = |
|
300 |
if (!fresh && build(options, selection = selection, |
|
301 |
build_heap = build_heap, no_build = true, dirs = dirs).ok) Process_Result.RC.ok |
|
302 |
else { |
|
303 |
progress.echo("Build started for Isabelle/" + logic + " ...") |
|
304 |
build(options, selection = selection, progress = progress, |
|
305 |
build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc |
|
306 |
} |
|
307 |
if (strict && rc != Process_Result.RC.ok) error("Failed to build Isabelle/" + logic) else rc |
|
308 |
} |
|
309 |
||
310 |
||
77553 | 311 |
/* command-line wrapper */ |
48341 | 312 |
|
77553 | 313 |
val isabelle_tool1 = Isabelle_Tool("build", "build and manage Isabelle sessions", |
75394 | 314 |
Scala_Project.here, |
315 |
{ args => |
|
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
316 |
var afp_root: Option[Path] = None |
78405 | 317 |
val base_sessions = new mutable.ListBuffer[String] |
318 |
val select_dirs = new mutable.ListBuffer[Path] |
|
78401 | 319 |
val build_hosts = new mutable.ListBuffer[Build_Cluster.Host] |
75394 | 320 |
var numa_shuffling = false |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
321 |
var browser_info = Browser_Info.Config.none |
75394 | 322 |
var requirements = false |
323 |
var soft_build = false |
|
78405 | 324 |
val exclude_session_groups = new mutable.ListBuffer[String] |
75394 | 325 |
var all_sessions = false |
326 |
var build_heap = false |
|
327 |
var clean_build = false |
|
78405 | 328 |
val dirs = new mutable.ListBuffer[Path] |
75394 | 329 |
var export_files = false |
330 |
var fresh_build = false |
|
78405 | 331 |
val session_groups = new mutable.ListBuffer[String] |
79616 | 332 |
var max_jobs: Option[Int] = None |
75394 | 333 |
var check_keywords: Set[String] = Set.empty |
334 |
var list_files = false |
|
335 |
var no_build = false |
|
77628 | 336 |
var options = Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS) |
75394 | 337 |
var verbose = false |
78405 | 338 |
val exclude_sessions = new mutable.ListBuffer[String] |
62590 | 339 |
|
75394 | 340 |
val getopts = Getopts(""" |
62590 | 341 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
342 |
||
343 |
Options are: |
|
78418
bc62be4144e6
added option -A for AFP root, following "isabelle sync";
wenzelm
parents:
78412
diff
changeset
|
344 |
-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
|
345 |
-B NAME include session NAME and all descendants |
62590 | 346 |
-D DIR include session directory and select its sessions |
79615 | 347 |
-H HOSTS additional cluster host specifications of the form |
348 |
NAMES:PARAMETERS (separated by commas) |
|
64265 | 349 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
72648 | 350 |
-P DIR enable HTML/PDF presentation in directory (":" for default) |
71807 | 351 |
-R refer to requirements of selected sessions |
66745 | 352 |
-S soft build: only observe changes of sources, not heap images |
62590 | 353 |
-X NAME exclude sessions from group NAME and all descendants |
354 |
-a select all sessions |
|
355 |
-b build heap images |
|
356 |
-c clean build |
|
357 |
-d DIR include session directory |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
358 |
-e export files from session specification into file-system |
66841 | 359 |
-f fresh build |
62590 | 360 |
-g NAME select session group NAME |
361 |
-j INT maximum number of parallel jobs (default 1) |
|
362 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
|
363 |
-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
|
364 |
-n no build -- take existing session build databases |
62590 | 365 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
366 |
-v verbose |
|
367 |
-x NAME exclude session NAME and all descendants |
|
368 |
||
77647 | 369 |
Build and manage Isabelle sessions: ML heaps, session databases, documents. |
62596 | 370 |
|
79615 | 371 |
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
|
372 |
""" + 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
|
373 |
""" |
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
374 |
|
77647 | 375 |
Notable system options: see "isabelle options -l -t build" |
376 |
||
377 |
Notable system settings: |
|
78408
092f1e435b3a
proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents:
78405
diff
changeset
|
378 |
""" + 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
|
379 |
"A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))), |
78405 | 380 |
"B:" -> (arg => base_sessions += arg), |
381 |
"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
|
382 |
"H:" -> (arg => build_hosts ++= Build_Cluster.Host.parse(Registry.global, arg)), |
75394 | 383 |
"N" -> (_ => numa_shuffling = true), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
384 |
"P:" -> (arg => browser_info = Browser_Info.Config.make(arg)), |
75394 | 385 |
"R" -> (_ => requirements = true), |
386 |
"S" -> (_ => soft_build = true), |
|
78405 | 387 |
"X:" -> (arg => exclude_session_groups += arg), |
75394 | 388 |
"a" -> (_ => all_sessions = true), |
389 |
"b" -> (_ => build_heap = true), |
|
390 |
"c" -> (_ => clean_build = true), |
|
78405 | 391 |
"d:" -> (arg => dirs += Path.explode(arg)), |
75394 | 392 |
"e" -> (_ => export_files = true), |
393 |
"f" -> (_ => fresh_build = true), |
|
78405 | 394 |
"g:" -> (arg => session_groups += arg), |
79616 | 395 |
"j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))), |
75394 | 396 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
397 |
"l" -> (_ => list_files = true), |
|
398 |
"n" -> (_ => no_build = true), |
|
399 |
"o:" -> (arg => options = options + arg), |
|
400 |
"v" -> (_ => verbose = true), |
|
78405 | 401 |
"x:" -> (arg => exclude_sessions += arg)) |
62590 | 402 |
|
75394 | 403 |
val sessions = getopts(args) |
62590 | 404 |
|
75394 | 405 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 406 |
|
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
407 |
progress.echo( |
78895 | 408 |
"Started at " + Build_Log.print_date(progress.start) + |
77719 | 409 |
" (" + Isabelle_System.ml_identifier() + " on " + hostname(options) +")", |
77521
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
410 |
verbose = true) |
5642de4d225d
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
77505
diff
changeset
|
411 |
progress.echo(Build_Log.Settings.show() + "\n", verbose = true) |
62590 | 412 |
|
75394 | 413 |
val results = |
414 |
progress.interrupt_handler { |
|
415 |
build(options, |
|
416 |
selection = Sessions.Selection( |
|
417 |
requirements = requirements, |
|
418 |
all_sessions = all_sessions, |
|
78405 | 419 |
base_sessions = base_sessions.toList, |
420 |
exclude_session_groups = exclude_session_groups.toList, |
|
421 |
exclude_sessions = exclude_sessions.toList, |
|
422 |
session_groups = session_groups.toList, |
|
75394 | 423 |
sessions = sessions), |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
424 |
browser_info = browser_info, |
75394 | 425 |
progress = progress, |
426 |
check_unknown_files = Mercurial.is_repository(Path.ISABELLE_HOME), |
|
427 |
build_heap = build_heap, |
|
428 |
clean_build = clean_build, |
|
78437 | 429 |
afp_root = afp_root, |
78405 | 430 |
dirs = dirs.toList, |
431 |
select_dirs = select_dirs.toList, |
|
77477 | 432 |
numa_shuffling = Host.numa_check(progress, numa_shuffling), |
75394 | 433 |
max_jobs = max_jobs, |
434 |
list_files = list_files, |
|
435 |
check_keywords = check_keywords, |
|
436 |
fresh_build = fresh_build, |
|
437 |
no_build = no_build, |
|
438 |
soft_build = soft_build, |
|
78401 | 439 |
export_files = export_files, |
440 |
build_hosts = build_hosts.toList) |
|
75394 | 441 |
} |
77545 | 442 |
val stop_date = Date.now() |
78895 | 443 |
val elapsed_time = stop_date.time - progress.start.time |
75394 | 444 |
|
77545 | 445 |
progress.echo("\nFinished at " + Build_Log.print_date(stop_date), verbose = true) |
62590 | 446 |
|
75394 | 447 |
val total_timing = |
448 |
results.sessions.iterator.map(a => results(a).timing).foldLeft(Timing.zero)(_ + _). |
|
449 |
copy(elapsed = elapsed_time) |
|
450 |
progress.echo(total_timing.message_resources) |
|
62590 | 451 |
|
75394 | 452 |
sys.exit(results.rc) |
453 |
}) |
|
68305 | 454 |
|
455 |
||
77553 | 456 |
|
78562 | 457 |
/** build cluster management **/ |
77557 | 458 |
|
78219 | 459 |
/* identified builds */ |
460 |
||
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
461 |
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
|
462 |
build_database match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
463 |
case None => Nil |
78634 | 464 |
case Some(db) => Build_Process.read_builds(db) |
78219 | 465 |
} |
466 |
||
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
467 |
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
|
468 |
{ |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
469 |
val print_database = |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
470 |
build_database match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
471 |
case None => "" |
78634 | 472 |
case Some(db) => " (database " + db + ")" |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
473 |
} |
78640 | 474 |
if (builds.isEmpty) "No build processes" + print_database |
78641 | 475 |
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
|
476 |
} |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
477 |
|
78410 | 478 |
def find_builds( |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
479 |
build_database: Option[SQL.Database], |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
480 |
build_id: String, |
78221 | 481 |
builds: List[Build_Process.Build] |
78410 | 482 |
): Build_Process.Build = { |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
483 |
(build_id, builds.length) match { |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
484 |
case (UUID(_), _) if builds.exists(_.build_uuid == build_id) => |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
485 |
builds.find(_.build_uuid == build_id).get |
78410 | 486 |
case ("", 1) => builds.head |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
487 |
case ("", 0) => error(print_builds(build_database, builds)) |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
488 |
case _ => |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
489 |
cat_error("Cannot identify build process " + quote(build_id), |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
490 |
print_builds(build_database, builds)) |
78219 | 491 |
} |
78410 | 492 |
} |
78219 | 493 |
|
494 |
||
78562 | 495 |
/* "isabelle build_process" */ |
496 |
||
497 |
def build_process( |
|
498 |
options: Options, |
|
499 |
list_builds: Boolean = false, |
|
78636 | 500 |
remove_builds: Boolean = false, |
501 |
force: Boolean = false, |
|
78562 | 502 |
progress: Progress = new Progress |
503 |
): Unit = { |
|
504 |
val build_engine = Engine(engine_name(options)) |
|
505 |
val store = build_engine.build_store(options) |
|
506 |
||
507 |
using(store.open_server()) { server => |
|
508 |
using_optional(store.maybe_open_build_database(server = server)) { build_database => |
|
78636 | 509 |
def print(builds: List[Build_Process.Build]): Unit = |
510 |
if (list_builds) progress.echo(print_builds(build_database, builds)) |
|
78562 | 511 |
|
78636 | 512 |
build_database match { |
513 |
case None => print(Nil) |
|
514 |
case Some(db) => |
|
515 |
Build_Process.private_data.transaction_lock(db, create = true, label = "build_process") { |
|
516 |
val builds = Build_Process.private_data.read_builds(db) |
|
517 |
val remove = |
|
518 |
if (!remove_builds) Nil |
|
519 |
else if (force) builds.map(_.build_uuid) |
|
520 |
else builds.flatMap(build => if (build.active) None else Some(build.build_uuid)) |
|
521 |
||
522 |
print(builds) |
|
523 |
if (remove.nonEmpty) { |
|
524 |
if (remove_builds) { |
|
525 |
progress.echo("Removing " + commas(remove) + " ...") |
|
526 |
Build_Process.private_data.remove_builds(db, remove) |
|
527 |
print(Build_Process.private_data.read_builds(db)) |
|
528 |
} |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
78562 | 532 |
} |
533 |
} |
|
534 |
} |
|
535 |
||
536 |
val isabelle_tool2 = Isabelle_Tool("build_process", "manage session build process", |
|
537 |
Scala_Project.here, |
|
538 |
{ args => |
|
78636 | 539 |
var force = false |
78562 | 540 |
var list_builds = false |
541 |
var options = |
|
542 |
Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS ::: |
|
78577
a945b541efff
clarified default options: SQLite build_database is unsupported for Isabelle2023, due to lack of proper transaction_lock;
wenzelm
parents:
78568
diff
changeset
|
543 |
List( |
a945b541efff
clarified default options: SQLite build_database is unsupported for Isabelle2023, due to lack of proper transaction_lock;
wenzelm
parents:
78568
diff
changeset
|
544 |
Options.Spec.make("build_database_server"), |
a945b541efff
clarified default options: SQLite build_database is unsupported for Isabelle2023, due to lack of proper transaction_lock;
wenzelm
parents:
78568
diff
changeset
|
545 |
Options.Spec.make("build_database"))) |
78636 | 546 |
var remove_builds = false |
78562 | 547 |
|
548 |
val getopts = Getopts(""" |
|
549 |
Usage: isabelle build_process [OPTIONS] |
|
550 |
||
551 |
Options are: |
|
78636 | 552 |
-f extra force for option -r |
78562 | 553 |
-l list build processes |
554 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
78636 | 555 |
-r remove data from build processes: inactive processes (default) |
556 |
or all processes (option -f) |
|
78562 | 557 |
""", |
78636 | 558 |
"f" -> (_ => force = true), |
78562 | 559 |
"l" -> (_ => list_builds = true), |
78636 | 560 |
"o:" -> (arg => options = options + arg), |
561 |
"r" -> (_ => remove_builds = true)) |
|
78562 | 562 |
|
563 |
val more_args = getopts(args) |
|
564 |
if (more_args.nonEmpty) getopts.usage() |
|
565 |
||
566 |
val progress = new Console_Progress() |
|
567 |
||
78636 | 568 |
build_process(options, list_builds = list_builds, remove_builds = remove_builds, |
569 |
force = force, progress = progress) |
|
78562 | 570 |
}) |
571 |
||
572 |
||
573 |
||
574 |
/* "isabelle build_worker" */ |
|
77557 | 575 |
|
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
576 |
def build_worker_command( |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
577 |
host: Build_Cluster.Host, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
578 |
ssh: SSH.System = SSH.Local, |
78558 | 579 |
build_options: List[Options.Spec] = Nil, |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
580 |
build_id: String = "", |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
581 |
isabelle_home: Path = Path.current, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
582 |
afp_root: Option[Path] = None, |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
583 |
dirs: List[Path] = Nil, |
78637 | 584 |
quiet: Boolean = false, |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
585 |
verbose: Boolean = false |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
586 |
): String = { |
78916 | 587 |
val options = build_options ::: Options.Spec.eq("build_hostname", host.name) :: host.options |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
588 |
ssh.bash_path(isabelle_home + Path.explode("bin/isabelle")) + " build_worker" + |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
589 |
if_proper(build_id, " -B " + Bash.string(build_id)) + |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
590 |
if_proper(afp_root, " -A " + ssh.bash_path(afp_root.get)) + |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
591 |
dirs.map(dir => " -d " + ssh.bash_path(dir)).mkString + |
78560 | 592 |
if_proper(host.numa, " -N") + " -j" + host.jobs + |
78915
90756ad4d8d7
more accurate treatment of surrounding whitespace;
wenzelm
parents:
78908
diff
changeset
|
593 |
Options.Spec.bash_strings(options, bg = true) + |
78637 | 594 |
if_proper(quiet, " -q") + |
78444
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
595 |
if_proper(verbose, " -v") |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
596 |
} |
3d1746a716fa
clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents:
78440
diff
changeset
|
597 |
|
77557 | 598 |
def build_worker( |
599 |
options: Options, |
|
78410 | 600 |
build_id: String = "", |
77557 | 601 |
progress: Progress = new Progress, |
78420 | 602 |
afp_root: Option[Path] = None, |
77557 | 603 |
dirs: List[Path] = Nil, |
604 |
numa_shuffling: Boolean = false, |
|
79616 | 605 |
max_jobs: Option[Int] = None |
78568 | 606 |
): Results = { |
78232 | 607 |
val build_engine = Engine(engine_name(options)) |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
608 |
val store = build_engine.build_store(options) |
77557 | 609 |
val build_options = store.options |
610 |
||
78372 | 611 |
using(store.open_server()) { server => |
612 |
using_optional(store.maybe_open_build_database(server = server)) { build_database => |
|
613 |
val builds = read_builds(build_database) |
|
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
614 |
|
78634 | 615 |
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
|
616 |
|
78562 | 617 |
val sessions_structure = |
618 |
Sessions.load_structure(build_options, dirs = AFP.make_dirs(afp_root) ::: dirs). |
|
619 |
selection(Sessions.Selection(sessions = build_master.sessions)) |
|
78219 | 620 |
|
78562 | 621 |
val build_deps = |
622 |
Sessions.deps(sessions_structure, progress = progress, inlined_files = true).check_errors |
|
78219 | 623 |
|
78562 | 624 |
val build_context = |
625 |
Context(store, build_engine, build_deps, afp_root = afp_root, |
|
626 |
hostname = hostname(build_options), numa_shuffling = numa_shuffling, |
|
627 |
max_jobs = max_jobs, build_uuid = build_master.build_uuid) |
|
78219 | 628 |
|
78568 | 629 |
build_engine.run_build_process(build_context, progress, server) |
78368
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
630 |
} |
6689b4c07bba
clarified signature: proper Scala function for command-line tool;
wenzelm
parents:
78280
diff
changeset
|
631 |
} |
77557 |