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