| author | blanchet |
| Fri, 08 Sep 2017 00:03:06 +0200 | |
| changeset 66635 | dbe1dc1f0016 |
| parent 66604 | 1af360d1cad2 |
| child 66668 | 6019cfb8256c |
| permissions | -rw-r--r-- |
| 62631 | 1 |
/* Title: Pure/Thy/sessions.scala |
2 |
Author: Makarius |
|
3 |
||
| 65430 | 4 |
Cumulative session information. |
| 62631 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
9 |
import java.io.{File => JFile}
|
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
10 |
import java.nio.ByteBuffer |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
11 |
import java.nio.channels.FileChannel |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
12 |
import java.nio.file.StandardOpenOption |
| 62631 | 13 |
|
14 |
import scala.collection.SortedSet |
|
15 |
import scala.collection.mutable |
|
16 |
||
17 |
||
18 |
object Sessions |
|
19 |
{
|
|
| 65360 | 20 |
/* base info and source dependencies */ |
| 62883 | 21 |
|
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65441
diff
changeset
|
22 |
val DRAFT = "Draft" |
|
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65441
diff
changeset
|
23 |
|
| 65360 | 24 |
def is_pure(name: String): Boolean = name == Thy_Header.PURE |
| 64856 | 25 |
|
| 65495 | 26 |
object Known |
| 64856 | 27 |
{
|
| 65495 | 28 |
val empty: Known = Known() |
| 65360 | 29 |
|
| 65495 | 30 |
def make(local_dir: Path, bases: List[Base], theories: List[Document.Node.Name]): Known = |
| 65427 | 31 |
{
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
32 |
def bases_iterator(local: Boolean) = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
33 |
for {
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
34 |
base <- bases.iterator |
| 65499 | 35 |
(_, name) <- (if (local) base.known.theories_local else base.known.theories).iterator |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
36 |
} yield name |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
37 |
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
38 |
def local_theories_iterator = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
39 |
{
|
| 65833 | 40 |
val local_path = local_dir.canonical_file.toPath |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
41 |
theories.iterator.filter(name => |
| 65833 | 42 |
Path.explode(name.node).canonical_file.toPath.startsWith(local_path)) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
43 |
} |
| 65427 | 44 |
|
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
45 |
val known_theories = |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
46 |
(Map.empty[String, Document.Node.Name] /: (bases_iterator(false) ++ theories.iterator))({
|
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
47 |
case (known, name) => |
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
48 |
known.get(name.theory) match {
|
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
49 |
case Some(name1) if name != name1 => |
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
50 |
error("Duplicate theory " + quote(name.node) + " vs. " + quote(name1.node))
|
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
51 |
case _ => known + (name.theory -> name) |
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
52 |
} |
|
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
53 |
}) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
54 |
val known_theories_local = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
55 |
(Map.empty[String, Document.Node.Name] /: |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
56 |
(bases_iterator(true) ++ local_theories_iterator))({
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
57 |
case (known, name) => known + (name.theory -> name) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
58 |
}) |
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
59 |
val known_files = |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
60 |
(Map.empty[JFile, List[Document.Node.Name]] /: |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
61 |
(bases_iterator(true) ++ bases_iterator(false) ++ theories.iterator))({
|
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
62 |
case (known, name) => |
| 65833 | 63 |
val file = Path.explode(name.node).canonical_file |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
64 |
val theories1 = known.getOrElse(file, Nil) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
65 |
if (theories1.exists(name1 => name.node == name1.node && name.theory == name1.theory)) |
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
66 |
known |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
67 |
else known + (file -> (name :: theories1)) |
| 65427 | 68 |
}) |
| 65495 | 69 |
Known(known_theories, known_theories_local, |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
70 |
known_files.iterator.map(p => (p._1, p._2.reverse)).toMap) |
| 65427 | 71 |
} |
| 64856 | 72 |
} |
73 |
||
| 65495 | 74 |
sealed case class Known( |
| 65499 | 75 |
theories: Map[String, Document.Node.Name] = Map.empty, |
76 |
theories_local: Map[String, Document.Node.Name] = Map.empty, |
|
77 |
files: Map[JFile, List[Document.Node.Name]] = Map.empty) |
|
| 65355 | 78 |
{
|
| 65495 | 79 |
def platform_path: Known = |
| 65499 | 80 |
copy(theories = for ((a, b) <- theories) yield (a, b.map(File.platform_path(_))), |
81 |
theories_local = for ((a, b) <- theories_local) yield (a, b.map(File.platform_path(_))), |
|
82 |
files = for ((a, b) <- files) yield (a, b.map(c => c.map(File.platform_path(_))))) |
|
| 65524 | 83 |
|
| 66195 | 84 |
def get_file(file: JFile, bootstrap: Boolean = false): Option[Document.Node.Name] = |
85 |
{
|
|
| 66234 | 86 |
val res = files.getOrElse(File.canonical(file), Nil).headOption |
| 66195 | 87 |
if (bootstrap) res.map(_.map_theory(Thy_Header.bootstrap_name(_))) else res |
88 |
} |
|
| 65495 | 89 |
} |
90 |
||
91 |
object Base |
|
92 |
{
|
|
93 |
def pure(options: Options): Base = session_base(options, Thy_Header.PURE) |
|
94 |
||
95 |
def bootstrap(global_theories: Map[String, String]): Base = |
|
96 |
Base( |
|
97 |
global_theories = global_theories, |
|
98 |
keywords = Thy_Header.bootstrap_header, |
|
99 |
syntax = Thy_Header.bootstrap_syntax) |
|
100 |
} |
|
101 |
||
102 |
sealed case class Base( |
|
| 66571 | 103 |
pos: Position.T = Position.none, |
|
65540
2b73ed8bf4d9
proper imports_resources for import_name: avoid self-referential name resolution;
wenzelm
parents:
65532
diff
changeset
|
104 |
imports: Option[Base] = None, |
| 65495 | 105 |
global_theories: Map[String, String] = Map.empty, |
106 |
loaded_theories: Map[String, String] = Map.empty, |
|
107 |
known: Known = Known.empty, |
|
108 |
keywords: Thy_Header.Keywords = Nil, |
|
109 |
syntax: Outer_Syntax = Outer_Syntax.empty, |
|
110 |
sources: List[(Path, SHA1.Digest)] = Nil, |
|
| 66571 | 111 |
session_graph: Graph_Display.Graph = Graph_Display.empty_graph, |
112 |
errors: List[String] = Nil) |
|
| 65495 | 113 |
{
|
|
65540
2b73ed8bf4d9
proper imports_resources for import_name: avoid self-referential name resolution;
wenzelm
parents:
65532
diff
changeset
|
114 |
def get_imports: Base = imports getOrElse Base.bootstrap(global_theories) |
|
2b73ed8bf4d9
proper imports_resources for import_name: avoid self-referential name resolution;
wenzelm
parents:
65532
diff
changeset
|
115 |
|
| 65495 | 116 |
def platform_path: Base = copy(known = known.platform_path) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
117 |
|
| 65355 | 118 |
def loaded_theory(name: Document.Node.Name): Boolean = |
|
65429
fcff401fb609
more explicit lookup of loaded_theories: base names allowed here;
wenzelm
parents:
65428
diff
changeset
|
119 |
loaded_theories.isDefinedAt(name.theory) |
| 65432 | 120 |
|
| 65498 | 121 |
def known_theory(name: String): Option[Document.Node.Name] = |
| 65499 | 122 |
known.theories.get(name) |
| 65498 | 123 |
|
| 65432 | 124 |
def dest_known_theories: List[(String, String)] = |
| 65499 | 125 |
for ((theory, node_name) <- known.theories.toList) |
| 65432 | 126 |
yield (theory, node_name.node) |
| 65355 | 127 |
} |
| 64856 | 128 |
|
| 65495 | 129 |
sealed case class Deps(session_bases: Map[String, Base], all_known: Known) |
| 65251 | 130 |
{
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
131 |
def is_empty: Boolean = session_bases.isEmpty |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
132 |
def apply(name: String): Base = session_bases(name) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
133 |
def sources(name: String): List[SHA1.Digest] = session_bases(name).sources.map(_._2) |
| 66571 | 134 |
|
135 |
def errors: List[String] = |
|
136 |
(for {
|
|
137 |
(name, base) <- session_bases.iterator |
|
138 |
if base.errors.nonEmpty |
|
139 |
} yield cat_lines(base.errors) + |
|
140 |
"\nThe error(s) above occurred in session " + quote(name) + Position.here(base.pos) |
|
141 |
).toList |
|
142 |
||
143 |
def check_errors: Deps = |
|
144 |
errors match {
|
|
145 |
case Nil => this |
|
146 |
case errs => error(cat_lines(errs)) |
|
147 |
} |
|
| 65251 | 148 |
} |
| 64856 | 149 |
|
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
150 |
def deps(sessions: T, |
| 65251 | 151 |
progress: Progress = No_Progress, |
152 |
inlined_files: Boolean = false, |
|
153 |
verbose: Boolean = false, |
|
154 |
list_files: Boolean = false, |
|
155 |
check_keywords: Set[String] = Set.empty, |
|
|
66575
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
156 |
global_theories: Map[String, String] = Map.empty): Deps = |
|
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
157 |
{
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
158 |
val session_bases = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
159 |
(Map.empty[String, Base] /: sessions.imports_topological_order)({
|
| 65519 | 160 |
case (session_bases, info) => |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
161 |
if (progress.stopped) throw Exn.Interrupt() |
| 65251 | 162 |
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
163 |
try {
|
| 65496 | 164 |
val parent_base: Sessions.Base = |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
165 |
info.parent match {
|
| 65475 | 166 |
case None => Base.bootstrap(global_theories) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
167 |
case Some(parent) => session_bases(parent) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
168 |
} |
| 65496 | 169 |
val imports_base: Sessions.Base = |
170 |
parent_base.copy(known = |
|
171 |
Known.make(info.dir, parent_base :: info.imports.map(session_bases(_)), Nil)) |
|
172 |
||
| 65532 | 173 |
val resources = new Resources(imports_base) |
| 65251 | 174 |
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
175 |
if (verbose || list_files) {
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
176 |
val groups = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
177 |
if (info.groups.isEmpty) "" |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
178 |
else info.groups.mkString(" (", " ", ")")
|
| 65519 | 179 |
progress.echo("Session " + info.chapter + "/" + info.name + groups)
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
180 |
} |
| 65251 | 181 |
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
182 |
val thy_deps = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
183 |
{
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
184 |
val root_theories = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
185 |
info.theories.flatMap({ case (_, thys) =>
|
| 65517 | 186 |
thys.map({ case (thy, pos) =>
|
| 65528 | 187 |
(resources.import_name(info.theory_qualifier, info.dir.implode, thy), pos) }) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
188 |
}) |
| 66571 | 189 |
resources.thy_info.dependencies(root_theories) |
| 65251 | 190 |
} |
191 |
||
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
192 |
val syntax = thy_deps.syntax |
| 65251 | 193 |
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
194 |
val theory_files = thy_deps.deps.map(dep => Path.explode(dep.name.node)) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
195 |
val loaded_files = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
196 |
if (inlined_files) {
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
197 |
val pure_files = |
| 65519 | 198 |
if (is_pure(info.name)) {
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
199 |
val roots = Thy_Header.ml_roots.map(p => info.dir + Path.explode(p._1)) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
200 |
val files = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
201 |
roots.flatMap(root => resources.loaded_files(syntax, File.read(root))). |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
202 |
map(file => info.dir + Path.explode(file)) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
203 |
roots ::: files |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
204 |
} |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
205 |
else Nil |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
206 |
pure_files ::: thy_deps.loaded_files |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
207 |
} |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
208 |
else Nil |
| 65251 | 209 |
|
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
210 |
val all_files = |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
211 |
(theory_files ::: loaded_files ::: |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
212 |
info.files.map(file => info.dir + file) ::: |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
213 |
info.document_files.map(file => info.dir + file._1 + file._2)).map(_.expand) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
214 |
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
215 |
if (list_files) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
216 |
progress.echo(cat_lines(all_files.map(_.implode).sorted.map(" " + _)))
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
217 |
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
218 |
if (check_keywords.nonEmpty) |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
219 |
Check_Keywords.check_keywords(progress, syntax.keywords, check_keywords, theory_files) |
| 65251 | 220 |
|
|
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
221 |
val session_graph: Graph_Display.Graph = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
222 |
{
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
223 |
def session_node(name: String): Graph_Display.Node = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
224 |
Graph_Display.Node("[" + name + "]", "session." + name)
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
225 |
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
226 |
def node(name: Document.Node.Name): Graph_Display.Node = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
227 |
{
|
| 65528 | 228 |
val qualifier = resources.theory_qualifier(name) |
229 |
if (qualifier == info.theory_qualifier) |
|
|
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
230 |
Graph_Display.Node(name.theory_base_name, "theory." + name.theory) |
| 65528 | 231 |
else session_node(qualifier) |
|
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
232 |
} |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
233 |
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
234 |
val imports_subgraph = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
235 |
sessions.imports_graph.restrict( |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
236 |
sessions.imports_graph.all_preds(info.parent.toList ::: info.imports).toSet) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
237 |
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
238 |
val graph0 = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
239 |
(Graph_Display.empty_graph /: imports_subgraph.topological_order)( |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
240 |
{ case (g, session) =>
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
241 |
val a = session_node(session) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
242 |
val bs = imports_subgraph.imm_preds(session).toList.map(session_node(_)) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
243 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
244 |
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
245 |
(graph0 /: thy_deps.deps)( |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
246 |
{ case (g, dep) =>
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
247 |
val a = node(dep.name) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
248 |
val bs = |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
249 |
dep.header.imports.map({ case (name, _) => node(name) }).
|
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
250 |
filterNot(_ == a) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
251 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
252 |
} |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
253 |
|
| 66604 | 254 |
val sources = |
255 |
for (p <- all_files if p.is_file) yield (p, SHA1.digest(p.file)) |
|
256 |
val sources_errors = |
|
257 |
for (p <- all_files if !p.is_file) yield "No such file: " + p |
|
258 |
||
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
259 |
val base = |
| 66571 | 260 |
Base( |
261 |
pos = info.pos, |
|
262 |
imports = Some(imports_base), |
|
|
65540
2b73ed8bf4d9
proper imports_resources for import_name: avoid self-referential name resolution;
wenzelm
parents:
65532
diff
changeset
|
263 |
global_theories = global_theories, |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
264 |
loaded_theories = thy_deps.loaded_theories, |
| 65496 | 265 |
known = Known.make(info.dir, List(imports_base), thy_deps.deps.map(_.name)), |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
266 |
keywords = thy_deps.keywords, |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
267 |
syntax = syntax, |
| 66604 | 268 |
sources = sources, |
| 66571 | 269 |
session_graph = session_graph, |
| 66604 | 270 |
errors = thy_deps.errors ::: sources_errors) |
| 65251 | 271 |
|
| 65519 | 272 |
session_bases + (info.name -> base) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
273 |
} |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
274 |
catch {
|
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
275 |
case ERROR(msg) => |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
276 |
cat_error(msg, "The error(s) above occurred in session " + |
| 65519 | 277 |
quote(info.name) + Position.here(info.pos)) |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
278 |
} |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
279 |
}) |
| 65251 | 280 |
|
|
66575
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
281 |
Deps(session_bases, Known.make(Path.current, session_bases.toList.map(_._2), Nil)) |
|
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
282 |
} |
| 65251 | 283 |
|
| 66571 | 284 |
def session_base_errors( |
| 65428 | 285 |
options: Options, |
286 |
session: String, |
|
287 |
dirs: List[Path] = Nil, |
|
| 66571 | 288 |
all_known: Boolean = false): (List[String], Base) = |
| 65251 | 289 |
{
|
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
290 |
val full_sessions = load(options, dirs = dirs) |
| 65428 | 291 |
val global_theories = full_sessions.global_theories |
|
66575
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
292 |
val (_, selected_sessions) = full_sessions.selection(Selection(sessions = List(session))) |
|
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
293 |
|
|
66575
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
294 |
val sessions: T = if (all_known) full_sessions else selected_sessions |
|
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
295 |
val deps = Sessions.deps(sessions, global_theories = global_theories) |
|
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
296 |
val base = if (all_known) deps(session).copy(known = deps.all_known) else deps(session) |
|
191048506504
clarified signature: provide all_known information uniformly (it is subject to Sessions.T selection);
wenzelm
parents:
66573
diff
changeset
|
297 |
(deps.errors, base) |
| 66571 | 298 |
} |
299 |
||
300 |
def session_base( |
|
301 |
options: Options, |
|
302 |
session: String, |
|
303 |
dirs: List[Path] = Nil, |
|
304 |
all_known: Boolean = false): Base = |
|
305 |
{
|
|
| 66573 | 306 |
val (errs, base) = session_base_errors(options, session, dirs = dirs, all_known = all_known) |
307 |
if (errs.isEmpty) base else error(cat_lines(errs)) |
|
| 65251 | 308 |
} |
309 |
||
310 |
||
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
311 |
/* cumulative session info */ |
| 62631 | 312 |
|
313 |
sealed case class Info( |
|
| 65519 | 314 |
name: String, |
| 62631 | 315 |
chapter: String, |
316 |
select: Boolean, |
|
317 |
pos: Position.T, |
|
318 |
groups: List[String], |
|
319 |
dir: Path, |
|
320 |
parent: Option[String], |
|
321 |
description: String, |
|
322 |
options: Options, |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
323 |
imports: List[String], |
| 65517 | 324 |
theories: List[(Options, List[(String, Position.T)])], |
| 65374 | 325 |
global_theories: List[String], |
| 62631 | 326 |
files: List[Path], |
327 |
document_files: List[(Path, Path)], |
|
328 |
meta_digest: SHA1.Digest) |
|
329 |
{
|
|
330 |
def timeout: Time = Time.seconds(options.real("timeout") * options.real("timeout_scale"))
|
|
|
65456
31e8a86971a8
explicit theory qualifier for session "HOL-Proofs": its theory name space overlaps with session "HOL", even for further imports;
wenzelm
parents:
65445
diff
changeset
|
331 |
|
| 65520 | 332 |
def theory_qualifier: String = |
|
65456
31e8a86971a8
explicit theory qualifier for session "HOL-Proofs": its theory name space overlaps with session "HOL", even for further imports;
wenzelm
parents:
65445
diff
changeset
|
333 |
options.string("theory_qualifier") match {
|
| 65520 | 334 |
case "" => name |
| 65457 | 335 |
case qualifier => qualifier |
|
65456
31e8a86971a8
explicit theory qualifier for session "HOL-Proofs": its theory name space overlaps with session "HOL", even for further imports;
wenzelm
parents:
65445
diff
changeset
|
336 |
} |
| 62631 | 337 |
} |
338 |
||
| 65419 | 339 |
object Selection |
340 |
{
|
|
| 65422 | 341 |
val empty: Selection = Selection() |
| 65525 | 342 |
val all: Selection = Selection(all_sessions = true) |
| 65419 | 343 |
} |
344 |
||
345 |
sealed case class Selection( |
|
346 |
requirements: Boolean = false, |
|
347 |
all_sessions: Boolean = false, |
|
348 |
exclude_session_groups: List[String] = Nil, |
|
349 |
exclude_sessions: List[String] = Nil, |
|
350 |
session_groups: List[String] = Nil, |
|
351 |
sessions: List[String] = Nil) |
|
352 |
{
|
|
| 65422 | 353 |
def + (other: Selection): Selection = |
354 |
Selection( |
|
355 |
requirements = requirements || other.requirements, |
|
356 |
all_sessions = all_sessions || other.all_sessions, |
|
357 |
exclude_session_groups = exclude_session_groups ::: other.exclude_session_groups, |
|
358 |
exclude_sessions = exclude_sessions ::: other.exclude_sessions, |
|
359 |
session_groups = session_groups ::: other.session_groups, |
|
360 |
sessions = sessions ::: other.sessions) |
|
361 |
||
| 65419 | 362 |
def apply(graph: Graph[String, Info]): (List[String], Graph[String, Info]) = |
363 |
{
|
|
364 |
val bad_sessions = |
|
365 |
SortedSet((exclude_sessions ::: sessions).filterNot(graph.defined(_)): _*).toList |
|
366 |
if (bad_sessions.nonEmpty) error("Undefined session(s): " + commas_quote(bad_sessions))
|
|
367 |
||
368 |
val excluded = |
|
369 |
{
|
|
370 |
val exclude_group = exclude_session_groups.toSet |
|
371 |
val exclude_group_sessions = |
|
372 |
(for {
|
|
373 |
(name, (info, _)) <- graph.iterator |
|
374 |
if graph.get_node(name).groups.exists(exclude_group) |
|
375 |
} yield name).toList |
|
376 |
graph.all_succs(exclude_group_sessions ::: exclude_sessions).toSet |
|
377 |
} |
|
378 |
||
379 |
val pre_selected = |
|
380 |
{
|
|
381 |
if (all_sessions) graph.keys |
|
382 |
else {
|
|
383 |
val select_group = session_groups.toSet |
|
384 |
val select = sessions.toSet |
|
385 |
(for {
|
|
386 |
(name, (info, _)) <- graph.iterator |
|
387 |
if info.select || select(name) || graph.get_node(name).groups.exists(select_group) |
|
388 |
} yield name).toList |
|
389 |
} |
|
390 |
}.filterNot(excluded) |
|
391 |
||
392 |
val selected = |
|
393 |
if (requirements) (graph.all_preds(pre_selected).toSet -- pre_selected).toList |
|
394 |
else pre_selected |
|
395 |
||
396 |
(selected, graph.restrict(graph.all_preds(selected).toSet)) |
|
397 |
} |
|
398 |
} |
|
399 |
||
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
400 |
def make(infos: Traversable[(String, Info)]): T = |
| 62631 | 401 |
{
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
402 |
def add_edges(graph: Graph[String, Info], kind: String, edges: Info => Traversable[String]) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
403 |
: Graph[String, Info] = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
404 |
{
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
405 |
def add_edge(pos: Position.T, name: String, g: Graph[String, Info], parent: String) = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
406 |
{
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
407 |
if (!g.defined(parent)) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
408 |
error("Bad " + kind + " session " + quote(parent) + " for " +
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
409 |
quote(name) + Position.here(pos)) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
410 |
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
411 |
try { g.add_edge_acyclic(parent, name) }
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
412 |
catch {
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
413 |
case exn: Graph.Cycles[_] => |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
414 |
error(cat_lines(exn.cycles.map(cycle => |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
415 |
"Cyclic session dependency of " + |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
416 |
cycle.map(c => quote(c.toString)).mkString(" via "))) + Position.here(pos))
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
417 |
} |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
418 |
} |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
419 |
(graph /: graph.iterator) {
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
420 |
case (g, (name, (info, _))) => (g /: edges(info))(add_edge(info.pos, name, _, _)) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
421 |
} |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
422 |
} |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
423 |
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
424 |
val graph0 = |
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
425 |
(Graph.string[Info] /: infos) {
|
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
426 |
case (graph, (name, info)) => |
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
427 |
if (graph.defined(name)) |
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
428 |
error("Duplicate session " + quote(name) + Position.here(info.pos) +
|
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
429 |
Position.here(graph.get_node(name).pos)) |
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
430 |
else graph.new_node(name, info) |
|
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
431 |
} |
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
432 |
val graph1 = add_edges(graph0, "parent", _.parent) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
433 |
val graph2 = add_edges(graph1, "imports", _.imports) |
| 62631 | 434 |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
435 |
new T(graph1, graph2) |
| 62631 | 436 |
} |
437 |
||
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
438 |
final class T private[Sessions]( |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
439 |
val build_graph: Graph[String, Info], |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
440 |
val imports_graph: Graph[String, Info]) |
| 62631 | 441 |
{
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
442 |
def apply(name: String): Info = imports_graph.get_node(name) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
443 |
def get(name: String): Option[Info] = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
444 |
if (imports_graph.defined(name)) Some(imports_graph.get_node(name)) else None |
| 62631 | 445 |
|
| 65457 | 446 |
def global_theories: Map[String, String] = |
| 65490 | 447 |
(Thy_Header.bootstrap_global_theories.toMap /: |
| 65424 | 448 |
(for {
|
| 65519 | 449 |
(_, (info, _)) <- imports_graph.iterator |
450 |
thy <- info.global_theories.iterator } |
|
451 |
yield (thy, info)))({
|
|
452 |
case (global, (thy, info)) => |
|
| 65520 | 453 |
val qualifier = info.theory_qualifier |
| 65457 | 454 |
global.get(thy) match {
|
455 |
case Some(qualifier1) if qualifier != qualifier1 => |
|
456 |
error("Duplicate global theory " + quote(thy) + Position.here(info.pos))
|
|
457 |
case _ => global + (thy -> qualifier) |
|
458 |
} |
|
459 |
}) |
|
|
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
460 |
|
| 65419 | 461 |
def selection(select: Selection): (List[String], T) = |
| 62631 | 462 |
{
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
463 |
val (_, build_graph1) = select(build_graph) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
464 |
val (selected, imports_graph1) = select(imports_graph) |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
465 |
(selected, new T(build_graph1, imports_graph1)) |
| 62631 | 466 |
} |
467 |
||
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
468 |
def build_ancestors(name: String): List[String] = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
469 |
build_graph.all_preds(List(name)).tail.reverse |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
470 |
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
471 |
def build_descendants(names: List[String]): List[String] = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
472 |
build_graph.all_succs(names) |
| 62631 | 473 |
|
| 65519 | 474 |
def build_topological_order: List[Info] = |
475 |
build_graph.topological_order.map(apply(_)) |
|
| 62631 | 476 |
|
| 65566 | 477 |
def imports_ancestors(name: String): List[String] = |
478 |
imports_graph.all_preds(List(name)).tail.reverse |
|
479 |
||
| 65519 | 480 |
def imports_topological_order: List[Info] = |
481 |
imports_graph.topological_order.map(apply(_)) |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
482 |
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
483 |
override def toString: String = |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
484 |
imports_graph.keys_iterator.mkString("Sessions.T(", ", ", ")")
|
| 62631 | 485 |
} |
486 |
||
487 |
||
488 |
/* parser */ |
|
489 |
||
| 62864 | 490 |
val ROOT = Path.explode("ROOT")
|
491 |
val ROOTS = Path.explode("ROOTS")
|
|
492 |
||
| 62631 | 493 |
private val CHAPTER = "chapter" |
494 |
private val SESSION = "session" |
|
495 |
private val IN = "in" |
|
496 |
private val DESCRIPTION = "description" |
|
497 |
private val OPTIONS = "options" |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
498 |
private val SESSIONS = "sessions" |
| 62631 | 499 |
private val THEORIES = "theories" |
| 65374 | 500 |
private val GLOBAL = "global" |
| 62631 | 501 |
private val FILES = "files" |
502 |
private val DOCUMENT_FILES = "document_files" |
|
503 |
||
504 |
lazy val root_syntax = |
|
| 65374 | 505 |
Outer_Syntax.init() + "(" + ")" + "+" + "," + "=" + "[" + "]" + GLOBAL + IN +
|
| 63443 | 506 |
(CHAPTER, Keyword.THY_DECL) + |
507 |
(SESSION, Keyword.THY_DECL) + |
|
508 |
(DESCRIPTION, Keyword.QUASI_COMMAND) + |
|
509 |
(OPTIONS, Keyword.QUASI_COMMAND) + |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
510 |
(SESSIONS, Keyword.QUASI_COMMAND) + |
| 63443 | 511 |
(THEORIES, Keyword.QUASI_COMMAND) + |
512 |
(FILES, Keyword.QUASI_COMMAND) + |
|
513 |
(DOCUMENT_FILES, Keyword.QUASI_COMMAND) |
|
| 62631 | 514 |
|
| 62968 | 515 |
private object Parser extends Parse.Parser with Options.Parser |
| 62631 | 516 |
{
|
517 |
private abstract class Entry |
|
518 |
private sealed case class Chapter(name: String) extends Entry |
|
519 |
private sealed case class Session_Entry( |
|
520 |
pos: Position.T, |
|
521 |
name: String, |
|
522 |
groups: List[String], |
|
523 |
path: String, |
|
524 |
parent: Option[String], |
|
525 |
description: String, |
|
526 |
options: List[Options.Spec], |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
527 |
imports: List[String], |
| 65517 | 528 |
theories: List[(List[Options.Spec], List[((String, Position.T), Boolean)])], |
| 62631 | 529 |
files: List[String], |
530 |
document_files: List[(String, String)]) extends Entry |
|
|
65580
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
531 |
{
|
|
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
532 |
def theories_no_position: List[(List[Options.Spec], List[(String, Boolean)])] = |
|
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
533 |
theories.map({ case (a, b) => (a, b.map({ case ((c, _), d) => (c, d) })) })
|
|
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
534 |
} |
| 62631 | 535 |
|
536 |
private val chapter: Parser[Chapter] = |
|
537 |
{
|
|
538 |
val chapter_name = atom("chapter name", _.is_name)
|
|
539 |
||
540 |
command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) }
|
|
541 |
} |
|
542 |
||
543 |
private val session_entry: Parser[Session_Entry] = |
|
544 |
{
|
|
545 |
val session_name = atom("session name", _.is_name)
|
|
546 |
||
547 |
val option = |
|
| 62968 | 548 |
option_name ~ opt($$$("=") ~! option_value ^^
|
549 |
{ case _ ~ x => x }) ^^ { case x ~ y => (x, y) }
|
|
| 62631 | 550 |
val options = $$$("[") ~> rep1sep(option, $$$(",")) <~ $$$("]")
|
551 |
||
| 65374 | 552 |
val global = |
553 |
($$$("(") ~! $$$(GLOBAL) ~ $$$(")")) ^^ { case _ => true } | success(false)
|
|
554 |
||
555 |
val theory_entry = |
|
| 65517 | 556 |
position(theory_name) ~ global ^^ { case x ~ y => (x, y) }
|
| 65374 | 557 |
|
| 62631 | 558 |
val theories = |
| 65374 | 559 |
$$$(THEORIES) ~! |
560 |
((options | success(Nil)) ~ rep(theory_entry)) ^^ |
|
561 |
{ case _ ~ (x ~ y) => (x, y) }
|
|
| 62631 | 562 |
|
563 |
val document_files = |
|
564 |
$$$(DOCUMENT_FILES) ~! |
|
565 |
(($$$("(") ~! ($$$(IN) ~! (path ~ $$$(")"))) ^^
|
|
566 |
{ case _ ~ (_ ~ (x ~ _)) => x } | success("document")) ~
|
|
567 |
rep1(path)) ^^ { case _ ~ (x ~ y) => y.map((x, _)) }
|
|
568 |
||
569 |
command(SESSION) ~! |
|
570 |
(position(session_name) ~ |
|
571 |
(($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
572 |
(($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~
|
|
573 |
($$$("=") ~!
|
|
574 |
(opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~
|
|
575 |
(($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~
|
|
576 |
(($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
577 |
(($$$(SESSIONS) ~! rep(session_name) ^^ { case _ ~ x => x }) | success(Nil)) ~
|
| 62631 | 578 |
rep1(theories) ~ |
579 |
(($$$(FILES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil)) ~
|
|
580 |
(rep(document_files) ^^ (x => x.flatten))))) ^^ |
|
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
581 |
{ case _ ~ ((a, pos) ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h ~ i ~ j))) =>
|
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
582 |
Session_Entry(pos, a, b, c, d, e, f, g, h, i, j) } |
| 62631 | 583 |
} |
584 |
||
585 |
def parse(options: Options, select: Boolean, dir: Path): List[(String, Info)] = |
|
586 |
{
|
|
587 |
def make_info(entry_chapter: String, entry: Session_Entry): (String, Info) = |
|
588 |
{
|
|
589 |
try {
|
|
590 |
val name = entry.name |
|
591 |
||
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65441
diff
changeset
|
592 |
if (name == "" || name == DRAFT) error("Bad session name")
|
| 65360 | 593 |
if (is_pure(name) && entry.parent.isDefined) error("Illegal parent session")
|
594 |
if (!is_pure(name) && !entry.parent.isDefined) error("Missing parent session")
|
|
| 62631 | 595 |
|
596 |
val session_options = options ++ entry.options |
|
597 |
||
598 |
val theories = |
|
|
65392
f365f61f2081
uniform import_name, with treatment of global and qualified theories;
wenzelm
parents:
65391
diff
changeset
|
599 |
entry.theories.map({ case (opts, thys) => (session_options ++ opts, thys.map(_._1)) })
|
| 65374 | 600 |
|
601 |
val global_theories = |
|
| 65517 | 602 |
for { (_, thys) <- entry.theories; ((thy, pos), global) <- thys if global }
|
| 65374 | 603 |
yield {
|
| 65999 | 604 |
val thy_name = Path.explode(thy).expand.base_name |
| 65374 | 605 |
if (Long_Name.is_qualified(thy_name)) |
| 65517 | 606 |
error("Bad qualified name for global theory " +
|
607 |
quote(thy_name) + Position.here(pos)) |
|
| 65374 | 608 |
else thy_name |
609 |
} |
|
610 |
||
| 62631 | 611 |
val files = entry.files.map(Path.explode(_)) |
612 |
val document_files = |
|
613 |
entry.document_files.map({ case (s1, s2) => (Path.explode(s1), Path.explode(s2)) })
|
|
614 |
||
615 |
val meta_digest = |
|
|
65580
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
616 |
SHA1.digest((entry_chapter, name, entry.parent, entry.options, entry.imports, |
|
66351f79c295
meta_digest without accidental source positions (amending 1544e61e5314): avoid spurious rebuild of unrelated sessions after editing ROOT;
wenzelm
parents:
65566
diff
changeset
|
617 |
entry.theories_no_position, entry.files, entry.document_files).toString) |
| 62631 | 618 |
|
619 |
val info = |
|
| 65519 | 620 |
Info(name, entry_chapter, select, entry.pos, entry.groups, |
621 |
dir + Path.explode(entry.path), entry.parent, entry.description, session_options, |
|
622 |
entry.imports, theories, global_theories, files, document_files, meta_digest) |
|
| 62631 | 623 |
|
624 |
(name, info) |
|
625 |
} |
|
626 |
catch {
|
|
627 |
case ERROR(msg) => |
|
628 |
error(msg + "\nThe error(s) above occurred in session entry " + |
|
629 |
quote(entry.name) + Position.here(entry.pos)) |
|
630 |
} |
|
631 |
} |
|
632 |
||
633 |
val root = dir + ROOT |
|
634 |
if (root.is_file) {
|
|
635 |
val toks = Token.explode(root_syntax.keywords, File.read(root)) |
|
636 |
val start = Token.Pos.file(root.implode) |
|
637 |
||
638 |
parse_all(rep(chapter | session_entry), Token.reader(toks, start)) match {
|
|
639 |
case Success(result, _) => |
|
640 |
var entry_chapter = "Unsorted" |
|
641 |
val infos = new mutable.ListBuffer[(String, Info)] |
|
642 |
result.foreach {
|
|
643 |
case Chapter(name) => entry_chapter = name |
|
644 |
case entry: Session_Entry => infos += make_info(entry_chapter, entry) |
|
645 |
} |
|
646 |
infos.toList |
|
647 |
case bad => error(bad.toString) |
|
648 |
} |
|
649 |
} |
|
650 |
else Nil |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
||
| 62635 | 655 |
/* load sessions from certain directories */ |
| 62631 | 656 |
|
657 |
private def is_session_dir(dir: Path): Boolean = |
|
658 |
(dir + ROOT).is_file || (dir + ROOTS).is_file |
|
659 |
||
660 |
private def check_session_dir(dir: Path): Path = |
|
|
65468
c41791ad75c3
early check and normalization of session directory, e.g. relevant for path information passed to ML process, which may have a different CWD;
wenzelm
parents:
65463
diff
changeset
|
661 |
if (is_session_dir(dir)) File.pwd() + dir.expand |
| 62631 | 662 |
else error("Bad session root directory: " + dir.toString)
|
663 |
||
| 65561 | 664 |
def directories(dirs: List[Path], select_dirs: List[Path]): List[(Boolean, Path)] = |
665 |
{
|
|
666 |
val default_dirs = Isabelle_System.components().filter(is_session_dir(_)) |
|
667 |
(default_dirs ::: dirs).map((false, _)) ::: select_dirs.map((true, _)) |
|
668 |
} |
|
669 |
||
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
670 |
def load(options: Options, dirs: List[Path] = Nil, select_dirs: List[Path] = Nil): T = |
| 62631 | 671 |
{
|
| 62635 | 672 |
def load_dir(select: Boolean, dir: Path): List[(String, Info)] = |
673 |
load_root(select, dir) ::: load_roots(select, dir) |
|
| 62631 | 674 |
|
| 62635 | 675 |
def load_root(select: Boolean, dir: Path): List[(String, Info)] = |
| 62631 | 676 |
Parser.parse(options, select, dir) |
677 |
||
| 62635 | 678 |
def load_roots(select: Boolean, dir: Path): List[(String, Info)] = |
| 62631 | 679 |
{
|
680 |
val roots = dir + ROOTS |
|
681 |
if (roots.is_file) {
|
|
682 |
for {
|
|
683 |
line <- split_lines(File.read(roots)) |
|
684 |
if !(line == "" || line.startsWith("#"))
|
|
685 |
dir1 = |
|
686 |
try { check_session_dir(dir + Path.explode(line)) }
|
|
687 |
catch {
|
|
688 |
case ERROR(msg) => |
|
689 |
error(msg + "\nThe error(s) above occurred in session catalog " + roots.toString) |
|
690 |
} |
|
| 62635 | 691 |
info <- load_dir(select, dir1) |
| 62631 | 692 |
} yield info |
693 |
} |
|
694 |
else Nil |
|
695 |
} |
|
696 |
||
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
697 |
make( |
| 62631 | 698 |
for {
|
| 65561 | 699 |
(select, dir) <- directories(dirs, select_dirs) |
|
65468
c41791ad75c3
early check and normalization of session directory, e.g. relevant for path information passed to ML process, which may have a different CWD;
wenzelm
parents:
65463
diff
changeset
|
700 |
info <- load_dir(select, check_session_dir(dir)) |
| 62631 | 701 |
} yield info) |
702 |
} |
|
| 62632 | 703 |
|
704 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
705 |
|
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
706 |
/** heap file with SHA1 digest **/ |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
707 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
708 |
private val sha1_prefix = "SHA1:" |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
709 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
710 |
def read_heap_digest(heap: Path): Option[String] = |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
711 |
{
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
712 |
if (heap.is_file) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
713 |
val file = FileChannel.open(heap.file.toPath, StandardOpenOption.READ) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
714 |
try {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
715 |
val len = file.size |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
716 |
val n = sha1_prefix.length + SHA1.digest_length |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
717 |
if (len >= n) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
718 |
file.position(len - n) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
719 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
720 |
val buf = ByteBuffer.allocate(n) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
721 |
var i = 0 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
722 |
var m = 0 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
723 |
do {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
724 |
m = file.read(buf) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
725 |
if (m != -1) i += m |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
726 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
727 |
while (m != -1 && n > i) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
728 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
729 |
if (i == n) {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
730 |
val prefix = new String(buf.array(), 0, sha1_prefix.length, UTF8.charset) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
731 |
val s = new String(buf.array(), sha1_prefix.length, SHA1.digest_length, UTF8.charset) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
732 |
if (prefix == sha1_prefix) Some(s) else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
733 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
734 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
735 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
736 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
737 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
738 |
finally { file.close }
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
739 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
740 |
else None |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
741 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
742 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
743 |
def write_heap_digest(heap: Path): String = |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
744 |
read_heap_digest(heap) match {
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
745 |
case None => |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
746 |
val s = SHA1.digest(heap).rep |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
747 |
File.append(heap, sha1_prefix + s) |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
748 |
s |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
749 |
case Some(s) => s |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
750 |
} |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
751 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
752 |
|
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
753 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
754 |
/** persistent store **/ |
| 62632 | 755 |
|
| 65296 | 756 |
object Session_Info |
757 |
{
|
|
| 65326 | 758 |
val session_name = SQL.Column.string("session_name", primary_key = true)
|
759 |
||
| 65296 | 760 |
// Build_Log.Session_Info |
761 |
val session_timing = SQL.Column.bytes("session_timing")
|
|
762 |
val command_timings = SQL.Column.bytes("command_timings")
|
|
763 |
val ml_statistics = SQL.Column.bytes("ml_statistics")
|
|
764 |
val task_statistics = SQL.Column.bytes("task_statistics")
|
|
| 65934 | 765 |
val errors = SQL.Column.bytes("errors")
|
| 65296 | 766 |
val build_log_columns = |
| 65934 | 767 |
List(session_name, session_timing, command_timings, ml_statistics, task_statistics, errors) |
| 65296 | 768 |
|
769 |
// Build.Session_Info |
|
770 |
val sources = SQL.Column.string("sources")
|
|
771 |
val input_heaps = SQL.Column.string("input_heaps")
|
|
772 |
val output_heap = SQL.Column.string("output_heap")
|
|
773 |
val return_code = SQL.Column.int("return_code")
|
|
774 |
val build_columns = List(sources, input_heaps, output_heap, return_code) |
|
775 |
||
776 |
val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns)
|
|
777 |
} |
|
778 |
||
| 62632 | 779 |
def store(system_mode: Boolean = false): Store = new Store(system_mode) |
780 |
||
| 65857 | 781 |
class Store private[Sessions](system_mode: Boolean) |
| 62632 | 782 |
{
|
| 65278 | 783 |
/* file names */ |
784 |
||
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
785 |
def database(name: String): Path = Path.basic("log") + Path.basic(name).ext("db")
|
| 65278 | 786 |
def log(name: String): Path = Path.basic("log") + Path.basic(name)
|
787 |
def log_gz(name: String): Path = log(name).ext("gz")
|
|
788 |
||
789 |
||
| 65286 | 790 |
/* SQL database content */ |
| 65283 | 791 |
|
| 65857 | 792 |
val xml_cache = new XML.Cache() |
793 |
||
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
794 |
def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
| 65698 | 795 |
db.using_statement(Session_Info.table.select(List(column), |
| 65699 | 796 |
Session_Info.session_name.where_equal(name)))(stmt => |
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
797 |
{
|
| 65740 | 798 |
val res = stmt.execute_query() |
799 |
if (!res.next()) Bytes.empty else res.bytes(column) |
|
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
800 |
}) |
| 65285 | 801 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
802 |
def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
| 65857 | 803 |
Properties.uncompress(read_bytes(db, name, column), Some(xml_cache)) |
| 65286 | 804 |
|
| 65283 | 805 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
806 |
/* output */ |
| 62632 | 807 |
|
808 |
val browser_info: Path = |
|
809 |
if (system_mode) Path.explode("~~/browser_info")
|
|
810 |
else Path.explode("$ISABELLE_BROWSER_INFO")
|
|
811 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
812 |
val output_dir: Path = |
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
813 |
if (system_mode) Path.explode("~~/heaps/$ML_IDENTIFIER")
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
814 |
else Path.explode("$ISABELLE_OUTPUT")
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
815 |
|
| 65298 | 816 |
override def toString: String = "Store(output_dir = " + output_dir.expand + ")" |
817 |
||
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
818 |
def prepare_output() { Isabelle_System.mkdirs(output_dir + Path.basic("log")) }
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
819 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
820 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
821 |
/* input */ |
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
822 |
|
|
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
823 |
private val input_dirs = |
| 62632 | 824 |
if (system_mode) List(output_dir) |
| 62633 | 825 |
else {
|
826 |
val ml_ident = Path.explode("$ML_IDENTIFIER").expand
|
|
827 |
output_dir :: Path.split(Isabelle_System.getenv_strict("ISABELLE_PATH")).map(_ + ml_ident)
|
|
828 |
} |
|
| 62632 | 829 |
|
|
65291
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
830 |
def find_database_heap(name: String): Option[(Path, Option[String])] = |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
831 |
input_dirs.find(dir => (dir + database(name)).is_file).map(dir => |
|
57c85c83c11b
maintain persistent session info in SQLite database instead of log file;
wenzelm
parents:
65288
diff
changeset
|
832 |
(dir + database(name), read_heap_digest(dir + Path.basic(name)))) |
| 62632 | 833 |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
834 |
def find_database(name: String): Option[Path] = |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
835 |
input_dirs.map(_ + database(name)).find(_.is_file) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
836 |
|
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
837 |
def heap(name: String): Path = |
| 65288 | 838 |
input_dirs.map(_ + Path.basic(name)).find(_.is_file) getOrElse |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
839 |
error("Unknown logic " + quote(name) + " -- no heap file found in:\n" +
|
| 62769 | 840 |
cat_lines(input_dirs.map(dir => " " + dir.expand.implode))) |
| 65287 | 841 |
|
842 |
||
| 65296 | 843 |
/* session info */ |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
844 |
|
| 65296 | 845 |
def write_session_info( |
|
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
846 |
db: SQL.Database, |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
847 |
name: String, |
|
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
848 |
build_log: Build_Log.Session_Info, |
|
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
849 |
build: Build.Session_Info) |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
850 |
{
|
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
851 |
db.transaction {
|
| 65296 | 852 |
db.create_table(Session_Info.table) |
| 65698 | 853 |
db.using_statement( |
| 65699 | 854 |
Session_Info.table.delete(Session_Info.session_name.where_equal(name)))(_.execute) |
| 65698 | 855 |
db.using_statement(Session_Info.table.insert())(stmt => |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
856 |
{
|
| 65748 | 857 |
stmt.string(1) = name |
| 65857 | 858 |
stmt.bytes(2) = Properties.encode(build_log.session_timing) |
859 |
stmt.bytes(3) = Properties.compress(build_log.command_timings) |
|
860 |
stmt.bytes(4) = Properties.compress(build_log.ml_statistics) |
|
861 |
stmt.bytes(5) = Properties.compress(build_log.task_statistics) |
|
| 65937 | 862 |
stmt.bytes(6) = Build_Log.compress_errors(build_log.errors) |
| 65934 | 863 |
stmt.string(7) = cat_lines(build.sources) |
864 |
stmt.string(8) = cat_lines(build.input_heaps) |
|
865 |
stmt.string(9) = build.output_heap getOrElse "" |
|
866 |
stmt.int(10) = build.return_code |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
867 |
stmt.execute() |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
868 |
}) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
869 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
870 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
871 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
872 |
def read_session_timing(db: SQL.Database, name: String): Properties.T = |
| 65857 | 873 |
Properties.decode(read_bytes(db, name, Session_Info.session_timing), Some(xml_cache)) |
| 65286 | 874 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
875 |
def read_command_timings(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
876 |
read_properties(db, name, Session_Info.command_timings) |
| 65286 | 877 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
878 |
def read_ml_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
879 |
read_properties(db, name, Session_Info.ml_statistics) |
| 65286 | 880 |
|
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
881 |
def read_task_statistics(db: SQL.Database, name: String): List[Properties.T] = |
|
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
882 |
read_properties(db, name, Session_Info.task_statistics) |
| 65286 | 883 |
|
| 65937 | 884 |
def read_errors(db: SQL.Database, name: String): List[String] = |
885 |
Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors)) |
|
886 |
||
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
887 |
def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
| 65698 | 888 |
db.using_statement(Session_Info.table.select(Session_Info.build_columns, |
| 65699 | 889 |
Session_Info.session_name.where_equal(name)))(stmt => |
| 65285 | 890 |
{
|
| 65740 | 891 |
val res = stmt.execute_query() |
892 |
if (!res.next()) None |
|
| 65285 | 893 |
else {
|
894 |
Some( |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
895 |
Build.Session_Info( |
| 65740 | 896 |
split_lines(res.string(Session_Info.sources)), |
897 |
split_lines(res.string(Session_Info.input_heaps)), |
|
898 |
res.string(Session_Info.output_heap) match { case "" => None case s => Some(s) },
|
|
899 |
res.int(Session_Info.return_code))) |
|
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
900 |
} |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
901 |
}) |
|
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
902 |
} |
| 62631 | 903 |
} |