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