author | wenzelm |
Mon, 02 Sep 2019 16:28:09 +0200 | |
changeset 70639 | ad7891a73230 |
parent 70638 | f164cec7ac22 |
child 70645 | fc27cecb66d8 |
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 Known |
64856 | 40 |
{ |
65495 | 41 |
val empty: Known = Known() |
65360 | 42 |
|
66701 | 43 |
def make(local_dir: Path, bases: List[Base], |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
44 |
sessions: List[(String, Position.T)] = Nil, |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
45 |
theories: List[Document.Node.Entry] = Nil, |
66701 | 46 |
loaded_files: List[(String, List[Path])] = Nil): Known = |
65427 | 47 |
{ |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
48 |
def bases_iterator(local: Boolean) = |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
49 |
for { |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
50 |
base <- bases.iterator |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
51 |
(_, entry) <- (if (local) base.known.theories_local else base.known.theories).iterator |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
52 |
} yield entry |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
53 |
|
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
54 |
def local_theories_iterator = |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
55 |
{ |
65833 | 56 |
val local_path = local_dir.canonical_file.toPath |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
57 |
theories.iterator.filter(entry => |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
58 |
entry.name.path.canonical_file.toPath.startsWith(local_path)) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
59 |
} |
65427 | 60 |
|
67219 | 61 |
val known_sessions = |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
62 |
(sessions.toMap /: bases)({ case (known, base) => known ++ base.known.sessions }) |
67219 | 63 |
|
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
64 |
val known_theories = |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
65 |
(Map.empty[String, Document.Node.Entry] /: (bases_iterator(false) ++ theories.iterator))({ |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
66 |
case (known, entry) => |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
67 |
known.get(entry.name.theory) match { |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
68 |
case Some(entry1) if entry.name != entry1.name => |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
69 |
error("Duplicate theory " + quote(entry.name.node) + " vs. " + |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
70 |
quote(entry1.name.node)) |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
71 |
case _ => known + (entry.name.theory -> entry) |
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
72 |
} |
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
73 |
}) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
74 |
val known_theories_local = |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
75 |
(Map.empty[String, Document.Node.Entry] /: |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
76 |
(bases_iterator(true) ++ local_theories_iterator))({ |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
77 |
case (known, entry) => known + (entry.name.theory -> entry) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
78 |
}) |
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
79 |
val known_files = |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
80 |
(Map.empty[JFile, List[Document.Node.Name]] /: |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
81 |
(bases_iterator(true) ++ bases_iterator(false) ++ theories.iterator))({ |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
82 |
case (known, entry) => |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
83 |
val name = entry.name |
66716 | 84 |
val file = name.path.canonical_file |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
85 |
val theories1 = known.getOrElse(file, Nil) |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
86 |
if (theories1.exists(name1 => name.node == name1.node && name.theory == name1.theory)) |
65461
b6c2e30dc018
support for known theories files (according to multiple uses);
wenzelm
parents:
65457
diff
changeset
|
87 |
known |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
88 |
else known + (file -> (name :: theories1)) |
65427 | 89 |
}) |
66701 | 90 |
|
91 |
val known_loaded_files = |
|
92 |
(loaded_files.toMap /: bases.map(base => base.known.loaded_files))(_ ++ _) |
|
93 |
||
67219 | 94 |
Known( |
95 |
known_sessions, |
|
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
96 |
known_theories, |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
97 |
known_theories_local, |
66701 | 98 |
known_files.iterator.map(p => (p._1, p._2.reverse)).toMap, |
99 |
known_loaded_files) |
|
65427 | 100 |
} |
64856 | 101 |
} |
102 |
||
65495 | 103 |
sealed case class Known( |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
104 |
sessions: Map[String, Position.T] = Map.empty, |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
105 |
theories: Map[String, Document.Node.Entry] = Map.empty, |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
106 |
theories_local: Map[String, Document.Node.Entry] = Map.empty, |
66701 | 107 |
files: Map[JFile, List[Document.Node.Name]] = Map.empty, |
108 |
loaded_files: Map[String, List[Path]] = Map.empty) |
|
65355 | 109 |
{ |
65495 | 110 |
def platform_path: Known = |
65499 | 111 |
copy(theories = for ((a, b) <- theories) yield (a, b.map(File.platform_path(_))), |
112 |
theories_local = for ((a, b) <- theories_local) yield (a, b.map(File.platform_path(_))), |
|
113 |
files = for ((a, b) <- files) yield (a, b.map(c => c.map(File.platform_path(_))))) |
|
65524 | 114 |
|
66668
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
115 |
def standard_path: Known = |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
116 |
copy(theories = for ((a, b) <- theories) yield (a, b.map(File.standard_path(_))), |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
117 |
theories_local = for ((a, b) <- theories_local) yield (a, b.map(File.standard_path(_))), |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
118 |
files = for ((a, b) <- files) yield (a, b.map(c => c.map(File.standard_path(_))))) |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
119 |
|
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
120 |
def theory_names: List[Document.Node.Name] = theories.iterator.map(p => p._2.name).toList |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
121 |
|
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
122 |
lazy val theory_graph: Graph[Document.Node.Name, Unit] = |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
123 |
{ |
68307
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
124 |
val entries = |
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
125 |
for ((_, entry) <- theories.toList) |
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70637
diff
changeset
|
126 |
yield ((entry.name, ()), entry.header.imports.map(imp => theories(imp.theory).name)) |
70637
4c98d37e1448
prefer Theory_Ordering theory names are unique (due to proper session context);
wenzelm
parents:
70636
diff
changeset
|
127 |
Graph.make(entries, symmetric = true)(Document.Node.Name.Theory_Ordering) |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
128 |
} |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
129 |
|
66195 | 130 |
def get_file(file: JFile, bootstrap: Boolean = false): Option[Document.Node.Name] = |
131 |
{ |
|
66234 | 132 |
val res = files.getOrElse(File.canonical(file), Nil).headOption |
66195 | 133 |
if (bootstrap) res.map(_.map_theory(Thy_Header.bootstrap_name(_))) else res |
134 |
} |
|
65495 | 135 |
} |
136 |
||
137 |
object Base |
|
138 |
{ |
|
139 |
def bootstrap(global_theories: Map[String, String]): Base = |
|
140 |
Base( |
|
141 |
global_theories = global_theories, |
|
66720 | 142 |
overall_syntax = Thy_Header.bootstrap_syntax) |
65495 | 143 |
} |
144 |
||
145 |
sealed case class Base( |
|
66571 | 146 |
pos: Position.T = Position.none, |
67471 | 147 |
doc_names: List[String] = Nil, |
65495 | 148 |
global_theories: Map[String, String] = Map.empty, |
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
149 |
loaded_theories: Graph[String, Outer_Syntax] = Graph.string, |
70636 | 150 |
used_theories: List[((Document.Node.Name, Options), List[Document.Node.Name])] = Nil, |
70634
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
151 |
dump_checkpoint: List[Document.Node.Name] = Nil, |
65495 | 152 |
known: Known = Known.empty, |
66720 | 153 |
overall_syntax: Outer_Syntax = Outer_Syntax.empty, |
66744 | 154 |
imported_sources: List[(Path, SHA1.Digest)] = Nil, |
65495 | 155 |
sources: List[(Path, SHA1.Digest)] = Nil, |
66822 | 156 |
session_graph_display: Graph_Display.Graph = Graph_Display.empty_graph, |
66694
41177b124067
tuned signature -- more readable output as Scala value;
wenzelm
parents:
66668
diff
changeset
|
157 |
errors: List[String] = Nil, |
41177b124067
tuned signature -- more readable output as Scala value;
wenzelm
parents:
66668
diff
changeset
|
158 |
imports: Option[Base] = None) |
65495 | 159 |
{ |
69102
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
160 |
override def toString: String = |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
161 |
"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
|
162 |
", used_theories = " + used_theories.length + ")" |
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
163 |
|
65495 | 164 |
def platform_path: Base = copy(known = known.platform_path) |
66668
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66604
diff
changeset
|
165 |
def standard_path: Base = copy(known = known.standard_path) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
166 |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
167 |
def theory_qualifier(name: String): String = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
168 |
global_theories.getOrElse(name, Long_Name.qualifier(name)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
169 |
def theory_qualifier(name: Document.Node.Name): String = theory_qualifier(name.theory) |
66966 | 170 |
|
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
171 |
def loaded_theory(name: String): Boolean = loaded_theories.defined(name) |
66712 | 172 |
def loaded_theory(name: Document.Node.Name): Boolean = loaded_theory(name.theory) |
65432 | 173 |
|
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
174 |
def loaded_theory_syntax(name: String): Option[Outer_Syntax] = |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
175 |
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
|
176 |
def loaded_theory_syntax(name: Document.Node.Name): Option[Outer_Syntax] = |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
177 |
loaded_theory_syntax(name.theory) |
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66716
diff
changeset
|
178 |
|
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
|
179 |
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
|
180 |
nodes(name).syntax orElse loaded_theory_syntax(name) getOrElse overall_syntax |
66721
ae38b8c0fdd9
more accurate node_syntax: avoid overall_syntax for PIDE edits;
wenzelm
parents:
66720
diff
changeset
|
181 |
|
65498 | 182 |
def known_theory(name: String): Option[Document.Node.Name] = |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
183 |
known.theories.get(name).map(_.name) |
65498 | 184 |
|
65432 | 185 |
def dest_known_theories: List[(String, String)] = |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
186 |
for ((theory, entry) <- known.theories.toList) |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
187 |
yield (theory, entry.name.node) |
66694
41177b124067
tuned signature -- more readable output as Scala value;
wenzelm
parents:
66668
diff
changeset
|
188 |
|
41177b124067
tuned signature -- more readable output as Scala value;
wenzelm
parents:
66668
diff
changeset
|
189 |
def get_imports: Base = imports getOrElse Base.bootstrap(global_theories) |
65355 | 190 |
} |
64856 | 191 |
|
68204 | 192 |
sealed case class Deps( |
193 |
sessions_structure: Structure, session_bases: Map[String, Base], all_known: Known) |
|
65251 | 194 |
{ |
69102
4b06a20b13b5
tuned output -- avoid bombing of Scala toplevel, e.g. for AFP deps;
wenzelm
parents:
69080
diff
changeset
|
195 |
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
|
196 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
197 |
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
|
198 |
def apply(name: String): Base = session_bases(name) |
66988 | 199 |
def get(name: String): Option[Base] = session_bases.get(name) |
66744 | 200 |
|
201 |
def imported_sources(name: String): List[SHA1.Digest] = |
|
202 |
session_bases(name).imported_sources.map(_._2) |
|
203 |
||
70634
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
204 |
def dump_checkpoint: List[Document.Node.Name] = |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
205 |
(for { |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
206 |
(_, base) <- session_bases.iterator |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
207 |
name <- base.dump_checkpoint.iterator |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
208 |
} yield name).toList |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
209 |
|
69857 | 210 |
def used_theories_condition(default_options: Options, progress: Progress = No_Progress) |
70636 | 211 |
: Graph[Document.Node.Name, Options] = |
69025 | 212 |
{ |
69026
6e2f9f62aafd
suppress some theories to allow "isabelle dump -o skip_proofs";
wenzelm
parents:
69025
diff
changeset
|
213 |
val default_skip_proofs = default_options.bool("skip_proofs") |
70636 | 214 |
val used = |
215 |
for { |
|
216 |
session_name <- sessions_structure.build_topological_order |
|
217 |
entry @ ((name, options), _) <- session_bases(session_name).used_theories |
|
218 |
if { |
|
219 |
def warn(msg: String): Unit = |
|
220 |
progress.echo_warning("Skipping theory " + name + " (" + msg + ")") |
|
69026
6e2f9f62aafd
suppress some theories to allow "isabelle dump -o skip_proofs";
wenzelm
parents:
69025
diff
changeset
|
221 |
|
70636 | 222 |
val conditions = |
223 |
space_explode(',', options.string("condition")). |
|
224 |
filter(cond => Isabelle_System.getenv(cond) == "") |
|
225 |
if (conditions.nonEmpty) { |
|
226 |
warn("undefined " + conditions.mkString(", ")) |
|
227 |
false |
|
228 |
} |
|
229 |
else if (default_skip_proofs && !options.bool("skip_proofs")) { |
|
230 |
warn("option skip_proofs") |
|
231 |
false |
|
232 |
} |
|
233 |
else true |
|
69008
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
wenzelm
parents:
68841
diff
changeset
|
234 |
} |
70636 | 235 |
} yield entry |
70639 | 236 |
Graph.make[Document.Node.Name, Options](used, symmetric = true, permissive = true)( |
70636 | 237 |
Document.Node.Name.Theory_Ordering) |
69025 | 238 |
} |
69008
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
wenzelm
parents:
68841
diff
changeset
|
239 |
|
66744 | 240 |
def sources(name: String): List[SHA1.Digest] = |
241 |
session_bases(name).sources.map(_._2) |
|
66571 | 242 |
|
243 |
def errors: List[String] = |
|
244 |
(for { |
|
245 |
(name, base) <- session_bases.iterator |
|
246 |
if base.errors.nonEmpty |
|
247 |
} yield cat_lines(base.errors) + |
|
248 |
"\nThe error(s) above occurred in session " + quote(name) + Position.here(base.pos) |
|
249 |
).toList |
|
250 |
||
251 |
def check_errors: Deps = |
|
252 |
errors match { |
|
253 |
case Nil => this |
|
254 |
case errs => error(cat_lines(errs)) |
|
255 |
} |
|
65251 | 256 |
} |
64856 | 257 |
|
67052 | 258 |
def deps(sessions_structure: Structure, |
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66960
diff
changeset
|
259 |
global_theories: Map[String, String], |
65251 | 260 |
progress: Progress = No_Progress, |
261 |
inlined_files: Boolean = false, |
|
262 |
verbose: Boolean = false, |
|
263 |
list_files: Boolean = false, |
|
66962
e1bde71bace6
clarified signature: global_theories is always required;
wenzelm
parents:
66960
diff
changeset
|
264 |
check_keywords: Set[String] = Set.empty): Deps = |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
265 |
{ |
66743 | 266 |
var cache_sources = Map.empty[JFile, SHA1.Digest] |
267 |
def check_sources(paths: List[Path]): List[(Path, SHA1.Digest)] = |
|
268 |
{ |
|
269 |
for { |
|
270 |
path <- paths |
|
271 |
file = path.file |
|
272 |
if cache_sources.isDefinedAt(file) || file.isFile |
|
273 |
} |
|
274 |
yield { |
|
275 |
cache_sources.get(file) match { |
|
276 |
case Some(digest) => (path, digest) |
|
277 |
case None => |
|
278 |
val digest = SHA1.digest(file) |
|
279 |
cache_sources = cache_sources + (file -> digest) |
|
280 |
(path, digest) |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
||
67471 | 285 |
val doc_names = Doc.doc_names() |
286 |
||
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
287 |
val session_bases = |
67024 | 288 |
(Map.empty[String, Base] /: sessions_structure.imports_topological_order)({ |
67023 | 289 |
case (session_bases, session_name) => |
67880 | 290 |
progress.expose_interrupt() |
65251 | 291 |
|
67024 | 292 |
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
|
293 |
try { |
65496 | 294 |
val parent_base: Sessions.Base = |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
295 |
info.parent match { |
65475 | 296 |
case None => Base.bootstrap(global_theories) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
297 |
case Some(parent) => session_bases(parent) |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
298 |
} |
65496 | 299 |
val imports_base: Sessions.Base = |
300 |
parent_base.copy(known = |
|
66701 | 301 |
Known.make(info.dir, parent_base :: info.imports.map(session_bases(_)))) |
65496 | 302 |
|
65532 | 303 |
val resources = new Resources(imports_base) |
65251 | 304 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
305 |
if (verbose || list_files) { |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
306 |
val groups = |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
307 |
if (info.groups.isEmpty) "" |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
308 |
else info.groups.mkString(" (", " ", ")") |
65519 | 309 |
progress.echo("Session " + info.chapter + "/" + info.name + groups) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
310 |
} |
65251 | 311 |
|
69008
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
wenzelm
parents:
68841
diff
changeset
|
312 |
val dependencies = resources.session_dependencies(info) |
65251 | 313 |
|
70634
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
314 |
val dump_checkpoint = resources.dump_checkpoint(info) |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
315 |
|
67053 | 316 |
val overall_syntax = dependencies.overall_syntax |
65251 | 317 |
|
67059 | 318 |
val theory_files = dependencies.theories.map(_.path) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
319 |
val loaded_files = |
69560 | 320 |
if (inlined_files) dependencies.loaded_files(Sessions.is_pure(info.name)) |
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
321 |
else Nil |
65251 | 322 |
|
66742 | 323 |
val session_files = |
66701 | 324 |
(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
|
325 |
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
|
326 |
|
67053 | 327 |
val imported_files = if (inlined_files) dependencies.imported_files else Nil |
66743 | 328 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
329 |
if (list_files) |
66742 | 330 |
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
|
331 |
|
66719
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
332 |
if (check_keywords.nonEmpty) { |
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
333 |
Check_Keywords.check_keywords( |
66720 | 334 |
progress, overall_syntax.keywords, check_keywords, theory_files) |
66719
d37efafd55b5
clarified theory syntax vs. overall session syntax;
wenzelm
parents:
66718
diff
changeset
|
335 |
} |
65251 | 336 |
|
66822 | 337 |
val session_graph_display: Graph_Display.Graph = |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
338 |
{ |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
339 |
def session_node(name: String): Graph_Display.Node = |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
340 |
Graph_Display.Node("[" + name + "]", "session." + name) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
341 |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
342 |
def node(name: Document.Node.Name): Graph_Display.Node = |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
343 |
{ |
66966 | 344 |
val qualifier = imports_base.theory_qualifier(name) |
66780
bf54ca580bf2
theory qualifier is always session name (see also 31e8a86971a8);
wenzelm
parents:
66770
diff
changeset
|
345 |
if (qualifier == info.name) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
346 |
Graph_Display.Node(name.theory_base_name, "theory." + name.theory) |
65528 | 347 |
else session_node(qualifier) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
348 |
} |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
349 |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
350 |
val imports_subgraph = |
67024 | 351 |
sessions_structure.imports_graph. |
352 |
restrict(sessions_structure.imports_graph.all_preds(info.deps).toSet) |
|
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
353 |
|
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
354 |
val graph0 = |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
355 |
(Graph_Display.empty_graph /: imports_subgraph.topological_order)( |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
356 |
{ case (g, session) => |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
357 |
val a = session_node(session) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
358 |
val bs = imports_subgraph.imm_preds(session).toList.map(session_node(_)) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
359 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
360 |
|
67053 | 361 |
(graph0 /: dependencies.entries)( |
66714 | 362 |
{ case (g, entry) => |
363 |
val a = node(entry.name) |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70637
diff
changeset
|
364 |
val bs = entry.header.imports.map(node).filterNot(_ == a) |
65507
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
365 |
((g /: (a :: bs))(_.default_node(_, Nil)) /: bs)(_.add_edge(_, a)) }) |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
366 |
} |
decdb95bd007
clarified session graph: collapse theories from other sessions;
wenzelm
parents:
65500
diff
changeset
|
367 |
|
66701 | 368 |
val known = |
369 |
Known.make(info.dir, List(imports_base), |
|
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
370 |
sessions = List(info.name -> info.pos), |
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68304
diff
changeset
|
371 |
theories = dependencies.entries, |
66701 | 372 |
loaded_files = loaded_files) |
373 |
||
70636 | 374 |
val used_theories = |
375 |
for ((options, name) <- dependencies.adjunct_theories) |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70637
diff
changeset
|
376 |
yield ((name, options), known.theories(name.theory).header.imports) |
70636 | 377 |
|
66743 | 378 |
val sources_errors = |
379 |
for (p <- session_files if !p.is_file) yield "No such file: " + p |
|
66604 | 380 |
|
69904 | 381 |
val path_errors = |
382 |
try { Path.check_case_insensitive(session_files ::: imported_files); Nil } |
|
383 |
catch { case ERROR(msg) => List(msg) } |
|
384 |
||
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
385 |
val bibtex_errors = |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
386 |
try { info.bibtex_entries; Nil } |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
387 |
catch { case ERROR(msg) => List(msg) } |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
388 |
|
65463
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
389 |
val base = |
66571 | 390 |
Base( |
391 |
pos = info.pos, |
|
67471 | 392 |
doc_names = doc_names, |
65540
2b73ed8bf4d9
proper imports_resources for import_name: avoid self-referential name resolution;
wenzelm
parents:
65532
diff
changeset
|
393 |
global_theories = global_theories, |
67053 | 394 |
loaded_theories = dependencies.loaded_theories, |
70636 | 395 |
used_theories = used_theories, |
70634
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
69904
diff
changeset
|
396 |
dump_checkpoint = dump_checkpoint, |
66701 | 397 |
known = known, |
66720 | 398 |
overall_syntax = overall_syntax, |
66744 | 399 |
imported_sources = check_sources(imported_files), |
66743 | 400 |
sources = check_sources(session_files), |
66822 | 401 |
session_graph_display = session_graph_display, |
69904 | 402 |
errors = dependencies.errors ::: sources_errors ::: path_errors ::: bibtex_errors, |
66694
41177b124067
tuned signature -- more readable output as Scala value;
wenzelm
parents:
66668
diff
changeset
|
403 |
imports = Some(imports_base)) |
65251 | 404 |
|
65519 | 405 |
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
|
406 |
} |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
407 |
catch { |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
408 |
case ERROR(msg) => |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
409 |
cat_error(msg, "The error(s) above occurred in session " + |
65519 | 410 |
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
|
411 |
} |
104502de757c
more informative known_files: known_theories within the local session directory come first;
wenzelm
parents:
65461
diff
changeset
|
412 |
}) |
65251 | 413 |
|
68307
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
414 |
val all_known = |
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
415 |
Known.make(Path.current, sessions_structure.imports_topological_order.map(session_bases(_))) |
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
416 |
|
812546f20c5c
more accurate theory_graph: avoid imports of loaded_theories with incomplete node name;
wenzelm
parents:
68306
diff
changeset
|
417 |
Deps(sessions_structure, session_bases, all_known) |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
418 |
} |
65251 | 419 |
|
66963 | 420 |
|
421 |
/* base info */ |
|
422 |
||
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
423 |
sealed case class Base_Info( |
67869 | 424 |
options: Options, |
425 |
dirs: List[Path], |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
426 |
session: String, |
67052 | 427 |
sessions_structure: Structure, |
66975 | 428 |
errors: List[String], |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
429 |
base: Base, |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
430 |
infos: List[Info]) |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
431 |
{ |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
432 |
def check_base: Base = if (errors.isEmpty) base else error(cat_lines(errors)) |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
433 |
} |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
434 |
|
67846 | 435 |
def base_info(options: Options, |
436 |
session: String, |
|
67852
f701a1d5d852
allow cancellation of Sessions.deps/base_info via progress.stopped (progress.echo only happens for options like "verbose");
wenzelm
parents:
67846
diff
changeset
|
437 |
progress: Progress = No_Progress, |
65428 | 438 |
dirs: List[Path] = Nil, |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
439 |
include_sessions: List[String] = Nil, |
68370 | 440 |
session_ancestor: Option[String] = None, |
441 |
session_requirements: Boolean = false, |
|
442 |
session_focus: Boolean = false, |
|
443 |
all_known: Boolean = false): Base_Info = |
|
65251 | 444 |
{ |
67026 | 445 |
val full_sessions = load_structure(options, dirs = dirs) |
65428 | 446 |
val global_theories = full_sessions.global_theories |
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
447 |
|
66990 | 448 |
val selected_sessions = |
68370 | 449 |
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
|
450 |
val info = selected_sessions(session) |
68370 | 451 |
val ancestor = session_ancestor orElse info.parent |
66963 | 452 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
453 |
val (session1, infos1) = |
68370 | 454 |
if (session_requirements && ancestor.isDefined) { |
67852
f701a1d5d852
allow cancellation of Sessions.deps/base_info via progress.stopped (progress.echo only happens for options like "verbose");
wenzelm
parents:
67846
diff
changeset
|
455 |
val deps = Sessions.deps(selected_sessions, global_theories, progress = progress) |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
456 |
val base = deps(session) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
457 |
|
66988 | 458 |
val ancestor_loaded = |
459 |
deps.get(ancestor.get) match { |
|
66990 | 460 |
case Some(ancestor_base) |
461 |
if !selected_sessions.imports_requirements(List(ancestor.get)).contains(session) => |
|
462 |
ancestor_base.loaded_theories.defined(_) |
|
463 |
case _ => |
|
66988 | 464 |
error("Bad ancestor " + quote(ancestor.get) + " for session " + quote(session)) |
465 |
} |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
466 |
|
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
467 |
val required_theories = |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
468 |
for { |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
469 |
thy <- base.loaded_theories.keys |
66988 | 470 |
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
|
471 |
} |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
472 |
yield thy |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
473 |
|
66988 | 474 |
if (required_theories.isEmpty) (ancestor.get, Nil) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
475 |
else { |
68370 | 476 |
val other_name = info.name + "_requirements(" + ancestor.get + ")" |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
477 |
(other_name, |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
478 |
List( |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
479 |
make_info(info.options, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
480 |
dir_selected = false, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
481 |
dir = info.dir, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
482 |
chapter = info.chapter, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
483 |
Session_Entry( |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
484 |
pos = info.pos, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
485 |
name = other_name, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
486 |
groups = info.groups, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
487 |
path = ".", |
66988 | 488 |
parent = ancestor, |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
489 |
description = "Required theory imports from other sessions", |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
490 |
options = Nil, |
66991 | 491 |
imports = info.deps, |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
492 |
theories = List((Nil, required_theories.map(thy => ((thy, Position.none), false)))), |
68292 | 493 |
document_files = Nil, |
494 |
export_files = Nil)))) |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
495 |
} |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
496 |
} |
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
497 |
else (session, Nil) |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
498 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
499 |
val full_sessions1 = |
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
500 |
if (infos1.isEmpty) full_sessions |
67026 | 501 |
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
|
502 |
|
352b23c97ac8
support focus_session, for much faster startup of Isabelle/jEdit;
wenzelm
parents:
66984
diff
changeset
|
503 |
val selected_sessions1 = |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
504 |
{ |
68483
087d32a40129
include target sessions as well: avoid default "Draft" qualification;
wenzelm
parents:
68370
diff
changeset
|
505 |
val sel_sessions1 = session1 :: session :: include_sessions |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
506 |
val select_sessions1 = |
68542 | 507 |
if (session_focus) { |
508 |
full_sessions1.check_sessions(sel_sessions1) |
|
509 |
full_sessions1.imports_descendants(sel_sessions1) |
|
510 |
} |
|
511 |
else sel_sessions1 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
512 |
full_sessions1.selection(Selection(sessions = select_sessions1)) |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
513 |
} |
66964 | 514 |
|
66974
b14c24b31f45
avoid duplicate invocation of expensive Sessions.deps on full_sessions;
wenzelm
parents:
66970
diff
changeset
|
515 |
val sessions1 = if (all_known) full_sessions1 else selected_sessions1 |
67852
f701a1d5d852
allow cancellation of Sessions.deps/base_info via progress.stopped (progress.echo only happens for options like "verbose");
wenzelm
parents:
67846
diff
changeset
|
516 |
val deps1 = Sessions.deps(sessions1, global_theories, progress = progress) |
67922
9e668ae81f97
clarified signature: prefer selective include_sessions;
wenzelm
parents:
67880
diff
changeset
|
517 |
val base1 = deps1(session1).copy(known = deps1.all_known) |
66964 | 518 |
|
68204 | 519 |
Base_Info(options, dirs, session1, deps1.sessions_structure, deps1.errors, base1, infos1) |
65251 | 520 |
} |
521 |
||
522 |
||
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
523 |
/* cumulative session info */ |
62631 | 524 |
|
525 |
sealed case class Info( |
|
65519 | 526 |
name: String, |
62631 | 527 |
chapter: String, |
66829 | 528 |
dir_selected: Boolean, |
62631 | 529 |
pos: Position.T, |
530 |
groups: List[String], |
|
531 |
dir: Path, |
|
532 |
parent: Option[String], |
|
533 |
description: String, |
|
534 |
options: Options, |
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
535 |
imports: List[String], |
65517 | 536 |
theories: List[(Options, List[(String, Position.T)])], |
65374 | 537 |
global_theories: List[String], |
62631 | 538 |
document_files: List[(Path, Path)], |
69671 | 539 |
export_files: List[(Path, Int, List[String])], |
62631 | 540 |
meta_digest: SHA1.Digest) |
541 |
{ |
|
66828 | 542 |
def deps: List[String] = parent.toList ::: imports |
543 |
||
62631 | 544 |
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
|
545 |
|
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
546 |
def bibtex_entries: List[Text.Info[String]] = |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
547 |
(for { |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67290
diff
changeset
|
548 |
(document_dir, file) <- document_files.iterator |
69366 | 549 |
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
|
550 |
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
|
551 |
} yield info).toList |
62631 | 552 |
} |
553 |
||
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
554 |
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
|
555 |
entry: Session_Entry): Info = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
556 |
{ |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
557 |
try { |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
558 |
val name = entry.name |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
559 |
|
67284 | 560 |
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
|
561 |
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
|
562 |
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
|
563 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
564 |
val session_options = options ++ entry.options |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
565 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
566 |
val theories = |
67216 | 567 |
entry.theories.map({ case (opts, thys) => |
568 |
(session_options ++ opts, |
|
569 |
thys.map({ case ((thy, pos), _) => |
|
67284 | 570 |
if (exclude_theory(thy)) |
67216 | 571 |
error("Bad theory name " + quote(thy) + Position.here(pos)) |
572 |
else (thy, pos) })) }) |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
573 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
574 |
val global_theories = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
575 |
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
|
576 |
yield { |
69366 | 577 |
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
|
578 |
if (Long_Name.is_qualified(thy_name)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
579 |
error("Bad qualified name for global theory " + |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
580 |
quote(thy_name) + Position.here(pos)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
581 |
else thy_name |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
582 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
583 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
584 |
val conditions = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
585 |
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
|
586 |
map(x => (x, Isabelle_System.getenv(x) != "")) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
587 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
588 |
val document_files = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
589 |
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
|
590 |
|
68292 | 591 |
val export_files = |
69671 | 592 |
entry.export_files.map({ case (dir, prune, pats) => (Path.explode(dir), prune, pats) }) |
68292 | 593 |
|
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
594 |
val meta_digest = |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
595 |
SHA1.digest((name, chapter, entry.parent, entry.options, entry.imports, |
69812
9487788a94c1
clarified meta_digest: export_files is a directive for physical output from existing build database;
wenzelm
parents:
69762
diff
changeset
|
596 |
entry.theories_no_position, conditions, entry.document_files).toString) |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
597 |
|
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
598 |
Info(name, chapter, dir_selected, entry.pos, entry.groups, |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
599 |
dir + Path.explode(entry.path), entry.parent, entry.description, session_options, |
68292 | 600 |
entry.imports, theories, global_theories, document_files, export_files, meta_digest) |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
601 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
602 |
catch { |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
603 |
case ERROR(msg) => |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
604 |
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
|
605 |
quote(entry.name) + Position.here(entry.pos)) |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
606 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
607 |
} |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
608 |
|
65419 | 609 |
object Selection |
610 |
{ |
|
65422 | 611 |
val empty: Selection = Selection() |
65525 | 612 |
val all: Selection = Selection(all_sessions = true) |
65419 | 613 |
} |
614 |
||
615 |
sealed case class Selection( |
|
616 |
requirements: Boolean = false, |
|
617 |
all_sessions: Boolean = false, |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
618 |
base_sessions: List[String] = Nil, |
65419 | 619 |
exclude_session_groups: List[String] = Nil, |
620 |
exclude_sessions: List[String] = Nil, |
|
621 |
session_groups: List[String] = Nil, |
|
622 |
sessions: List[String] = Nil) |
|
623 |
{ |
|
66736 | 624 |
def ++ (other: Selection): Selection = |
65422 | 625 |
Selection( |
626 |
requirements = requirements || other.requirements, |
|
627 |
all_sessions = all_sessions || other.all_sessions, |
|
66737
2edc0c42c883
option -B for "isabelle build" and "isabelle imports";
wenzelm
parents:
66736
diff
changeset
|
628 |
base_sessions = Library.merge(base_sessions, other.base_sessions), |
66736 | 629 |
exclude_session_groups = Library.merge(exclude_session_groups, other.exclude_session_groups), |
630 |
exclude_sessions = Library.merge(exclude_sessions, other.exclude_sessions), |
|
631 |
session_groups = Library.merge(session_groups, other.session_groups), |
|
632 |
sessions = Library.merge(sessions, other.sessions)) |
|
65419 | 633 |
} |
634 |
||
67052 | 635 |
def make(infos: List[Info]): Structure = |
62631 | 636 |
{ |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
637 |
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
|
638 |
: Graph[String, Info] = |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
639 |
{ |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
640 |
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
|
641 |
{ |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
642 |
if (!g.defined(parent)) |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
643 |
error("Bad " + kind + " session " + quote(parent) + " for " + |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
644 |
quote(name) + Position.here(pos)) |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
645 |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
646 |
try { g.add_edge_acyclic(parent, name) } |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
647 |
catch { |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
648 |
case exn: Graph.Cycles[_] => |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
649 |
error(cat_lines(exn.cycles.map(cycle => |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
650 |
"Cyclic session dependency of " + |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
651 |
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
|
652 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
653 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
654 |
(graph /: graph.iterator) { |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
655 |
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
|
656 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
657 |
} |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
658 |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
659 |
val graph0 = |
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
660 |
(Graph.string[Info] /: infos) { |
66960 | 661 |
case (graph, info) => |
662 |
if (graph.defined(info.name)) |
|
663 |
error("Duplicate session " + quote(info.name) + Position.here(info.pos) + |
|
664 |
Position.here(graph.get_node(info.name).pos)) |
|
665 |
else graph.new_node(info.name, info) |
|
65415
8cd54b18b68b
clarified signature: tree structure is not essential;
wenzelm
parents:
65410
diff
changeset
|
666 |
} |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
667 |
val graph1 = add_edges(graph0, "parent", _.parent) |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
668 |
val graph2 = add_edges(graph1, "imports", _.imports) |
62631 | 669 |
|
67052 | 670 |
new Structure(graph1, graph2) |
62631 | 671 |
} |
672 |
||
67052 | 673 |
final class Structure private[Sessions]( |
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
674 |
val build_graph: Graph[String, Info], |
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
675 |
val imports_graph: Graph[String, Info]) |
62631 | 676 |
{ |
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
677 |
sessions_structure => |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
678 |
|
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
679 |
lazy val chapters: SortedMap[String, List[Info]] = |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
680 |
(SortedMap.empty[String, List[Info]] /: build_graph.iterator)( |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
681 |
{ case (chs, (_, (info, _))) => |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
682 |
chs + (info.chapter -> (info :: chs.getOrElse(info.chapter, Nil))) }) |
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
683 |
|
66823 | 684 |
def build_graph_display: Graph_Display.Graph = Graph_Display.make_graph(build_graph) |
685 |
def imports_graph_display: Graph_Display.Graph = Graph_Display.make_graph(imports_graph) |
|
686 |
||
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
687 |
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
|
688 |
def apply(name: String): Info = imports_graph.get_node(name) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
689 |
def get(name: String): Option[Info] = if (defined(name)) Some(apply(name)) else None |
62631 | 690 |
|
65457 | 691 |
def global_theories: Map[String, String] = |
65490 | 692 |
(Thy_Header.bootstrap_global_theories.toMap /: |
65424 | 693 |
(for { |
65519 | 694 |
(_, (info, _)) <- imports_graph.iterator |
695 |
thy <- info.global_theories.iterator } |
|
696 |
yield (thy, info)))({ |
|
697 |
case (global, (thy, info)) => |
|
66780
bf54ca580bf2
theory qualifier is always session name (see also 31e8a86971a8);
wenzelm
parents:
66770
diff
changeset
|
698 |
val qualifier = info.name |
65457 | 699 |
global.get(thy) match { |
700 |
case Some(qualifier1) if qualifier != qualifier1 => |
|
701 |
error("Duplicate global theory " + quote(thy) + Position.here(info.pos)) |
|
702 |
case _ => global + (thy -> qualifier) |
|
703 |
} |
|
704 |
}) |
|
65372
b722ee40c26c
refer to global_theories from all sessions, before selection;
wenzelm
parents:
65371
diff
changeset
|
705 |
|
68542 | 706 |
def check_sessions(names: List[String]) |
707 |
{ |
|
708 |
val bad_sessions = SortedSet(names.filterNot(defined(_)): _*).toList |
|
709 |
if (bad_sessions.nonEmpty) |
|
710 |
error("Undefined session(s): " + commas_quote(bad_sessions)) |
|
711 |
} |
|
712 |
||
68733 | 713 |
def check_sessions(sel: Selection): Unit = |
714 |
check_sessions(sel.base_sessions ::: sel.exclude_sessions ::: sel.sessions) |
|
715 |
||
68732 | 716 |
private def selected(graph: Graph[String, Info], sel: Selection): List[String] = |
717 |
{ |
|
68733 | 718 |
check_sessions(sel) |
719 |
||
68732 | 720 |
val select_group = sel.session_groups.toSet |
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
721 |
val select_session = sel.sessions.toSet ++ imports_graph.all_succs(sel.base_sessions) |
68732 | 722 |
|
723 |
val selected0 = |
|
724 |
if (sel.all_sessions) graph.keys |
|
725 |
else { |
|
726 |
(for { |
|
727 |
(name, (info, _)) <- graph.iterator |
|
728 |
if info.dir_selected || select_session(name) || |
|
729 |
graph.get_node(name).groups.exists(select_group) |
|
730 |
} yield name).toList |
|
731 |
} |
|
732 |
||
733 |
if (sel.requirements) (graph.all_preds(selected0).toSet -- selected0).toList |
|
734 |
else selected0 |
|
735 |
} |
|
736 |
||
67052 | 737 |
def selection(sel: Selection): Structure = |
62631 | 738 |
{ |
68733 | 739 |
check_sessions(sel) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
740 |
|
68732 | 741 |
val excluded = |
742 |
{ |
|
743 |
val exclude_group = sel.exclude_session_groups.toSet |
|
744 |
val exclude_group_sessions = |
|
745 |
(for { |
|
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
746 |
(name, (info, _)) <- imports_graph.iterator |
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
747 |
if imports_graph.get_node(name).groups.exists(exclude_group) |
68732 | 748 |
} yield name).toList |
68734
c14a2cc9b5ef
isabelle build options -c -x -B refer to imports_graph;
wenzelm
parents:
68733
diff
changeset
|
749 |
imports_graph.all_succs(exclude_group_sessions ::: sel.exclude_sessions).toSet |
68732 | 750 |
} |
67027 | 751 |
|
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
752 |
def restrict(graph: Graph[String, Info]): Graph[String, Info] = |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
753 |
{ |
68732 | 754 |
val sessions = graph.all_preds(selected(graph, sel)).filterNot(excluded) |
67029 | 755 |
graph.restrict(graph.all_preds(sessions).toSet) |
67025
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
756 |
} |
961285f581e6
clarifified selection: always wrt. build_graph structure;
wenzelm
parents:
67024
diff
changeset
|
757 |
|
67052 | 758 |
new Structure(restrict(build_graph), restrict(imports_graph)) |
62631 | 759 |
} |
760 |
||
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
761 |
def selection_deps( |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
762 |
options: Options, |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
763 |
selection: Selection, |
68304 | 764 |
progress: Progress = No_Progress, |
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
765 |
uniform_session: Boolean = false, |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
766 |
loading_sessions: Boolean = false, |
68304 | 767 |
inlined_files: Boolean = false, |
768 |
verbose: Boolean = false): Deps = |
|
769 |
{ |
|
69524
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
770 |
val selection1 = |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
771 |
if (uniform_session) { |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
772 |
val sessions_structure1 = sessions_structure.selection(selection) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
773 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
774 |
val default_record_proofs = options.int("record_proofs") |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
775 |
val sessions_record_proofs = |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
776 |
for { |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
777 |
name <- sessions_structure1.build_topological_order |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
778 |
info <- sessions_structure1.get(name) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
779 |
if info.options.int("record_proofs") > default_record_proofs |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
780 |
} yield name |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
781 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
782 |
val excluded = |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
783 |
for (name <- sessions_structure1.build_descendants(sessions_record_proofs)) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
784 |
yield { |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
785 |
progress.echo_warning("Skipping session " + name + " (option record_proofs)") |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
786 |
name |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
787 |
} |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
788 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
789 |
selection.copy(exclude_sessions = excluded ::: selection.exclude_sessions) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
790 |
} |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
791 |
else selection |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
792 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
793 |
val deps = |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
794 |
Sessions.deps(sessions_structure.selection(selection1), global_theories, |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
795 |
progress = progress, inlined_files = inlined_files, verbose = verbose) |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
796 |
|
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
797 |
if (loading_sessions) { |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
798 |
val selection_size = deps.sessions_structure.build_graph.size |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
799 |
if (selection_size > 1) progress.echo("Loading " + selection_size + " sessions ...") |
fa94f2b2a877
clarified sessions_deps, according to Isabelle/MMT usage;
wenzelm
parents:
69393
diff
changeset
|
800 |
} |
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 |
deps |
68304 | 803 |
} |
804 |
||
68732 | 805 |
def build_selection(sel: Selection): List[String] = selected(build_graph, sel) |
67029 | 806 |
def build_descendants(ss: List[String]): List[String] = build_graph.all_succs(ss) |
807 |
def build_requirements(ss: List[String]): List[String] = build_graph.all_preds(ss).reverse |
|
808 |
def build_topological_order: List[String] = build_graph.topological_order |
|
62631 | 809 |
|
68732 | 810 |
def imports_selection(sel: Selection): List[String] = selected(imports_graph, sel) |
67029 | 811 |
def imports_descendants(ss: List[String]): List[String] = imports_graph.all_succs(ss) |
812 |
def imports_requirements(ss: List[String]): List[String] = imports_graph.all_preds(ss).reverse |
|
813 |
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
|
814 |
|
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
815 |
override def toString: String = |
67052 | 816 |
imports_graph.keys_iterator.mkString("Sessions.Structure(", ", ", ")") |
62631 | 817 |
} |
818 |
||
819 |
||
820 |
/* parser */ |
|
821 |
||
62864 | 822 |
val ROOT = Path.explode("ROOT") |
823 |
val ROOTS = Path.explode("ROOTS") |
|
824 |
||
62631 | 825 |
private val CHAPTER = "chapter" |
826 |
private val SESSION = "session" |
|
827 |
private val IN = "in" |
|
828 |
private val DESCRIPTION = "description" |
|
829 |
private val OPTIONS = "options" |
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
830 |
private val SESSIONS = "sessions" |
62631 | 831 |
private val THEORIES = "theories" |
65374 | 832 |
private val GLOBAL = "global" |
62631 | 833 |
private val DOCUMENT_FILES = "document_files" |
68292 | 834 |
private val EXPORT_FILES = "export_files" |
62631 | 835 |
|
67004
af72fa58f71b
clarified lazy Completion within Outer_Syntax: measurable speedup of Sessions.deps;
wenzelm
parents:
66991
diff
changeset
|
836 |
val root_syntax = |
af72fa58f71b
clarified lazy Completion within Outer_Syntax: measurable speedup of Sessions.deps;
wenzelm
parents:
66991
diff
changeset
|
837 |
Outer_Syntax.empty + "(" + ")" + "+" + "," + "=" + "[" + "]" + GLOBAL + IN + |
63443 | 838 |
(CHAPTER, Keyword.THY_DECL) + |
839 |
(SESSION, Keyword.THY_DECL) + |
|
840 |
(DESCRIPTION, Keyword.QUASI_COMMAND) + |
|
841 |
(OPTIONS, Keyword.QUASI_COMMAND) + |
|
65420
695d4e22345a
support for static session imports, without affect build hierarchy;
wenzelm
parents:
65419
diff
changeset
|
842 |
(SESSIONS, Keyword.QUASI_COMMAND) + |
63443 | 843 |
(THEORIES, Keyword.QUASI_COMMAND) + |
68292 | 844 |
(DOCUMENT_FILES, Keyword.QUASI_COMMAND) + |
845 |
(EXPORT_FILES, Keyword.QUASI_COMMAND) |
|
62631 | 846 |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
847 |
abstract class Entry |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
848 |
sealed case class Chapter(name: String) extends Entry |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
849 |
sealed case class Session_Entry( |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
850 |
pos: Position.T, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
851 |
name: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
852 |
groups: List[String], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
853 |
path: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
854 |
parent: Option[String], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
855 |
description: String, |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
856 |
options: List[Options.Spec], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
857 |
imports: List[String], |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
858 |
theories: List[(List[Options.Spec], List[((String, Position.T), Boolean)])], |
68292 | 859 |
document_files: List[(String, String)], |
69671 | 860 |
export_files: List[(String, Int, List[String])]) extends Entry |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
861 |
{ |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
862 |
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
|
863 |
theories.map({ case (a, b) => (a, b.map({ case ((c, _), d) => (c, d) })) }) |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
864 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
865 |
|
68841 | 866 |
private object Parser extends Options.Parser |
62631 | 867 |
{ |
868 |
private val chapter: Parser[Chapter] = |
|
869 |
{ |
|
870 |
val chapter_name = atom("chapter name", _.is_name) |
|
871 |
||
872 |
command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter(a) } |
|
873 |
} |
|
874 |
||
875 |
private val session_entry: Parser[Session_Entry] = |
|
876 |
{ |
|
877 |
val option = |
|
67210 | 878 |
option_name ~ opt($$$("=") ~! option_value ^^ { case _ ~ x => x }) ^^ |
879 |
{ case x ~ y => (x, y) } |
|
62631 | 880 |
val options = $$$("[") ~> rep1sep(option, $$$(",")) <~ $$$("]") |
881 |
||
65374 | 882 |
val global = |
883 |
($$$("(") ~! $$$(GLOBAL) ~ $$$(")")) ^^ { case _ => true } | success(false) |
|
884 |
||
885 |
val theory_entry = |
|
65517 | 886 |
position(theory_name) ~ global ^^ { case x ~ y => (x, y) } |
65374 | 887 |
|
62631 | 888 |
val theories = |
65374 | 889 |
$$$(THEORIES) ~! |
66970
13857f49d215
clarified ROOT syntax: 'sessions' and 'theories' are optional, but need to be non-empty;
wenzelm
parents:
66969
diff
changeset
|
890 |
((options | success(Nil)) ~ rep1(theory_entry)) ^^ |
65374 | 891 |
{ case _ ~ (x ~ y) => (x, y) } |
62631 | 892 |
|
68292 | 893 |
val in_path = $$$("(") ~! ($$$(IN) ~ path ~ $$$(")")) ^^ { case _ ~ (_ ~ x ~ _) => x } |
894 |
||
62631 | 895 |
val document_files = |
896 |
$$$(DOCUMENT_FILES) ~! |
|
68292 | 897 |
((in_path | success("document")) ~ rep1(path)) ^^ { case _ ~ (x ~ y) => y.map((x, _)) } |
898 |
||
69671 | 899 |
val prune = $$$("[") ~! (nat ~ $$$("]")) ^^ { case _ ~ (x ~ _) => x } | success(0) |
900 |
||
68292 | 901 |
val export_files = |
69671 | 902 |
$$$(EXPORT_FILES) ~! ((in_path | success("export")) ~ prune ~ rep1(embedded)) ^^ |
903 |
{ case _ ~ (x ~ y ~ z) => (x, y, z) } |
|
62631 | 904 |
|
905 |
command(SESSION) ~! |
|
906 |
(position(session_name) ~ |
|
907 |
(($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~ |
|
908 |
(($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~ |
|
909 |
($$$("=") ~! |
|
910 |
(opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~ |
|
911 |
(($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")) ~ |
|
912 |
(($$$(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
|
913 |
(($$$(SESSIONS) ~! rep1(session_name) ^^ { case _ ~ x => x }) | success(Nil)) ~ |
13857f49d215
clarified ROOT syntax: 'sessions' and 'theories' are optional, but need to be non-empty;
wenzelm
parents:
66969
diff
changeset
|
914 |
rep(theories) ~ |
68292 | 915 |
(rep(document_files) ^^ (x => x.flatten)) ~ |
916 |
(rep(export_files))))) ^^ |
|
917 |
{ case _ ~ ((a, pos) ~ b ~ c ~ (_ ~ (d ~ e ~ f ~ g ~ h ~ i ~ j))) => |
|
918 |
Session_Entry(pos, a, b, c, d, e, f, g, h, i, j) } |
|
62631 | 919 |
} |
920 |
||
66819 | 921 |
def parse_root(path: Path): List[Entry] = |
62631 | 922 |
{ |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
923 |
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
|
924 |
val start = Token.Pos.file(path.implode) |
62631 | 925 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
926 |
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
|
927 |
case Success(result, _) => result |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
928 |
case bad => error(bad.toString) |
62631 | 929 |
} |
930 |
} |
|
931 |
} |
|
932 |
||
66819 | 933 |
def parse_root(path: Path): List[Entry] = Parser.parse_root(path) |
934 |
||
935 |
def parse_root_entries(path: Path): List[Session_Entry] = |
|
936 |
for (entry <- Parser.parse_root(path) if entry.isInstanceOf[Session_Entry]) |
|
937 |
yield entry.asInstanceOf[Session_Entry] |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
938 |
|
66960 | 939 |
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
|
940 |
{ |
69762
58fb0d779583
support for session information via virtual file-system;
wenzelm
parents:
69671
diff
changeset
|
941 |
var entry_chapter = UNSORTED |
66960 | 942 |
val infos = new mutable.ListBuffer[Info] |
66819 | 943 |
parse_root(path).foreach { |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
944 |
case Chapter(name) => entry_chapter = name |
66967
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
945 |
case entry: Session_Entry => |
e365c91c72a9
synthesize session with all required theories from other session imports;
wenzelm
parents:
66966
diff
changeset
|
946 |
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
|
947 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
948 |
infos.toList |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
949 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
950 |
|
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
951 |
def parse_roots(roots: Path): List[String] = |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
952 |
{ |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
953 |
for { |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
954 |
line <- split_lines(File.read(roots)) |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
955 |
if !(line == "" || line.startsWith("#")) |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
956 |
} yield line |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
957 |
} |
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
958 |
|
62631 | 959 |
|
62635 | 960 |
/* load sessions from certain directories */ |
62631 | 961 |
|
962 |
private def is_session_dir(dir: Path): Boolean = |
|
963 |
(dir + ROOT).is_file || (dir + ROOTS).is_file |
|
964 |
||
965 |
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
|
966 |
if (is_session_dir(dir)) File.pwd() + dir.expand |
62631 | 967 |
else error("Bad session root directory: " + dir.toString) |
968 |
||
65561 | 969 |
def directories(dirs: List[Path], select_dirs: List[Path]): List[(Boolean, Path)] = |
970 |
{ |
|
971 |
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
|
972 |
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
|
973 |
yield (select, dir.canonical) |
65561 | 974 |
} |
975 |
||
67026 | 976 |
def load_structure(options: Options, |
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
977 |
dirs: List[Path] = Nil, |
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
978 |
select_dirs: List[Path] = Nil, |
67052 | 979 |
infos: List[Info] = Nil): Structure = |
62631 | 980 |
{ |
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
981 |
def load_dir(select: Boolean, dir: Path): List[(Boolean, Path)] = |
62635 | 982 |
load_root(select, dir) ::: load_roots(select, dir) |
62631 | 983 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
984 |
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
|
985 |
{ |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
986 |
val root = dir + ROOT |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
987 |
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
|
988 |
} |
62631 | 989 |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
990 |
def load_roots(select: Boolean, dir: Path): List[(Boolean, Path)] = |
62631 | 991 |
{ |
992 |
val roots = dir + ROOTS |
|
993 |
if (roots.is_file) { |
|
994 |
for { |
|
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
995 |
entry <- parse_roots(roots) |
62631 | 996 |
dir1 = |
66818
5bc903a60932
clarified signature: public access to ROOT file syntax;
wenzelm
parents:
66780
diff
changeset
|
997 |
try { check_session_dir(dir + Path.explode(entry)) } |
62631 | 998 |
catch { |
999 |
case ERROR(msg) => |
|
1000 |
error(msg + "\nThe error(s) above occurred in session catalog " + roots.toString) |
|
1001 |
} |
|
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1002 |
res <- load_dir(select, dir1) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1003 |
} yield res |
62631 | 1004 |
} |
1005 |
else Nil |
|
1006 |
} |
|
1007 |
||
66764
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1008 |
val roots = |
62631 | 1009 |
for { |
65561 | 1010 |
(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
|
1011 |
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
|
1012 |
} yield res |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1013 |
|
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1014 |
val unique_roots = |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1015 |
((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
|
1016 |
val file = path.canonical_file |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1017 |
m.get(file) match { |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1018 |
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
|
1019 |
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
|
1020 |
} |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1021 |
}).toList.map(_._2) |
006deaf5c3dc
process ROOT files only once, which allows duplicate (or overlapping) session root directories;
wenzelm
parents:
66759
diff
changeset
|
1022 |
|
66968
9991671c98aa
allow to augment session context via explicit session infos;
wenzelm
parents:
66967
diff
changeset
|
1023 |
make(unique_roots.flatMap(p => read_root(options, p._1, p._2)) ::: infos) |
62631 | 1024 |
} |
62632 | 1025 |
|
1026 |
||
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1027 |
|
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1028 |
/** 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
|
1029 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1030 |
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
|
1031 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1032 |
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
|
1033 |
{ |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1034 |
if (heap.is_file) { |
69393
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69366
diff
changeset
|
1035 |
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
|
1036 |
{ |
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1037 |
val len = file.size |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1038 |
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
|
1039 |
if (len >= n) { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1040 |
file.position(len - n) |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1041 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1042 |
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
|
1043 |
var i = 0 |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1044 |
var m = 0 |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1045 |
do { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1046 |
m = file.read(buf) |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1047 |
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
|
1048 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1049 |
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
|
1050 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1051 |
if (i == n) { |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1052 |
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
|
1053 |
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
|
1054 |
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
|
1055 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1056 |
else None |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1057 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1058 |
else None |
69393
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69366
diff
changeset
|
1059 |
}) |
62704
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1060 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1061 |
else None |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1062 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1063 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1064 |
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
|
1065 |
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
|
1066 |
case None => |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1067 |
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
|
1068 |
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
|
1069 |
s |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1070 |
case Some(s) => s |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1071 |
} |
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1072 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1073 |
|
478b49f0d726
proper SHA1 digest as annex to heap file: Poly/ML reads precise segment length;
wenzelm
parents:
62637
diff
changeset
|
1074 |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1075 |
/** persistent store **/ |
62632 | 1076 |
|
65296 | 1077 |
object Session_Info |
1078 |
{ |
|
66857 | 1079 |
val session_name = SQL.Column.string("session_name").make_primary_key |
65326 | 1080 |
|
65296 | 1081 |
// Build_Log.Session_Info |
1082 |
val session_timing = SQL.Column.bytes("session_timing") |
|
1083 |
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
|
1084 |
val theory_timings = SQL.Column.bytes("theory_timings") |
65296 | 1085 |
val ml_statistics = SQL.Column.bytes("ml_statistics") |
1086 |
val task_statistics = SQL.Column.bytes("task_statistics") |
|
65934 | 1087 |
val errors = SQL.Column.bytes("errors") |
65296 | 1088 |
val build_log_columns = |
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1089 |
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
|
1090 |
ml_statistics, task_statistics, errors) |
65296 | 1091 |
|
1092 |
// Build.Session_Info |
|
1093 |
val sources = SQL.Column.string("sources") |
|
1094 |
val input_heaps = SQL.Column.string("input_heaps") |
|
1095 |
val output_heap = SQL.Column.string("output_heap") |
|
1096 |
val return_code = SQL.Column.int("return_code") |
|
66746 | 1097 |
val build_columns = List(sources, input_heaps, output_heap, return_code) |
65296 | 1098 |
|
1099 |
val table = SQL.Table("isabelle_session_info", build_log_columns ::: build_columns) |
|
1100 |
} |
|
1101 |
||
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1102 |
def store(options: Options): Store = new Store(options) |
62632 | 1103 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1104 |
class Store private[Sessions](val options: Options) |
62632 | 1105 |
{ |
68219 | 1106 |
override def toString: String = "Store(output_dir = " + output_dir.expand + ")" |
1107 |
||
1108 |
||
1109 |
/* directories */ |
|
1110 |
||
68523
ccacc84e0251
clarified settings -- avoid hard-wired directories;
wenzelm
parents:
68483
diff
changeset
|
1111 |
val system_output_dir: Path = Path.explode("$ISABELLE_HEAPS_SYSTEM/$ML_IDENTIFIER") |
ccacc84e0251
clarified settings -- avoid hard-wired directories;
wenzelm
parents:
68483
diff
changeset
|
1112 |
val user_output_dir: Path = Path.explode("$ISABELLE_HEAPS/$ML_IDENTIFIER") |
68219 | 1113 |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1114 |
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
|
1115 |
|
68221 | 1116 |
val output_dir: Path = |
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1117 |
if (system_heaps) system_output_dir else user_output_dir |
68219 | 1118 |
|
68221 | 1119 |
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
|
1120 |
if (system_heaps) List(system_output_dir) |
68219 | 1121 |
else List(user_output_dir, system_output_dir) |
62632 | 1122 |
|
1123 |
val browser_info: Path = |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1124 |
if (system_heaps) Path.explode("$ISABELLE_BROWSER_INFO_SYSTEM") |
62632 | 1125 |
else Path.explode("$ISABELLE_BROWSER_INFO") |
1126 |
||
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1127 |
|
68221 | 1128 |
/* file names */ |
65298 | 1129 |
|
68221 | 1130 |
def heap(name: String): Path = Path.basic(name) |
1131 |
def database(name: String): Path = Path.basic("log") + Path.basic(name).ext("db") |
|
1132 |
def log(name: String): Path = Path.basic("log") + Path.basic(name) |
|
1133 |
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
|
1134 |
|
68221 | 1135 |
def output_heap(name: String): Path = output_dir + heap(name) |
1136 |
def output_database(name: String): Path = output_dir + database(name) |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1137 |
def output_log(name: String): Path = output_dir + log(name) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1138 |
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
|
1139 |
|
68221 | 1140 |
def prepare_output_dir() { Isabelle_System.mkdirs(output_dir + Path.basic("log")) } |
68220
8fc4e3d1df86
clarified store.clean_output: cleanup user_output_dir even in system_mode;
wenzelm
parents:
68219
diff
changeset
|
1141 |
|
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1142 |
|
68221 | 1143 |
/* heap */ |
62637
0189fe0f6452
support for Poly/ML heap hierarchy, which saves a lot of disk space;
wenzelm
parents:
62636
diff
changeset
|
1144 |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1145 |
def find_heap(name: String): Option[Path] = |
68221 | 1146 |
input_dirs.map(_ + heap(name)).find(_.is_file) |
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1147 |
|
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1148 |
def find_heap_digest(name: String): Option[String] = |
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1149 |
find_heap(name).flatMap(read_heap_digest(_)) |
62632 | 1150 |
|
68221 | 1151 |
def the_heap(name: String): Path = |
1152 |
find_heap(name) getOrElse |
|
1153 |
error("Missing heap image for session " + quote(name) + " -- expected in:\n" + |
|
1154 |
cat_lines(input_dirs.map(dir => " " + dir.expand.implode))) |
|
1155 |
||
1156 |
||
1157 |
/* database */ |
|
1158 |
||
1159 |
private def database_server: Boolean = options.bool("build_database_server") |
|
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1160 |
|
68221 | 1161 |
def access_database(name: String, output: Boolean = false): Option[SQL.Database] = |
1162 |
{ |
|
1163 |
if (database_server) { |
|
1164 |
val db = |
|
1165 |
PostgreSQL.open_database( |
|
1166 |
user = options.string("build_database_user"), |
|
1167 |
password = options.string("build_database_password"), |
|
1168 |
database = options.string("build_database_name"), |
|
1169 |
host = options.string("build_database_host"), |
|
1170 |
port = options.int("build_database_port"), |
|
1171 |
ssh = |
|
69074 | 1172 |
options.proper_string("build_database_ssh_host").map(ssh_host => |
68221 | 1173 |
SSH.open_session(options, |
1174 |
host = ssh_host, |
|
1175 |
user = options.string("build_database_ssh_user"), |
|
1176 |
port = options.int("build_database_ssh_port"))), |
|
1177 |
ssh_close = true) |
|
1178 |
if (output || has_session_info(db, name)) Some(db) else { db.close; None } |
|
1179 |
} |
|
1180 |
else if (output) Some(SQLite.open_database(output_database(name))) |
|
1181 |
else input_dirs.map(_ + database(name)).find(_.is_file).map(SQLite.open_database(_)) |
|
1182 |
} |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1183 |
|
68221 | 1184 |
def open_database(name: String, output: Boolean = false): SQL.Database = |
1185 |
access_database(name, output = output) getOrElse |
|
1186 |
error("Missing build database for session " + quote(name)) |
|
68205 | 1187 |
|
68221 | 1188 |
def clean_output(name: String): (Boolean, Boolean) = |
1189 |
{ |
|
1190 |
val relevant_db = |
|
1191 |
database_server && |
|
1192 |
{ |
|
1193 |
access_database(name) match { |
|
1194 |
case Some(db) => |
|
1195 |
try { |
|
1196 |
db.transaction { |
|
1197 |
val relevant_db = has_session_info(db, name) |
|
1198 |
init_session_info(db, name) |
|
1199 |
relevant_db |
|
1200 |
} |
|
1201 |
} finally { db.close } |
|
1202 |
case None => false |
|
1203 |
} |
|
1204 |
} |
|
68212
5a59fded83c7
clarified heap vs. database operations: discontinued correlation of directory;
wenzelm
parents:
68210
diff
changeset
|
1205 |
|
68221 | 1206 |
val del = |
1207 |
for { |
|
69854
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1208 |
dir <- |
cc0b3e177b49
system option "system_heaps" supersedes various command-line options for "system build mode";
wenzelm
parents:
69812
diff
changeset
|
1209 |
(if (system_heaps) List(user_output_dir, system_output_dir) else List(user_output_dir)) |
68221 | 1210 |
file <- List(heap(name), database(name), log(name), log_gz(name)) |
1211 |
path = dir + file if path.is_file |
|
1212 |
} yield path.file.delete |
|
1213 |
||
1214 |
val relevant = relevant_db || del.nonEmpty |
|
1215 |
val ok = del.forall(b => b) |
|
1216 |
(relevant, ok) |
|
1217 |
} |
|
65287 | 1218 |
|
1219 |
||
68218 | 1220 |
/* SQL database content */ |
1221 |
||
68294 | 1222 |
val xml_cache: XML.Cache = XML.make_cache() |
1223 |
val xz_cache: XZ.Cache = XZ.make_cache() |
|
68218 | 1224 |
|
1225 |
def read_bytes(db: SQL.Database, name: String, column: SQL.Column): Bytes = |
|
1226 |
db.using_statement(Session_Info.table.select(List(column), |
|
1227 |
Session_Info.session_name.where_equal(name)))(stmt => |
|
1228 |
{ |
|
1229 |
val res = stmt.execute_query() |
|
1230 |
if (!res.next()) Bytes.empty else res.bytes(column) |
|
1231 |
}) |
|
1232 |
||
1233 |
def read_properties(db: SQL.Database, name: String, column: SQL.Column): List[Properties.T] = |
|
1234 |
Properties.uncompress( |
|
1235 |
read_bytes(db, name, column), cache = xz_cache, xml_cache = Some(xml_cache)) |
|
1236 |
||
1237 |
||
65296 | 1238 |
/* session info */ |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1239 |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1240 |
def init_session_info(db: SQL.Database, name: String) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1241 |
{ |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1242 |
db.transaction { |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1243 |
db.create_table(Session_Info.table) |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1244 |
db.using_statement( |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1245 |
Session_Info.table.delete(Session_Info.session_name.where_equal(name)))(_.execute) |
68221 | 1246 |
|
1247 |
db.create_table(Export.Data.table) |
|
1248 |
db.using_statement( |
|
1249 |
Export.Data.table.delete(Export.Data.session_name.where_equal(name)))(_.execute) |
|
1250 |
} |
|
1251 |
} |
|
1252 |
||
1253 |
def has_session_info(db: SQL.Database, name: String): Boolean = |
|
1254 |
{ |
|
1255 |
db.transaction { |
|
1256 |
db.tables.contains(Session_Info.table.name) && |
|
1257 |
{ |
|
1258 |
db.using_statement( |
|
1259 |
Session_Info.table.select(List(Session_Info.session_name), |
|
1260 |
Session_Info.session_name.where_equal(name)))(stmt => stmt.execute_query().next()) |
|
1261 |
} |
|
68086
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1262 |
} |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1263 |
} |
9e1c670301b8
cleanup session output before starting build job;
wenzelm
parents:
68018
diff
changeset
|
1264 |
|
65296 | 1265 |
def write_session_info( |
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1266 |
db: SQL.Database, |
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1267 |
name: String, |
65318
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1268 |
build_log: Build_Log.Session_Info, |
342efc382558
eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents:
65298
diff
changeset
|
1269 |
build: Build.Session_Info) |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1270 |
{ |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1271 |
db.transaction { |
65698 | 1272 |
db.using_statement(Session_Info.table.insert())(stmt => |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1273 |
{ |
65748 | 1274 |
stmt.string(1) = name |
65857 | 1275 |
stmt.bytes(2) = Properties.encode(build_log.session_timing) |
68018 | 1276 |
stmt.bytes(3) = Properties.compress(build_log.command_timings, cache = xz_cache) |
1277 |
stmt.bytes(4) = Properties.compress(build_log.theory_timings, cache = xz_cache) |
|
1278 |
stmt.bytes(5) = Properties.compress(build_log.ml_statistics, cache = xz_cache) |
|
1279 |
stmt.bytes(6) = Properties.compress(build_log.task_statistics, cache = xz_cache) |
|
1280 |
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
|
1281 |
stmt.string(8) = build.sources |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1282 |
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
|
1283 |
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
|
1284 |
stmt.int(11) = build.return_code |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1285 |
stmt.execute() |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1286 |
}) |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1287 |
} |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1288 |
} |
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1289 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1290 |
def read_session_timing(db: SQL.Database, name: String): Properties.T = |
65857 | 1291 |
Properties.decode(read_bytes(db, name, Session_Info.session_timing), Some(xml_cache)) |
65286 | 1292 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1293 |
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
|
1294 |
read_properties(db, name, Session_Info.command_timings) |
65286 | 1295 |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66857
diff
changeset
|
1296 |
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
|
1297 |
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
|
1298 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1299 |
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
|
1300 |
read_properties(db, name, Session_Info.ml_statistics) |
65286 | 1301 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1302 |
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
|
1303 |
read_properties(db, name, Session_Info.task_statistics) |
65286 | 1304 |
|
65937 | 1305 |
def read_errors(db: SQL.Database, name: String): List[String] = |
68018 | 1306 |
Build_Log.uncompress_errors(read_bytes(db, name, Session_Info.errors), cache = xz_cache) |
65937 | 1307 |
|
65320
52861eebf58d
access table via session_name: db may in principle contain multiple entries;
wenzelm
parents:
65318
diff
changeset
|
1308 |
def read_build(db: SQL.Database, name: String): Option[Build.Session_Info] = |
66744 | 1309 |
{ |
66957
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1310 |
if (db.tables.contains(Session_Info.table.name)) { |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1311 |
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
|
1312 |
Session_Info.session_name.where_equal(name)))(stmt => |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1313 |
{ |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1314 |
val res = stmt.execute_query() |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1315 |
if (!res.next()) None |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1316 |
else { |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1317 |
Some( |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1318 |
Build.Session_Info( |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1319 |
res.string(Session_Info.sources), |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1320 |
split_lines(res.string(Session_Info.input_heaps)), |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1321 |
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
|
1322 |
res.int(Session_Info.return_code))) |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1323 |
} |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1324 |
}) |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1325 |
} |
82d13ba817b2
more permissive: db could be empty after hard crash;
wenzelm
parents:
66914
diff
changeset
|
1326 |
else None |
66744 | 1327 |
} |
65281
c70e7d24a16d
SQL database operations for combined session info;
wenzelm
parents:
65278
diff
changeset
|
1328 |
} |
62631 | 1329 |
} |