Skip to content

Commit

Permalink
[settings] fix multiple settings in modules
Browse files Browse the repository at this point in the history
close #901
  • Loading branch information
gautierhattenberger committed Nov 14, 2014
1 parent 7fe8001 commit de20040
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
46 changes: 32 additions & 14 deletions sw/lib/ocaml/env.ml
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sw/lib/ocaml/env.mli
Expand Up @@ -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 *)
Expand Down
4 changes: 1 addition & 3 deletions sw/lib/ocaml/gen_common.ml
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions sw/lib/ocaml/gen_common.mli
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions sw/supervision/pc_aircraft.ml
Expand Up @@ -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
(* 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 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 *)
let settings_list = List.fold_left (fun l s ->
try
Expand All @@ -184,10 +184,10 @@ let get_settings_modules = fun ac_xml settings_modules ->
then failwith "Paparazzicenter: no white space allowed in modules settings name";
l @ [(Env.filter_absolute_path f)^"~"^name^"~"]
with
| Failure x -> prerr_endline x; l
| _ -> l
| Failure x -> prerr_endline x; l @ [Env.filter_absolute_path f]
| _ -> l @ [Env.filter_absolute_path f]
) [] settings_list in
l @ file_list @ module_file @ settings_list
l @ file_list (*@ module_file*) @ settings_list
) [] modules in
(* store current state in a hashtable *)
let current = Hashtbl.create 7 in
Expand Down
2 changes: 1 addition & 1 deletion sw/tools/generators/gen_aircraft.ml
Expand Up @@ -116,7 +116,7 @@ let dump_module_section = fun xml f ->
(* add extra targets only if default is used *)
let et = try ignore(Xml.attrib l "target"); [] with _ -> m.extra_targets in
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, ... *)
List.iter (fun field ->
match String.lowercase (Xml.tag field) with
Expand Down
2 changes: 1 addition & 1 deletion sw/tools/generators/gen_settings.ml
Expand Up @@ -291,7 +291,7 @@ let join_xml_files = fun xml_files ->
(* test if the module is loaded or not *)
if List.exists (fun n ->
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
end
else false
Expand Down

0 comments on commit de20040

Please sign in to comment.