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