src/Pure/Tools/build.ML
author wenzelm
Sun May 12 15:05:15 2013 +0200 (2013-05-12 ago)
changeset 51941 ead4248aef3b
parent 51666 b97aeb018900
child 51949 f6858bb224c9
permissions -rw-r--r--
full default options for Isabelle_Process and Build;
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@51662
    15
(* command timings *)
wenzelm@51662
    16
wenzelm@51662
    17
type timings = ((string * Time.time) Inttab.table) Symtab.table;  (*file -> offset -> name * time *)
wenzelm@51662
    18
wenzelm@51662
    19
val empty_timings: timings = Symtab.empty;
wenzelm@51662
    20
wenzelm@51662
    21
fun update_timings props =
wenzelm@51662
    22
  (case Markup.parse_command_timing_properties props of
wenzelm@51662
    23
    SOME ({file, offset, name}, time) =>
wenzelm@51666
    24
      Symtab.map_default (file, Inttab.empty)
wenzelm@51666
    25
        (Inttab.map_default (offset, (name, time)) (fn (_, t) => (name, Time.+ (t, time))))
wenzelm@51662
    26
  | NONE => I);
wenzelm@51662
    27
wenzelm@51662
    28
fun approximative_id name pos =
wenzelm@51662
    29
  (case (Position.file_of pos, Position.offset_of pos) of
wenzelm@51662
    30
    (SOME file, SOME offset) =>
wenzelm@51662
    31
      if name = "" then NONE else SOME {file = file, offset = offset, name = name}
wenzelm@51662
    32
  | _ => NONE);
wenzelm@51662
    33
wenzelm@51662
    34
fun lookup_timings timings tr =
wenzelm@51662
    35
  (case approximative_id (Toplevel.name_of tr) (Toplevel.pos_of tr) of
wenzelm@51662
    36
    SOME {file, offset, name} =>
wenzelm@51662
    37
      (case Symtab.lookup timings file of
wenzelm@51662
    38
        SOME offsets =>
wenzelm@51662
    39
          (case Inttab.lookup offsets offset of
wenzelm@51662
    40
            SOME (name', time) => if name = name' then SOME time else NONE
wenzelm@51662
    41
          | NONE => NONE)
wenzelm@51662
    42
      | NONE => NONE)
wenzelm@51662
    43
  | NONE => NONE);
wenzelm@51662
    44
wenzelm@51662
    45
wenzelm@50683
    46
(* protocol messages *)
wenzelm@50683
    47
wenzelm@51662
    48
fun inline_message a args =
wenzelm@51662
    49
  writeln ("\f" ^ a ^ " = " ^ YXML.string_of_body (XML.Encode.properties args));
wenzelm@50683
    50
wenzelm@50683
    51
fun protocol_message props output =
wenzelm@51216
    52
  (case props of
wenzelm@51216
    53
    function :: args =>
wenzelm@51662
    54
      if function = Markup.ML_statistics orelse function = Markup.task_statistics then
wenzelm@51662
    55
        inline_message (#2 function) args
wenzelm@51662
    56
      else if function = Markup.command_timing then
wenzelm@51662
    57
        let
wenzelm@51662
    58
          val name = the_default "" (Properties.get args Markup.nameN);
wenzelm@51662
    59
          val pos = Position.of_properties args;
wenzelm@51662
    60
          val {elapsed, ...} = Markup.parse_timing_properties args;
wenzelm@51662
    61
        in
wenzelm@51662
    62
          (case approximative_id name pos of
wenzelm@51662
    63
            SOME id => inline_message (#2 function) (Markup.command_timing_properties id elapsed)
wenzelm@51662
    64
          | NONE => ())
wenzelm@51662
    65
        end
wenzelm@51216
    66
      else
wenzelm@51216
    67
        (case Markup.dest_loading_theory props of
wenzelm@51216
    68
          SOME name => writeln ("\floading_theory = " ^ name)
wenzelm@51661
    69
        | NONE => raise Output.Protocol_Message props)
wenzelm@51661
    70
  | [] => raise Output.Protocol_Message props);
wenzelm@51045
    71
wenzelm@50683
    72
wenzelm@50683
    73
(* build *)
wenzelm@50683
    74
wenzelm@48465
    75
local
wenzelm@48465
    76
wenzelm@48500
    77
fun no_document options =
wenzelm@50121
    78
  (case Options.string options "document" of "" => true | "false" => true | _ => false);
wenzelm@48500
    79
wenzelm@51217
    80
fun use_theories last_timing options =
wenzelm@51217
    81
  Thy_Info.use_theories {last_timing = last_timing, master_dir = Path.current}
wenzelm@48457
    82
    |> Unsynchronized.setmp Proofterm.proofs (Options.int options "proofs")
wenzelm@48457
    83
    |> Unsynchronized.setmp print_mode
wenzelm@48457
    84
        (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
wenzelm@48457
    85
    |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
wenzelm@51423
    86
    |> Unsynchronized.setmp Goal.parallel_subproofs_saturation
wenzelm@51423
    87
        (Options.int options "parallel_subproofs_saturation")
wenzelm@51423
    88
    |> Unsynchronized.setmp Goal.parallel_subproofs_threshold
wenzelm@51423
    89
        (Options.real options "parallel_subproofs_threshold")
wenzelm@48457
    90
    |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
wenzelm@48460
    91
    |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@50698
    92
    |> Unsynchronized.setmp Future.ML_statistics true
wenzelm@48500
    93
    |> no_document options ? Present.no_document
wenzelm@48486
    94
    |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
wenzelm@51553
    95
    |> Unsynchronized.setmp Goal.skip_proofs (Options.bool options "skip_proofs")
wenzelm@48486
    96
    |> Unsynchronized.setmp Printer.show_question_marks_default
wenzelm@48486
    97
        (Options.bool options "show_question_marks")
wenzelm@48486
    98
    |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
wenzelm@48486
    99
    |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
wenzelm@48492
   100
    |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
wenzelm@48520
   101
    |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
wenzelm@48520
   102
    |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
wenzelm@48520
   103
    |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
wenzelm@48520
   104
    |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
wenzelm@48520
   105
    |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
wenzelm@48527
   106
    |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
wenzelm@48492
   107
    |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
wenzelm@48457
   108
wenzelm@51217
   109
fun use_theories_condition last_timing (options, thys) =
wenzelm@48465
   110
  let val condition = space_explode "," (Options.string options "condition") in
wenzelm@48465
   111
    (case filter_out (can getenv_strict) condition of
wenzelm@51941
   112
      [] =>
wenzelm@51941
   113
        (Options.set_default options;
wenzelm@51941
   114
         use_theories last_timing options (map (rpair Position.none) thys))
wenzelm@48465
   115
    | conds =>
wenzelm@48512
   116
        Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
wenzelm@48477
   117
          " (undefined " ^ commas conds ^ ")\n"))
wenzelm@48465
   118
  end;
wenzelm@48465
   119
wenzelm@48465
   120
in
wenzelm@48465
   121
wenzelm@48681
   122
fun build args_file = Command_Line.tool (fn () =>
wenzelm@48672
   123
    let
wenzelm@51220
   124
      val (command_timings, (do_output, (options, (verbose, (browser_info,
wenzelm@51399
   125
          (parent_name, (chapter, (name, theories)))))))) =
wenzelm@48672
   126
        File.read (Path.explode args_file) |> YXML.parse_body |>
wenzelm@48672
   127
          let open XML.Decode in
wenzelm@51218
   128
            pair (list properties) (pair bool (pair Options.decode (pair bool (pair string
wenzelm@51399
   129
              (pair string (pair string (pair string
wenzelm@51399
   130
                ((list (pair Options.decode (list string)))))))))))
wenzelm@48672
   131
          end;
wenzelm@48418
   132
wenzelm@51941
   133
      val _ = Options.set_default options;
wenzelm@51941
   134
wenzelm@48804
   135
      val document_variants =
wenzelm@48804
   136
        map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
wenzelm@48672
   137
      val _ =
wenzelm@48805
   138
        (case duplicates (op =) (map fst document_variants) of
wenzelm@48805
   139
          [] => ()
wenzelm@48805
   140
        | dups => error ("Duplicate document variants: " ^ commas_quote dups));
wenzelm@49242
   141
wenzelm@50982
   142
      val _ = writeln ("\fSession.name = " ^ name);
wenzelm@49242
   143
      val _ =
wenzelm@51399
   144
        Session.init do_output
wenzelm@51399
   145
          (Options.bool options "browser_info")
wenzelm@51399
   146
          (Path.explode browser_info)
wenzelm@48672
   147
          (Options.string options "document")
wenzelm@48672
   148
          (Options.bool options "document_graph")
wenzelm@48805
   149
          (Options.string options "document_output")
wenzelm@48804
   150
          document_variants
wenzelm@51399
   151
          parent_name (chapter, name)
wenzelm@51398
   152
          (false, "")
wenzelm@50121
   153
          verbose;
wenzelm@49911
   154
wenzelm@51228
   155
      val last_timing = lookup_timings (fold update_timings command_timings empty_timings);
wenzelm@51218
   156
wenzelm@49911
   157
      val res1 =
wenzelm@48673
   158
        theories |>
wenzelm@51218
   159
          (List.app (use_theories_condition last_timing)
wenzelm@48673
   160
            |> Session.with_timing name verbose
wenzelm@50683
   161
            |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
wenzelm@49911
   162
            |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@49911
   163
            |> Exn.capture);
wenzelm@49911
   164
      val res2 = Exn.capture Session.finish ();
wenzelm@49911
   165
      val _ = Par_Exn.release_all [res1, res2];
wenzelm@48673
   166
wenzelm@51941
   167
      val _ = Options.reset_default ();
wenzelm@48734
   168
      val _ = if do_output then () else exit 0;
wenzelm@48681
   169
    in 0 end);
wenzelm@48418
   170
wenzelm@48418
   171
end;
wenzelm@48465
   172
wenzelm@48465
   173
end;