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