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