src/Pure/Thy/presentation.scala
changeset 72882 1dc2ad97e062
parent 72880 2fce0ce47627
child 72955 942bf91545fa
equal deleted inserted replaced
72881:220a094a42d8 72882:1dc2ad97e062
   446   val session_tex_path = Path.explode("session.tex")
   446   val session_tex_path = Path.explode("session.tex")
   447 
   447 
   448   def tex_name(name: Document.Node.Name): String = name.theory_base_name + ".tex"
   448   def tex_name(name: Document.Node.Name): String = name.theory_base_name + ".tex"
   449   def document_tex_name(name: Document.Node.Name): String = "document/" + tex_name(name)
   449   def document_tex_name(name: Document.Node.Name): String = "document/" + tex_name(name)
   450 
   450 
       
   451   class Build_Error(val log_lines: List[String], val message: String)
       
   452     extends Exn.User_Error(message)
       
   453 
   451   def build_documents(
   454   def build_documents(
   452     session: String,
   455     session: String,
   453     deps: Sessions.Deps,
   456     deps: Sessions.Deps,
   454     db_context: Sessions.Database_Context,
   457     db_context: Sessions.Database_Context,
   455     progress: Progress = new Progress,
   458     progress: Progress = new Progress,
   574             // result
   577             // result
   575 
   578 
   576             val root_pdf = Path.basic(root).pdf
   579             val root_pdf = Path.basic(root).pdf
   577             val result_path = doc_dir + root_pdf
   580             val result_path = doc_dir + root_pdf
   578 
   581 
       
   582             val log_lines = result.out_lines ::: result.err_lines
       
   583 
   579             if (!result.ok) {
   584             if (!result.ok) {
   580               cat_error(
   585               val message =
   581                 Library.trim_line(result.err),
   586                 Exn.cat_message(
   582                 cat_lines(Latex.latex_errors(doc_dir, root) ::: Bibtex.bibtex_errors(doc_dir, root)),
   587                   Library.trim_line(result.err),
   583                 "Failed to build document " + quote(doc.name))
   588                   cat_lines(Latex.latex_errors(doc_dir, root) ::: Bibtex.bibtex_errors(doc_dir, root)),
       
   589                   "Failed to build document " + quote(doc.name))
       
   590               throw new Build_Error(log_lines, message)
   584             }
   591             }
   585             else if (!result_path.is_file) {
   592             else if (!result_path.is_file) {
   586               error("Bad document result: expected to find " + root_pdf)
   593               val message = "Bad document result: expected to find " + root_pdf
       
   594               throw new Build_Error(log_lines, message)
   587             }
   595             }
   588             else {
   596             else {
   589               val stop = Time.now()
   597               val stop = Time.now()
   590               val timing = stop - start
   598               val timing = stop - start
   591               progress.echo("Finished " + session + "/" + doc.name +
   599               progress.echo("Finished " + session + "/" + doc.name +
   592                 " (" + timing.message_hms + " elapsed time)")
   600                 " (" + timing.message_hms + " elapsed time)")
   593 
   601 
   594               val log_xz = Bytes(cat_lines(result.out_lines ::: result.err_lines)).compress()
   602               val log_xz = Bytes(cat_lines(log_lines)).compress()
   595               val pdf = Bytes.read(result_path)
   603               val pdf = Bytes.read(result_path)
   596               Document_Output(doc.name, sources, log_xz, pdf)
   604               Document_Output(doc.name, sources, log_xz, pdf)
   597             }
   605             }
   598           }
   606           }
   599         })
   607         })