src/Pure/Thy/sessions.scala
changeset 65519 d244d8f8e13f
parent 65517 1544e61e5314
child 65520 f47bc12b6e8a
equal deleted inserted replaced
65518:bc8fa59211b7 65519:d244d8f8e13f
   135       global_theories: Map[String, String] = Map.empty,
   135       global_theories: Map[String, String] = Map.empty,
   136       all_known: Boolean = false): Deps =
   136       all_known: Boolean = false): Deps =
   137   {
   137   {
   138     val session_bases =
   138     val session_bases =
   139       (Map.empty[String, Base] /: sessions.imports_topological_order)({
   139       (Map.empty[String, Base] /: sessions.imports_topological_order)({
   140         case (session_bases, (session_name, info)) =>
   140         case (session_bases, info) =>
   141           if (progress.stopped) throw Exn.Interrupt()
   141           if (progress.stopped) throw Exn.Interrupt()
   142 
   142 
   143           try {
   143           try {
   144             val parent_base: Sessions.Base =
   144             val parent_base: Sessions.Base =
   145               info.parent match {
   145               info.parent match {
   149             val imports_base: Sessions.Base =
   149             val imports_base: Sessions.Base =
   150               parent_base.copy(known =
   150               parent_base.copy(known =
   151                 Known.make(info.dir, parent_base :: info.imports.map(session_bases(_)), Nil))
   151                 Known.make(info.dir, parent_base :: info.imports.map(session_bases(_)), Nil))
   152 
   152 
   153             val resources = new Resources(imports_base,
   153             val resources = new Resources(imports_base,
   154               default_qualifier = info.theory_qualifier(session_name))
   154               default_qualifier = info.theory_qualifier(info.name))
   155 
   155 
   156             if (verbose || list_files) {
   156             if (verbose || list_files) {
   157               val groups =
   157               val groups =
   158                 if (info.groups.isEmpty) ""
   158                 if (info.groups.isEmpty) ""
   159                 else info.groups.mkString(" (", " ", ")")
   159                 else info.groups.mkString(" (", " ", ")")
   160               progress.echo("Session " + info.chapter + "/" + session_name + groups)
   160               progress.echo("Session " + info.chapter + "/" + info.name + groups)
   161             }
   161             }
   162 
   162 
   163             val thy_deps =
   163             val thy_deps =
   164             {
   164             {
   165               val root_theories =
   165               val root_theories =
   166                 info.theories.flatMap({ case (_, thys) =>
   166                 info.theories.flatMap({ case (_, thys) =>
   167                   thys.map({ case (thy, pos) =>
   167                   thys.map({ case (thy, pos) =>
   168                     (resources.import_name(session_name, info.dir.implode, thy), pos) })
   168                     (resources.import_name(info.name, info.dir.implode, thy), pos) })
   169                 })
   169                 })
   170               val thy_deps = resources.thy_info.dependencies(root_theories)
   170               val thy_deps = resources.thy_info.dependencies(root_theories)
   171 
   171 
   172               thy_deps.errors match {
   172               thy_deps.errors match {
   173                 case Nil => thy_deps
   173                 case Nil => thy_deps
   179 
   179 
   180             val theory_files = thy_deps.deps.map(dep => Path.explode(dep.name.node))
   180             val theory_files = thy_deps.deps.map(dep => Path.explode(dep.name.node))
   181             val loaded_files =
   181             val loaded_files =
   182               if (inlined_files) {
   182               if (inlined_files) {
   183                 val pure_files =
   183                 val pure_files =
   184                   if (is_pure(session_name)) {
   184                   if (is_pure(info.name)) {
   185                     val roots = Thy_Header.ml_roots.map(p => info.dir + Path.explode(p._1))
   185                     val roots = Thy_Header.ml_roots.map(p => info.dir + Path.explode(p._1))
   186                     val files =
   186                     val files =
   187                       roots.flatMap(root => resources.loaded_files(syntax, File.read(root))).
   187                       roots.flatMap(root => resources.loaded_files(syntax, File.read(root))).
   188                         map(file => info.dir + Path.explode(file))
   188                         map(file => info.dir + Path.explode(file))
   189                     roots ::: files
   189                     roots ::: files
   210                 Graph_Display.Node("[" + name + "]", "session." + name)
   210                 Graph_Display.Node("[" + name + "]", "session." + name)
   211 
   211 
   212               def node(name: Document.Node.Name): Graph_Display.Node =
   212               def node(name: Document.Node.Name): Graph_Display.Node =
   213               {
   213               {
   214                 val session = resources.theory_qualifier(name)
   214                 val session = resources.theory_qualifier(name)
   215                 if (session == session_name)
   215                 if (session == info.name)
   216                   Graph_Display.Node(name.theory_base_name, "theory." + name.theory)
   216                   Graph_Display.Node(name.theory_base_name, "theory." + name.theory)
   217                 else session_node(session)
   217                 else session_node(session)
   218               }
   218               }
   219 
   219 
   220               val imports_subgraph =
   220               val imports_subgraph =
   244                 keywords = thy_deps.keywords,
   244                 keywords = thy_deps.keywords,
   245                 syntax = syntax,
   245                 syntax = syntax,
   246                 sources = all_files.map(p => (p, SHA1.digest(p.file))),
   246                 sources = all_files.map(p => (p, SHA1.digest(p.file))),
   247                 session_graph = session_graph)
   247                 session_graph = session_graph)
   248 
   248 
   249             session_bases + (session_name -> base)
   249             session_bases + (info.name -> base)
   250           }
   250           }
   251           catch {
   251           catch {
   252             case ERROR(msg) =>
   252             case ERROR(msg) =>
   253               cat_error(msg, "The error(s) above occurred in session " +
   253               cat_error(msg, "The error(s) above occurred in session " +
   254                 quote(session_name) + Position.here(info.pos))
   254                 quote(info.name) + Position.here(info.pos))
   255           }
   255           }
   256       })
   256       })
   257 
   257 
   258     Deps(session_bases,
   258     Deps(session_bases,
   259       if (all_known) Known.make(Path.current, session_bases.toList.map(_._2), Nil)
   259       if (all_known) Known.make(Path.current, session_bases.toList.map(_._2), Nil)
   281 
   281 
   282 
   282 
   283   /* cumulative session info */
   283   /* cumulative session info */
   284 
   284 
   285   sealed case class Info(
   285   sealed case class Info(
       
   286     name: String,
   286     chapter: String,
   287     chapter: String,
   287     select: Boolean,
   288     select: Boolean,
   288     pos: Position.T,
   289     pos: Position.T,
   289     groups: List[String],
   290     groups: List[String],
   290     dir: Path,
   291     dir: Path,
   414       if (imports_graph.defined(name)) Some(imports_graph.get_node(name)) else None
   415       if (imports_graph.defined(name)) Some(imports_graph.get_node(name)) else None
   415 
   416 
   416     def global_theories: Map[String, String] =
   417     def global_theories: Map[String, String] =
   417       (Thy_Header.bootstrap_global_theories.toMap /:
   418       (Thy_Header.bootstrap_global_theories.toMap /:
   418         (for {
   419         (for {
   419           (session_name, (info, _)) <- imports_graph.iterator
   420           (_, (info, _)) <- imports_graph.iterator
   420           thy <- info.global_theories.iterator } yield (thy, session_name, info)))({
   421           thy <- info.global_theories.iterator }
   421             case (global, (thy, session_name, info)) =>
   422          yield (thy, info)))({
   422               val qualifier = info.theory_qualifier(session_name)
   423             case (global, (thy, info)) =>
       
   424               val qualifier = info.theory_qualifier(info.name)
   423               global.get(thy) match {
   425               global.get(thy) match {
   424                 case Some(qualifier1) if qualifier != qualifier1 =>
   426                 case Some(qualifier1) if qualifier != qualifier1 =>
   425                   error("Duplicate global theory " + quote(thy) + Position.here(info.pos))
   427                   error("Duplicate global theory " + quote(thy) + Position.here(info.pos))
   426                 case _ => global + (thy -> qualifier)
   428                 case _ => global + (thy -> qualifier)
   427               }
   429               }
   438       build_graph.all_preds(List(name)).tail.reverse
   440       build_graph.all_preds(List(name)).tail.reverse
   439 
   441 
   440     def build_descendants(names: List[String]): List[String] =
   442     def build_descendants(names: List[String]): List[String] =
   441       build_graph.all_succs(names)
   443       build_graph.all_succs(names)
   442 
   444 
   443     def build_topological_order: List[(String, Info)] =
   445     def build_topological_order: List[Info] =
   444       build_graph.topological_order.map(name => (name, apply(name)))
   446       build_graph.topological_order.map(apply(_))
   445 
   447 
   446     def imports_topological_order: List[(String, Info)] =
   448     def imports_topological_order: List[Info] =
   447       imports_graph.topological_order.map(name => (name, apply(name)))
   449       imports_graph.topological_order.map(apply(_))
   448 
   450 
   449     override def toString: String =
   451     override def toString: String =
   450       imports_graph.keys_iterator.mkString("Sessions.T(", ", ", ")")
   452       imports_graph.keys_iterator.mkString("Sessions.T(", ", ", ")")
   451   }
   453   }
   452 
   454 
   577           val meta_digest =
   579           val meta_digest =
   578             SHA1.digest((entry_chapter, name, entry.parent, entry.options,
   580             SHA1.digest((entry_chapter, name, entry.parent, entry.options,
   579               entry.imports, entry.theories, entry.files, entry.document_files).toString)
   581               entry.imports, entry.theories, entry.files, entry.document_files).toString)
   580 
   582 
   581           val info =
   583           val info =
   582             Info(entry_chapter, select, entry.pos, entry.groups, dir + Path.explode(entry.path),
   584             Info(name, entry_chapter, select, entry.pos, entry.groups,
   583               entry.parent, entry.description, session_options, entry.imports, theories,
   585               dir + Path.explode(entry.path), entry.parent, entry.description, session_options,
   584               global_theories, files, document_files, meta_digest)
   586               entry.imports, theories, global_theories, files, document_files, meta_digest)
   585 
   587 
   586           (name, info)
   588           (name, info)
   587         }
   589         }
   588         catch {
   590         catch {
   589           case ERROR(msg) =>
   591           case ERROR(msg) =>