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