author | wenzelm |
Tue, 24 Nov 2020 16:39:58 +0100 | |
changeset 72696 | 7af210f1f13b |
parent 72683 | b5e6f0d137a7 |
child 72715 | 2615b8c05337 |
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 |
|
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
14 |
import scala.collection.{SortedSet, SortedMap} |
62631 | 15 |
import scala.collection.mutable |
16 |
||
17 |
||
18 |
object Sessions |
|
19 |
{ |
|
67284 | 20 |
/* session and theory names */ |
62883 | 21 |
|
67215 | 22 |
val root_name: String = "ROOT" |
23 |
val theory_name: String = "Pure.Sessions" |
|
24 |
||
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
25 |
val UNSORTED = "Unsorted" |
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65441
diff
changeset
|
26 |
val DRAFT = "Draft" |
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65441
diff
changeset
|
27 |
|
65360 | 28 |
def is_pure(name: String): Boolean = name == Thy_Header.PURE |
64856 | 29 |
|
67284 | 30 |
|
31 |
def exclude_session(name: String): Boolean = name == "" || name == DRAFT |
|
32 |
||
67286 | 33 |
def exclude_theory(name: String): Boolean = |
67290 | 34 |
name == root_name || name == "README" || name == "index" || name == "bib" |
67284 | 35 |
|
36 |
||
37 |
/* base info and source dependencies */ |
|
38 |
||
65495 | 39 |
object Base |
40 |
{ |
|
70673
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
wenzelm
parents:
70672
diff
changeset
|
41 |
def bootstrap( |
70681 | 42 |
session_directories: Map[JFile, String], |
70673
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
wenzelm
parents:
70672
diff
changeset
|
43 |
global_theories: Map[String, String]): Base = |
65495 | 44 |
Base( |
70673
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
wenzelm
parents:
70672
diff
changeset
|
45 |
session_directories = session_directories, |
65495 | 46 |
global_theories = global_theories, |
66720 | 47 |
overall_syntax = Thy_Header.bootstrap_syntax) |
65495 | 48 |
} |
49 |
||
50 |
sealed case class Base( |
|
66571 | 51 |
pos: Position.T = Position.none, |
67471 | 52 |
doc_names: List[String] = Nil, |
70681 | 53 |
session_directories: Map[JFile, String] = Map.empty, |
65495 | 54 |
global_theories: Map[String, String] = Map.empty, |
72323
e36f94e2eb6b
some support for document preparation in Isabelle/Scala;
wenzelm
parents:
72068
diff
changeset
|
55 |
session_theories: List[Document.Node.Name] = Nil, |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
56 |
document_theories: List[Document.Node.Name] = Nil, |
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
57 |
loaded_theories: Graph[String, Outer_Syntax] = Graph.string, |
70687
086575316fd5
eliminated pointless theory graph (reverting parts of a56eab490f4e): it caused problems with loaded vs. non-loaded node names, e.g. for theory Pure (see also 29bb1ebb188f);
wenzelm
parents:
70686
diff
changeset
|
58 |
used_theories: List[(Document.Node.Name, Options)] = Nil, |
70740 | 59 |
known_theories: Map[String, Document.Node.Entry] = Map.empty, |
60 |
known_loaded_files: Map[String, List[Path]] = Map.empty, |
|
66720 | 61 |
overall_syntax: Outer_Syntax = Outer_Syntax.empty, |
66744 | 62 |
imported_sources: List[(Path, SHA1.Digest)] = Nil, |
65495 | 63 |
sources: List[(Path, SHA1.Digest)] = Nil, |
66822 | 64 |
session_graph_display: Graph_Display.Graph = Graph_Display.empty_graph, |
72064 | 65 |
errors: List[String] = Nil) |
65495 | 66 |
{ |
69102
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
67 |
override def toString: String = |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
68 |
"Sessions.Base(loaded_theories = " + loaded_theories.size + |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
69 |
", used_theories = " + used_theories.length + ")" |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
70 |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
71 |
def theory_qualifier(name: String): String = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
72 |
global_theories.getOrElse(name, Long_Name.qualifier(name)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
73 |
def theory_qualifier(name: Document.Node.Name): String = theory_qualifier(name.theory) |
66966 | 74 |
|
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
75 |
def loaded_theory(name: String): Boolean = loaded_theories.defined(name) |
66712 | 76 |
def loaded_theory(name: Document.Node.Name): Boolean = loaded_theory(name.theory) |
65432 | 77 |
|
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
78 |
def loaded_theory_syntax(name: String): Option[Outer_Syntax] = |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
79 |
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
|
80 |
def loaded_theory_syntax(name: Document.Node.Name): Option[Outer_Syntax] = |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
81 |
loaded_theory_syntax(name.theory) |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
82 |
|
72669 | 83 |
def theory_syntax(name: Document.Node.Name): Outer_Syntax = |
84 |
loaded_theory_syntax(name) getOrElse overall_syntax |
|
85 |
||
66770
122df1fde073
clarified node_syntax (amending ae38b8c0fdd9): default to overall_syntax, e.g. relevant for command spans wrt. bad header;
wenzelm
parents:
66764
diff
changeset
|
86 |
def node_syntax(nodes: Document.Nodes, name: Document.Node.Name): Outer_Syntax = |
122df1fde073
clarified node_syntax (amending ae38b8c0fdd9): default to overall_syntax, e.g. relevant for command spans wrt. bad header;
wenzelm
parents:
66764
diff
changeset
|
87 |
nodes(name).syntax orElse loaded_theory_syntax(name) getOrElse overall_syntax |
65355 | 88 |
} |
64856 | 89 |
|
70686
9cde8c4ea5a5
discontinued obsolete "isabelle imports" and all_known data;
wenzelm
parents:
70685
diff
changeset
|
90 |
sealed case class Deps(sessions_structure: Structure, session_bases: Map[String, Base]) |
65251 | 91 |
{ |
69102
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
92 |
override def toString: String = "Sessions.Deps(" + sessions_structure + ")" |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
93 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
94 |
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
|
95 |
def apply(name: String): Base = session_bases(name) |
66988 | 96 |
def get(name: String): Option[Base] = session_bases.get(name) |
66744 | 97 |
|
98 |
def imported_sources(name: String): List[SHA1.Digest] = |
|
99 |
session_bases(name).imported_sources.map(_._2) |
|
100 |
||
101 |
def sources(name: String): List[SHA1.Digest] = |
|
102 |
session_bases(name).sources.map(_._2) |
|
66571 | 103 |
|
104 |
def errors: List[String] = |
|
105 |
(for { |
|
106 |
(name, base) <- session_bases.iterator |
|
107 |
if base.errors.nonEmpty |
|
108 |
} yield cat_lines(base.errors) + |
|
109 |
"\nThe error(s) above occurred in session " + quote(name) + Position.here(base.pos) |
|
110 |
).toList |
|
111 |
||
112 |
def check_errors: Deps = |
|
113 |
errors match { |
|
114 |
case Nil => this |
|
115 |
case errs => error(cat_lines(errs)) |
|
116 |
} |
|
65251 | 117 |
} |
64856 | 118 |
|
67052 | 119 |
def deps(sessions_structure: Structure, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71642
diff
changeset
|
120 |
progress: Progress = new Progress, |
65251 | 121 |
inlined_files: Boolean = false, |
122 |
verbose: Boolean = false, |
|
123 |
list_files: Boolean = false, |
|
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66960
diff
changeset
|
124 |
check_keywords: Set[String] = Set.empty): Deps = |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
125 |
{ |
66743 | 126 |
var cache_sources = Map.empty[JFile, SHA1.Digest] |
127 |
def check_sources(paths: List[Path]): List[(Path, SHA1.Digest)] = |
|
128 |
{ |
|
129 |
for { |
|
130 |
path <- paths |
|
131 |
file = path.file |
|
132 |
if cache_sources.isDefinedAt(file) || file.isFile |
|
133 |
} |
|
134 |
yield { |
|
135 |
cache_sources.get(file) match { |
|
136 |
case Some(digest) => (path, digest) |
|
137 |
case None => |
|
138 |
val digest = SHA1.digest(file) |
|
139 |
cache_sources = cache_sources + (file -> digest) |
|
140 |
(path, digest) |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
||
67471 | 145 |
val doc_names = Doc.doc_names() |
146 |
||
71642 | 147 |
val bootstrap = |
148 |
Sessions.Base.bootstrap( |
|
149 |
sessions_structure.session_directories, |
|
150 |
sessions_structure.global_theories) |
|
151 |
||
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
152 |
val session_bases = |
71642 | 153 |
(Map("" -> bootstrap) /: sessions_structure.imports_topological_order)({ |
67023 | 154 |
case (session_bases, session_name) => |
67880 | 155 |
progress.expose_interrupt() |
65251 | 156 |
|
67024 | 157 |
val info = sessions_structure(session_name) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
158 |
try { |
72066 | 159 |
val deps_base = info.deps_base(session_bases) |
160 |
val resources = new Resources(sessions_structure, deps_base) |
|
65251 | 161 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
162 |
if (verbose || list_files) { |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
163 |
val groups = |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
164 |
if (info.groups.isEmpty) "" |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
165 |
else info.groups.mkString(" (", " ", ")") |
72670 | 166 |
progress.echo("Session " + info.chapter_session + groups) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
167 |
} |
65251 | 168 |
|
69008
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
wenzelm
parents:
68841
diff
changeset
|
169 |
val dependencies = resources.session_dependencies(info) |
65251 | 170 |
|
67053 | 171 |
val overall_syntax = dependencies.overall_syntax |
65251 | 172 |
|
72323
e36f94e2eb6b
some support for document preparation in Isabelle/Scala;
wenzelm
parents:
72068
diff
changeset
|
173 |
val session_theories = |
72565 | 174 |
dependencies.theories.filter(name => deps_base.theory_qualifier(name) == session_name) |
72323
e36f94e2eb6b
some support for document preparation in Isabelle/Scala;
wenzelm
parents:
72068
diff
changeset
|
175 |
|
67059 | 176 |
val theory_files = dependencies.theories.map(_.path) |
72068
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
177 |
|
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
178 |
val (loaded_files, loaded_files_errors) = |
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
179 |
try { |
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
180 |
if (inlined_files) (dependencies.loaded_files(Sessions.is_pure(info.name)), Nil) |
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
181 |
else (Nil, Nil) |
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
182 |
} |
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
183 |
catch { case ERROR(msg) => (Nil, List(msg)) } |
65251 | 184 |
|
66742 | 185 |
val session_files = |
66701 | 186 |
(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
|
187 |
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
|
188 |
|
67053 | 189 |
val imported_files = if (inlined_files) dependencies.imported_files else Nil |
66743 | 190 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
191 |
if (list_files) |
66742 | 192 |
progress.echo(cat_lines(session_files.map(_.implode).sorted.map(" " + _))) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
193 |
|
66719
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
194 |
if (check_keywords.nonEmpty) { |
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
195 |
Check_Keywords.check_keywords( |
66720 | 196 |
progress, overall_syntax.keywords, check_keywords, theory_files) |
66719
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
197 |
} |
65251 | 198 |
|
66822 | 199 |
val session_graph_display: Graph_Display.Graph = |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
200 |
{ |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
201 |
def session_node(name: String): Graph_Display.Node = |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
202 |
Graph_Display.Node("[" + name + "]", "session." + name) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
203 |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
204 |
def node(name: Document.Node.Name): Graph_Display.Node = |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
205 |
{ |
72066 | 206 |
val qualifier = deps_base.theory_qualifier(name) |
66780
bf54ca580bf2
theory qualifier is always session name (see also 31e8a86971a8);
wenzelm
parents:
66770
diff
changeset
|
207 |
if (qualifier == info.name) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
208 |
Graph_Display.Node(name.theory_base_name, "theory." + name.theory) |
65528 | 209 |
else session_node(qualifier) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
210 |
} |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
211 |
|
70946
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
212 |
val required_sessions = |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
213 |
dependencies.loaded_theories.all_preds(dependencies.theories.map(_.theory)) |
72066 | 214 |
.map(theory => deps_base.theory_qualifier(theory)) |
71574
95460356d633
avoid premature crash due to missing session parents/imports;
wenzelm
parents:
71569
diff
changeset
|
215 |
.filter(name => name != info.name && sessions_structure.defined(name)) |
70946
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
216 |
|
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
217 |
val required_subgraph = |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
218 |
sessions_structure.imports_graph |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
219 |
.restrict(sessions_structure.imports_graph.all_preds(required_sessions).toSet) |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
220 |
.transitive_closure |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
221 |
.restrict(required_sessions.toSet) |
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
222 |
.transitive_reduction_acyclic |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
223 |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
224 |
val graph0 = |
70946
79d23e6436d0
clarified session_graph_display: restrict sessions to actually required theories;
wenzelm
parents:
70869
diff
changeset
|
225 |
(Graph_Display.empty_graph /: required_subgraph.topological_order)( |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
226 |
{ case (g, session) => |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
227 |
val a = session_node(session) |
71601 | 228 |
val bs = required_subgraph.imm_preds(session).toList.map(session_node) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
229 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
230 |
|
67053 | 231 |
(graph0 /: dependencies.entries)( |
66714 | 232 |
{ case (g, entry) => |
233 |
val a = node(entry.name) |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70637
diff
changeset
|
234 |
val bs = entry.header.imports.map(node).filterNot(_ == a) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
235 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
236 |
} |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
237 |
|
70740 | 238 |
val known_theories = |
72066 | 239 |
(deps_base.known_theories /: |
70740 | 240 |
dependencies.entries.iterator.map(entry => entry.name.theory -> entry))(_ + _) |
241 |
||
72066 | 242 |
val known_loaded_files = deps_base.known_loaded_files ++ loaded_files |
66701 | 243 |
|
72067
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
244 |
val import_errors = |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
245 |
{ |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
246 |
val known_sessions = |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
247 |
sessions_structure.imports_requirements(List(session_name)).toSet |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
248 |
for { |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
249 |
name <- dependencies.theories |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
250 |
qualifier = deps_base.theory_qualifier(name) |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
251 |
if !known_sessions(qualifier) |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
252 |
} yield "Bad import of theory " + quote(name.toString) + |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
253 |
": need to include sessions " + quote(qualifier) + " in ROOT" |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
254 |
} |
17507b48b6f5
clarified errors: avoid accidental import from other session that happens to be within overall selection (notably "isabelle build -a");
wenzelm
parents:
72066
diff
changeset
|
255 |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
256 |
val document_errors = |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
257 |
info.document_theories.flatMap( |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
258 |
{ |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
259 |
case (thy, pos) => |
72647
fd6dc1a4b9ca
more robust, e.g. for "isabelle build_doc system";
wenzelm
parents:
72634
diff
changeset
|
260 |
val parent_sessions = |
fd6dc1a4b9ca
more robust, e.g. for "isabelle build_doc system";
wenzelm
parents:
72634
diff
changeset
|
261 |
if (sessions_structure.build_graph.defined(session_name)) { |
fd6dc1a4b9ca
more robust, e.g. for "isabelle build_doc system";
wenzelm
parents:
72634
diff
changeset
|
262 |
sessions_structure.build_requirements(List(session_name)) |
fd6dc1a4b9ca
more robust, e.g. for "isabelle build_doc system";
wenzelm
parents:
72634
diff
changeset
|
263 |
} |
fd6dc1a4b9ca
more robust, e.g. for "isabelle build_doc system";
wenzelm
parents:
72634
diff
changeset
|
264 |
else Nil |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
265 |
|
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
266 |
def err(msg: String): Option[String] = |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
267 |
Some(msg + " " + quote(thy) + Position.here(pos)) |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
268 |
|
72604 | 269 |
known_theories.get(thy).map(_.name) match { |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
270 |
case None => err("Unknown document theory") |
72604 | 271 |
case Some(name) => |
272 |
val qualifier = deps_base.theory_qualifier(name) |
|
273 |
if (session_theories.contains(name)) { |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
274 |
err("Redundant document theory from this session:") |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
275 |
} |
72604 | 276 |
else if (parent_sessions.contains(qualifier)) None |
277 |
else if (dependencies.theories.contains(name)) None |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
278 |
else err("Document theory from other session not imported properly:") |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
279 |
} |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
280 |
}) |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
281 |
val document_theories = |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
282 |
info.document_theories.map({ case (thy, _) => known_theories(thy).name }) |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
283 |
|
70676 | 284 |
val dir_errors = |
285 |
{ |
|
70681 | 286 |
val ok = info.dirs.map(_.canonical_file).toSet |
70679 | 287 |
val bad = |
288 |
(for { |
|
72565 | 289 |
name <- session_theories.iterator |
70719 | 290 |
path = name.master_dir_path |
70676 | 291 |
if !ok(path.canonical_file) |
70679 | 292 |
path1 = File.relative_path(info.dir.canonical, path).getOrElse(path) |
293 |
} yield (path1, name)).toList |
|
71602 | 294 |
val bad_dirs = (for { (path1, _) <- bad } yield path1.toString).distinct.sorted |
70679 | 295 |
|
296 |
val errs1 = |
|
297 |
for { (path1, name) <- bad } |
|
298 |
yield "Implicit use of directory " + path1 + " for theory " + quote(name.toString) |
|
299 |
val errs2 = |
|
300 |
if (bad_dirs.isEmpty) Nil |
|
301 |
else List("Implicit use of session directories: " + commas(bad_dirs)) |
|
70693 | 302 |
val errs3 = for (p <- info.dirs if !p.is_dir) yield "No such directory: " + p |
70719 | 303 |
val errs4 = |
304 |
(for { |
|
72565 | 305 |
name <- session_theories.iterator |
70719 | 306 |
name1 <- resources.find_theory_node(name.theory) |
307 |
if name.node != name1.node |
|
308 |
} yield "Incoherent theory file import:\n " + name.path + " vs. \n " + name1.path) |
|
309 |
.toList |
|
70693 | 310 |
|
70719 | 311 |
errs1 ::: errs2 ::: errs3 ::: errs4 |
70676 | 312 |
} |
313 |
||
66743 | 314 |
val sources_errors = |
315 |
for (p <- session_files if !p.is_file) yield "No such file: " + p |
|
66604 | 316 |
|
69904 | 317 |
val path_errors = |
318 |
try { Path.check_case_insensitive(session_files ::: imported_files); Nil } |
|
319 |
catch { case ERROR(msg) => List(msg) } |
|
320 |
||
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
321 |
val bibtex_errors = |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
322 |
try { info.bibtex_entries; Nil } |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
323 |
catch { case ERROR(msg) => List(msg) } |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
324 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
325 |
val base = |
66571 | 326 |
Base( |
327 |
pos = info.pos, |
|
67471 | 328 |
doc_names = doc_names, |
70673
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
wenzelm
parents:
70672
diff
changeset
|
329 |
session_directories = sessions_structure.session_directories, |
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
330 |
global_theories = sessions_structure.global_theories, |
72323
e36f94e2eb6b
some support for document preparation in Isabelle/Scala;
wenzelm
parents:
72068
diff
changeset
|
331 |
session_theories = session_theories, |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
332 |
document_theories = document_theories, |
67053 | 333 |
loaded_theories = dependencies.loaded_theories, |
72062 | 334 |
used_theories = dependencies.theories_adjunct, |
70740 | 335 |
known_theories = known_theories, |
336 |
known_loaded_files = known_loaded_files, |
|
66720 | 337 |
overall_syntax = overall_syntax, |
66744 | 338 |
imported_sources = check_sources(imported_files), |
66743 | 339 |
sources = check_sources(session_files), |
66822 | 340 |
session_graph_display = session_graph_display, |
72068
4768b1facec2
clarified errors: avoid hiding of import_errors/dir_errors by their consequences (file-access problems);
wenzelm
parents:
72067
diff
changeset
|
341 |
errors = dependencies.errors ::: loaded_files_errors ::: import_errors ::: |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
342 |
document_errors ::: dir_errors ::: sources_errors ::: path_errors ::: |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
343 |
bibtex_errors) |
65251 | 344 |
|
65519 | 345 |
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
|
346 |
} |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
347 |
catch { |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
348 |
case ERROR(msg) => |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
349 |
cat_error(msg, "The error(s) above occurred in session " + |
65519 | 350 |
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
|
351 |
} |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
352 |
}) |
65251 | 353 |
|
70686
9cde8c4ea5a5
discontinued obsolete "isabelle imports" and all_known data;
wenzelm
parents:
70685
diff
changeset
|
354 |
Deps(sessions_structure, session_bases) |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
355 |
} |
65251 | 356 |
|
66963 | 357 |
|
358 |
/* base info */ |
|
359 |
||
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
360 |
sealed case class Base_Info( |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
361 |
session: String, |
67052 | 362 |
sessions_structure: Structure, |
66975 | 363 |
errors: List[String], |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
364 |
base: Base, |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
365 |
infos: List[Info]) |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
366 |
{ |
72627 | 367 |
def check: Base_Info = if (errors.isEmpty) this else error(cat_lines(errors)) |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
368 |
} |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
369 |
|
67846 | 370 |
def base_info(options: Options, |
371 |
session: String, |
|
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71642
diff
changeset
|
372 |
progress: Progress = new Progress, |
65428 | 373 |
dirs: List[Path] = Nil, |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
374 |
include_sessions: List[String] = Nil, |
68370 | 375 |
session_ancestor: Option[String] = None, |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
376 |
session_requirements: Boolean = false): Base_Info = |
65251 | 377 |
{ |
67026 | 378 |
val full_sessions = load_structure(options, dirs = dirs) |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
379 |
|
66990 | 380 |
val selected_sessions = |
68370 | 381 |
full_sessions.selection(Selection(sessions = session :: session_ancestor.toList)) |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
382 |
val info = selected_sessions(session) |
68370 | 383 |
val ancestor = session_ancestor orElse info.parent |
66963 | 384 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
385 |
val (session1, infos1) = |
68370 | 386 |
if (session_requirements && ancestor.isDefined) { |
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
387 |
val deps = Sessions.deps(selected_sessions, progress = progress) |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
388 |
val base = deps(session) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
389 |
|
66988 | 390 |
val ancestor_loaded = |
391 |
deps.get(ancestor.get) match { |
|
66990 | 392 |
case Some(ancestor_base) |
393 |
if !selected_sessions.imports_requirements(List(ancestor.get)).contains(session) => |
|
71601 | 394 |
ancestor_base.loaded_theories.defined _ |
66990 | 395 |
case _ => |
66988 | 396 |
error("Bad ancestor " + quote(ancestor.get) + " for session " + quote(session)) |
397 |
} |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
398 |
|
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
399 |
val required_theories = |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
400 |
for { |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
401 |
thy <- base.loaded_theories.keys |
66988 | 402 |
if !ancestor_loaded(thy) && base.theory_qualifier(thy) != session |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
403 |
} |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
404 |
yield thy |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
405 |
|
66988 | 406 |
if (required_theories.isEmpty) (ancestor.get, Nil) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
407 |
else { |
68370 | 408 |
val other_name = info.name + "_requirements(" + ancestor.get + ")" |
71569
391ea80ff27c
more robust re-use of $ISABELLE_TMP_PREFIX (amending c1597167563e);
wenzelm
parents:
70946
diff
changeset
|
409 |
Isabelle_System.isabelle_tmp_prefix() |
391ea80ff27c
more robust re-use of $ISABELLE_TMP_PREFIX (amending c1597167563e);
wenzelm
parents:
70946
diff
changeset
|
410 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
411 |
(other_name, |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
412 |
List( |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
413 |
make_info(info.options, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
414 |
dir_selected = false, |
70685
c1597167563e
avoid duplicate directories wrt. synthetic session;
wenzelm
parents:
70684
diff
changeset
|
415 |
dir = Path.explode("$ISABELLE_TMP_PREFIX"), |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
416 |
chapter = info.chapter, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
417 |
Session_Entry( |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
418 |
pos = info.pos, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
419 |
name = other_name, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
420 |
groups = info.groups, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
421 |
path = ".", |
66988 | 422 |
parent = ancestor, |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
423 |
description = "Required theory imports from other sessions", |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
424 |
options = Nil, |
66991 | 425 |
imports = info.deps, |
70678
36c8c32346cb
clarified syntax: 'directories' and 'theories' belong together;
wenzelm
parents:
70676
diff
changeset
|
426 |
directories = Nil, |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
427 |
theories = List((Nil, required_theories.map(thy => ((thy, Position.none), false)))), |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
428 |
document_theories = Nil, |
68292 | 429 |
document_files = Nil, |
430 |
export_files = Nil)))) |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
431 |
} |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
432 |
} |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
433 |
else (session, Nil) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
434 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
435 |
val full_sessions1 = |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
436 |
if (infos1.isEmpty) full_sessions |
67026 | 437 |
else load_structure(options, dirs = dirs, infos = infos1) |
66987
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66984
diff
changeset
|
438 |
|
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66984
diff
changeset
|
439 |
val selected_sessions1 = |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
440 |
full_sessions1.selection(Selection(sessions = session1 :: session :: include_sessions)) |
66964 | 441 |
|
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
442 |
val deps1 = Sessions.deps(selected_sessions1, progress = progress) |
66964 | 443 |
|
71599 | 444 |
Base_Info(session1, full_sessions1, deps1.errors, deps1(session1), infos1) |
65251 | 445 |
} |
446 |
||
447 |
||
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
448 |
/* cumulative session info */ |
62631 | 449 |
|
450 |
sealed case class Info( |
|
65519 | 451 |
name: String, |
62631 | 452 |
chapter: String, |
66829 | 453 |
dir_selected: Boolean, |
62631 | 454 |
pos: Position.T, |
455 |
groups: List[String], |
|
456 |
dir: Path, |
|
457 |
parent: Option[String], |
|
458 |
description: String, |
|
70681 | 459 |
directories: List[Path], |
62631 | 460 |
options: Options, |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
461 |
imports: List[String], |
65517 | 462 |
theories: List[(Options, List[(String, Position.T)])], |
65374 | 463 |
global_theories: List[String], |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
464 |
document_theories: List[(String, Position.T)], |
62631 | 465 |
document_files: List[(Path, Path)], |
69671 | 466 |
export_files: List[(Path, Int, List[String])], |
62631 | 467 |
meta_digest: SHA1.Digest) |
468 |
{ |
|
72670 | 469 |
def chapter_session: String = chapter + "/" + name |
470 |
||
66828 | 471 |
def deps: List[String] = parent.toList ::: imports |
472 |
||
72066 | 473 |
def deps_base(session_bases: String => Base): Base = |
474 |
{ |
|
475 |
val parent_base = session_bases(parent.getOrElse("")) |
|
476 |
val imports_bases = imports.map(session_bases) |
|
477 |
parent_base.copy( |
|
478 |
known_theories = |
|
479 |
(parent_base.known_theories /: |
|
480 |
(for { |
|
481 |
base <- imports_bases.iterator |
|
482 |
(_, entry) <- base.known_theories.iterator |
|
483 |
} yield (entry.name.theory -> entry)))(_ + _), |
|
484 |
known_loaded_files = |
|
485 |
(parent_base.known_loaded_files /: |
|
486 |
imports_bases.iterator.map(_.known_loaded_files))(_ ++ _)) |
|
487 |
} |
|
488 |
||
70681 | 489 |
def dirs: List[Path] = dir :: directories |
70668 | 490 |
|
62631 | 491 |
def timeout: Time = Time.seconds(options.real("timeout") * options.real("timeout_scale")) |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
492 |
|
72574
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
493 |
def document_enabled: Boolean = |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
494 |
options.string("document") match { |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
495 |
case "" | "false" => false |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
496 |
case "pdf" => true |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
497 |
case doc => error("Bad document specification " + quote(doc)) |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
498 |
} |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
499 |
|
72672 | 500 |
def document_variants: List[Presentation.Document_Variant] = |
72574
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
501 |
{ |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
502 |
val variants = |
72649 | 503 |
Library.space_explode(':', options.string("document_variants")). |
72652 | 504 |
map(Presentation.Document_Variant.parse) |
72649 | 505 |
|
506 |
val dups = Library.duplicates(variants.map(_.name)) |
|
72574
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
507 |
if (dups.nonEmpty) error("Duplicate document variants: " + commas_quote(dups)) |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
508 |
|
72649 | 509 |
variants |
510 |
} |
|
511 |
||
72652 | 512 |
def documents: List[Presentation.Document_Variant] = |
72649 | 513 |
{ |
72672 | 514 |
val variants = document_variants |
72574
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
515 |
if (!document_enabled || document_files.isEmpty) Nil else variants |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
516 |
} |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
517 |
|
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
518 |
def document_output: Option[Path] = |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
519 |
options.string("document_output") match { |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
520 |
case "" => None |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
521 |
case s => Some(dir + Path.explode(s)) |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
522 |
} |
d892f6d66402
build documents in Isabelle/Scala, based on generated tex files as session exports;
wenzelm
parents:
72571
diff
changeset
|
523 |
|
72648 | 524 |
def browser_info: Boolean = options.bool("browser_info") |
525 |
||
72613
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
526 |
lazy val bibtex_entries: List[Text.Info[String]] = |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
527 |
(for { |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
528 |
(document_dir, file) <- document_files.iterator |
69366 | 529 |
if Bibtex.is_bibtex(file.file_name) |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
530 |
info <- Bibtex.entries(File.read(dir + document_dir + file)).iterator |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
531 |
} yield info).toList |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
532 |
|
70869 | 533 |
def record_proofs: Boolean = options.int("record_proofs") >= 2 |
534 |
||
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
535 |
def is_afp: Boolean = chapter == AFP.chapter |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
536 |
def is_afp_bulky: Boolean = is_afp && groups.exists(AFP.groups_bulky.contains) |
62631 | 537 |
} |
538 |
||
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
539 |
def make_info(options: Options, dir_selected: Boolean, dir: Path, chapter: String, |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
540 |
entry: Session_Entry): Info = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
541 |
{ |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
542 |
try { |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
543 |
val name = entry.name |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
544 |
|
67284 | 545 |
if (exclude_session(name)) error("Bad session name") |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
546 |
if (is_pure(name) && entry.parent.isDefined) error("Illegal parent session") |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
547 |
if (!is_pure(name) && !entry.parent.isDefined) error("Missing parent session") |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
548 |
|
70672
e4bba654d085
clarified session_directories: relative to session_path, with overlapping information;
wenzelm
parents:
70671
diff
changeset
|
549 |
val session_path = dir + Path.explode(entry.path) |
70681 | 550 |
val directories = entry.directories.map(dir => session_path + Path.explode(dir)) |
70668 | 551 |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
552 |
val session_options = options ++ entry.options |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
553 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
554 |
val theories = |
67216 | 555 |
entry.theories.map({ case (opts, thys) => |
556 |
(session_options ++ opts, |
|
557 |
thys.map({ case ((thy, pos), _) => |
|
67284 | 558 |
if (exclude_theory(thy)) |
67216 | 559 |
error("Bad theory name " + quote(thy) + Position.here(pos)) |
560 |
else (thy, pos) })) }) |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
561 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
562 |
val global_theories = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
563 |
for { (_, thys) <- entry.theories; ((thy, pos), global) <- thys if global } |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
564 |
yield { |
69366 | 565 |
val thy_name = Path.explode(thy).file_name |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
566 |
if (Long_Name.is_qualified(thy_name)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
567 |
error("Bad qualified name for global theory " + |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
568 |
quote(thy_name) + Position.here(pos)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
569 |
else thy_name |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
570 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
571 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
572 |
val conditions = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
573 |
theories.flatMap(thys => space_explode(',', thys._1.string("condition"))).distinct.sorted. |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
574 |
map(x => (x, Isabelle_System.getenv(x) != "")) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
575 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
576 |
val document_files = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
577 |
entry.document_files.map({ case (s1, s2) => (Path.explode(s1), Path.explode(s2)) }) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
578 |
|
68292 | 579 |
val export_files = |
69671 | 580 |
entry.export_files.map({ case (dir, prune, pats) => (Path.explode(dir), prune, pats) }) |
68292 | 581 |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
582 |
val meta_digest = |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
583 |
SHA1.digest( |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
584 |
(name, chapter, entry.parent, entry.directories, entry.options, entry.imports, |
72666
945cee776e79
proper meta_digest: avoid non-portable position information;
wenzelm
parents:
72653
diff
changeset
|
585 |
entry.theories_no_position, conditions, entry.document_theories_no_position, |
945cee776e79
proper meta_digest: avoid non-portable position information;
wenzelm
parents:
72653
diff
changeset
|
586 |
entry.document_files) |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
587 |
.toString) |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
588 |
|
70672
e4bba654d085
clarified session_directories: relative to session_path, with overlapping information;
wenzelm
parents:
70671
diff
changeset
|
589 |
Info(name, chapter, dir_selected, entry.pos, entry.groups, session_path, |
70668 | 590 |
entry.parent, entry.description, directories, session_options, |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
591 |
entry.imports, theories, global_theories, entry.document_theories, document_files, |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
592 |
export_files, meta_digest) |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
593 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
594 |
catch { |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
595 |
case ERROR(msg) => |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
596 |
error(msg + "\nThe error(s) above occurred in session entry " + |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
597 |
quote(entry.name) + Position.here(entry.pos)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
598 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
599 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
600 |
|
65419 | 601 |
object Selection |
602 |
{ |
|
65422 | 603 |
val empty: Selection = Selection() |
65525 | 604 |
val all: Selection = Selection(all_sessions = true) |
70788 | 605 |
def session(session: String): Selection = Selection(sessions = List(session)) |
65419 | 606 |
} |
607 |
||
608 |
sealed case class Selection( |
|
609 |
requirements: Boolean = false, |
|
610 |
all_sessions: Boolean = false, |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
611 |
base_sessions: List[String] = Nil, |
65419 | 612 |
exclude_session_groups: List[String] = Nil, |
613 |
exclude_sessions: List[String] = Nil, |
|
614 |
session_groups: List[String] = Nil, |
|
615 |
sessions: List[String] = Nil) |
|
616 |
{ |
|
66736 | 617 |
def ++ (other: Selection): Selection = |
65422 | 618 |
Selection( |
619 |
requirements = requirements || other.requirements, |
|
620 |
all_sessions = all_sessions || other.all_sessions, |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
621 |
base_sessions = Library.merge(base_sessions, other.base_sessions), |
66736 | 622 |
exclude_session_groups = Library.merge(exclude_session_groups, other.exclude_session_groups), |
623 |
exclude_sessions = Library.merge(exclude_sessions, other.exclude_sessions), |
|
624 |
session_groups = Library.merge(session_groups, other.session_groups), |
|
625 |
sessions = Library.merge(sessions, other.sessions)) |
|
65419 | 626 |
} |
627 |
||
67052 | 628 |
def make(infos: List[Info]): Structure = |
62631 | 629 |
{ |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
630 |
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
|
631 |
: Graph[String, Info] = |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
632 |
{ |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
633 |
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
|
634 |
{ |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
635 |
if (!g.defined(parent)) |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
636 |
error("Bad " + kind + " session " + quote(parent) + " for " + |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
637 |
quote(name) + Position.here(pos)) |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
638 |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
639 |
try { g.add_edge_acyclic(parent, name) } |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
640 |
catch { |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
641 |
case exn: Graph.Cycles[_] => |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
642 |
error(cat_lines(exn.cycles.map(cycle => |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
643 |
"Cyclic session dependency of " + |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
644 |
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
|
645 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
646 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
647 |
(graph /: graph.iterator) { |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
648 |
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
|
649 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
650 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
651 |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
652 |
val info_graph = |
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
653 |
(Graph.string[Info] /: infos) { |
66960 | 654 |
case (graph, info) => |
655 |
if (graph.defined(info.name)) |
|
656 |
error("Duplicate session " + quote(info.name) + Position.here(info.pos) + |
|
657 |
Position.here(graph.get_node(info.name).pos)) |
|
658 |
else graph.new_node(info.name, info) |
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
659 |
} |
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
660 |
val build_graph = add_edges(info_graph, "parent", _.parent) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
661 |
val imports_graph = add_edges(build_graph, "imports", _.imports) |
62631 | 662 |
|
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
663 |
val session_positions: List[(String, Position.T)] = |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
664 |
(for ((name, (info, _)) <- info_graph.iterator) yield (name, info.pos)).toList |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
665 |
|
70681 | 666 |
val session_directories: Map[JFile, String] = |
667 |
(Map.empty[JFile, String] /: |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
668 |
(for { |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
669 |
session <- imports_graph.topological_order.iterator |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
670 |
info = info_graph.get_node(session) |
70681 | 671 |
dir <- info.dirs.iterator |
672 |
} yield (info, dir)))({ case (dirs, (info, dir)) => |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
673 |
val session = info.name |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
674 |
val canonical_dir = dir.canonical_file |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
675 |
dirs.get(canonical_dir) match { |
70684
60b1eda998f3
disallow accidental duplicates within the same session specification -- proper total match;
wenzelm
parents:
70683
diff
changeset
|
676 |
case Some(session1) => |
70681 | 677 |
val info1 = info_graph.get_node(session1) |
678 |
error("Duplicate use of directory " + dir + |
|
679 |
"\n for session " + quote(session1) + Position.here(info1.pos) + |
|
680 |
"\n vs. session " + quote(session) + Position.here(info.pos)) |
|
681 |
case None => dirs + (canonical_dir -> session) |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
682 |
} |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
683 |
}) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
684 |
|
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
685 |
val global_theories: Map[String, String] = |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
686 |
(Thy_Header.bootstrap_global_theories.toMap /: |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
687 |
(for { |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
688 |
session <- imports_graph.topological_order.iterator |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
689 |
info = info_graph.get_node(session) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
690 |
thy <- info.global_theories.iterator } |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
691 |
yield (info, thy)))({ case (global, (info, thy)) => |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
692 |
val qualifier = info.name |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
693 |
global.get(thy) match { |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
694 |
case Some(qualifier1) if qualifier != qualifier1 => |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
695 |
error("Duplicate global theory " + quote(thy) + Position.here(info.pos)) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
696 |
case _ => global + (thy -> qualifier) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
697 |
} |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
698 |
}) |
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
699 |
|
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
700 |
new Structure( |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
701 |
session_positions, session_directories, global_theories, build_graph, imports_graph) |
62631 | 702 |
} |
703 |
||
67052 | 704 |
final class Structure private[Sessions]( |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
705 |
val session_positions: List[(String, Position.T)], |
70681 | 706 |
val session_directories: Map[JFile, String], |
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
707 |
val global_theories: Map[String, String], |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
708 |
val build_graph: Graph[String, Info], |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
709 |
val imports_graph: Graph[String, Info]) |
62631 | 710 |
{ |
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
711 |
sessions_structure => |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
712 |
|
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
713 |
def dest_session_directories: List[(String, String)] = |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
714 |
for ((file, session) <- session_directories.toList) |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
715 |
yield (File.standard_path(file), session) |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
716 |
|
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
717 |
lazy val chapters: SortedMap[String, List[Info]] = |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
718 |
(SortedMap.empty[String, List[Info]] /: build_graph.iterator)( |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
719 |
{ case (chs, (_, (info, _))) => |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
720 |
chs + (info.chapter -> (info :: chs.getOrElse(info.chapter, Nil))) }) |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
721 |
|
66823 | 722 |
def build_graph_display: Graph_Display.Graph = Graph_Display.make_graph(build_graph) |
723 |
def imports_graph_display: Graph_Display.Graph = Graph_Display.make_graph(imports_graph) |
|
724 |
||
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
725 |
def defined(name: String): Boolean = imports_graph.defined(name) |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
726 |
def apply(name: String): Info = imports_graph.get_node(name) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
727 |
def get(name: String): Option[Info] = if (defined(name)) Some(apply(name)) else None |
62631 | 728 |
|
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
729 |
def theory_qualifier(name: String): String = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
730 |
global_theories.getOrElse(name, Long_Name.qualifier(name)) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70796
diff
changeset
|
731 |
|
68542 | 732 |
def check_sessions(names: List[String]) |
733 |
{ |
|
71601 | 734 |
val bad_sessions = SortedSet(names.filterNot(defined): _*).toList |
68542 | 735 |
if (bad_sessions.nonEmpty) |
736 |
error("Undefined session(s): " + commas_quote(bad_sessions)) |
|
737 |
} |
|
738 |
||
68733 | 739 |
def check_sessions(sel: Selection): Unit = |
740 |
check_sessions(sel.base_sessions ::: sel.exclude_sessions ::: sel.sessions) |
|
741 |
||
68732 | 742 |
private def selected(graph: Graph[String, Info], sel: Selection): List[String] = |
743 |
{ |
|
68733 | 744 |
check_sessions(sel) |
745 |
||
68732 | 746 |
val select_group = sel.session_groups.toSet |
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
747 |
val select_session = sel.sessions.toSet ++ imports_graph.all_succs(sel.base_sessions) |
68732 | 748 |
|
749 |
val selected0 = |
|
750 |
if (sel.all_sessions) graph.keys |
|
751 |
else { |
|
752 |
(for { |
|
753 |
(name, (info, _)) <- graph.iterator |
|
754 |
if info.dir_selected || select_session(name) || |
|
755 |
graph.get_node(name).groups.exists(select_group) |
|
756 |
} yield name).toList |
|
757 |
} |
|
758 |
||
759 |
if (sel.requirements) (graph.all_preds(selected0).toSet -- selected0).toList |
|
760 |
else selected0 |
|
761 |
} |
|
762 |
||
67052 | 763 |
def selection(sel: Selection): Structure = |
62631 | 764 |
{ |
68733 | 765 |
check_sessions(sel) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
766 |
|
68732 | 767 |
val excluded = |
768 |
{ |
|
769 |
val exclude_group = sel.exclude_session_groups.toSet |
|
770 |
val exclude_group_sessions = |
|
771 |
(for { |
|
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
772 |
(name, (info, _)) <- imports_graph.iterator |
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
773 |
if imports_graph.get_node(name).groups.exists(exclude_group) |
68732 | 774 |
} yield name).toList |
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
775 |
imports_graph.all_succs(exclude_group_sessions ::: sel.exclude_sessions).toSet |
68732 | 776 |
} |
67027 | 777 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
778 |
def restrict(graph: Graph[String, Info]): Graph[String, Info] = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
779 |
{ |
68732 | 780 |
val sessions = graph.all_preds(selected(graph, sel)).filterNot(excluded) |
67029 | 781 |
graph.restrict(graph.all_preds(sessions).toSet) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
782 |
} |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
783 |
|
70671
cb1776c8e216
clarified signature: retain global session information, unaffected by later restriction;
wenzelm
parents:
70668
diff
changeset
|
784 |
new Structure( |
70683
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
785 |
session_positions, session_directories, global_theories, |
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents:
70681
diff
changeset
|
786 |
restrict(build_graph), restrict(imports_graph)) |
62631 | 787 |
} |
788 |
||
72571 | 789 |
def selection(session: String): Structure = selection(Selection.session(session)) |
790 |
||
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
791 |
def selection_deps( |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
792 |
selection: Selection, |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71642
diff
changeset
|
793 |
progress: Progress = new Progress, |
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
794 |
loading_sessions: Boolean = false, |
68304 | 795 |
inlined_files: Boolean = false, |
796 |
verbose: Boolean = false): Deps = |
|
797 |
{ |
|
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
798 |
val deps = |
70869 | 799 |
Sessions.deps(sessions_structure.selection(selection), |
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
800 |
progress = progress, inlined_files = inlined_files, verbose = verbose) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
801 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
802 |
if (loading_sessions) { |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
803 |
val selection_size = deps.sessions_structure.build_graph.size |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
804 |
if (selection_size > 1) progress.echo("Loading " + selection_size + " sessions ...") |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
805 |
} |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
806 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
807 |
deps |
68304 | 808 |
} |
809 |
||
68732 | 810 |
def build_selection(sel: Selection): List[String] = selected(build_graph, sel) |
67029 | 811 |
def build_descendants(ss: List[String]): List[String] = build_graph.all_succs(ss) |
72065
11dc8929832d
clarified order --- proper sorting of requirements;
wenzelm
parents:
72064
diff
changeset
|
812 |
def build_requirements(ss: List[String]): List[String] = build_graph.all_preds_rev(ss) |
67029 | 813 |
def build_topological_order: List[String] = build_graph.topological_order |
62631 | 814 |
|
68732 | 815 |
def imports_selection(sel: Selection): List[String] = selected(imports_graph, sel) |
67029 | 816 |
def imports_descendants(ss: List[String]): List[String] = imports_graph.all_succs(ss) |
72065
11dc8929832d
clarified order --- proper sorting of requirements;
wenzelm
parents:
72064
diff
changeset
|
817 |
def imports_requirements(ss: List[String]): List[String] = imports_graph.all_preds_rev(ss) |
67029 | 818 |
def imports_topological_order: List[String] = imports_graph.topological_order |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
819 |
|
72613
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
820 |
def bibtex_entries: List[(String, List[String])] = |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
821 |
build_topological_order.flatMap(name => |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
822 |
apply(name).bibtex_entries match { |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
823 |
case Nil => None |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
824 |
case entries => Some(name -> entries.map(_.info)) |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
825 |
}) |
d01ea9e3bd2d
clarified bibtex_entries: refer to overall session structure;
wenzelm
parents:
72604
diff
changeset
|
826 |
|
72616 | 827 |
def session_chapters: List[(String, String)] = |
72626
5a616815cc44
clarified signature: theory imports could be from other sessions;
wenzelm
parents:
72622
diff
changeset
|
828 |
imports_topological_order.map(name => name -> apply(name).chapter) |
72616 | 829 |
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
830 |
override def toString: String = |
67052 | 831 |
imports_graph.keys_iterator.mkString("Sessions.Structure(", ", ", ")") |
62631 | 832 |
} |
833 |
||
834 |
||
835 |
/* parser */ |
|
836 |
||
71601 | 837 |
val ROOT: Path = Path.explode("ROOT") |
838 |
val ROOTS: Path = Path.explode("ROOTS") |
|
62864 | 839 |
|
62631 | 840 |
private val CHAPTER = "chapter" |
841 |
private val SESSION = "session" |
|
842 |
private val IN = "in" |
|
843 |
private val DESCRIPTION = "description" |
|
70668 | 844 |
private val DIRECTORIES = "directories" |
62631 | 845 |
private val OPTIONS = "options" |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
846 |
private val SESSIONS = "sessions" |
62631 | 847 |
private val THEORIES = "theories" |
65374 | 848 |
private val GLOBAL = "global" |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
849 |
private val DOCUMENT_THEORIES = "document_theories" |
62631 | 850 |
private val DOCUMENT_FILES = "document_files" |
68292 | 851 |
private val EXPORT_FILES = "export_files" |
62631 | 852 |
|
71601 | 853 |
val root_syntax: Outer_Syntax = |
70668 | 854 |
Outer_Syntax.empty + "(" + ")" + "+" + "," + "=" + "[" + "]" + |
70681 | 855 |
GLOBAL + IN + |
63443 | 856 |
(CHAPTER, Keyword.THY_DECL) + |
857 |
(SESSION, Keyword.THY_DECL) + |
|
858 |
(DESCRIPTION, Keyword.QUASI_COMMAND) + |
|
70668 | 859 |
(DIRECTORIES, Keyword.QUASI_COMMAND) + |
63443 | 860 |
(OPTIONS, Keyword.QUASI_COMMAND) + |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
861 |
(SESSIONS, Keyword.QUASI_COMMAND) + |
63443 | 862 |
(THEORIES, Keyword.QUASI_COMMAND) + |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
863 |
(DOCUMENT_THEORIES, Keyword.QUASI_COMMAND) + |
68292 | 864 |
(DOCUMENT_FILES, Keyword.QUASI_COMMAND) + |
865 |
(EXPORT_FILES, Keyword.QUASI_COMMAND) |
|
62631 | 866 |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
867 |
abstract class Entry |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
868 |
sealed case class Chapter(name: String) extends Entry |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
869 |
sealed case class Session_Entry( |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
870 |
pos: Position.T, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
871 |
name: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
872 |
groups: List[String], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
873 |
path: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
874 |
parent: Option[String], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
875 |
description: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
876 |
options: List[Options.Spec], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
877 |
imports: List[String], |
70681 | 878 |
directories: List[String], |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
879 |
theories: List[(List[Options.Spec], List[((String, Position.T), Boolean)])], |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
880 |
document_theories: List[(String, Position.T)], |
68292 | 881 |
document_files: List[(String, String)], |
69671 | 882 |
export_files: List[(String, Int, List[String])]) extends Entry |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
883 |
{ |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
884 |
def theories_no_position: List[(List[Options.Spec], List[(String, Boolean)])] = |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
885 |
theories.map({ case (a, b) => (a, b.map({ case ((c, _), d) => (c, d) })) }) |
72666
945cee776e79
proper meta_digest: avoid non-portable position information;
wenzelm
parents:
72653
diff
changeset
|
886 |
def document_theories_no_position: List[String] = |
945cee776e79
proper meta_digest: avoid non-portable position information;
wenzelm
parents:
72653
diff
changeset
|
887 |
document_theories.map(_._1) |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
888 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
889 |
|
68841 | 890 |
private object Parser extends Options.Parser |
62631 | 891 |
{ |
892 |
private val chapter: Parser[Chapter] = |
|
893 |
{ |
|
894 |
val chapter_name = atom("chapter name", _.is_name) |
|
895 |
||
896 |
command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) } |
|
897 |
} |
|
898 |
||
899 |
private val session_entry: Parser[Session_Entry] = |
|
900 |
{ |
|
901 |
val option = |
|
67210 | 902 |
option_name ~ opt($$$("=") ~! option_value ^^ { case _ ~ x => x }) ^^ |
903 |
{ case x ~ y => (x, y) } |
|
62631 | 904 |
val options = $$$("[") ~> rep1sep(option, $$$(",")) <~ $$$("]") |
905 |
||
65374 | 906 |
val theory_entry = |
70668 | 907 |
position(theory_name) ~ opt_keyword(GLOBAL) ^^ { case x ~ y => (x, y) } |
65374 | 908 |
|
62631 | 909 |
val theories = |
65374 | 910 |
$$$(THEORIES) ~! |
66970
13857f49d215
clarified ROOT syntax: 'sessions' and 'theories' are optional, but need to be non-empty;
wenzelm
parents:
66969
diff
changeset
|
911 |
((options | success(Nil)) ~ rep1(theory_entry)) ^^ |
65374 | 912 |
{ case _ ~ (x ~ y) => (x, y) } |
62631 | 913 |
|
68292 | 914 |
val in_path = $$$("(") ~! ($$$(IN) ~ path ~ $$$(")")) ^^ { case _ ~ (_ ~ x ~ _) => x } |
915 |
||
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
916 |
val document_theories = |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
917 |
$$$(DOCUMENT_THEORIES) ~! rep1(position(name)) ^^ { case _ ~ x => x } |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
918 |
|
62631 | 919 |
val document_files = |
920 |
$$$(DOCUMENT_FILES) ~! |
|
68292 | 921 |
((in_path | success("document")) ~ rep1(path)) ^^ { case _ ~ (x ~ y) => y.map((x, _)) } |
922 |
||
69671 | 923 |
val prune = $$$("[") ~! (nat ~ $$$("]")) ^^ { case _ ~ (x ~ _) => x } | success(0) |
924 |
||
68292 | 925 |
val export_files = |
69671 | 926 |
$$$(EXPORT_FILES) ~! ((in_path | success("export")) ~ prune ~ rep1(embedded)) ^^ |
927 |
{ case _ ~ (x ~ y ~ z) => (x, y, z) } |
|
62631 | 928 |
|
929 |
command(SESSION) ~! |
|
930 |
(position(session_name) ~ |
|
931 |
(($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~ |
|
932 |
(($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~ |
|
933 |
($$$("=") ~! |
|
934 |
(opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~ |
|
935 |
(($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~ |
|
936 |
(($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~ |
|
66970
13857f49d215
clarified ROOT syntax: 'sessions' and 'theories' are optional, but need to be non-empty;
wenzelm
parents:
66969
diff
changeset
|
937 |
(($$$(SESSIONS) ~! rep1(session_name) ^^ { case _ ~ x => x }) | success(Nil)) ~ |
70681 | 938 |
(($$$(DIRECTORIES) ~! rep1(path) ^^ { case _ ~ x => x }) | success(Nil)) ~ |
66970
13857f49d215
clarified ROOT syntax: 'sessions' and 'theories' are optional, but need to be non-empty;
wenzelm
parents:
66969
diff
changeset
|
939 |
rep(theories) ~ |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
940 |
(opt(document_theories) ^^ (x => x.getOrElse(Nil))) ~ |
68292 | 941 |
(rep(document_files) ^^ (x => x.flatten)) ~ |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
942 |
rep(export_files)))) ^^ |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
943 |
{ case _ ~ ((a, pos) ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h ~ i ~ j ~ k ~ l))) => |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
72574
diff
changeset
|
944 |
Session_Entry(pos, a, b, c, d, e, f, g, h, i, j, k, l) } |
62631 | 945 |
} |
946 |
||
66819 | 947 |
def parse_root(path: Path): List[Entry] = |
62631 | 948 |
{ |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
949 |
val toks = Token.explode(root_syntax.keywords, File.read(path)) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
950 |
val start = Token.Pos.file(path.implode) |
62631 | 951 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
952 |
parse_all(rep(chapter | session_entry), Token.reader(toks, start)) match { |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
953 |
case Success(result, _) => result |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
954 |
case bad => error(bad.toString) |
62631 | 955 |
} |
956 |
} |
|
957 |
} |
|
958 |
||
66819 | 959 |
def parse_root(path: Path): List[Entry] = Parser.parse_root(path) |
960 |
||
961 |
def parse_root_entries(path: Path): List[Session_Entry] = |
|
962 |
for (entry <- Parser.parse_root(path) if entry.isInstanceOf[Session_Entry]) |
|
963 |
yield entry.asInstanceOf[Session_Entry] |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
964 |
|
66960 | 965 |
def read_root(options: Options, select: Boolean, path: Path): List[Info] = |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
966 |
{ |
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
967 |
var entry_chapter = UNSORTED |
66960 | 968 |
val infos = new mutable.ListBuffer[Info] |
66819 | 969 |
parse_root(path).foreach { |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
970 |
case Chapter(name) => entry_chapter = name |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
971 |
case entry: Session_Entry => |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
972 |
infos += make_info(options, select, path.dir, entry_chapter, entry) |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
973 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
974 |
infos.toList |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
975 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
976 |
|
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
977 |
def parse_roots(roots: Path): List[String] = |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
978 |
{ |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
979 |
for { |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
980 |
line <- split_lines(File.read(roots)) |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
981 |
if !(line == "" || line.startsWith("#")) |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
982 |
} yield line |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
983 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
984 |
|
62631 | 985 |
|
62635 | 986 |
/* load sessions from certain directories */ |
62631 | 987 |
|
988 |
private def is_session_dir(dir: Path): Boolean = |
|
989 |
(dir + ROOT).is_file || (dir + ROOTS).is_file |
|
990 |
||
991 |
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
|
992 |
if (is_session_dir(dir)) File.pwd() + dir.expand |
62631 | 993 |
else error("Bad session root directory: " + dir.toString) |
994 |
||
65561 | 995 |
def directories(dirs: List[Path], select_dirs: List[Path]): List[(Boolean, Path)] = |
996 |
{ |
|
71601 | 997 |
val default_dirs = Isabelle_System.components().filter(is_session_dir) |
68746
f95e2f145ea5
canonical session directories in correspondence to Known.files;
wenzelm
parents:
68734
diff
changeset
|
998 |
for { (select, dir) <- (default_dirs ::: dirs).map((false, _)) ::: select_dirs.map((true, _)) } |
f95e2f145ea5
canonical session directories in correspondence to Known.files;
wenzelm
parents:
68734
diff
changeset
|
999 |
yield (select, dir.canonical) |
65561 | 1000 |
} |
1001 |
||
67026 | 1002 |
def load_structure(options: Options, |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
1003 |
dirs: List[Path] = Nil, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
1004 |
select_dirs: List[Path] = Nil, |
67052 | 1005 |
infos: List[Info] = Nil): Structure = |
62631 | 1006 |
{ |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1007 |
def load_dir(select: Boolean, dir: Path): List[(Boolean, Path)] = |
62635 | 1008 |
load_root(select, dir) ::: load_roots(select, dir) |
62631 | 1009 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1010 |
def load_root(select: Boolean, dir: Path): List[(Boolean, Path)] = |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1011 |
{ |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1012 |
val root = dir + ROOT |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1013 |
if (root.is_file) List((select, root)) else Nil |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1014 |
} |
62631 | 1015 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1016 |
def load_roots(select: Boolean, dir: Path): List[(Boolean, Path)] = |
62631 | 1017 |
{ |
1018 |
val roots = dir + ROOTS |
|
1019 |
if (roots.is_file) { |
|
1020 |
for { |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
1021 |
entry <- parse_roots(roots) |
62631 | 1022 |
dir1 = |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
1023 |
try { check_session_dir(dir + Path.explode(entry)) } |
62631 | 1024 |
catch { |
1025 |
case ERROR(msg) => |
|
1026 |
error(msg + "\nThe error(s) above occurred in session catalog " + roots.toString) |
|
1027 |
} |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1028 |
res <- load_dir(select, dir1) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1029 |
} yield res |
62631 | 1030 |
} |
1031 |
else Nil |
|
1032 |
} |
|
1033 |
||
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1034 |
val roots = |
62631 | 1035 |
for { |
65561 | 1036 |
(select, dir) <- directories(dirs, select_dirs) |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1037 |
res <- load_dir(select, check_session_dir(dir)) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1038 |
} yield res |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1039 |
|
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1040 |
val unique_roots = |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1041 |
((Map.empty[JFile, (Boolean, Path)] /: roots) { case (m, (select, path)) => |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1042 |
val file = path.canonical_file |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1043 |
m.get(file) match { |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1044 |
case None => m + (file -> (select, path)) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1045 |
case Some((select1, path1)) => m + (file -> (select1 || select, path1)) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1046 |
} |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1047 |
}).toList.map(_._2) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1048 |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
1049 |
make(unique_roots.flatMap(p => read_root(options, p._1, p._2)) ::: infos) |
62631 | 1050 |
} |
62632 | 1051 |
|
1052 |
||
71808 | 1053 |
/* Isabelle tool wrapper */ |
1054 |
||
1055 |
val isabelle_tool = Isabelle_Tool("sessions", "explore structure of Isabelle sessions", args => |
|
1056 |
{ |
|
1057 |
var base_sessions: List[String] = Nil |
|
1058 |
var select_dirs: List[Path] = Nil |
|
1059 |
var requirements = false |
|
1060 |
var exclude_session_groups: List[String] = Nil |
|
1061 |
var all_sessions = false |
|
1062 |
var dirs: List[Path] = Nil |
|
1063 |
var session_groups: List[String] = Nil |
|
1064 |
var exclude_sessions: List[String] = Nil |
|
1065 |
||
1066 |
val getopts = Getopts(""" |
|
1067 |
Usage: isabelle sessions [OPTIONS] [SESSIONS ...] |
|
1068 |
||
1069 |
Options are: |
|
1070 |
-B NAME include session NAME and all descendants |
|
1071 |
-D DIR include session directory and select its sessions |
|
1072 |
-R refer to requirements of selected sessions |
|
1073 |
-X NAME exclude sessions from group NAME and all descendants |
|
1074 |
-a select all sessions |
|
1075 |
-d DIR include session directory |
|
1076 |
-g NAME select session group NAME |
|
1077 |
-x NAME exclude session NAME and all descendants |
|
1078 |
||
1079 |
Explore the structure of Isabelle sessions and print result names in |
|
1080 |
topological order (on stdout). |
|
1081 |
""", |
|
1082 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
|
1083 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
|
1084 |
"R" -> (_ => requirements = true), |
|
1085 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
|
1086 |
"a" -> (_ => all_sessions = true), |
|
1087 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
1088 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
|
1089 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
|
1090 |
||
1091 |
val sessions = getopts(args) |
|
1092 |
||
1093 |
val options = Options.init() |
|
1094 |
||
1095 |
val selection = |
|
1096 |
Selection(requirements = requirements, all_sessions = all_sessions, base_sessions = base_sessions, |
|
1097 |
exclude_session_groups = exclude_session_groups, exclude_sessions = exclude_sessions, |
|
1098 |
session_groups = session_groups, sessions = sessions) |
|
1099 |
val sessions_structure = |
|
1100 |
load_structure(options, dirs = dirs, select_dirs = select_dirs).selection(selection) |
|
1101 |
||
1102 |
for (name <- sessions_structure.imports_topological_order) { |
|
1103 |
Output.writeln(name, stdout = true) |
|
1104 |
} |
|
1105 |
}) |
|
1106 |
||
1107 |
||
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1108 |
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1109 |
/** 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
|
1110 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1111 |
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
|
1112 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1113 |
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
|
1114 |
{ |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1115 |
if (heap.is_file) { |
69393
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69366
diff
changeset
|
1116 |
using(FileChannel.open(heap.file.toPath, StandardOpenOption.READ))(file => |
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69366
diff
changeset
|
1117 |
{ |
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1118 |
val len = file.size |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1119 |
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
|
1120 |
if (len >= n) { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1121 |
file.position(len - n) |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1122 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1123 |
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
|
1124 |
var i = 0 |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1125 |
var m = 0 |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1126 |
do { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1127 |
m = file.read(buf) |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1128 |
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
|
1129 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1130 |
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
|
1131 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1132 |
if (i == n) { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1133 |
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
|
1134 |
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
|
1135 |
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
|
1136 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1137 |
else None |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1138 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1139 |
else None |
69393
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69366
diff
changeset
|
1140 |
}) |
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1141 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1142 |
else None |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1143 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1144 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1145 |
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
|
1146 |
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
|
1147 |
case None => |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1148 |
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
|
1149 |
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
|
1150 |
s |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1151 |
case Some(s) => s |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1152 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1153 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1154 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1155 |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1156 |
/** persistent store **/ |
62632 | 1157 |
|
65296 | 1158 |
object Session_Info |
1159 |
{ |
|
66857 | 1160 |
val session_name = SQL.Column.string("session_name").make_primary_key |
65326 | 1161 |
|
65296 | 1162 |
// Build_Log.Session_Info |
1163 |
val session_timing = SQL.Column.bytes("session_timing") |
|
1164 |
val command_timings = SQL.Column.bytes("command_timings") |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1165 |
val theory_timings = SQL.Column.bytes("theory_timings") |
65296 | 1166 |
val ml_statistics = SQL.Column.bytes("ml_statistics") |
1167 |
val task_statistics = SQL.Column.bytes("task_statistics") |
|
65934 | 1168 |
val errors = SQL.Column.bytes("errors") |
65296 | 1169 |
val build_log_columns = |
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1170 |
List(session_name, session_timing, command_timings, theory_timings, |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1171 |
ml_statistics, task_statistics, errors) |
65296 | 1172 |
|
1173 |
// Build.Session_Info |
|
1174 |
val sources = SQL.Column.string("sources") |
|
1175 |
val input_heaps = SQL.Column.string("input_heaps") |
|
1176 |
val output_heap = SQL.Column.string("output_heap") |
|
1177 |
val return_code = SQL.Column.int("return_code") |
|
66746 | 1178 |
val build_columns = List(sources, input_heaps, output_heap, return_code) |
65296 | 1179 |
|
1180 |
val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns) |
|
1181 |
} |
|
1182 |
||
72682 | 1183 |
class Database_Context private[Sessions]( |
1184 |
val store: Sessions.Store, |
|
72683 | 1185 |
val sessions_structure: Sessions.Structure, |
72682 | 1186 |
database_server: Option[SQL.Database]) extends AutoCloseable |
1187 |
{ |
|
72683 | 1188 |
def xml_cache: XML.Cache = store.xml_cache |
1189 |
def xz_cache: XZ.Cache = store.xz_cache |
|
1190 |
||
72682 | 1191 |
def close { database_server.foreach(_.close) } |
1192 |
||
72683 | 1193 |
def read_export(session: String, theory_name: String, name: String): Option[Export.Entry] = |
72682 | 1194 |
{ |
1195 |
val hierarchy = sessions_structure.build_graph.all_preds(List(session)).view |
|
1196 |
val attempts = |
|
1197 |
database_server match { |
|
1198 |
case Some(db) => |
|
1199 |
hierarchy.map(session_name => Export.read_entry(db, session_name, theory_name, name)) |
|
1200 |
case None => |
|
1201 |
hierarchy.map(session_name => |
|
1202 |
store.try_open_database(session_name) match { |
|
1203 |
case Some(db) => using(db)(Export.read_entry(_, session_name, theory_name, name)) |
|
1204 |
case None => None |
|
1205 |
}) |
|
1206 |
} |
|
1207 |
attempts.collectFirst({ case Some(entry) => entry }) |
|
1208 |
} |
|
1209 |
||
72683 | 1210 |
def get_export(session: String, theory_name: String, name: String): Export.Entry = |
1211 |
read_export(session, theory_name, name) getOrElse |
|
72682 | 1212 |
Export.empty_entry(session, theory_name, name) |
1213 |
||
72696 | 1214 |
def read_document(session_name: String, name: String): Option[Presentation.Document_Output] = |
72683 | 1215 |
database_server match { |
1216 |
case Some(db) => Presentation.read_document(db, session_name, name) |
|
1217 |
case None => |
|
1218 |
store.try_open_database(session_name) match { |
|
1219 |
case Some(db) => using(db)(Presentation.read_document(_, session_name, name)) |
|
1220 |
case None => None |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
72682 | 1224 |
override def toString: String = |
1225 |
{ |
|
1226 |
val s = |
|
1227 |
database_server match { |
|
1228 |
case Some(db) => db.toString |
|
1229 |
case None => "input_dirs = " + store.input_dirs.map(_.absolute).mkString(", ") |
|
1230 |
} |
|
1231 |
"Database_Context(" + s + ")" |
|
1232 |
} |
|
1233 |
} |
|
1234 |
||
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1235 |
def store(options: Options): Store = new Store(options) |
62632 | 1236 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1237 |
class Store private[Sessions](val options: Options) |
62632 | 1238 |
{ |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1239 |
store => |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1240 |
|
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1241 |
override def toString: String = "Store(output_dir = " + output_dir.absolute + ")" |
68219 | 1242 |
|
71971 | 1243 |
val xml_cache: XML.Cache = XML.make_cache() |
1244 |
val xz_cache: XZ.Cache = XZ.make_cache() |
|
1245 |
||
68219 | 1246 |
|
1247 |
/* directories */ |
|
1248 |
||
68523
ccacc84e0251
clarified settings -- avoid hard-wired directories;
wenzelm
parents:
68483
diff
changeset
|
1249 |
val system_output_dir: Path = Path.explode("$ISABELLE_HEAPS_SYSTEM/$ML_IDENTIFIER") |
ccacc84e0251
clarified settings -- avoid hard-wired directories;
wenzelm
parents:
68483
diff
changeset
|
1250 |
val user_output_dir: Path = Path.explode("$ISABELLE_HEAPS/$ML_IDENTIFIER") |
68219 | 1251 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1252 |
def system_heaps: Boolean = options.bool("system_heaps") |
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1253 |
|
68221 | 1254 |
val output_dir: Path = |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1255 |
if (system_heaps) system_output_dir else user_output_dir |
68219 | 1256 |
|
68221 | 1257 |
val input_dirs: List[Path] = |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1258 |
if (system_heaps) List(system_output_dir) |
68219 | 1259 |
else List(user_output_dir, system_output_dir) |
62632 | 1260 |
|
72648 | 1261 |
def presentation_dir: Path = |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1262 |
if (system_heaps) Path.explode("$ISABELLE_BROWSER_INFO_SYSTEM") |
62632 | 1263 |
else Path.explode("$ISABELLE_BROWSER_INFO") |
1264 |
||
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1265 |
|
68221 | 1266 |
/* file names */ |
65298 | 1267 |
|
68221 | 1268 |
def heap(name: String): Path = Path.basic(name) |
1269 |
def database(name: String): Path = Path.basic("log") + Path.basic(name).ext("db") |
|
1270 |
def log(name: String): Path = Path.basic("log") + Path.basic(name) |
|
1271 |
def log_gz(name: String): Path = log(name).ext("gz") |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1272 |
|
68221 | 1273 |
def output_heap(name: String): Path = output_dir + heap(name) |
1274 |
def output_database(name: String): Path = output_dir + database(name) |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1275 |
def output_log(name: String): Path = output_dir + log(name) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1276 |
def output_log_gz(name: String): Path = output_dir + log_gz(name) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1277 |
|
72375 | 1278 |
def prepare_output_dir() { Isabelle_System.make_directory(output_dir + Path.basic("log")) } |
68220
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
1279 |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1280 |
|
68221 | 1281 |
/* heap */ |
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1282 |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1283 |
def find_heap(name: String): Option[Path] = |
68221 | 1284 |
input_dirs.map(_ + heap(name)).find(_.is_file) |
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1285 |
|
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1286 |
def find_heap_digest(name: String): Option[String] = |
71601 | 1287 |
find_heap(name).flatMap(read_heap_digest) |
62632 | 1288 |
|
68221 | 1289 |
def the_heap(name: String): Path = |
1290 |
find_heap(name) getOrElse |
|
1291 |
error("Missing heap image for session " + quote(name) + " -- expected in:\n" + |
|
1292 |
cat_lines(input_dirs.map(dir => " " + dir.expand.implode))) |
|
1293 |
||
1294 |
||
1295 |
/* database */ |
|
1296 |
||
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1297 |
def database_server: Boolean = options.bool("build_database_server") |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1298 |
|
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1299 |
def open_database_server(): SQL.Database = |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1300 |
PostgreSQL.open_database( |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1301 |
user = options.string("build_database_user"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1302 |
password = options.string("build_database_password"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1303 |
database = options.string("build_database_name"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1304 |
host = options.string("build_database_host"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1305 |
port = options.int("build_database_port"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1306 |
ssh = |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1307 |
options.proper_string("build_database_ssh_host").map(ssh_host => |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1308 |
SSH.open_session(options, |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1309 |
host = ssh_host, |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1310 |
user = options.string("build_database_ssh_user"), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1311 |
port = options.int("build_database_ssh_port"))), |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1312 |
ssh_close = true) |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1313 |
|
72682 | 1314 |
def open_database_context(sessions_structure: Sessions.Structure): Database_Context = |
1315 |
new Database_Context(store, sessions_structure, |
|
1316 |
if (database_server) Some(open_database_server()) else None) |
|
1317 |
||
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1318 |
def try_open_database(name: String, output: Boolean = false): Option[SQL.Database] = |
68221 | 1319 |
{ |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1320 |
def check(db: SQL.Database): Option[SQL.Database] = |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1321 |
if (output || session_info_exists(db)) Some(db) else { db.close; None } |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1322 |
|
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1323 |
if (database_server) check(open_database_server()) |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1324 |
else if (output) Some(SQLite.open_database(output_database(name))) |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1325 |
else { |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1326 |
(for { |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1327 |
dir <- input_dirs.view |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1328 |
path = dir + database(name) if path.is_file |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1329 |
db <- check(SQLite.open_database(path)) |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1330 |
} yield db).headOption |
68221 | 1331 |
} |
1332 |
} |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1333 |
|
68221 | 1334 |
def open_database(name: String, output: Boolean = false): SQL.Database = |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1335 |
try_open_database(name, output = output) getOrElse |
68221 | 1336 |
error("Missing build database for session " + quote(name)) |
68205 | 1337 |
|
68221 | 1338 |
def clean_output(name: String): (Boolean, Boolean) = |
1339 |
{ |
|
1340 |
val relevant_db = |
|
1341 |
database_server && |
|
1342 |
{ |
|
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1343 |
try_open_database(name) match { |
68221 | 1344 |
case Some(db) => |
1345 |
try { |
|
1346 |
db.transaction { |
|
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1347 |
val relevant_db = session_info_defined(db, name) |
68221 | 1348 |
init_session_info(db, name) |
1349 |
relevant_db |
|
1350 |
} |
|
1351 |
} finally { db.close } |
|
1352 |
case None => false |
|
1353 |
} |
|
1354 |
} |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1355 |
|
68221 | 1356 |
val del = |
1357 |
for { |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1358 |
dir <- |
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1359 |
(if (system_heaps) List(user_output_dir, system_output_dir) else List(user_output_dir)) |
68221 | 1360 |
file <- List(heap(name), database(name), log(name), log_gz(name)) |
1361 |
path = dir + file if path.is_file |
|
1362 |
} yield path.file.delete |
|
1363 |
||
1364 |
val relevant = relevant_db || del.nonEmpty |
|
1365 |
val ok = del.forall(b => b) |
|
1366 |
(relevant, ok) |
|
1367 |
} |
|
65287 | 1368 |
|
1369 |
||
68218 | 1370 |
/* SQL database content */ |
1371 |
||
1372 |
def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
1373 |
db.using_statement(Session_Info.table.select(List(column), |
|
1374 |
Session_Info.session_name.where_equal(name)))(stmt => |
|
1375 |
{ |
|
1376 |
val res = stmt.execute_query() |
|
1377 |
if (!res.next()) Bytes.empty else res.bytes(column) |
|
1378 |
}) |
|
1379 |
||
1380 |
def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
|
1381 |
Properties.uncompress( |
|
1382 |
read_bytes(db, name, column), cache = xz_cache, xml_cache = Some(xml_cache)) |
|
1383 |
||
1384 |
||
65296 | 1385 |
/* session info */ |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1386 |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1387 |
def init_session_info(db: SQL.Database, name: String) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1388 |
{ |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1389 |
db.transaction { |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1390 |
db.create_table(Session_Info.table) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1391 |
db.using_statement( |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1392 |
Session_Info.table.delete(Session_Info.session_name.where_equal(name)))(_.execute) |
68221 | 1393 |
|
1394 |
db.create_table(Export.Data.table) |
|
1395 |
db.using_statement( |
|
1396 |
Export.Data.table.delete(Export.Data.session_name.where_equal(name)))(_.execute) |
|
72653
ea35afdb1366
store documents within session database, instead of browser_info directory;
wenzelm
parents:
72652
diff
changeset
|
1397 |
|
ea35afdb1366
store documents within session database, instead of browser_info directory;
wenzelm
parents:
72652
diff
changeset
|
1398 |
db.create_table(Presentation.Data.table) |
ea35afdb1366
store documents within session database, instead of browser_info directory;
wenzelm
parents:
72652
diff
changeset
|
1399 |
db.using_statement( |
ea35afdb1366
store documents within session database, instead of browser_info directory;
wenzelm
parents:
72652
diff
changeset
|
1400 |
Presentation.Data.table.delete( |
ea35afdb1366
store documents within session database, instead of browser_info directory;
wenzelm
parents:
72652
diff
changeset
|
1401 |
Presentation.Data.session_name.where_equal(name)))(_.execute) |
68221 | 1402 |
} |
1403 |
} |
|
1404 |
||
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1405 |
def session_info_exists(db: SQL.Database): Boolean = |
68221 | 1406 |
{ |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1407 |
val tables = db.tables |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1408 |
tables.contains(Session_Info.table.name) && |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1409 |
tables.contains(Export.Data.table.name) |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1410 |
} |
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1411 |
|
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1412 |
def session_info_defined(db: SQL.Database, name: String): Boolean = |
68221 | 1413 |
db.transaction { |
72634
5cea0993ee4f
clarified access to single database server vs. collection of database files;
wenzelm
parents:
72627
diff
changeset
|
1414 |
session_info_exists(db) && |
68221 | 1415 |
{ |
1416 |
db.using_statement( |
|
1417 |
Session_Info.table.select(List(Session_Info.session_name), |
|
1418 |
Session_Info.session_name.where_equal(name)))(stmt => stmt.execute_query().next()) |
|
1419 |
} |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1420 |
} |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1421 |
|
65296 | 1422 |
def write_session_info( |
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1423 |
db: SQL.Database, |
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1424 |
name: String, |
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1425 |
build_log: Build_Log.Session_Info, |
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1426 |
build: Build.Session_Info) |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1427 |
{ |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1428 |
db.transaction { |
65698 | 1429 |
db.using_statement(Session_Info.table.insert())(stmt => |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1430 |
{ |
65748 | 1431 |
stmt.string(1) = name |
65857 | 1432 |
stmt.bytes(2) = Properties.encode(build_log.session_timing) |
68018 | 1433 |
stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = xz_cache) |
1434 |
stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = xz_cache) |
|
1435 |
stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = xz_cache) |
|
1436 |
stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = xz_cache) |
|
1437 |
stmt.bytes(7) = Build_Log.compress_errors(build_log.errors, cache = xz_cache) |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1438 |
stmt.string(8) = build.sources |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1439 |
stmt.string(9) = cat_lines(build.input_heaps) |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1440 |
stmt.string(10) = build.output_heap getOrElse "" |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1441 |
stmt.int(11) = build.return_code |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1442 |
stmt.execute() |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1443 |
}) |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1444 |
} |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1445 |
} |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1446 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1447 |
def read_session_timing(db: SQL.Database, name: String): Properties.T = |
65857 | 1448 |
Properties.decode(read_bytes(db, name, Session_Info.session_timing), Some(xml_cache)) |
65286 | 1449 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1450 |
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
|
1451 |
read_properties(db, name, Session_Info.command_timings) |
65286 | 1452 |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1453 |
def read_theory_timings(db: SQL.Database, name: String): List[Properties.T] = |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1454 |
read_properties(db, name, Session_Info.theory_timings) |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1455 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1456 |
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
|
1457 |
read_properties(db, name, Session_Info.ml_statistics) |
65286 | 1458 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1459 |
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
|
1460 |
read_properties(db, name, Session_Info.task_statistics) |
65286 | 1461 |
|
65937 | 1462 |
def read_errors(db: SQL.Database, name: String): List[String] = |
68018 | 1463 |
Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = xz_cache) |
65937 | 1464 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1465 |
def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
66744 | 1466 |
{ |
66957
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1467 |
if (db.tables.contains(Session_Info.table.name)) { |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1468 |
db.using_statement(Session_Info.table.select(Session_Info.build_columns, |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1469 |
Session_Info.session_name.where_equal(name)))(stmt => |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1470 |
{ |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1471 |
val res = stmt.execute_query() |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1472 |
if (!res.next()) None |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1473 |
else { |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1474 |
Some( |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1475 |
Build.Session_Info( |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1476 |
res.string(Session_Info.sources), |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1477 |
split_lines(res.string(Session_Info.input_heaps)), |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1478 |
res.string(Session_Info.output_heap) match { case "" => None case s => Some(s) }, |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1479 |
res.int(Session_Info.return_code))) |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1480 |
} |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1481 |
}) |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1482 |
} |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1483 |
else None |
66744 | 1484 |
} |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1485 |
} |
62631 | 1486 |
} |