Warn if data file is missing.
[virt-mem.git] / extract / codegen / pahole_parser.ml
index 029ecde..19cbbf1 100644 (file)
@@ -79,6 +79,10 @@ and string_of_f_type = function
   | FInteger -> "int"
   | FString width -> sprintf "char[%d]" width
 
+let file_exists name =
+  try Unix.access name [Unix.F_OK]; true
+  with Unix.Unix_error _ -> false
+
 (* Regular expressions.  We really really should use ocaml-mikmatch ... *)
 let re_oldformat = Pcre.regexp "^RPM: \\d+: \\(build \\d+\\) ([-\\w]+) ([\\w.]+) ([\\w.]+) \\(.*?\\) (\\w+)"
 let re_keyvalue = Pcre.regexp "^(\\w+): (.*)"
@@ -151,6 +155,23 @@ let list_kernels path =
        basename = basename; arch = arch;
        kernel_version = version }
   ) infos in
+
+  (* Check the .data, .data.gz or .data.bz2 file exists, and skip with
+   * a warning if not.
+   *)
+  let infos = List.filter (
+    fun { basename = basename } ->
+      if not (file_exists (basename ^ ".data")) &&
+       not (file_exists (basename ^ ".data.gz")) &&
+       not (file_exists (basename ^ ".data.bz2")) then (
+         eprintf "warning: %s: no data file found for this kernel - skipping\n%!"
+           basename;
+         false
+       )
+      else
+       true
+  ) infos in
+
   infos
 
 (* XXX This would be better as a proper lex/yacc parser.
@@ -175,10 +196,6 @@ let load_structures { basename = basename } struct_names =
   ) struct_names;
 
   (* Now read the data file and parse out the structures of interest. *)
-  let file_exists name =
-    try Unix.access name [Unix.F_OK]; true
-    with Unix.Unix_error _ -> false
-  in
   let close_process_in cmd chan =
     match Unix.close_process_in chan with
     | Unix.WEXITED 0 -> ()