summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-09-05 11:12:52 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-09-05 11:45:41 +0100
commit3d84ca76fec491015030daa53e9122b03032ddfd (patch)
tree322bb535f9745fc0efced977402be4db9469d835 /generator
parent169ac913e9930f7e4a27f395e6c06901f7c849c3 (diff)
downloadlibguestfs-3d84ca76fec491015030daa53e9122b03032ddfd.tar.gz
libguestfs-3d84ca76fec491015030daa53e9122b03032ddfd.tar.xz
libguestfs-3d84ca76fec491015030daa53e9122b03032ddfd.zip
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.
Diffstat (limited to 'generator')
-rw-r--r--generator/main.ml9
-rw-r--r--generator/pr.ml32
-rw-r--r--generator/pr.mli4
3 files changed, 44 insertions, 1 deletions
diff --git a/generator/main.ml b/generator/main.ml
index 74419f10..4cb3c7c0 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -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;
diff --git a/generator/pr.ml b/generator/pr.ml
index fd927206..1c3812a1 100644
--- a/generator/pr.ml
+++ b/generator/pr.ml
@@ -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
diff --git a/generator/pr.mli b/generator/pr.mli
index 693c6813..e0a8227c 100644
--- a/generator/pr.mli
+++ b/generator/pr.mli
@@ -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. *)