src/Pure/Tools/build.ML
author wenzelm
Tue, 15 Mar 2016 16:23:27 +0100
changeset 62630 bc772694cfbd
parent 62599 f35858c831e5
child 62666 00aff1da05ae
permissions -rw-r--r--
ML save_state under control of Isabelle/Scala;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50686
d703e3aafa8c moved files;
wenzelm
parents: 50683
diff changeset
     1
(*  Title:      Pure/Tools/build.ML
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     3
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     4
Build Isabelle sessions.
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     5
*)
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     6
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     7
signature BUILD =
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     8
sig
48731
a45ba78abcc1 more casual exit back to ML toplevel, to accomodate commit in SML/NJ which continues at the saved point;
wenzelm
parents: 48681
diff changeset
     9
  val build: string -> unit
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    10
end;
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    11
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    12
structure Build: BUILD =
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    13
struct
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    14
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    15
(* command timings *)
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    16
56615
47c1dbeec36a tuned comments;
wenzelm
parents: 56614
diff changeset
    17
type timings = ((string * Time.time) Inttab.table) Symtab.table;  (*file -> offset -> name, time*)
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    18
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    19
val empty_timings: timings = Symtab.empty;
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    20
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    21
fun update_timings props =
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    22
  (case Markup.parse_command_timing_properties props of
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    23
    SOME ({file, offset, name}, time) =>
51666
b97aeb018900 add command timings (like document command status);
wenzelm
parents: 51662
diff changeset
    24
      Symtab.map_default (file, Inttab.empty)
b97aeb018900 add command timings (like document command status);
wenzelm
parents: 51662
diff changeset
    25
        (Inttab.map_default (offset, (name, time)) (fn (_, t) => (name, Time.+ (t, time))))
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    26
  | NONE => I);
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    27
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    28
fun approximative_id name pos =
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    29
  (case (Position.file_of pos, Position.offset_of pos) of
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    30
    (SOME file, SOME offset) =>
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    31
      if name = "" then NONE else SOME {file = file, offset = offset, name = name}
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    32
  | _ => NONE);
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    33
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    34
fun lookup_timings timings tr =
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    35
  (case approximative_id (Toplevel.name_of tr) (Toplevel.pos_of tr) of
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    36
    SOME {file, offset, name} =>
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    37
      (case Symtab.lookup timings file of
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    38
        SOME offsets =>
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    39
          (case Inttab.lookup offsets offset of
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    40
            SOME (name', time) => if name = name' then SOME time else NONE
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    41
          | NONE => NONE)
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    42
      | NONE => NONE)
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    43
  | NONE => NONE);
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    44
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    45
52052
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    46
(* session timing *)
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    47
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    48
fun session_timing name verbose f x =
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    49
  let
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    50
    val start = Timing.start ();
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    51
    val y = f x;
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    52
    val timing = Timing.result start;
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    53
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    54
    val threads = string_of_int (Multithreading.max_threads_value ());
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    55
    val factor = Time.toReal (#cpu timing) / Time.toReal (#elapsed timing)
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    56
      |> Real.fmt (StringCvt.FIX (SOME 2));
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    57
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    58
    val timing_props =
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    59
      [("threads", threads)] @ Markup.timing_properties timing @ [("factor", factor)];
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    60
    val _ = writeln ("\fTiming = " ^ YXML.string_of_body (XML.Encode.properties timing_props));
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    61
    val _ =
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    62
      if verbose then
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    63
        Output.physical_stderr ("Timing " ^ name ^ " (" ^
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    64
          threads ^ " threads, " ^ Timing.message timing ^ ", factor " ^ factor ^ ")\n")
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    65
      else ();
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    66
  in y end;
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    67
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52041
diff changeset
    68
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    69
(* protocol messages *)
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    70
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    71
fun inline_message a args =
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    72
  writeln ("\f" ^ a ^ " = " ^ YXML.string_of_body (XML.Encode.properties args));
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    73
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    74
fun protocol_message props output =
51216
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    75
  (case props of
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    76
    function :: args =>
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    77
      if function = Markup.ML_statistics orelse function = Markup.task_statistics then
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    78
        inline_message (#2 function) args
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    79
      else if function = Markup.command_timing then
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    80
        let
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    81
          val name = the_default "" (Properties.get args Markup.nameN);
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    82
          val pos = Position.of_properties args;
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    83
          val {elapsed, ...} = Markup.parse_timing_properties args;
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    84
        in
59149
0070053570c4 suppress irrelevant timing messages (the majority);
wenzelm
parents: 59058
diff changeset
    85
          if Timing.is_relevant_time elapsed then
0070053570c4 suppress irrelevant timing messages (the majority);
wenzelm
parents: 59058
diff changeset
    86
            (case approximative_id name pos of
0070053570c4 suppress irrelevant timing messages (the majority);
wenzelm
parents: 59058
diff changeset
    87
              SOME id => inline_message (#2 function) (Markup.command_timing_properties id elapsed)
0070053570c4 suppress irrelevant timing messages (the majority);
wenzelm
parents: 59058
diff changeset
    88
            | NONE => ())
0070053570c4 suppress irrelevant timing messages (the majority);
wenzelm
parents: 59058
diff changeset
    89
          else ()
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51661
diff changeset
    90
        end
51216
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    91
      else
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    92
        (case Markup.dest_loading_theory props of
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    93
          SOME name => writeln ("\floading_theory = " ^ name)
51661
92e58b76dbb1 clarified protocol_message undefinedness;
wenzelm
parents: 51553
diff changeset
    94
        | NONE => raise Output.Protocol_Message props)
92e58b76dbb1 clarified protocol_message undefinedness;
wenzelm
parents: 51553
diff changeset
    95
  | [] => raise Output.Protocol_Message props);
51045
630c0895d9d1 more efficient inlined properties, especially relevant for voluminous tasks trace;
wenzelm
parents: 50982
diff changeset
    96
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    97
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    98
(* build *)
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    99
61381
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   100
fun build_theories symbols last_timing master_dir (options, thys) =
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   101
  let
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   102
    val condition = space_explode "," (Options.string options "condition");
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   103
    val conds = filter_out (can getenv_strict) condition;
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   104
  in
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   105
    if null conds then
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   106
      (Options.set_default options;
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   107
        (Thy_Info.use_theories {
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   108
          document = Present.document_enabled (Options.string options "document"),
61381
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   109
          symbols = symbols,
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   110
          last_timing = last_timing,
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   111
          master_dir = master_dir}
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   112
        |> Unsynchronized.setmp print_mode
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   113
            (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   114
        |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
59368
wenzelm
parents: 59366
diff changeset
   115
        |> Multithreading.max_threads_setmp (Options.int options "threads")
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   116
        |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   117
        |> Unsynchronized.setmp Future.ML_statistics true) thys)
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   118
    else
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   119
      Output.physical_stderr ("Skipping theories " ^ commas_quote (map #1 thys) ^
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   120
        " (undefined " ^ commas conds ^ ")\n")
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   121
  end;
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   122
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   123
fun build args_file =
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   124
  let
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   125
    val _ = SHA1_Samples.test ();
53212
387b9f7cb0ac added SHA1 library integrity test, which is invoked at compile time and Isabelle_Process run-time;
wenzelm
parents: 52852
diff changeset
   126
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   127
    val (symbol_codes, (command_timings, (do_output, (verbose, (browser_info,
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   128
          (document_files, (graph_file, (parent_name, (chapter, (name, theories)))))))))) =
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   129
      File.read (Path.explode args_file) |> YXML.parse_body |>
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   130
        let open XML.Decode in
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   131
          pair (list (pair string int)) (pair (list properties) (pair bool
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   132
            (pair bool (pair string (pair (list (pair string string)) (pair string
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   133
              (pair string (pair string (pair string
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   134
              ((list (pair Options.decode (list (string #> rpair Position.none))))))))))))))
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   135
        end;
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   136
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   137
    val symbols = HTML.make_symbols symbol_codes;
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   138
    val _ = Isabelle_Process.init_build_options ();
51941
ead4248aef3b full default options for Isabelle_Process and Build;
wenzelm
parents: 51666
diff changeset
   139
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   140
    val _ = writeln ("\fSession.name = " ^ name);
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   141
    val _ =
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   142
      Session.init
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   143
        symbols
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   144
        do_output
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   145
        (Options.default_bool "browser_info")
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   146
        (Path.explode browser_info)
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   147
        (Options.default_string "document")
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   148
        (Options.default_string "document_output")
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   149
        (Present.document_variants (Options.default_string "document_variants"))
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   150
        (map (apply2 Path.explode) document_files)
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   151
        (Path.explode graph_file)
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   152
        parent_name (chapter, name)
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   153
        verbose;
49911
262c36fd5f26 collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
wenzelm
parents: 49242
diff changeset
   154
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   155
    val last_timing = lookup_timings (fold update_timings command_timings empty_timings);
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
   156
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   157
    val res1 =
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   158
      theories |>
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   159
        (List.app (build_theories symbols last_timing Path.current)
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   160
          |> session_timing name verbose
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   161
          |> Unsynchronized.setmp Output.protocol_message_fn protocol_message
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   162
          |> Multithreading.max_threads_setmp (Options.default_int "threads")
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   163
          |> Exn.capture);
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   164
    val res2 = Exn.capture Session.finish ();
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   165
    val _ = Par_Exn.release_all [res1, res2];
48673
b2b09970c571 let with_timing report overall number of threads;
wenzelm
parents: 48672
diff changeset
   166
62630
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   167
    val _ = Options.reset_default ();
bc772694cfbd ML save_state under control of Isabelle/Scala;
wenzelm
parents: 62599
diff changeset
   168
  in () end;
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   169
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   170
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   171
(* PIDE protocol *)
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   172
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   173
val _ =
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   174
  Isabelle_Process.protocol_command "build_theories"
61381
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   175
    (fn [id, symbol_codes_yxml, master_dir, theories_yxml] =>
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   176
      let
61381
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   177
        val symbols =
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   178
          YXML.parse_body symbol_codes_yxml
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   179
          |> let open XML.Decode in list (pair string int) end
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   180
          |> HTML.make_symbols;
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   181
        val theories =
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   182
          YXML.parse_body theories_yxml |>
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   183
            let open XML.Decode
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   184
            in list (pair Options.decode (list (string #> rpair Position.none))) end;
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   185
        val res1 =
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   186
          Exn.capture (fn () =>
61381
ddca85598c65 more explicit HTML.symbols;
wenzelm
parents: 61376
diff changeset
   187
            theories |> List.app (build_theories symbols (K NONE) (Path.explode master_dir))) ();
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   188
        val res2 = Exn.capture Session.shutdown ();
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   189
        val result =
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   190
          (Par_Exn.release_all [res1, res2]; "") handle exn =>
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   191
            (Runtime.exn_message exn handle _ (*sic!*) =>
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   192
              "Exception raised, but failed to print details!");
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59368
diff changeset
   193
    in Output.protocol_message (Markup.build_theories_result id) [result] end);
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 59364
diff changeset
   194
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   195
end;