author | wenzelm |
Fri, 16 Mar 2018 15:43:56 +0100 | |
changeset 67878 | 15027fb50a0c |
parent 67026 | 687c822ee5e3 |
child 68204 | a554da2811f2 |
permissions | -rw-r--r-- |
65557 | 1 |
/* Title: Pure/Tools/imports.scala |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
3 |
|
65557 | 4 |
Maintain theory imports wrt. session structure. |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
5 |
*/ |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
6 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
8 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
9 |
|
65526 | 10 |
import java.io.{File => JFile} |
11 |
||
12 |
||
65557 | 13 |
object Imports |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
14 |
{ |
65824 | 15 |
/* repository files */ |
65561 | 16 |
|
65830 | 17 |
def repository_files(progress: Progress, start: Path, pred: JFile => Boolean = _ => true) |
18 |
: List[JFile] = |
|
65561 | 19 |
Mercurial.find_repository(start) match { |
20 |
case None => |
|
65830 | 21 |
progress.echo_warning("Ignoring directory " + start + " (no Mercurial repository)") |
65561 | 22 |
Nil |
23 |
case Some(hg) => |
|
65833 | 24 |
val start_path = start.canonical_file.toPath |
65561 | 25 |
for { |
65824 | 26 |
name <- hg.known_files() |
65561 | 27 |
file = (hg.root + Path.explode(name)).file |
66234 | 28 |
if pred(file) && File.canonical(file).toPath.startsWith(start_path) |
65561 | 29 |
} yield file |
30 |
} |
|
31 |
||
32 |
||
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
33 |
/* report imports */ |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
34 |
|
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
35 |
sealed case class Report( |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
36 |
info: Sessions.Info, |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
37 |
declared_imports: Set[String], |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
38 |
potential_imports: Option[List[String]], |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
39 |
actual_imports: Option[List[String]]) |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
40 |
{ |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
41 |
def print(keywords: Keyword.Keywords, result: List[String]): String = |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
42 |
{ |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
43 |
def print_name(name: String): String = Token.quote_name(keywords, name) |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
44 |
|
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
45 |
" session " + print_name(info.name) + ": " + result.map(print_name(_)).mkString(" ") |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
46 |
} |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
47 |
} |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
48 |
|
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
49 |
|
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
50 |
/* update imports */ |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
51 |
|
65526 | 52 |
sealed case class Update(range: Text.Range, old_text: String, new_text: String) |
53 |
{ |
|
54 |
def edits: List[Text.Edit] = |
|
55 |
Text.Edit.replace(range.start, old_text, new_text) |
|
56 |
||
57 |
override def toString: String = |
|
58 |
range.toString + ": " + old_text + " -> " + new_text |
|
59 |
} |
|
60 |
||
61 |
def update_name(keywords: Keyword.Keywords, pos: Position.T, update: String => String) |
|
62 |
: Option[(JFile, Update)] = |
|
63 |
{ |
|
64 |
val file = |
|
65 |
pos match { |
|
65833 | 66 |
case Position.File(file) => Path.explode(file).canonical_file |
65526 | 67 |
case _ => error("Missing file in position" + Position.here(pos)) |
68 |
} |
|
69 |
||
70 |
val text = File.read(file) |
|
71 |
||
72 |
val range = |
|
73 |
pos match { |
|
74 |
case Position.Range(symbol_range) => Symbol.Text_Chunk(text).decode(symbol_range) |
|
75 |
case _ => error("Missing range in position" + Position.here(pos)) |
|
76 |
} |
|
77 |
||
78 |
Token.read_name(keywords, range.substring(text)) match { |
|
79 |
case Some(tok) => |
|
80 |
val s1 = tok.source |
|
81 |
val s2 = Token.quote_name(keywords, update(tok.content)) |
|
82 |
if (s1 == s2) None else Some((file, Update(range, s1, s2))) |
|
83 |
case None => error("Name token expected" + Position.here(pos)) |
|
84 |
} |
|
85 |
} |
|
86 |
||
65561 | 87 |
|
88 |
/* collective operations */ |
|
89 |
||
65558 | 90 |
def imports( |
91 |
options: Options, |
|
65566 | 92 |
operation_imports: Boolean = false, |
65824 | 93 |
operation_repository_files: Boolean = false, |
65558 | 94 |
operation_update: Boolean = false, |
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
95 |
update_message: String = "", |
65558 | 96 |
progress: Progress = No_Progress, |
97 |
selection: Sessions.Selection = Sessions.Selection.empty, |
|
98 |
dirs: List[Path] = Nil, |
|
99 |
select_dirs: List[Path] = Nil, |
|
100 |
verbose: Boolean = false) = |
|
101 |
{ |
|
67026 | 102 |
val full_sessions = Sessions.load_structure(options, dirs = dirs, select_dirs = select_dirs) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
103 |
val selected_sessions = full_sessions.selection(selection) |
65558 | 104 |
|
105 |
val deps = |
|
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
106 |
Sessions.deps(selected_sessions, full_sessions.global_theories, |
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66961
diff
changeset
|
107 |
progress = progress, verbose = verbose).check_errors |
65561 | 108 |
|
65566 | 109 |
val root_keywords = Sessions.root_syntax.keywords |
110 |
||
111 |
if (operation_imports) { |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
112 |
val report_imports: List[Report] = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
113 |
selected_sessions.build_topological_order.map((session_name: String) => |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
114 |
{ |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
115 |
val info = selected_sessions(session_name) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
116 |
val session_base = deps(session_name) |
65566 | 117 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
118 |
val declared_imports = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
119 |
selected_sessions.imports_requirements(List(session_name)).toSet |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
120 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
121 |
val extra_imports = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
122 |
(for { |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
123 |
(_, a) <- session_base.known.theories.iterator |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
124 |
if session_base.theory_qualifier(a) == info.name |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
125 |
b <- deps.all_known.get_file(a.path.file) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
126 |
qualifier = session_base.theory_qualifier(b) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
127 |
if !declared_imports.contains(qualifier) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
128 |
} yield qualifier).toSet |
65566 | 129 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
130 |
val loaded_imports = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
131 |
selected_sessions.imports_requirements( |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
132 |
session_base.loaded_theories.keys.map(a => |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
133 |
session_base.theory_qualifier(session_base.known.theories(a)))) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
134 |
.toSet - session_name |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
135 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
136 |
val minimal_imports = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
137 |
loaded_imports.filter(s1 => |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
138 |
!loaded_imports.exists(s2 => selected_sessions.imports_graph.is_edge(s1, s2))) |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
139 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
140 |
def make_result(set: Set[String]): Option[List[String]] = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
141 |
if (set.isEmpty) None |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
142 |
else Some(selected_sessions.imports_topological_order.filter(set)) |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
143 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
144 |
Report(info, declared_imports, make_result(extra_imports), |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
145 |
if (loaded_imports == declared_imports - session_name) None |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
146 |
else make_result(minimal_imports)) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
147 |
}) |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
148 |
|
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
149 |
progress.echo("\nPotential session imports:") |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
150 |
for { |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
151 |
report <- report_imports.sortBy(_.declared_imports.size) |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
152 |
potential_imports <- report.potential_imports |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
153 |
} progress.echo(report.print(root_keywords, potential_imports)) |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
154 |
|
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
155 |
progress.echo("\nActual session imports:") |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
156 |
for { |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
157 |
report <- report_imports |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
158 |
actual_imports <- report.actual_imports |
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
159 |
} progress.echo(report.print(root_keywords, actual_imports)) |
65566 | 160 |
} |
161 |
||
65824 | 162 |
if (operation_repository_files) { |
66671 | 163 |
progress.echo("\nMercurial repository check:") |
65561 | 164 |
val unused_files = |
165 |
for { |
|
166 |
(_, dir) <- Sessions.directories(dirs, select_dirs) |
|
65830 | 167 |
file <- repository_files(progress, dir, file => file.getName.endsWith(".thy")) |
65561 | 168 |
if deps.all_known.get_file(file).isEmpty |
169 |
} yield file |
|
170 |
unused_files.foreach(file => progress.echo("unused file " + quote(file.toString))) |
|
171 |
} |
|
65558 | 172 |
|
173 |
if (operation_update) { |
|
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
174 |
progress.echo("\nUpdate theory imports" + update_message + ":") |
65558 | 175 |
val updates = |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
176 |
selected_sessions.build_topological_order.flatMap(session_name => |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
177 |
{ |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
178 |
val info = selected_sessions(session_name) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
179 |
val session_base = deps(session_name) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
180 |
val session_resources = new Resources(session_base) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
181 |
val imports_base = session_base.get_imports |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
182 |
val imports_resources = new Resources(imports_base) |
65558 | 183 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
184 |
def standard_import(qualifier: String, dir: String, s: String): String = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
185 |
imports_resources.standard_import(session_base, qualifier, dir, s) |
65558 | 186 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
187 |
val updates_root = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
188 |
for { |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
189 |
(_, pos) <- info.theories.flatMap(_._2) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
190 |
upd <- update_name(root_keywords, pos, standard_import(info.name, info.dir.implode, _)) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
191 |
} yield upd |
65558 | 192 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
193 |
val updates_theories = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
194 |
for { |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
195 |
(_, name) <- session_base.known.theories_local.toList |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
196 |
if session_base.theory_qualifier(name) == info.name |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
197 |
(_, pos) <- session_resources.check_thy(name, Token.Pos.file(name.node)).imports |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
198 |
upd <- update_name(session_base.overall_syntax.keywords, pos, |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
199 |
standard_import(session_base.theory_qualifier(name), name.master_dir, _)) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
200 |
} yield upd |
65558 | 201 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
202 |
updates_root ::: updates_theories |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
203 |
}) |
65564 | 204 |
|
205 |
val file_updates = (Multi_Map.empty[JFile, Update] /: updates)(_ + _) |
|
206 |
val conflicts = |
|
207 |
file_updates.iterator_list.flatMap({ case (file, upds) => |
|
208 |
Library.duplicates(upds.sortBy(_.range.start), |
|
209 |
(x: Update, y: Update) => x.range overlaps y.range) match |
|
210 |
{ |
|
211 |
case Nil => None |
|
212 |
case bad => Some((file, bad)) |
|
213 |
} |
|
214 |
}) |
|
215 |
if (conflicts.nonEmpty) |
|
216 |
error(cat_lines( |
|
217 |
conflicts.map({ case (file, bad) => |
|
218 |
"Conflicting updates for file " + file + bad.mkString("\n ", "\n ", "") }))) |
|
219 |
||
65566 | 220 |
for ((file, upds) <- file_updates.iterator_list.toList.sortBy(p => p._1.toString)) { |
65564 | 221 |
progress.echo("file " + quote(file.toString)) |
222 |
val edits = |
|
223 |
upds.sortBy(upd => - upd.range.start).flatMap(upd => |
|
224 |
Text.Edit.replace(upd.range.start, upd.old_text, upd.new_text)) |
|
225 |
val new_text = |
|
226 |
(File.read(file) /: edits)({ case (text, edit) => |
|
227 |
edit.edit(text, 0) match { |
|
228 |
case (None, text1) => text1 |
|
229 |
case (Some(_), _) => error("Failed to apply edit " + edit + " to file " + file) |
|
230 |
} |
|
231 |
}) |
|
232 |
File.write_backup2(Path.explode(File.standard_path(file)), new_text) |
|
233 |
} |
|
65558 | 234 |
} |
235 |
} |
|
236 |
||
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
237 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
238 |
/* Isabelle tool wrapper */ |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
239 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
240 |
val isabelle_tool = |
65557 | 241 |
Isabelle_Tool("imports", "maintain theory imports wrt. session structure", args => |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
242 |
{ |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66720
diff
changeset
|
243 |
var base_sessions: List[String] = Nil |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
244 |
var select_dirs: List[Path] = Nil |
65566 | 245 |
var operation_imports = false |
65824 | 246 |
var operation_repository_files = false |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
247 |
var requirements = false |
65558 | 248 |
var operation_update = false |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
249 |
var exclude_session_groups: List[String] = Nil |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
250 |
var all_sessions = false |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
251 |
var dirs: List[Path] = Nil |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
252 |
var session_groups: List[String] = Nil |
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
253 |
var incremental_update = false |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
254 |
var options = Options.init() |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
255 |
var verbose = false |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
256 |
var exclude_sessions: List[String] = Nil |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
257 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
258 |
val getopts = Getopts(""" |
65557 | 259 |
Usage: isabelle imports [OPTIONS] [SESSIONS ...] |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
260 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
261 |
Options are: |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66720
diff
changeset
|
262 |
-B NAME include session NAME and all descendants |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
263 |
-D DIR include session directory and select its sessions |
66851
c75769065548
more informative Imports.Report with actual session imports (minimized);
wenzelm
parents:
66848
diff
changeset
|
264 |
-I operation: report session imports |
66671 | 265 |
-M operation: Mercurial repository check for theory files |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
266 |
-R operate on requirements of selected sessions |
65558 | 267 |
-U operation: update theory imports to use session qualifiers |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
268 |
-X NAME exclude sessions from group NAME and all descendants |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
269 |
-a select all sessions |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
270 |
-d DIR include session directory |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
271 |
-g NAME select session group NAME |
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
272 |
-i incremental update according to session graph structure |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
273 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
274 |
-v verbose |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
275 |
-x NAME exclude session NAME and all descendants |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
276 |
|
65558 | 277 |
Maintain theory imports wrt. session structure. At least one operation |
65566 | 278 |
needs to be specified (see options -I -M -U). |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
279 |
""", |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66720
diff
changeset
|
280 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
281 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
65566 | 282 |
"I" -> (_ => operation_imports = true), |
65824 | 283 |
"M" -> (_ => operation_repository_files = true), |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
284 |
"R" -> (_ => requirements = true), |
65558 | 285 |
"U" -> (_ => operation_update = true), |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
286 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
287 |
"a" -> (_ => all_sessions = true), |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
288 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
289 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
290 |
"i" -> (_ => incremental_update = true), |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
291 |
"o:" -> (arg => options = options + arg), |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
292 |
"v" -> (_ => verbose = true), |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
293 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
294 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
295 |
val sessions = getopts(args) |
65824 | 296 |
if (args.isEmpty || !(operation_imports || operation_repository_files || operation_update)) |
65561 | 297 |
getopts.usage() |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
298 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
299 |
val selection = |
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66720
diff
changeset
|
300 |
Sessions.Selection(requirements, all_sessions, base_sessions, exclude_session_groups, |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
301 |
exclude_sessions, session_groups, sessions) |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
302 |
|
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
303 |
val progress = new Console_Progress(verbose = verbose) |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
304 |
|
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
305 |
if (operation_imports || operation_repository_files || |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
306 |
operation_update && !incremental_update) |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
307 |
{ |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
308 |
imports(options, operation_imports = operation_imports, |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
309 |
operation_repository_files = operation_repository_files, |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
310 |
operation_update = operation_update, |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
311 |
progress = progress, selection = selection, dirs = dirs, select_dirs = select_dirs, |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
312 |
verbose = verbose) |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
313 |
} |
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
314 |
else if (operation_update && incremental_update) { |
67026 | 315 |
Sessions.load_structure(options, dirs = dirs, select_dirs = select_dirs). |
316 |
selection(selection).imports_topological_order.foreach(name => |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
317 |
{ |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
318 |
imports(options, operation_update = operation_update, progress = progress, |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
319 |
update_message = " for session " + quote(name), |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
320 |
selection = Sessions.Selection(sessions = List(name)), |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
321 |
dirs = dirs ::: select_dirs, verbose = verbose) |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67023
diff
changeset
|
322 |
}) |
66449
1be102db1598
support for incremental update according to session graph structure;
wenzelm
parents:
66234
diff
changeset
|
323 |
} |
65518
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
324 |
}) |
bc8fa59211b7
wrapper for "isabelle update_imports" with selection options like "isabelle build";
wenzelm
parents:
diff
changeset
|
325 |
} |