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