src/Pure/Tools/build.ML
author wenzelm
Wed Jan 02 17:58:53 2013 +0100 (2013-01-02 ago)
changeset 50686 d703e3aafa8c
parent 50683 src/Pure/System/build.ML@34b109c5324c
child 50698 49621c755075
permissions -rw-r--r--
moved files;
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@50683
    17
fun ML_statistics (function :: stats) "" =
wenzelm@50683
    18
      if function = Markup.ML_statistics then SOME stats
wenzelm@50683
    19
      else NONE
wenzelm@50683
    20
  | ML_statistics _ _ = NONE;
wenzelm@50683
    21
wenzelm@50683
    22
fun protocol_message props output =
wenzelm@50683
    23
  (case ML_statistics props output of
wenzelm@50683
    24
    SOME stats =>
wenzelm@50683
    25
      writeln ("\f" ^ #2 Markup.ML_statistics ^ " = " ^ ML_Syntax.print_properties stats)
wenzelm@50683
    26
  | NONE => raise Fail "Undefined Output.protocol_message");
wenzelm@50683
    27
wenzelm@50683
    28
wenzelm@50683
    29
(* build *)
wenzelm@50683
    30
wenzelm@48465
    31
local
wenzelm@48465
    32
wenzelm@48500
    33
fun no_document options =
wenzelm@50121
    34
  (case Options.string options "document" of "" => true | "false" => true | _ => false);
wenzelm@48500
    35
wenzelm@48465
    36
fun use_thys options =
wenzelm@48457
    37
  Thy_Info.use_thys
wenzelm@48457
    38
    |> Unsynchronized.setmp Proofterm.proofs (Options.int options "proofs")
wenzelm@48457
    39
    |> Unsynchronized.setmp print_mode
wenzelm@48457
    40
        (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
wenzelm@48457
    41
    |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
wenzelm@48457
    42
    |> Unsynchronized.setmp Goal.parallel_proofs_threshold
wenzelm@48457
    43
        (Options.int options "parallel_proofs_threshold")
wenzelm@48457
    44
    |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
wenzelm@48460
    45
    |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@50280
    46
    |> Unsynchronized.setmp Future.ML_statistics (Options.bool options "ML_statistics")
wenzelm@48500
    47
    |> no_document options ? Present.no_document
wenzelm@48486
    48
    |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
wenzelm@48634
    49
    |> Unsynchronized.setmp Toplevel.skip_proofs (Options.bool options "skip_proofs")
wenzelm@48486
    50
    |> Unsynchronized.setmp Printer.show_question_marks_default
wenzelm@48486
    51
        (Options.bool options "show_question_marks")
wenzelm@48486
    52
    |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
wenzelm@48486
    53
    |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
wenzelm@48492
    54
    |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
wenzelm@48520
    55
    |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
wenzelm@48520
    56
    |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
wenzelm@48520
    57
    |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
wenzelm@48520
    58
    |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
wenzelm@48520
    59
    |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
wenzelm@48527
    60
    |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
wenzelm@48492
    61
    |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
wenzelm@48457
    62
wenzelm@48465
    63
fun use_theories (options, thys) =
wenzelm@48465
    64
  let val condition = space_explode "," (Options.string options "condition") in
wenzelm@48465
    65
    (case filter_out (can getenv_strict) condition of
wenzelm@48927
    66
      [] => use_thys options (map (rpair Position.none) thys)
wenzelm@48465
    67
    | conds =>
wenzelm@48512
    68
        Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
wenzelm@48477
    69
          " (undefined " ^ commas conds ^ ")\n"))
wenzelm@48465
    70
  end;
wenzelm@48465
    71
wenzelm@48465
    72
in
wenzelm@48465
    73
wenzelm@48681
    74
fun build args_file = Command_Line.tool (fn () =>
wenzelm@48672
    75
    let
wenzelm@48672
    76
      val (do_output, (options, (verbose, (browser_info, (parent_name,
wenzelm@48672
    77
          (name, theories)))))) =
wenzelm@48672
    78
        File.read (Path.explode args_file) |> YXML.parse_body |>
wenzelm@48672
    79
          let open XML.Decode in
wenzelm@48672
    80
            pair bool (pair Options.decode (pair bool (pair string (pair string
wenzelm@48672
    81
              (pair string ((list (pair Options.decode (list string)))))))))
wenzelm@48672
    82
          end;
wenzelm@48418
    83
wenzelm@48804
    84
      val document_variants =
wenzelm@48804
    85
        map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
wenzelm@48672
    86
      val _ =
wenzelm@48805
    87
        (case duplicates (op =) (map fst document_variants) of
wenzelm@48805
    88
          [] => ()
wenzelm@48805
    89
        | dups => error ("Duplicate document variants: " ^ commas_quote dups));
wenzelm@49242
    90
wenzelm@49242
    91
      val _ =
wenzelm@48672
    92
        Session.init do_output false
wenzelm@48672
    93
          (Options.bool options "browser_info") browser_info
wenzelm@48672
    94
          (Options.string options "document")
wenzelm@48672
    95
          (Options.bool options "document_graph")
wenzelm@48805
    96
          (Options.string options "document_output")
wenzelm@48804
    97
          document_variants
wenzelm@48672
    98
          parent_name name
wenzelm@50121
    99
          (false, "") ""
wenzelm@50121
   100
          verbose;
wenzelm@49911
   101
wenzelm@49911
   102
      val res1 =
wenzelm@48673
   103
        theories |>
wenzelm@48673
   104
          (List.app use_theories
wenzelm@48673
   105
            |> Session.with_timing name verbose
wenzelm@50683
   106
            |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
wenzelm@49911
   107
            |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
wenzelm@49911
   108
            |> Exn.capture);
wenzelm@49911
   109
      val res2 = Exn.capture Session.finish ();
wenzelm@49911
   110
      val _ = Par_Exn.release_all [res1, res2];
wenzelm@48673
   111
wenzelm@48734
   112
      val _ = if do_output then () else exit 0;
wenzelm@48681
   113
    in 0 end);
wenzelm@48418
   114
wenzelm@48418
   115
end;
wenzelm@48465
   116
wenzelm@48465
   117
end;