src/Pure/System/build.scala
changeset 48423 0ccf143a2a69
parent 48422 9613780a805b
child 48424 e6b0c14f04c8
equal deleted inserted replaced
48422:9613780a805b 48423:0ccf143a2a69
    50       parent: Option[String],
    50       parent: Option[String],
    51       description: String,
    51       description: String,
    52       options: Options,
    52       options: Options,
    53       theories: List[(Options, List[Path])],
    53       theories: List[(Options, List[Path])],
    54       files: List[Path],
    54       files: List[Path],
       
    55       digest: SHA1.Digest,
    55       status: Status = Pending)
    56       status: Status = Pending)
    56 
    57 
    57 
    58 
    58     /* Queue */
    59     /* Queue */
    59 
    60 
   201         val key = Session.Key(full_name, entry.order)
   202         val key = Session.Key(full_name, entry.order)
   202 
   203 
   203         val theories =
   204         val theories =
   204           entry.theories.map({ case (opts, thys) => (options ++ opts, thys.map(Path.explode(_))) })
   205           entry.theories.map({ case (opts, thys) => (options ++ opts, thys.map(Path.explode(_))) })
   205         val files = entry.files.map(Path.explode(_))
   206         val files = entry.files.map(Path.explode(_))
       
   207         val digest = SHA1.digest((full_name, entry.parent, entry.options, entry.theories).toString)
       
   208 
   206         val info =
   209         val info =
   207           Session.Info(dir + path, entry.parent,
   210           Session.Info(dir + path, entry.parent,
   208             entry.description, options ++ entry.options, theories, files)
   211             entry.description, options ++ entry.options, theories, files, digest)
   209 
   212 
   210         queue1 + (key, info)
   213         queue1 + (key, info)
   211       }
   214       }
   212       catch {
   215       catch {
   213         case ERROR(msg) =>
   216         case ERROR(msg) =>
   268 
   271 
   269   /* dependencies */
   272   /* dependencies */
   270 
   273 
   271   sealed case class Node(
   274   sealed case class Node(
   272     loaded_theories: Set[String],
   275     loaded_theories: Set[String],
   273     sources: List[Path])
   276     sources: List[(Path, SHA1.Digest)])
   274 
   277 
   275   def dependencies(queue: Session.Queue): Map[String, Node] =
   278   sealed case class Deps(deps: Map[String, Node])
   276     (Map.empty[String, Node] /: queue.topological_order)(
   279   {
       
   280     def sources(name: String): List[(Path, SHA1.Digest)] = deps(name).sources
       
   281   }
       
   282 
       
   283   def dependencies(queue: Session.Queue): Deps =
       
   284     Deps((Map.empty[String, Node] /: queue.topological_order)(
   277       { case (deps, (name, info)) =>
   285       { case (deps, (name, info)) =>
   278           val preloaded =
   286           val preloaded =
   279             info.parent match {
   287             info.parent match {
   280               case None => Set.empty[String]
   288               case None => Set.empty[String]
   281               case Some(parent) => deps(parent).loaded_theories
   289               case Some(parent) => deps(parent).loaded_theories
   286             thy_info.dependencies(
   294             thy_info.dependencies(
   287               info.theories.map(_._2).flatten.
   295               info.theories.map(_._2).flatten.
   288                 map(thy => Document.Node.Name(info.dir + Thy_Load.thy_path(thy))))
   296                 map(thy => Document.Node.Name(info.dir + Thy_Load.thy_path(thy))))
   289 
   297 
   290           val loaded_theories = preloaded ++ thy_deps.map(_._1.theory)
   298           val loaded_theories = preloaded ++ thy_deps.map(_._1.theory)
   291           val sources =
   299 
       
   300           val all_files =
   292             thy_deps.map({ case (n, h) =>
   301             thy_deps.map({ case (n, h) =>
   293               val thy = Path.explode(n.node).expand
   302               val thy = Path.explode(n.node).expand
   294               val uses =
   303               val uses =
   295                 h match {
   304                 h match {
   296                   case Exn.Res(d) =>
   305                   case Exn.Res(d) =>
   297                     d.uses.map(p => (Path.explode(n.dir) + Path.explode(p._1)).expand)
   306                     d.uses.map(p => (Path.explode(n.dir) + Path.explode(p._1)).expand)
   298                   case _ => Nil
   307                   case _ => Nil
   299                 }
   308                 }
   300               thy :: uses
   309               thy :: uses
   301             }).flatten ::: info.files.map(file => info.dir + file)
   310             }).flatten ::: info.files.map(file => info.dir + file)
       
   311           val sources = all_files.par.map(p => (p, SHA1.digest(p))).toList
   302 
   312 
   303           deps + (name -> Node(loaded_theories, sources))
   313           deps + (name -> Node(loaded_theories, sources))
   304       })
   314       }))
   305 
   315 
   306 
   316 
   307 
   317 
   308   /** build **/
   318   /** build **/
   309 
   319 
   365   def build(all_sessions: Boolean, build_images: Boolean, list_only: Boolean,
   375   def build(all_sessions: Boolean, build_images: Boolean, list_only: Boolean,
   366     more_dirs: List[Path], more_options: List[String], sessions: List[String]): Int =
   376     more_dirs: List[Path], more_options: List[String], sessions: List[String]): Int =
   367   {
   377   {
   368     val options = (Options.init() /: more_options)(_.define_simple(_))
   378     val options = (Options.init() /: more_options)(_.define_simple(_))
   369     val queue = find_sessions(options, all_sessions, sessions, more_dirs)
   379     val queue = find_sessions(options, all_sessions, sessions, more_dirs)
       
   380     val deps = dependencies(queue)
   370 
   381 
   371 
   382 
   372     // prepare browser info dir
   383     // prepare browser info dir
   373     if (options.bool("browser_info") &&
   384     if (options.bool("browser_info") &&
   374       !Path.explode("$ISABELLE_BROWSER_INFO/index.html").file.isFile)
   385       !Path.explode("$ISABELLE_BROWSER_INFO/index.html").file.isFile)
   398           val (out, err, rc) = build_job(save, name, info).join
   409           val (out, err, rc) = build_job(save, name, info).join
   399           echo_n(err)
   410           echo_n(err)
   400 
   411 
   401           val log = log_dir + Path.basic(name)
   412           val log = log_dir + Path.basic(name)
   402           if (rc == 0) {
   413           if (rc == 0) {
   403             File.write_zip(log.ext("gz"), out)
   414             val sources =
       
   415               (info.digest :: deps.sources(name).map(_._2)).map(_.toString).sorted
       
   416                 .mkString("sources: ", " ", "\n")
       
   417             File.write_zip(log.ext("gz"), sources + out)
   404           }
   418           }
   405           else {
   419           else {
   406             File.write(log, out)
   420             File.write(log, out)
   407             echo(name + " FAILED")
   421             echo(name + " FAILED")
   408             echo("(see also " + log.file + ")")
   422             echo("(see also " + log.file + ")")