paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [6067] unload modules from telemetry if target is no


From: Gautier Hattenberger
Subject: [paparazzi-commits] [6067] unload modules from telemetry if target is not supported
Date: Tue, 05 Oct 2010 09:05:37 +0000

Revision: 6067
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=6067
Author:   gautier
Date:     2010-10-05 09:05:37 +0000 (Tue, 05 Oct 2010)
Log Message:
-----------
unload modules from telemetry if target is not supported
TODO some functions could be factorized

Modified Paths:
--------------
    paparazzi3/trunk/sw/tools/gen_periodic.ml

Modified: paparazzi3/trunk/sw/tools/gen_periodic.ml
===================================================================
--- paparazzi3/trunk/sw/tools/gen_periodic.ml   2010-10-05 09:02:56 UTC (rev 
6066)
+++ paparazzi3/trunk/sw/tools/gen_periodic.ml   2010-10-05 09:05:37 UTC (rev 
6067)
@@ -107,6 +107,35 @@
       lprintf avr_h "}\\\n")
     modes
 
+(** [get_targets_of_module xml] Returns the list of targets of a module *)
+let get_targets_of_module = fun m ->
+  let pipe_regexp = Str.regexp "|" in
+  let targets_of_field = fun field -> try 
+    Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim") 
with _ -> [] in
+  let rec singletonize = fun l ->
+    match l with
+      [] | [_] -> l
+    | x :: ((y :: t) as yt) -> if x = y then singletonize yt else x :: 
singletonize yt
+  in
+  let targets = List.map (fun x ->
+    match String.lowercase (Xml.tag x) with
+      "makefile" -> targets_of_field x
+    | _ -> []
+  ) (Xml.children m) in
+  (* return a singletonized list *)
+  singletonize (List.sort compare (List.flatten targets))
+
+let unload_unused_modules = fun modules ->
+  let target = try Sys.getenv "TARGET" with _ -> "" in
+  let is_target_in_module = fun m ->
+    let target_is_in_module = List.exists (fun x -> String.compare target x = 
0) (get_targets_of_module m) in
+    target_is_in_module
+  in
+  if String.length target = 0 then
+    modules
+  else
+    List.find_all is_target_in_module modules
+
 (** [get_modules_name dir xml] Returns a list of modules name *)
 let get_modules_name = fun dir xml ->
   (* extract all "modules" sections *)
@@ -117,8 +146,11 @@
     ) (Xml.children xml) in
   (* flatten the list (result is a list of "load" xml nodes) *)
   let modules = List.flatten modules in
+  (* parse modules *)
+  let modules = List.map (fun m -> ExtXml.parse_file (dir // ExtXml.attrib m 
"name")) modules in
+  (* filter the list if target is not supported *)
+  let modules = unload_unused_modules modules in
   (* return a list of modules name *)
-  let modules = List.map (fun m -> ExtXml.parse_file (dir // ExtXml.attrib m 
"name")) modules in
   List.map (fun m -> ExtXml.attrib m "name") modules
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]