src/Pure/Tools/build.ML
changeset 50686 d703e3aafa8c
parent 50683 34b109c5324c
child 50698 49621c755075
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Tools/build.ML	Wed Jan 02 17:58:53 2013 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +(*  Title:      Pure/Tools/build.ML
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Build Isabelle sessions.
     1.8 +*)
     1.9 +
    1.10 +signature BUILD =
    1.11 +sig
    1.12 +  val build: string -> unit
    1.13 +end;
    1.14 +
    1.15 +structure Build: BUILD =
    1.16 +struct
    1.17 +
    1.18 +(* protocol messages *)
    1.19 +
    1.20 +fun ML_statistics (function :: stats) "" =
    1.21 +      if function = Markup.ML_statistics then SOME stats
    1.22 +      else NONE
    1.23 +  | ML_statistics _ _ = NONE;
    1.24 +
    1.25 +fun protocol_message props output =
    1.26 +  (case ML_statistics props output of
    1.27 +    SOME stats =>
    1.28 +      writeln ("\f" ^ #2 Markup.ML_statistics ^ " = " ^ ML_Syntax.print_properties stats)
    1.29 +  | NONE => raise Fail "Undefined Output.protocol_message");
    1.30 +
    1.31 +
    1.32 +(* build *)
    1.33 +
    1.34 +local
    1.35 +
    1.36 +fun no_document options =
    1.37 +  (case Options.string options "document" of "" => true | "false" => true | _ => false);
    1.38 +
    1.39 +fun use_thys options =
    1.40 +  Thy_Info.use_thys
    1.41 +    |> Unsynchronized.setmp Proofterm.proofs (Options.int options "proofs")
    1.42 +    |> Unsynchronized.setmp print_mode
    1.43 +        (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
    1.44 +    |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
    1.45 +    |> Unsynchronized.setmp Goal.parallel_proofs_threshold
    1.46 +        (Options.int options "parallel_proofs_threshold")
    1.47 +    |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
    1.48 +    |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
    1.49 +    |> Unsynchronized.setmp Future.ML_statistics (Options.bool options "ML_statistics")
    1.50 +    |> no_document options ? Present.no_document
    1.51 +    |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
    1.52 +    |> Unsynchronized.setmp Toplevel.skip_proofs (Options.bool options "skip_proofs")
    1.53 +    |> Unsynchronized.setmp Printer.show_question_marks_default
    1.54 +        (Options.bool options "show_question_marks")
    1.55 +    |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
    1.56 +    |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
    1.57 +    |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
    1.58 +    |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
    1.59 +    |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
    1.60 +    |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
    1.61 +    |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
    1.62 +    |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
    1.63 +    |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
    1.64 +    |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
    1.65 +
    1.66 +fun use_theories (options, thys) =
    1.67 +  let val condition = space_explode "," (Options.string options "condition") in
    1.68 +    (case filter_out (can getenv_strict) condition of
    1.69 +      [] => use_thys options (map (rpair Position.none) thys)
    1.70 +    | conds =>
    1.71 +        Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
    1.72 +          " (undefined " ^ commas conds ^ ")\n"))
    1.73 +  end;
    1.74 +
    1.75 +in
    1.76 +
    1.77 +fun build args_file = Command_Line.tool (fn () =>
    1.78 +    let
    1.79 +      val (do_output, (options, (verbose, (browser_info, (parent_name,
    1.80 +          (name, theories)))))) =
    1.81 +        File.read (Path.explode args_file) |> YXML.parse_body |>
    1.82 +          let open XML.Decode in
    1.83 +            pair bool (pair Options.decode (pair bool (pair string (pair string
    1.84 +              (pair string ((list (pair Options.decode (list string)))))))))
    1.85 +          end;
    1.86 +
    1.87 +      val document_variants =
    1.88 +        map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
    1.89 +      val _ =
    1.90 +        (case duplicates (op =) (map fst document_variants) of
    1.91 +          [] => ()
    1.92 +        | dups => error ("Duplicate document variants: " ^ commas_quote dups));
    1.93 +
    1.94 +      val _ =
    1.95 +        Session.init do_output false
    1.96 +          (Options.bool options "browser_info") browser_info
    1.97 +          (Options.string options "document")
    1.98 +          (Options.bool options "document_graph")
    1.99 +          (Options.string options "document_output")
   1.100 +          document_variants
   1.101 +          parent_name name
   1.102 +          (false, "") ""
   1.103 +          verbose;
   1.104 +
   1.105 +      val res1 =
   1.106 +        theories |>
   1.107 +          (List.app use_theories
   1.108 +            |> Session.with_timing name verbose
   1.109 +            |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
   1.110 +            |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
   1.111 +            |> Exn.capture);
   1.112 +      val res2 = Exn.capture Session.finish ();
   1.113 +      val _ = Par_Exn.release_all [res1, res2];
   1.114 +
   1.115 +      val _ = if do_output then () else exit 0;
   1.116 +    in 0 end);
   1.117 +
   1.118 +end;
   1.119 +
   1.120 +end;