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