src/Pure/Tools/build.ML
author wenzelm
Fri Jan 18 23:33:17 2013 +0100 (2013-01-18 ago)
changeset 50982 a7aa17a1f721
parent 50975 73ec6ad6700e
child 51045 630c0895d9d1
permissions -rw-r--r--
use inlined session name as title for charts;
tuned signature;
     1 (*  Title:      Pure/Tools/build.ML
     2     Author:     Makarius
     3 
     4 Build Isabelle sessions.
     5 *)
     6 
     7 signature BUILD =
     8 sig
     9   val build: string -> unit
    10 end;
    11 
    12 structure Build: BUILD =
    13 struct
    14 
    15 (* protocol messages *)
    16 
    17 fun ML_statistics (function :: stats) "" =
    18       if function = Markup.ML_statistics then SOME stats
    19       else NONE
    20   | ML_statistics _ _ = NONE;
    21 
    22 fun task_statistics (function :: stats) "" =
    23       if function = Markup.task_statistics then SOME stats
    24       else NONE
    25   | task_statistics _ _ = NONE;
    26 
    27 fun protocol_message props output =
    28   (case ML_statistics props output of
    29     SOME stats => writeln ("\fML_statistics = " ^ ML_Syntax.print_properties stats)
    30   | NONE =>
    31       (case task_statistics props output of
    32         SOME stats => writeln ("\ftask_statistics = " ^ ML_Syntax.print_properties stats)
    33       | NONE =>
    34           (case Markup.dest_loading_theory props of
    35             SOME name => writeln ("\floading_theory = " ^ name)
    36           | NONE => raise Fail "Undefined Output.protocol_message")));
    37 
    38 
    39 (* build *)
    40 
    41 local
    42 
    43 fun no_document options =
    44   (case Options.string options "document" of "" => true | "false" => true | _ => false);
    45 
    46 fun use_thys options =
    47   Thy_Info.use_thys
    48     |> Unsynchronized.setmp Proofterm.proofs (Options.int options "proofs")
    49     |> Unsynchronized.setmp print_mode
    50         (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
    51     |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
    52     |> Unsynchronized.setmp Goal.parallel_proofs_threshold
    53         (Options.int options "parallel_proofs_threshold")
    54     |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
    55     |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
    56     |> Unsynchronized.setmp Future.ML_statistics true
    57     |> no_document options ? Present.no_document
    58     |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
    59     |> Unsynchronized.setmp Toplevel.skip_proofs (Options.bool options "skip_proofs")
    60     |> Unsynchronized.setmp Printer.show_question_marks_default
    61         (Options.bool options "show_question_marks")
    62     |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
    63     |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
    64     |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
    65     |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
    66     |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
    67     |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
    68     |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
    69     |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
    70     |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
    71     |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
    72 
    73 fun use_theories (options, thys) =
    74   let val condition = space_explode "," (Options.string options "condition") in
    75     (case filter_out (can getenv_strict) condition of
    76       [] => use_thys options (map (rpair Position.none) thys)
    77     | conds =>
    78         Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
    79           " (undefined " ^ commas conds ^ ")\n"))
    80   end;
    81 
    82 in
    83 
    84 fun build args_file = Command_Line.tool (fn () =>
    85     let
    86       val (do_output, (options, (verbose, (browser_info, (parent_name,
    87           (name, theories)))))) =
    88         File.read (Path.explode args_file) |> YXML.parse_body |>
    89           let open XML.Decode in
    90             pair bool (pair Options.decode (pair bool (pair string (pair string
    91               (pair string ((list (pair Options.decode (list string)))))))))
    92           end;
    93 
    94       val document_variants =
    95         map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
    96       val _ =
    97         (case duplicates (op =) (map fst document_variants) of
    98           [] => ()
    99         | dups => error ("Duplicate document variants: " ^ commas_quote dups));
   100 
   101       val _ = writeln ("\fSession.name = " ^ name);
   102       val _ =
   103         (case Session.path () of
   104           [] => ()
   105         | path => writeln ("\fSession.parent_path = " ^ space_implode "/" path));
   106       val _ =
   107         Session.init do_output false
   108           (Options.bool options "browser_info") browser_info
   109           (Options.string options "document")
   110           (Options.bool options "document_graph")
   111           (Options.string options "document_output")
   112           document_variants
   113           parent_name name
   114           (false, "") ""
   115           verbose;
   116 
   117       val res1 =
   118         theories |>
   119           (List.app use_theories
   120             |> Session.with_timing name verbose
   121             |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
   122             |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
   123             |> Exn.capture);
   124       val res2 = Exn.capture Session.finish ();
   125       val _ = Par_Exn.release_all [res1, res2];
   126 
   127       val _ = if do_output then () else exit 0;
   128     in 0 end);
   129 
   130 end;
   131 
   132 end;