src/Pure/Tools/build.ML
author wenzelm
Wed Mar 27 16:38:25 2013 +0100 (2013-03-27 ago)
changeset 51553 63327f679cff
parent 51423 e5f9a6d9ca82
child 51661 92e58b76dbb1
permissions -rw-r--r--
more ambitious Goal.skip_proofs: covers Goal.prove forms as well, and do not insist in quick_and_dirty (for the sake of Isabelle/jEdit);
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@51217
    47
fun use_theories last_timing options =
wenzelm@51217
    48
  Thy_Info.use_theories {last_timing = last_timing, master_dir = Path.current}
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@51423
    53
    |> Unsynchronized.setmp Goal.parallel_subproofs_saturation
wenzelm@51423
    54
        (Options.int options "parallel_subproofs_saturation")
wenzelm@51423
    55
    |> Unsynchronized.setmp Goal.parallel_subproofs_threshold
wenzelm@51423
    56
        (Options.real options "parallel_subproofs_threshold")
wenzelm@48457
    57
    |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
wenzelm@48460
    58
    |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@50698
    59
    |> Unsynchronized.setmp Future.ML_statistics true
wenzelm@48500
    60
    |> no_document options ? Present.no_document
wenzelm@48486
    61
    |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
wenzelm@51553
    62
    |> Unsynchronized.setmp Goal.skip_proofs (Options.bool options "skip_proofs")
wenzelm@48486
    63
    |> Unsynchronized.setmp Printer.show_question_marks_default
wenzelm@48486
    64
        (Options.bool options "show_question_marks")
wenzelm@48486
    65
    |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
wenzelm@48486
    66
    |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
wenzelm@48492
    67
    |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
wenzelm@48520
    68
    |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
wenzelm@48520
    69
    |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
wenzelm@48520
    70
    |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
wenzelm@48520
    71
    |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
wenzelm@48520
    72
    |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
wenzelm@48527
    73
    |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
wenzelm@48492
    74
    |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
wenzelm@48457
    75
wenzelm@51217
    76
fun use_theories_condition last_timing (options, thys) =
wenzelm@48465
    77
  let val condition = space_explode "," (Options.string options "condition") in
wenzelm@48465
    78
    (case filter_out (can getenv_strict) condition of
wenzelm@51217
    79
      [] => use_theories last_timing options (map (rpair Position.none) thys)
wenzelm@48465
    80
    | conds =>
wenzelm@48512
    81
        Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
wenzelm@48477
    82
          " (undefined " ^ commas conds ^ ")\n"))
wenzelm@48465
    83
  end;
wenzelm@48465
    84
wenzelm@51228
    85
wenzelm@51228
    86
(* command timings *)
wenzelm@51228
    87
wenzelm@51228
    88
type timings = ((string * Time.time) Inttab.table) Symtab.table;  (*file -> offset -> name * time *)
wenzelm@51228
    89
wenzelm@51228
    90
val empty_timings: timings = Symtab.empty;
wenzelm@51218
    91
wenzelm@51228
    92
fun update_timings props =
wenzelm@51228
    93
  (case Markup.parse_command_timing_properties props of
wenzelm@51228
    94
    SOME ({file, offset, name}, time) =>
wenzelm@51228
    95
      Symtab.map_default (file, Inttab.empty) (Inttab.update (offset, (name, time)))
wenzelm@51228
    96
  | NONE => I);
wenzelm@51218
    97
wenzelm@51228
    98
fun lookup_timings timings tr =
wenzelm@51228
    99
  (case Toplevel.approximative_id tr of
wenzelm@51228
   100
    SOME {file, offset, name} =>
wenzelm@51228
   101
      (case Symtab.lookup timings file of
wenzelm@51228
   102
        SOME offsets =>
wenzelm@51228
   103
          (case Inttab.lookup offsets offset of
wenzelm@51423
   104
            SOME (name', time) => if name = name' then SOME time else NONE
wenzelm@51423
   105
          | NONE => NONE)
wenzelm@51423
   106
      | NONE => NONE)
wenzelm@51423
   107
  | NONE => NONE);
wenzelm@51218
   108
wenzelm@48465
   109
in
wenzelm@48465
   110
wenzelm@48681
   111
fun build args_file = Command_Line.tool (fn () =>
wenzelm@48672
   112
    let
wenzelm@51220
   113
      val (command_timings, (do_output, (options, (verbose, (browser_info,
wenzelm@51399
   114
          (parent_name, (chapter, (name, theories)))))))) =
wenzelm@48672
   115
        File.read (Path.explode args_file) |> YXML.parse_body |>
wenzelm@48672
   116
          let open XML.Decode in
wenzelm@51218
   117
            pair (list properties) (pair bool (pair Options.decode (pair bool (pair string
wenzelm@51399
   118
              (pair string (pair string (pair string
wenzelm@51399
   119
                ((list (pair Options.decode (list string)))))))))))
wenzelm@48672
   120
          end;
wenzelm@48418
   121
wenzelm@48804
   122
      val document_variants =
wenzelm@48804
   123
        map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
wenzelm@48672
   124
      val _ =
wenzelm@48805
   125
        (case duplicates (op =) (map fst document_variants) of
wenzelm@48805
   126
          [] => ()
wenzelm@48805
   127
        | dups => error ("Duplicate document variants: " ^ commas_quote dups));
wenzelm@49242
   128
wenzelm@50982
   129
      val _ = writeln ("\fSession.name = " ^ name);
wenzelm@49242
   130
      val _ =
wenzelm@51399
   131
        Session.init do_output
wenzelm@51399
   132
          (Options.bool options "browser_info")
wenzelm@51399
   133
          (Path.explode browser_info)
wenzelm@48672
   134
          (Options.string options "document")
wenzelm@48672
   135
          (Options.bool options "document_graph")
wenzelm@48805
   136
          (Options.string options "document_output")
wenzelm@48804
   137
          document_variants
wenzelm@51399
   138
          parent_name (chapter, name)
wenzelm@51398
   139
          (false, "")
wenzelm@50121
   140
          verbose;
wenzelm@49911
   141
wenzelm@51228
   142
      val last_timing = lookup_timings (fold update_timings command_timings empty_timings);
wenzelm@51218
   143
wenzelm@49911
   144
      val res1 =
wenzelm@48673
   145
        theories |>
wenzelm@51218
   146
          (List.app (use_theories_condition last_timing)
wenzelm@48673
   147
            |> Session.with_timing name verbose
wenzelm@50683
   148
            |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
wenzelm@49911
   149
            |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@49911
   150
            |> Exn.capture);
wenzelm@49911
   151
      val res2 = Exn.capture Session.finish ();
wenzelm@49911
   152
      val _ = Par_Exn.release_all [res1, res2];
wenzelm@48673
   153
wenzelm@48734
   154
      val _ = if do_output then () else exit 0;
wenzelm@48681
   155
    in 0 end);
wenzelm@48418
   156
wenzelm@48418
   157
end;
wenzelm@48465
   158
wenzelm@48465
   159
end;