diff --git a/sw/lib/ocaml/gen_common.ml b/sw/lib/ocaml/gen_common.ml index 9ffb319cdd..6072250968 100644 --- a/sw/lib/ocaml/gen_common.ml +++ b/sw/lib/ocaml/gen_common.ml @@ -196,8 +196,32 @@ let get_modules_of_flight_plan = fun xml -> | Xml.Element (tag, _attrs, children) -> List.fold_left (fun acc xml -> iter_modules targets acc xml) modules children in - iter_modules [] [] xml + List.rev (iter_modules [] [] xml) +(** [singletonize_modules xml] + * Returns a list of singletonized modules were options are merged + *) +let singletonize_modules = fun xml -> + let rec loop = fun l -> + match l with + | [] | [_] -> l + | x::xs -> + let (duplicates, rest) = List.partition (fun m -> m.file = x.file) xs in + let m = { name = x.name; xml = x.xml; file = x.file; filename = x.filename; + vpath = x.vpath; param = List.flatten (List.map (fun m -> m.param) ([x] @ duplicates)); + targets = singletonize (List.flatten (List.map (fun m -> m.targets) ([x] @ duplicates))) } in + m::loop rest + in + loop xml + +(** [get_modules_of_config ?target flight_plan airframe] + * Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan. + * The modules are singletonized and options are merged *) +let get_modules_of_config = fun ?target af_xml fp_xml -> + let af_modules = get_modules_of_airframe ?target af_xml + and fp_modules = get_modules_of_flight_plan fp_xml in + (* singletonize modules list *) + singletonize_modules (af_modules @ fp_modules) (** [get_modules_name xml] * Returns a list of loaded modules' name *) diff --git a/sw/lib/ocaml/gen_common.mli b/sw/lib/ocaml/gen_common.mli index 1ea06158fc..c8fa98b5ef 100644 --- a/sw/lib/ocaml/gen_common.mli +++ b/sw/lib/ocaml/gen_common.mli @@ -55,6 +55,11 @@ val get_modules_of_airframe : ?target: string -> Xml.xml -> module_conf list * Returns a list of module configuration from flight plan file *) val get_modules_of_flight_plan : Xml.xml -> module_conf list +(** [get_modules_of_config ?target flight_plan airframe] + * Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan. + * The modules are singletonized and options are merged *) +val get_modules_of_config : ?target: string -> Xml.xml -> Xml.xml -> module_conf list + (** [test_targets target targets] * Test if [target] is allowed [targets] * Return true if target is allowed, false if target is not in list or rejected (prefixed by !) *) diff --git a/sw/supervision/pc_aircraft.ml b/sw/supervision/pc_aircraft.ml index 9b789a7e3c..e4af20ab5d 100644 --- a/sw/supervision/pc_aircraft.ml +++ b/sw/supervision/pc_aircraft.ml @@ -167,7 +167,7 @@ type selected_t = Selected | Unselected | Unknown (* Get the settings (string list) with current modules *) let get_settings_modules = fun ac_xml fp_xml settings_modules -> (* get modules *) - let modules = Gen_common.get_modules_of_airframe ac_xml @ Gen_common.get_modules_of_flight_plan fp_xml in + let modules = Gen_common.get_modules_of_config ac_xml fp_xml in let modules = List.map (fun m -> m.Gen_common.xml, m.Gen_common.file ) modules in (* get list of settings files *) let settings = List.fold_left (fun l (m, f) -> diff --git a/sw/tools/generators/gen_aircraft.ml b/sw/tools/generators/gen_aircraft.ml index 7b0add0262..0c66b74a58 100644 --- a/sw/tools/generators/gen_aircraft.ml +++ b/sw/tools/generators/gen_aircraft.ml @@ -146,8 +146,7 @@ let module_xml2mk = fun f target firmware m -> ) m.xml let modules_xml2mk = fun f target xml fp -> - let modules = Gen_common.get_modules_of_airframe ~target xml in - let modules = (modules @ Gen_common.get_modules_of_flight_plan fp) in + let modules = Gen_common.get_modules_of_config ~target xml fp in (* print modules directories and includes for all targets *) fprintf f "\n# include modules directory for all targets\n"; (* get dir list *) @@ -337,8 +336,7 @@ let () = mkdir (aircraft_conf_dir // "telemetry"); let target = try Sys.getenv "TARGET" with _ -> "" in - let modules = Gen_common.get_modules_of_airframe ~target (Xml.parse_file abs_airframe_file) in - let modules = (modules @ Gen_common.get_modules_of_flight_plan (Xml.parse_file abs_flight_plan_file)) in + let modules = Gen_common.get_modules_of_config ~target (Xml.parse_file abs_airframe_file) (Xml.parse_file abs_flight_plan_file) in (* normal settings *) let settings = try Env.filter_settings (value "settings") with _ -> "" in (* remove settings if not supported for the current target *) diff --git a/sw/tools/generators/gen_modules.ml b/sw/tools/generators/gen_modules.ml index b1ea363217..f7c626e21e 100644 --- a/sw/tools/generators/gen_modules.ml +++ b/sw/tools/generators/gen_modules.ml @@ -407,7 +407,7 @@ let () = let modules = try let target = Sys.getenv "TARGET" in - (GC.get_modules_of_airframe ~target xml) @ (GC.get_modules_of_flight_plan (Xml.parse_file fp_file)) + GC.get_modules_of_config ~target xml (Xml.parse_file fp_file) with | Not_found -> failwith "TARTGET env needs to be specified to generate modules files" in