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