mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
generator: Remove generated and unused files from previous runs of the generator.
If you go back in time in git (eg. git reset, git bisect) then you can end up in a situation where a file that was generated by a later version is left around unused in the earlier version. This isn't a problem for most things, but gobject documentation generation picks up any file in a directory, even unreferenced ones, and breaks. So the correct thing to do is to remove these files.
This commit is contained in:
@@ -126,8 +126,11 @@ Run it from the top source directory using the command
|
||||
fun (typ, jtyp) ->
|
||||
let cols = cols_of_struct typ in
|
||||
let filename = sprintf "java/com/redhat/et/libguestfs/%s.java" jtyp in
|
||||
output_to filename (generate_java_struct jtyp cols);
|
||||
output_to filename (generate_java_struct jtyp cols)
|
||||
) camel_structs;
|
||||
delete_except_generated
|
||||
~skip:["java/com/redhat/et/libguestfs/LibGuestFSException.java"]
|
||||
"java/com/redhat/et/libguestfs/*.java";
|
||||
|
||||
output_to "java/Makefile.inc" generate_java_makefile_inc;
|
||||
output_to "java/com_redhat_et_libguestfs_GuestFS.c" generate_java_c;
|
||||
@@ -156,6 +159,8 @@ Run it from the top source directory using the command
|
||||
let filename = sprintf "gobject/src/%s.c" short in
|
||||
output_to filename (generate_gobject_struct_source short typ cols)
|
||||
) structs;
|
||||
delete_except_generated "gobject/include/guestfs-gobject/struct-*.h";
|
||||
delete_except_generated "gobject/src/struct-*.c";
|
||||
|
||||
List.iter (
|
||||
function
|
||||
@@ -170,6 +175,8 @@ Run it from the top source directory using the command
|
||||
(generate_gobject_optargs_source short name optargs f)
|
||||
| { style = _, _, [] } -> ()
|
||||
) all_functions;
|
||||
delete_except_generated "gobject/include/guestfs-gobject/optargs-*.h";
|
||||
delete_except_generated "gobject/src/optargs-*.c";
|
||||
|
||||
output_to "gobject/include/guestfs-gobject/tristate.h"
|
||||
generate_gobject_tristate_header;
|
||||
|
||||
@@ -31,6 +31,7 @@ let lines = ref 0
|
||||
|
||||
(* Name of each file generated. *)
|
||||
let files = ref []
|
||||
let fileshash = Hashtbl.create 13
|
||||
|
||||
(* Print-to-current-output function, used everywhere. It has
|
||||
* printf-like semantics.
|
||||
@@ -45,6 +46,7 @@ let pr fs =
|
||||
|
||||
let output_to ?(perm = 0o444) filename k =
|
||||
files := filename :: !files;
|
||||
Hashtbl.add fileshash filename ();
|
||||
|
||||
let filename_new = filename ^ ".new" in
|
||||
chan := open_out filename_new;
|
||||
@@ -63,6 +65,36 @@ let output_to ?(perm = 0o444) filename k =
|
||||
printf "written %s\n%!" filename;
|
||||
)
|
||||
|
||||
let delete_except_generated ?(skip = []) glob =
|
||||
let cmd = sprintf "ls -1 %s" glob in
|
||||
let chan = open_process_in cmd in
|
||||
let lines = ref [] in
|
||||
let rec loop () =
|
||||
lines := input_line chan :: !lines;
|
||||
loop ()
|
||||
in
|
||||
let lines = try loop () with End_of_file -> List.rev !lines in
|
||||
(match close_process_in chan with
|
||||
| WEXITED 0 -> ()
|
||||
| WEXITED i ->
|
||||
failwithf "command exited with non-zero status (%d)" i
|
||||
| WSIGNALED i | WSTOPPED i ->
|
||||
failwithf "command signalled or stopped with non-zero status (%d)" i
|
||||
);
|
||||
|
||||
(* Build the final skip hash. *)
|
||||
let skiphash = Hashtbl.copy fileshash in
|
||||
List.iter (fun filename -> Hashtbl.add skiphash filename ()) skip;
|
||||
|
||||
(* Remove the files. *)
|
||||
List.iter (
|
||||
fun filename ->
|
||||
if not (Hashtbl.mem skiphash filename) then (
|
||||
unlink filename;
|
||||
printf "deleted %s\n%!" filename
|
||||
)
|
||||
) lines
|
||||
|
||||
let get_lines_generated () =
|
||||
!lines
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ val output_to : ?perm:int -> string -> (unit -> unit) -> unit
|
||||
[filename] is only updated if the output is different from what
|
||||
is in the file already. *)
|
||||
|
||||
val delete_except_generated : ?skip: string list -> string -> unit
|
||||
(** Remove files matching [glob], unless those files have been
|
||||
generated (so far), OR match a name in the [~skip] list. *)
|
||||
|
||||
val get_lines_generated : unit -> int
|
||||
(** Return number of lines of code generated. *)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user