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