Skip to content
Snippets Groups Projects
Commit e6bc8387 authored by David Bühler's avatar David Bühler
Browse files

[kernel] File: new utilitary function [create_temp_file].

parent 1851b74f
No related branches found
No related tags found
No related merge requests found
...@@ -406,6 +406,12 @@ let pretty_machdep ?fmt ?machdep () = ...@@ -406,6 +406,12 @@ let pretty_machdep ?fmt ?machdep () =
(** {2 Initializations} *) (** {2 Initializations} *)
(* ************************************************************************* *) (* ************************************************************************* *)
let create_temp_file ?debug name suffix =
let of_string = Filepath.Normalized.of_string in
try of_string (Extlib.temp_file_cleanup_at_exit ?debug name suffix)
with Extlib.Temp_file_error s ->
Kernel.abort "cannot create temporary file: %s" s
let safe_remove_file (f : Datatype.Filepath.t) = let safe_remove_file (f : Datatype.Filepath.t) =
if not (Kernel.is_debug_key_enabled Kernel.dkey_parser) then if not (Kernel.is_debug_key_enabled Kernel.dkey_parser) then
Extlib.safe_remove (f :> string) Extlib.safe_remove (f :> string)
...@@ -461,14 +467,7 @@ let build_cpp_cmd = function ...@@ -461,14 +467,7 @@ let build_cpp_cmd = function
opt; opt;
[opt] [opt]
in in
let ppf = let ppf = create_temp_file ~debug (Filename.basename (f :> string)) ".i" in
try
Datatype.Filepath.of_string
(Extlib.temp_file_cleanup_at_exit ~debug
(Filename.basename (f :> string)) ".i")
with Extlib.Temp_file_error s ->
Kernel.abort "cannot create temporary file: %s" s
in
(* Hypothesis: the preprocessor is POSIX compliant, (* Hypothesis: the preprocessor is POSIX compliant,
hence understands -I and -D. *) hence understands -I and -D. *)
let include_args = let include_args =
...@@ -1663,12 +1662,7 @@ let compute_sources_table cpp_commands = ...@@ -1663,12 +1662,7 @@ let compute_sources_table cpp_commands =
| None -> () | None -> ()
| Some (cpp_cmd, _ppf, _sl) -> | Some (cpp_cmd, _ppf, _sl) ->
let audit_sources_tmpfile = let audit_sources_tmpfile =
try create_temp_file "audit_produce_sources" ".txt"
Datatype.Filepath.of_string
(Extlib.temp_file_cleanup_at_exit
"audit_produce_sources" ".txt")
with Extlib.Temp_file_error s ->
Kernel.abort "cannot create temporary file: %s" s
in in
let cmd_for_sources = let cmd_for_sources =
cpp_cmd ^ " -H -MM >/dev/null 2>" ^ (audit_sources_tmpfile:>string) cpp_cmd ^ " -H -MM >/dev/null 2>" ^ (audit_sources_tmpfile:>string)
...@@ -1887,8 +1881,7 @@ let create_rebuilt_project_from_visitor ...@@ -1887,8 +1881,7 @@ let create_rebuilt_project_from_visitor
let name = "frama_c_project_" ^ prj_name ^ "_" in let name = "frama_c_project_" ^ prj_name ^ "_" in
let ext = if preprocess then ".c" else ".i" in let ext = if preprocess then ".c" else ".i" in
let debug = Kernel.Debug.get () > 0 in let debug = Kernel.Debug.get () > 0 in
let tmp_fname = Extlib.temp_file_cleanup_at_exit ~debug name ext in create_temp_file ~debug name ext
Filepath.Normalized.of_string tmp_fname
in in
let cout = open_out (f :> string) in let cout = open_out (f :> string) in
let fmt = Format.formatter_of_out_channel cout in let fmt = Format.formatter_of_out_channel cout in
...@@ -1900,7 +1893,7 @@ let create_rebuilt_project_from_visitor ...@@ -1900,7 +1893,7 @@ let create_rebuilt_project_from_visitor
in in
Project.on prj redo (); Project.on prj redo ();
prj prj
with Extlib.Temp_file_error s | Sys_error s -> with Sys_error s ->
Kernel.abort "cannot create temporary file: %s" s Kernel.abort "cannot create temporary file: %s" s
(* (*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment