prefer general Command_Line.tool wrapper (cf. Scala version);
authorwenzelm
Sun, 05 Aug 2012 13:42:21 +0200
changeset 48681 181b91e1d1c1
parent 48680 463daacae6c2
child 48682 162579d4ba15
prefer general Command_Line.tool wrapper (cf. Scala version);
src/Pure/IsaMakefile
src/Pure/ROOT
src/Pure/ROOT.ML
src/Pure/System/build.ML
src/Pure/System/command_line.ML
--- a/src/Pure/IsaMakefile	Sun Aug 05 13:23:54 2012 +0200
+++ b/src/Pure/IsaMakefile	Sun Aug 05 13:42:21 2012 +0200
@@ -189,6 +189,7 @@
   Syntax/syntax_trans.ML				\
   Syntax/term_position.ML				\
   System/build.ML					\
+  System/command_line.ML				\
   System/invoke_scala.ML				\
   System/isabelle_process.ML				\
   System/isabelle_system.ML				\
--- a/src/Pure/ROOT	Sun Aug 05 13:23:54 2012 +0200
+++ b/src/Pure/ROOT	Sun Aug 05 13:42:21 2012 +0200
@@ -178,6 +178,7 @@
     "Syntax/syntax_trans.ML"
     "Syntax/term_position.ML"
     "System/build.ML"
+    "System/command_line.ML"
     "System/invoke_scala.ML"
     "System/isabelle_process.ML"
     "System/isabelle_system.ML"
--- a/src/Pure/ROOT.ML	Sun Aug 05 13:23:54 2012 +0200
+++ b/src/Pure/ROOT.ML	Sun Aug 05 13:42:21 2012 +0200
@@ -268,6 +268,7 @@
 (* Isabelle/Isar system *)
 
 use "System/session.ML";
+use "System/command_line.ML";
 use "System/build.ML";
 use "System/system_channel.ML";
 use "System/isabelle_process.ML";
--- a/src/Pure/System/build.ML	Sun Aug 05 13:23:54 2012 +0200
+++ b/src/Pure/System/build.ML	Sun Aug 05 13:42:21 2012 +0200
@@ -6,7 +6,7 @@
 
 signature BUILD =
 sig
-  val build: string -> unit
+  val build: string -> 'a
 end;
 
 structure Build: BUILD =
@@ -55,8 +55,7 @@
 
 in
 
-fun build args_file = uninterruptible (fn restore_attributes => fn () =>
-  restore_attributes (fn () =>
+fun build args_file = Command_Line.tool (fn () =>
     let
       val (do_output, (options, (verbose, (browser_info, (parent_name,
           (name, theories)))))) =
@@ -83,11 +82,8 @@
             |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads"));
 
       val _ = Session.finish ();
-      val _ = if do_output then () else quit ();
-    in () end) ()) ()
-  handle exn =>
-    (Output.error_msg (ML_Compiler.exn_message exn);
-     if Exn.is_interrupt exn then exit 130 else exit 1);
+      val _ = if do_output then Secure.commit () else ();
+    in 0 end);
 
 end;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/System/command_line.ML	Sun Aug 05 13:42:21 2012 +0200
@@ -0,0 +1,23 @@
+(*  Title:      Pure/System/command_line.ML
+    Author:     Makarius
+
+Support for Isabelle/ML command line tools.
+*)
+
+signature COMMAND_LINE =
+sig
+  val tool: (unit -> int) -> 'a
+end;
+
+structure Command_Line: COMMAND_LINE =
+struct
+
+fun tool body =
+  uninterruptible (fn restore_attributes => fn () =>
+    let val rc =
+      restore_attributes body () handle exn =>
+        (Output.error_msg (ML_Compiler.exn_message exn); if Exn.is_interrupt exn then 130 else 1);
+    in exit rc; raise Fail "ERROR" end) ();
+
+end;
+