author | wenzelm |
Thu, 02 Mar 2023 14:58:59 +0100 | |
changeset 77477 | f376aebca9c1 |
parent 77453 | e72b1f5fd88d |
child 77505 | 7ee426daafa3 |
permissions | -rw-r--r-- |
50686 | 1 |
/* Title: Pure/Tools/build.scala |
48276 | 2 |
Author: Makarius |
57923 | 3 |
Options: :folding=explicit: |
48276 | 4 |
|
5 |
Build and manage Isabelle sessions. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
75393 | 11 |
object Build { |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
12 |
/* results */ |
48424 | 13 |
|
77311 | 14 |
object Results { |
15 |
def apply(context: Build_Process.Context, results: Map[String, Process_Result]): Results = |
|
77453 | 16 |
new Results(context.store, context.build_deps, results) |
77311 | 17 |
} |
18 |
||
19 |
class Results private( |
|
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
20 |
val store: Sessions.Store, |
76209 | 21 |
val deps: Sessions.Deps, |
77253
792dad9cb04f
clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents:
77252
diff
changeset
|
22 |
results: Map[String, Process_Result] |
76198
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
23 |
) { |
76206
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
24 |
def cache: Term.Cache = store.cache |
769a7cd5a16a
clarified signature: re-use store/cache from build results;
wenzelm
parents:
76202
diff
changeset
|
25 |
|
77311 | 26 |
def sessions_ok: List[String] = |
27 |
(for { |
|
28 |
name <- deps.sessions_structure.build_topological_order.iterator |
|
29 |
result <- results.get(name) if result.ok |
|
30 |
} yield name).toList |
|
31 |
||
77250
22016642d6af
clarified data structure: use static info from deps, not dynamic results;
wenzelm
parents:
77246
diff
changeset
|
32 |
def info(name: String): Sessions.Info = deps.sessions_structure(name) |
62403 | 33 |
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
|
34 |
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
|
35 |
def apply(name: String): Process_Result = results(name).strict |
792dad9cb04f
clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents:
77252
diff
changeset
|
36 |
val rc: Int = results.valuesIterator.map(_.strict.rc).foldLeft(Process_Result.RC.ok)(_ max _) |
74306 | 37 |
def ok: Boolean = rc == Process_Result.RC.ok |
62406 | 38 |
|
76202 | 39 |
def unfinished: List[String] = sessions.iterator.filterNot(apply(_).ok).toList.sorted |
76199 | 40 |
|
62406 | 41 |
override def toString: String = rc.toString |
62403 | 42 |
} |
43 |
||
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
44 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
45 |
/* engine */ |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
46 |
|
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
47 |
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
|
48 |
override def toString: String = name |
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
49 |
def init(build_context: Build_Process.Context): Build_Process = |
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
50 |
new Build_Process(build_context) |
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
51 |
} |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
52 |
|
77411
149cc77f7348
clafified signature: simplify object-oriented reuse;
wenzelm
parents:
77384
diff
changeset
|
53 |
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
|
54 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
55 |
lazy val engines: List[Engine] = |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
56 |
Isabelle_System.make_services(classOf[Engine]) |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
57 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
58 |
def get_engine(name: String): Engine = |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
59 |
engines.find(_.name == name).getOrElse(error("Bad build engine " + quote(name))) |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
60 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
61 |
|
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
62 |
/* build */ |
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
63 |
|
62641 | 64 |
def build( |
50404
898cac1dad5e
avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents:
50367
diff
changeset
|
65 |
options: Options, |
71981 | 66 |
selection: Sessions.Selection = Sessions.Selection.empty, |
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
67 |
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
|
68 |
progress: Progress = new Progress, |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
69 |
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
|
70 |
build_heap: Boolean = false, |
48595 | 71 |
clean_build: Boolean = false, |
56890 | 72 |
dirs: List[Path] = Nil, |
73 |
select_dirs: List[Path] = Nil, |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66962
diff
changeset
|
74 |
infos: List[Sessions.Info] = Nil, |
64265 | 75 |
numa_shuffling: Boolean = false, |
48509 | 76 |
max_jobs: Int = 1, |
48903 | 77 |
list_files: Boolean = false, |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
59811
diff
changeset
|
78 |
check_keywords: Set[String] = Set.empty, |
66841 | 79 |
fresh_build: Boolean = false, |
48509 | 80 |
no_build: Boolean = false, |
66745 | 81 |
soft_build: Boolean = false, |
48509 | 82 |
verbose: Boolean = false, |
73805
b73777a0c076
allow build session setup, e.g. for protocol handlers;
wenzelm
parents:
73804
diff
changeset
|
83 |
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
|
84 |
augment_options: String => List[Options.Spec] = _ => Nil, |
75393 | 85 |
session_setup: (String, Session) => Unit = (_, _) => () |
86 |
): Results = { |
|
71677 | 87 |
val build_options = |
71679
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
88 |
options + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
89 |
"completion_limit=0" + |
eeaa4021f080
proper "editor_tracing_messages=0" as in "isabelle dump";
wenzelm
parents:
71677
diff
changeset
|
90 |
"editor_tracing_messages=0" + |
72728
caa182bdab7a
clarified options: batch-build has pide_reports disabled by default (requires significant resources);
wenzelm
parents:
72693
diff
changeset
|
91 |
("pide_reports=" + options.bool("build_pide_reports")) |
51220 | 92 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69811
diff
changeset
|
93 |
val store = Sessions.store(build_options) |
66745 | 94 |
|
69369
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
95 |
Isabelle_Fonts.init() |
6ecc85955e04
prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents:
68957
diff
changeset
|
96 |
|
66745 | 97 |
|
98 |
/* session selection and dependencies */ |
|
65422 | 99 |
|
66961 | 100 |
val full_sessions = |
76927
da13da82f6f9
treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents:
76919
diff
changeset
|
101 |
Sessions.load_structure(build_options, dirs = dirs, select_dirs = select_dirs, infos = infos, |
da13da82f6f9
treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents:
76919
diff
changeset
|
102 |
augment_options = augment_options) |
73012
238ddf525da4
clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents:
72993
diff
changeset
|
103 |
val full_sessions_selection = full_sessions.imports_selection(selection) |
238ddf525da4
clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents:
72993
diff
changeset
|
104 |
|
75948 | 105 |
val build_deps = { |
66745 | 106 |
val deps0 = |
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
107 |
Sessions.deps(full_sessions.selection(selection), |
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
108 |
progress = progress, inlined_files = true, verbose = verbose, |
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
109 |
list_files = list_files, check_keywords = check_keywords).check_errors |
66745 | 110 |
|
66841 | 111 |
if (soft_build && !fresh_build) { |
66745 | 112 |
val outdated = |
68204 | 113 |
deps0.sessions_structure.build_topological_order.flatMap(name => |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72624
diff
changeset
|
114 |
store.try_open_database(name) match { |
68214 | 115 |
case Some(db) => |
68216 | 116 |
using(db)(store.read_build(_, name)) match { |
66745 | 117 |
case Some(build) |
77204 | 118 |
if build.ok && build.sources == deps0.sources_shasum(name) => None |
66745 | 119 |
case _ => Some(name) |
120 |
} |
|
121 |
case None => Some(name) |
|
122 |
}) |
|
68204 | 123 |
|
124 |
Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)), |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70509
diff
changeset
|
125 |
progress = progress, inlined_files = true).check_errors |
66745 | 126 |
} |
68204 | 127 |
else deps0 |
66745 | 128 |
} |
129 |
||
130 |
||
131 |
/* check unknown files */ |
|
48504
21dfd6c04482
actually check source vs. target stamps, based on information from log files;
wenzelm
parents:
48494
diff
changeset
|
132 |
|
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
133 |
if (check_unknown_files) { |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
134 |
val source_files = |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
135 |
(for { |
75948 | 136 |
(_, base) <- build_deps.session_bases.iterator |
75741 | 137 |
(path, _) <- base.session_sources.iterator |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
138 |
} yield path).toList |
76670
b04d45bebbc5
discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents:
76669
diff
changeset
|
139 |
Mercurial.check_files(source_files)._2 match { |
b04d45bebbc5
discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents:
76669
diff
changeset
|
140 |
case Nil => |
b04d45bebbc5
discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents:
76669
diff
changeset
|
141 |
case unknown_files => |
b04d45bebbc5
discontinued somewhat pointless dependency: avoid illusion of extra accuracy (see also 09fb749d1a1e and 0f750a6dc754);
wenzelm
parents:
76669
diff
changeset
|
142 |
progress.echo_warning("Unknown files (not part of the underlying Mercurial repository):" + |
76883 | 143 |
unknown_files.map(File.standard_path).sorted.mkString("\n ", "\n ", "")) |
65832
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
144 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
145 |
} |
2fb85623c386
implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents:
65831
diff
changeset
|
146 |
|
51220 | 147 |
|
77257 | 148 |
/* build process and results */ |
51220 | 149 |
|
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77311
diff
changeset
|
150 |
val build_context = |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77311
diff
changeset
|
151 |
Build_Process.Context(store, build_deps, progress = progress, |
77384
ef6673859c38
option build_hostname allows to change hostname easily;
wenzelm
parents:
77372
diff
changeset
|
152 |
hostname = Isabelle_System.hostname(build_options.string("build_hostname")), |
77315
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77311
diff
changeset
|
153 |
build_heap = build_heap, numa_shuffling = numa_shuffling, max_jobs = max_jobs, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77311
diff
changeset
|
154 |
fresh_build = fresh_build, no_build = no_build, verbose = verbose, |
f34559b24277
clarified signature: move all parameters into Build_Process.Context;
wenzelm
parents:
77311
diff
changeset
|
155 |
session_setup = session_setup) |
77254
8d34f53871b4
clarified signature: make dynamic Queue from static Context;
wenzelm
parents:
77253
diff
changeset
|
156 |
|
68219 | 157 |
store.prepare_output_dir() |
48373 | 158 |
|
48595 | 159 |
if (clean_build) { |
73012
238ddf525da4
clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents:
72993
diff
changeset
|
160 |
for (name <- full_sessions.imports_descendants(full_sessions_selection)) { |
68220
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
161 |
val (relevant, ok) = store.clean_output(name) |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
162 |
if (relevant) { |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
163 |
if (ok) progress.echo("Cleaned " + name) |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
164 |
else progress.echo(name + " FAILED to clean") |
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
165 |
} |
48595 | 166 |
} |
167 |
} |
|
168 |
||
77311 | 169 |
val results = |
170 |
Isabelle_Thread.uninterruptible { |
|
77330
47eb96592aa2
support alternative build engines, via system option "build_engine";
wenzelm
parents:
77326
diff
changeset
|
171 |
val engine = get_engine(build_options.string("build_engine")) |
77372 | 172 |
using(engine.init(build_context)) { build_process => |
173 |
val res = build_process.run() |
|
174 |
Results(build_context, res) |
|
175 |
} |
|
77311 | 176 |
} |
62641 | 177 |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
178 |
if (export_files) { |
76196 | 179 |
for (name <- full_sessions_selection.iterator if results(name).ok) { |
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
180 |
val info = results.info(name) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
181 |
if (info.export_files.nonEmpty) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
182 |
progress.echo("Exporting " + info.name + " ...") |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
183 |
for ((dir, prune, pats) <- info.export_files) { |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
184 |
Export.export_files(store, name, info.dir + dir, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
185 |
progress = if (verbose) progress else new Progress, |
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
186 |
export_prune = prune, |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
187 |
export_patterns = pats) |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
188 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
189 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
190 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
191 |
} |
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
192 |
|
76901 | 193 |
val presentation_sessions = |
194 |
results.sessions_ok.filter(name => browser_info.enabled(results.info(name))) |
|
76230 | 195 |
if (presentation_sessions.nonEmpty && !progress.stopped) { |
196 |
Browser_Info.build(browser_info, results.store, results.deps, presentation_sessions, |
|
76198
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
197 |
progress = progress, verbose = verbose) |
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
198 |
} |
fb4215da4919
clarified presentation_sessions: work with partial results;
wenzelm
parents:
76197
diff
changeset
|
199 |
|
76196 | 200 |
if (!results.ok && (verbose || !no_build)) { |
76199 | 201 |
progress.echo("Unfinished session(s): " + commas(results.unfinished)) |
62641 | 202 |
} |
203 |
||
204 |
results |
|
48341 | 205 |
} |
206 |
||
207 |
||
62833 | 208 |
/* Isabelle tool wrapper */ |
48341 | 209 |
|
72763 | 210 |
val isabelle_tool = Isabelle_Tool("build", "build and manage Isabelle sessions", |
75394 | 211 |
Scala_Project.here, |
212 |
{ args => |
|
213 |
val build_options = Word.explode(Isabelle_System.getenv("ISABELLE_BUILD_OPTIONS")) |
|
62590 | 214 |
|
75394 | 215 |
var base_sessions: List[String] = Nil |
216 |
var select_dirs: List[Path] = Nil |
|
217 |
var numa_shuffling = false |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
218 |
var browser_info = Browser_Info.Config.none |
75394 | 219 |
var requirements = false |
220 |
var soft_build = false |
|
221 |
var exclude_session_groups: List[String] = Nil |
|
222 |
var all_sessions = false |
|
223 |
var build_heap = false |
|
224 |
var clean_build = false |
|
225 |
var dirs: List[Path] = Nil |
|
226 |
var export_files = false |
|
227 |
var fresh_build = false |
|
228 |
var session_groups: List[String] = Nil |
|
229 |
var max_jobs = 1 |
|
230 |
var check_keywords: Set[String] = Set.empty |
|
231 |
var list_files = false |
|
232 |
var no_build = false |
|
233 |
var options = Options.init(opts = build_options) |
|
234 |
var verbose = false |
|
235 |
var exclude_sessions: List[String] = Nil |
|
62590 | 236 |
|
75394 | 237 |
val getopts = Getopts(""" |
62590 | 238 |
Usage: isabelle build [OPTIONS] [SESSIONS ...] |
239 |
||
240 |
Options are: |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
241 |
-B NAME include session NAME and all descendants |
62590 | 242 |
-D DIR include session directory and select its sessions |
64265 | 243 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
72648 | 244 |
-P DIR enable HTML/PDF presentation in directory (":" for default) |
71807 | 245 |
-R refer to requirements of selected sessions |
66745 | 246 |
-S soft build: only observe changes of sources, not heap images |
62590 | 247 |
-X NAME exclude sessions from group NAME and all descendants |
248 |
-a select all sessions |
|
249 |
-b build heap images |
|
250 |
-c clean build |
|
251 |
-d DIR include session directory |
|
69811
18f61ce86425
clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents:
69777
diff
changeset
|
252 |
-e export files from session specification into file-system |
66841 | 253 |
-f fresh build |
62590 | 254 |
-g NAME select session group NAME |
255 |
-j INT maximum number of parallel jobs (default 1) |
|
256 |
-k KEYWORD check theory sources for conflicts with proposed keywords |
|
257 |
-l list session source files |
|
76919 | 258 |
-n no build -- take existing build databases |
62590 | 259 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
260 |
-v verbose |
|
261 |
-x NAME exclude session NAME and all descendants |
|
262 |
||
62596 | 263 |
Build and manage Isabelle sessions, depending on implicit settings: |
264 |
||
73736 | 265 |
""" + Library.indent_lines(2, Build_Log.Settings.show()) + "\n", |
75394 | 266 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
267 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
|
268 |
"N" -> (_ => numa_shuffling = true), |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
269 |
"P:" -> (arg => browser_info = Browser_Info.Config.make(arg)), |
75394 | 270 |
"R" -> (_ => requirements = true), |
271 |
"S" -> (_ => soft_build = true), |
|
272 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
|
273 |
"a" -> (_ => all_sessions = true), |
|
274 |
"b" -> (_ => build_heap = true), |
|
275 |
"c" -> (_ => clean_build = true), |
|
276 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
277 |
"e" -> (_ => export_files = true), |
|
278 |
"f" -> (_ => fresh_build = true), |
|
279 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
|
280 |
"j:" -> (arg => max_jobs = Value.Int.parse(arg)), |
|
281 |
"k:" -> (arg => check_keywords = check_keywords + arg), |
|
282 |
"l" -> (_ => list_files = true), |
|
283 |
"n" -> (_ => no_build = true), |
|
284 |
"o:" -> (arg => options = options + arg), |
|
285 |
"v" -> (_ => verbose = true), |
|
286 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
62590 | 287 |
|
75394 | 288 |
val sessions = getopts(args) |
62590 | 289 |
|
75394 | 290 |
val progress = new Console_Progress(verbose = verbose) |
62590 | 291 |
|
75394 | 292 |
val start_date = Date.now() |
64140 | 293 |
|
75394 | 294 |
if (verbose) { |
77384
ef6673859c38
option build_hostname allows to change hostname easily;
wenzelm
parents:
77372
diff
changeset
|
295 |
val hostname = Isabelle_System.hostname(options.string("build_hostname")) |
75394 | 296 |
progress.echo( |
297 |
"Started at " + Build_Log.print_date(start_date) + |
|
77384
ef6673859c38
option build_hostname allows to change hostname easily;
wenzelm
parents:
77372
diff
changeset
|
298 |
" (" + Isabelle_System.getenv("ML_IDENTIFIER") + " on " + hostname +")") |
75394 | 299 |
progress.echo(Build_Log.Settings.show() + "\n") |
300 |
} |
|
62590 | 301 |
|
75394 | 302 |
val results = |
303 |
progress.interrupt_handler { |
|
304 |
build(options, |
|
305 |
selection = Sessions.Selection( |
|
306 |
requirements = requirements, |
|
307 |
all_sessions = all_sessions, |
|
308 |
base_sessions = base_sessions, |
|
309 |
exclude_session_groups = exclude_session_groups, |
|
310 |
exclude_sessions = exclude_sessions, |
|
311 |
session_groups = session_groups, |
|
312 |
sessions = sessions), |
|
75942
603852abed8f
clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents:
75941
diff
changeset
|
313 |
browser_info = browser_info, |
75394 | 314 |
progress = progress, |
315 |
check_unknown_files = Mercurial.is_repository(Path.ISABELLE_HOME), |
|
316 |
build_heap = build_heap, |
|
317 |
clean_build = clean_build, |
|
318 |
dirs = dirs, |
|
319 |
select_dirs = select_dirs, |
|
77477 | 320 |
numa_shuffling = Host.numa_check(progress, numa_shuffling), |
75394 | 321 |
max_jobs = max_jobs, |
322 |
list_files = list_files, |
|
323 |
check_keywords = check_keywords, |
|
324 |
fresh_build = fresh_build, |
|
325 |
no_build = no_build, |
|
326 |
soft_build = soft_build, |
|
327 |
verbose = verbose, |
|
328 |
export_files = export_files) |
|
329 |
} |
|
330 |
val end_date = Date.now() |
|
331 |
val elapsed_time = end_date.time - start_date.time |
|
332 |
||
333 |
if (verbose) { |
|
334 |
progress.echo("\nFinished at " + Build_Log.print_date(end_date)) |
|
62833 | 335 |
} |
62590 | 336 |
|
75394 | 337 |
val total_timing = |
338 |
results.sessions.iterator.map(a => results(a).timing).foldLeft(Timing.zero)(_ + _). |
|
339 |
copy(elapsed = elapsed_time) |
|
340 |
progress.echo(total_timing.message_resources) |
|
62590 | 341 |
|
75394 | 342 |
sys.exit(results.rc) |
343 |
}) |
|
68305 | 344 |
|
345 |
||
346 |
/* build logic image */ |
|
347 |
||
348 |
def build_logic(options: Options, logic: String, |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71718
diff
changeset
|
349 |
progress: Progress = new Progress, |
68305 | 350 |
build_heap: Boolean = false, |
351 |
dirs: List[Path] = Nil, |
|
70791 | 352 |
fresh: Boolean = false, |
75393 | 353 |
strict: Boolean = false |
354 |
): Int = { |
|
71896
ce06d6456cc8
clarified signature --- fit within limit of 22 arguments;
wenzelm
parents:
71895
diff
changeset
|
355 |
val selection = Sessions.Selection.session(logic) |
69540 | 356 |
val rc = |
71981 | 357 |
if (!fresh && build(options, selection = selection, |
74306 | 358 |
build_heap = build_heap, no_build = true, dirs = dirs).ok) Process_Result.RC.ok |
69540 | 359 |
else { |
360 |
progress.echo("Build started for Isabelle/" + logic + " ...") |
|
71981 | 361 |
Build.build(options, selection = selection, progress = progress, |
362 |
build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc |
|
69540 | 363 |
} |
74306 | 364 |
if (strict && rc != Process_Result.RC.ok) error("Failed to build Isabelle/" + logic) else rc |
68305 | 365 |
} |
48276 | 366 |
} |