[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 default_module_targets = "ap|sim|nps"
let filter_absolute_path = fun path ->
Str.replace_first (Str.regexp (paparazzi_home // "conf/")) "" path
@@ -67,26 +69,42 @@ let filter_settings = fun settings ->
String.concat " " sl
(* 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
(* 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"
then begin
(* test if the module is loaded or not *)
if List.exists (fun n ->
let t = ExtXml.attrib_or_default n "target" "" in
Str.string_match (Str.regexp (".*"^target^".*")) t 0
) (Xml.children module_xml)
then Xml.Element ("settings", [], List.filter (fun t -> Xml.tag t = "settings") (Xml.children module_xml))
else Xml.Element ("",[],[])
end
else module_xml
then
begin
(* test if the module is loaded or not
* and if a specific sub-settings is selected *)
if List.exists (fun n ->
let local_target = ExtXml.attrib_or_default n "target" default_module_targets
and tag = Xml.tag n in
if tag = "makefile" then
Str.string_match (Str.regexp (".*"^target^".*")) local_target 0
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 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
parse_filter (ExtXml.parse_file file)
parse_filter file
with
Failure msg ->
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] []
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
(fun filename -> parse_file ~parse_filter a (prefix filename))
(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
(* Default targets for modules *)
val default_module_targets : string
val filter_absolute_path : string -> string
(** remove absolute path paparazzi_home/conf if it exists
* 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 autopilot_dir = paparazzi_conf // "autopilot"
let default_module_targets = "ap|sim|nps"
(** remove all duplicated elements of a list *)
let singletonize = 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 targets = List.map (fun x ->
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
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 *)
val modules_dir : string
(* Default targets for modules *)
val default_module_targets : string
(** remove all duplicated elements of a list *)
val singletonize : 'a list -> 'a list