[settings] fix multiple settings in modules

close #901
This commit is contained in:
Gautier Hattenberger
2014-11-14 15:04:20 +01:00
parent 7fe8001571
commit de200404ab
7 changed files with 42 additions and 25 deletions
+32 -14
View File
@@ -56,6 +56,8 @@ let gcs_icons_path = paparazzi_home // "data" // "pictures" // "gcs_icons"
let dump_fp = paparazzi_src // "sw" // "tools" // "generators" // "gen_flight_plan.out -dump" let dump_fp = paparazzi_src // "sw" // "tools" // "generators" // "gen_flight_plan.out -dump"
let default_module_targets = "ap|sim|nps"
let filter_absolute_path = fun path -> let filter_absolute_path = fun path ->
Str.replace_first (Str.regexp (paparazzi_home // "conf/")) "" path Str.replace_first (Str.regexp (paparazzi_home // "conf/")) "" path
@@ -67,26 +69,42 @@ let filter_settings = fun settings ->
String.concat " " sl String.concat " " sl
(* filter on modules based on target *) (* filter on modules based on target *)
let filter_modules_target = fun module_xml -> let filter_modules_target = fun module_file ->
(* get TARGET env *)
let target = try Sys.getenv "TARGET" with _ -> "" in let target = try Sys.getenv "TARGET" with _ -> "" in
(* look for a specific name after settings file (in case of modules) *)
let split = Str.split (Str.regexp "~") module_file in
let xml_file, name = match split with
| [f; n] -> f, n
| _ -> module_file, ""
in
let module_xml = Xml.parse_file xml_file in
if Xml.tag module_xml = "module" if Xml.tag module_xml = "module"
then begin then
(* test if the module is loaded or not *) begin
if List.exists (fun n -> (* test if the module is loaded or not
let t = ExtXml.attrib_or_default n "target" "" in * and if a specific sub-settings is selected *)
Str.string_match (Str.regexp (".*"^target^".*")) t 0 if List.exists (fun n ->
) (Xml.children module_xml) let local_target = ExtXml.attrib_or_default n "target" default_module_targets
then Xml.Element ("settings", [], List.filter (fun t -> Xml.tag t = "settings") (Xml.children module_xml)) and tag = Xml.tag n in
else Xml.Element ("",[],[]) if tag = "makefile" then
end Str.string_match (Str.regexp (".*"^target^".*")) local_target 0
else module_xml else false
) (Xml.children module_xml)
then Xml.Element ("settings", [],
List.filter (fun t ->
Xml.tag t = "settings" && ExtXml.attrib_or_default t "name" "" = name)
(Xml.children module_xml))
else Xml.Element ("",[],[])
end
else module_xml
let expand_ac_xml = fun ?(raise_exception = true) ac_conf -> let expand_ac_xml = fun ?(raise_exception = true) ac_conf ->
let prefix = fun s -> sprintf "%s/conf/%s" paparazzi_home s in let prefix = fun s -> sprintf "%s/conf/%s" paparazzi_home s in
let parse_file = fun ?(parse_filter=(fun x -> x)) a file -> let parse_file = fun ?(parse_filter=(fun x -> ExtXml.parse_file x)) a file ->
try try
parse_filter (ExtXml.parse_file file) parse_filter file
with with
Failure msg -> Failure msg ->
if raise_exception then if raise_exception then
@@ -96,7 +114,7 @@ let expand_ac_xml = fun ?(raise_exception = true) ac_conf ->
make_element "parse error" ["file",a; "msg", msg] [] make_element "parse error" ["file",a; "msg", msg] []
end in end in
let parse = fun ?(pre_filter=(fun x -> x)) ?(parse_filter=(fun x -> x)) a -> let parse = fun ?(pre_filter=(fun x -> x)) ?(parse_filter=(fun x -> ExtXml.parse_file x)) a ->
List.map List.map
(fun filename -> parse_file ~parse_filter a (prefix filename)) (fun filename -> parse_file ~parse_filter a (prefix filename))
(Str.split space_regexp (pre_filter (ExtXml.attrib ac_conf a))) in (Str.split space_regexp (pre_filter (ExtXml.attrib ac_conf a))) in
+3
View File
@@ -48,6 +48,9 @@ val gconf_file : string
val gcs_icons_path : string val gcs_icons_path : string
(* Default targets for modules *)
val default_module_targets : string
val filter_absolute_path : string -> string val filter_absolute_path : string -> string
(** remove absolute path paparazzi_home/conf if it exists (** remove absolute path paparazzi_home/conf if it exists
* returns a relative path *) * returns a relative path *)
+1 -3
View File
@@ -32,8 +32,6 @@ let paparazzi_conf = Env.paparazzi_home // "conf"
let modules_dir = paparazzi_conf // "modules" let modules_dir = paparazzi_conf // "modules"
let autopilot_dir = paparazzi_conf // "autopilot" let autopilot_dir = paparazzi_conf // "autopilot"
let default_module_targets = "ap|sim|nps"
(** remove all duplicated elements of a list *) (** remove all duplicated elements of a list *)
let singletonize = fun l -> let singletonize = fun l ->
let rec loop = fun l -> let rec loop = fun l ->
@@ -120,7 +118,7 @@ let rec get_modules_of_airframe = fun xml ->
let get_targets_of_module = fun conf -> let get_targets_of_module = fun conf ->
let targets = List.map (fun x -> let targets = List.map (fun x ->
match String.lowercase (Xml.tag x) with match String.lowercase (Xml.tag x) with
"makefile" -> targets_of_field x default_module_targets "makefile" -> targets_of_field x Env.default_module_targets
| _ -> [] | _ -> []
) (Xml.children conf.xml) in ) (Xml.children conf.xml) in
let targets = (List.flatten targets) @ conf.extra_targets in let targets = (List.flatten targets) @ conf.extra_targets in
-2
View File
@@ -33,8 +33,6 @@ type module_conf = { xml : Xml.xml; file : string; vpath : string option; param
(* Modules directory *) (* Modules directory *)
val modules_dir : string val modules_dir : string
(* Default targets for modules *)
val default_module_targets : string
(** remove all duplicated elements of a list *) (** remove all duplicated elements of a list *)
val singletonize : 'a list -> 'a list val singletonize : 'a list -> 'a list
+4 -4
View File
@@ -174,7 +174,7 @@ let get_settings_modules = fun ac_xml settings_modules ->
let file_list = List.map (fun s -> "settings/"^(Xml.attrib s "name")) settings_file_list in let file_list = List.map (fun s -> "settings/"^(Xml.attrib s "name")) settings_file_list in
(* include module file in the list only if it has a 'settings' node *) (* include module file in the list only if it has a 'settings' node *)
let settings_list = List.filter (fun t -> Xml.tag t = "settings") (Xml.children m) in let settings_list = List.filter (fun t -> Xml.tag t = "settings") (Xml.children m) in
let module_file = if List.length settings_list > 0 then [Env.filter_absolute_path f] else [] in (*let module_file = if List.length settings_list > 0 then [Env.filter_absolute_path f] else [] in*)
(* include module file with specific name if they exist *) (* include module file with specific name if they exist *)
let settings_list = List.fold_left (fun l s -> let settings_list = List.fold_left (fun l s ->
try try
@@ -184,10 +184,10 @@ let get_settings_modules = fun ac_xml settings_modules ->
then failwith "Paparazzicenter: no white space allowed in modules settings name"; then failwith "Paparazzicenter: no white space allowed in modules settings name";
l @ [(Env.filter_absolute_path f)^"~"^name^"~"] l @ [(Env.filter_absolute_path f)^"~"^name^"~"]
with with
| Failure x -> prerr_endline x; l | Failure x -> prerr_endline x; l @ [Env.filter_absolute_path f]
| _ -> l | _ -> l @ [Env.filter_absolute_path f]
) [] settings_list in ) [] settings_list in
l @ file_list @ module_file @ settings_list l @ file_list (*@ module_file*) @ settings_list
) [] modules in ) [] modules in
(* store current state in a hashtable *) (* store current state in a hashtable *)
let current = Hashtbl.create 7 in let current = Hashtbl.create 7 in
+1 -1
View File
@@ -116,7 +116,7 @@ let dump_module_section = fun xml f ->
(* add extra targets only if default is used *) (* add extra targets only if default is used *)
let et = try ignore(Xml.attrib l "target"); [] with _ -> m.extra_targets in let et = try ignore(Xml.attrib l "target"); [] with _ -> m.extra_targets in
let targets = Gen_common.singletonize ( let targets = Gen_common.singletonize (
Gen_common.targets_of_field l Gen_common.default_module_targets @ et) in Gen_common.targets_of_field l Env.default_module_targets @ et) in
(* Look for defines, flags, files, ... *) (* Look for defines, flags, files, ... *)
List.iter (fun field -> List.iter (fun field ->
match String.lowercase (Xml.tag field) with match String.lowercase (Xml.tag field) with
+1 -1
View File
@@ -291,7 +291,7 @@ let join_xml_files = fun xml_files ->
(* test if the module is loaded or not *) (* test if the module is loaded or not *)
if List.exists (fun n -> if List.exists (fun n ->
if Xml.tag n = "makefile" then begin if Xml.tag n = "makefile" then begin
let t = ExtXml.attrib_or_default n "target" Gen_common.default_module_targets in let t = ExtXml.attrib_or_default n "target" Env.default_module_targets in
Str.string_match (Str.regexp (".*"^target^".*")) t 0 Str.string_match (Str.regexp (".*"^target^".*")) t 0
end end
else false else false