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