[build] expand airframe includes so firmware sections are parsed

fix #1863
This commit is contained in:
Gautier Hattenberger
2016-09-25 11:02:05 +02:00
parent 4316871b63
commit 88a9bce08d
6 changed files with 62 additions and 31 deletions
+1 -1
View File
@@ -212,7 +212,7 @@ $(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(FLIGHT_PLAN_XML) $(GENERATORS)/gen_modu
$(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED) $(Q)test -d $(AC_GENERATED) || mkdir -p $(AC_GENERATED)
@echo GENERATE $@ @echo GENERATE $@
$(eval $@_TMP := $(shell $(MKTEMP))) $(eval $@_TMP := $(shell $(MKTEMP)))
$(Q)$(GENERATORS)/gen_modules.out $(SETTINGS_MODULES) $(DEFAULT_MODULES_FREQUENCY) $(FLIGHT_PLAN_XML) $< > $($@_TMP) $(Q)$(GENERATORS)/gen_modules.out $(AC_ID) $(SETTINGS_MODULES) $(DEFAULT_MODULES_FREQUENCY) $(FLIGHT_PLAN_XML) $< > $($@_TMP)
$(Q)mv $($@_TMP) $@ $(Q)mv $($@_TMP) $@
$(Q)chmod a+r $@ $(Q)chmod a+r $@
+28 -4
View File
@@ -178,6 +178,26 @@ let rec get_autoloaded_modules = fun m ->
let test_targets = fun target targets -> let test_targets = fun target targets ->
eval_bool target targets eval_bool target targets
(** [expand_includes ac_id xml]
* Expand xml airframe file if it contains 'include' nodes
*)
let expand_includes = fun ac_id xml ->
match xml with
| Xml.PCData d -> Xml.PCData d
| Xml.Element (tag, attrs, children) ->
Xml.Element (tag, attrs,
List.fold_left (fun x c ->
if Xml.tag c = "include" then begin
let filename = Str.global_replace (Str.regexp "\\$AC_ID") ac_id (ExtXml.attrib c "href") in
let filename =
if Filename.is_relative filename then Env.paparazzi_home // filename
else filename in
let subxml = ExtXml.parse_file filename in
x @ (Xml.children subxml)
end
else x @ [c]
) [] children)
exception Firmware_Found of string exception Firmware_Found of string
(** [get_modules_of_airframe xml] (** [get_modules_of_airframe xml]
* Returns a list of module configuration from airframe file *) * Returns a list of module configuration from airframe file *)
@@ -235,6 +255,10 @@ let rec get_modules_of_airframe = fun ?target xml ->
List.fold_left List.fold_left
(fun acc xml -> iter_modules targets acc xml) modules children (fun acc xml -> iter_modules targets acc xml) modules children
| _ -> modules end | _ -> modules end
| Xml.Element (tag, _attrs, _children) when tag = "include" ->
let filename = ExtXml.attrib xml "href" in
let subxml = ExtXml.parse_file filename in
iter_modules targets modules subxml
| Xml.Element (tag, _attrs, children) -> | Xml.Element (tag, _attrs, children) ->
let (targets, use_fallback) = let (targets, use_fallback) =
if tag = "modules" then (targets_of_field xml "", false) else (targets, true) in if tag = "modules" then (targets_of_field xml "", false) else (targets, true) in
@@ -307,18 +331,18 @@ let singletonize_modules = fun ?(verbose=false) ?target xml ->
(** [get_modules_of_config ?target flight_plan airframe] (** [get_modules_of_config ?target flight_plan airframe]
* Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan. * Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan.
* The modules are singletonized and options are merged *) * The modules are singletonized and options are merged *)
let get_modules_of_config = fun ?target ?verbose af_xml fp_xml -> let get_modules_of_config = fun ?target ?verbose ac_id af_xml fp_xml ->
let af_modules = get_modules_of_airframe ?target af_xml let af_modules = get_modules_of_airframe ?target (expand_includes ac_id af_xml)
and fp_modules = get_modules_of_flight_plan fp_xml in and fp_modules = get_modules_of_flight_plan fp_xml in
(* singletonize modules list *) (* singletonize modules list *)
singletonize_modules ?verbose ?target (af_modules @ fp_modules) singletonize_modules ?verbose ?target (af_modules @ fp_modules)
(** [get_modules_name xml] (** [get_modules_name xml]
* Returns a list of loaded modules' name *) * Returns a list of loaded modules' name *)
let get_modules_name = fun xml -> let get_modules_name = fun ac_id xml ->
let target = try Sys.getenv "TARGET" with _ -> "" in let target = try Sys.getenv "TARGET" with _ -> "" in
(* extract all modules sections for a given target *) (* extract all modules sections for a given target *)
let modules = get_modules_of_airframe ~target xml in let modules = get_modules_of_airframe ~target (expand_includes ac_id xml) in
(* return a list of modules name *) (* return a list of modules name *)
List.map (fun m -> ExtXml.attrib m.xml "name") modules List.map (fun m -> ExtXml.attrib m.xml "name") modules
+9 -4
View File
@@ -54,6 +54,11 @@ exception Subsystem of string
val module_name : Xml.xml -> string val module_name : Xml.xml -> string
val get_module : Xml.xml -> bool_expr -> module_conf val get_module : Xml.xml -> bool_expr -> module_conf
(** [expand_includes ac_id xml]
* Expand xml airframe file if it contains 'include' nodes
*)
val expand_includes : string -> Xml.xml -> Xml.xml
(** [get_modules_of_airframe xml] (** [get_modules_of_airframe xml]
* Returns a list of pair (modules ("load" node), targets) from airframe file *) * Returns a list of pair (modules ("load" node), targets) from airframe file *)
val get_modules_of_airframe : ?target: string -> Xml.xml -> module_conf list val get_modules_of_airframe : ?target: string -> Xml.xml -> module_conf list
@@ -62,10 +67,10 @@ val get_modules_of_airframe : ?target: string -> Xml.xml -> module_conf list
* Returns a list of module configuration from flight plan file *) * Returns a list of module configuration from flight plan file *)
val get_modules_of_flight_plan : Xml.xml -> module_conf list val get_modules_of_flight_plan : Xml.xml -> module_conf list
(** [get_modules_of_config ?target flight_plan airframe] (** [get_modules_of_config ?target ac_id flight_plan airframe]
* Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan. * Returns a list of pair (modules ("load" node), targets) from airframe file and flight plan.
* The modules are singletonized and options are merged *) * The modules are singletonized and options are merged *)
val get_modules_of_config : ?target:string -> ?verbose:bool -> Xml.xml -> Xml.xml -> module_conf list val get_modules_of_config : ?target:string -> ?verbose:bool -> string -> Xml.xml -> Xml.xml -> module_conf list
(** [test_targets target targets] (** [test_targets target targets]
* Test if [target] is allowed [targets] * Test if [target] is allowed [targets]
@@ -75,9 +80,9 @@ val test_targets : string -> bool_expr -> bool
(** [get_targets_of_module xml] Returns the boolean expression of targets of a module *) (** [get_targets_of_module xml] Returns the boolean expression of targets of a module *)
val get_targets_of_module : Xml.xml -> bool_expr val get_targets_of_module : Xml.xml -> bool_expr
(** [get_modules_name xml] (** [get_modules_name ac_id xml]
* Returns a list of loaded modules' name *) * Returns a list of loaded modules' name *)
val get_modules_name : Xml.xml -> string list val get_modules_name : string -> Xml.xml -> string list
(** [get_modules_dir xml] (** [get_modules_dir xml]
* Returns the list of modules directories *) * Returns the list of modules directories *)
+5 -5
View File
@@ -165,9 +165,9 @@ let save_callback = fun ?user_save gui ac_combo tree tree_modules () ->
type selected_t = Selected | Unselected | Unknown type selected_t = Selected | Unselected | Unknown
(* Get the settings (string list) with current modules *) (* Get the settings (string list) with current modules *)
let get_settings_modules = fun ac_xml fp_xml settings_modules -> let get_settings_modules = fun ac_id ac_xml fp_xml settings_modules ->
(* get modules *) (* get modules *)
let modules = Gen_common.get_modules_of_config ac_xml fp_xml in let modules = Gen_common.get_modules_of_config ac_id ac_xml fp_xml in
let modules = List.map (fun m -> m.Gen_common.xml, m.Gen_common.file ) modules in let modules = List.map (fun m -> m.Gen_common.xml, m.Gen_common.file ) modules in
(* get list of settings files *) (* get list of settings files *)
let settings = List.fold_left (fun l (m, f) -> let settings = List.fold_left (fun l (m, f) ->
@@ -318,8 +318,9 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com
in in
let fp_file = (Env.paparazzi_home // "conf" // (Xml.attrib aircraft "flight_plan")) in let fp_file = (Env.paparazzi_home // "conf" // (Xml.attrib aircraft "flight_plan")) in
let fp_xml = ExtXml.parse_file fp_file in let fp_xml = ExtXml.parse_file fp_file in
let ac_id = ExtXml.attrib aircraft "ac_id" in
let settings_modules = try let settings_modules = try
get_settings_modules af_xml fp_xml (ExtXml.attrib_or_default aircraft "settings_modules" "") get_settings_modules ac_id af_xml fp_xml (ExtXml.attrib_or_default aircraft "settings_modules" "")
with with
| Failure x -> prerr_endline x; [] | Failure x -> prerr_endline x; []
| _ -> [] | _ -> []
@@ -338,8 +339,7 @@ let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo flash_com
let names = Str.split regexp_space (value a) in let names = Str.split regexp_space (value a) in
List.iter (Gtk_tools.add_to_tree t) names; List.iter (Gtk_tools.add_to_tree t) names;
) ac_files; ) ac_files;
let ac_id = ExtXml.attrib aircraft "ac_id" let gui_color = ExtXml.attrib_or_default aircraft "gui_color" "white" in
and gui_color = ExtXml.attrib_or_default aircraft "gui_color" "white" in
gui#button_clean#misc#set_sensitive true; gui#button_clean#misc#set_sensitive true;
gui#button_build#misc#set_sensitive true; gui#button_build#misc#set_sensitive true;
gui#button_upload#misc#set_sensitive true; gui#button_upload#misc#set_sensitive true;
+11 -10
View File
@@ -187,8 +187,8 @@ let module_xml2mk = fun f target firmware m ->
) section ) section
) m.xml ) m.xml
let modules_xml2mk = fun f target xml fp -> let modules_xml2mk = fun f target ac_id xml fp ->
let modules = Gen_common.get_modules_of_config ~target ~verbose:true xml fp in let modules = Gen_common.get_modules_of_config ~target ~verbose:true ac_id xml fp in
(* print modules directories and includes for all targets *) (* print modules directories and includes for all targets *)
fprintf f "\n# include modules directory for all targets\n"; fprintf f "\n# include modules directory for all targets\n";
(* get dir list *) (* get dir list *)
@@ -247,7 +247,7 @@ let fallback_subsys_xml2mk = fun f global_targets firmware target xml ->
ignore(Gen_common.get_module xml global_targets) ignore(Gen_common.get_module xml global_targets)
with Gen_common.Subsystem _file -> subsystem_xml2mk f firmware xml with Gen_common.Subsystem _file -> subsystem_xml2mk f firmware xml
let parse_firmware = fun makefile_ac ac_xml firmware fp -> let parse_firmware = fun makefile_ac ac_id ac_xml firmware fp ->
let firmware_name = Xml.attrib firmware "name" in let firmware_name = Xml.attrib firmware "name" in
(* get the configures, targets, subsystems and defines for this firmware *) (* get the configures, targets, subsystems and defines for this firmware *)
let config, rest = ExtXml.partition_tag "configure" (Xml.children firmware) in let config, rest = ExtXml.partition_tag "configure" (Xml.children firmware) in
@@ -267,7 +267,7 @@ let parse_firmware = fun makefile_ac ac_xml firmware fp ->
fprintf makefile_ac "\n###########\n# -target: '%s'\n" target_name; fprintf makefile_ac "\n###########\n# -target: '%s'\n" target_name;
fprintf makefile_ac "ifeq ($(TARGET), %s)\n" target_name; fprintf makefile_ac "ifeq ($(TARGET), %s)\n" target_name;
let target_name = Xml.attrib target "name" in let target_name = Xml.attrib target "name" in
let modules = modules_xml2mk makefile_ac target_name ac_xml fp in let modules = modules_xml2mk makefile_ac target_name ac_id ac_xml fp in
begin (* Check for "processor" attribute *) begin (* Check for "processor" attribute *)
try try
let proc = Xml.attrib target "processor" in let proc = Xml.attrib target "processor" in
@@ -295,21 +295,22 @@ let parse_firmware = fun makefile_ac ac_xml firmware fp ->
(** Search and dump the firmware section *) (** Search and dump the firmware section *)
let dump_firmware = fun f ac_xml firmware fp -> let dump_firmware = fun f ac_id ac_xml firmware fp ->
try try
fprintf f "\n####################################################\n"; fprintf f "\n####################################################\n";
fprintf f "# makefile firmware '%s'\n" (Xml.attrib firmware "name"); fprintf f "# makefile firmware '%s'\n" (Xml.attrib firmware "name");
fprintf f "####################################################\n"; fprintf f "####################################################\n";
parse_firmware f ac_xml firmware fp parse_firmware f ac_id ac_xml firmware fp
with Xml.No_attribute _ -> failwith "Warning: firmware name is undeclared" with Xml.No_attribute _ -> failwith "Warning: firmware name is undeclared"
let dump_firmware_sections = fun makefile_ac fp xml -> let dump_firmware_sections = fun makefile_ac ac_id fp xml ->
ExtXml.iter_tag "firmware" ExtXml.iter_tag "firmware"
(fun tag -> dump_firmware makefile_ac xml tag fp) xml (fun tag -> dump_firmware makefile_ac ac_id xml tag fp) xml
(** Extracts the makefile sections of an airframe file *) (** Extracts the makefile sections of an airframe file *)
let extract_makefile = fun ac_id airframe_file flight_plan_file makefile_ac -> let extract_makefile = fun ac_id airframe_file flight_plan_file makefile_ac ->
let xml = ExtXml.parse_file airframe_file in let xml = ExtXml.parse_file airframe_file in
let xml = Gen_common.expand_includes ac_id xml in
let fp = ExtXml.parse_file flight_plan_file in let fp = ExtXml.parse_file flight_plan_file in
let f = open_out makefile_ac in let f = open_out makefile_ac in
fprintf f "# This file has been generated by gen_aircraft from %s by %s\n" fprintf f "# This file has been generated by gen_aircraft from %s by %s\n"
@@ -321,7 +322,7 @@ let extract_makefile = fun ac_id airframe_file flight_plan_file makefile_ac ->
(** Search and dump makefile sections that have a "location" attribute set to "before" or no attribute *) (** Search and dump makefile sections that have a "location" attribute set to "before" or no attribute *)
dump_makefile_section xml f airframe_file "before"; dump_makefile_section xml f airframe_file "before";
(** Search and dump the firmware sections *) (** Search and dump the firmware sections *)
dump_firmware_sections f fp xml; dump_firmware_sections f ac_id fp xml;
(** Search and dump makefile sections that have a "location" attribute set to "after" *) (** Search and dump makefile sections that have a "location" attribute set to "after" *)
dump_makefile_section xml f airframe_file "after"; dump_makefile_section xml f airframe_file "after";
close_out f close_out f
@@ -379,7 +380,7 @@ let () =
mkdir (aircraft_conf_dir // "telemetry"); mkdir (aircraft_conf_dir // "telemetry");
let target = try Sys.getenv "TARGET" with _ -> "" in let target = try Sys.getenv "TARGET" with _ -> "" in
let modules = Gen_common.get_modules_of_config ~target (ExtXml.parse_file abs_airframe_file) (ExtXml.parse_file abs_flight_plan_file) in let modules = Gen_common.get_modules_of_config ~target (value "ac_id") (ExtXml.parse_file abs_airframe_file) (ExtXml.parse_file abs_flight_plan_file) in
(* normal settings *) (* normal settings *)
let settings = try Env.filter_settings (value "settings") with _ -> "" in let settings = try Env.filter_settings (value "settings") with _ -> "" in
(* remove settings if not supported for the current target *) (* remove settings if not supported for the current target *)
+8 -7
View File
@@ -417,12 +417,13 @@ let write_settings = fun xml_file out_set modules ->
let h_name = "MODULES_H" let h_name = "MODULES_H"
let () = let () =
if Array.length Sys.argv <> 5 then if Array.length Sys.argv <> 6 then
failwith (Printf.sprintf "Usage: %s out_settings_file default_freq fp_file xml_file" Sys.argv.(0)); failwith (Printf.sprintf "Usage: %s ac_id out_settings_file default_freq fp_file xml_file" Sys.argv.(0));
let xml_file = Sys.argv.(4) let xml_file = Sys.argv.(5)
and fp_file = Sys.argv.(3) and fp_file = Sys.argv.(4)
and default_freq = int_of_string(Sys.argv.(2)) and default_freq = int_of_string(Sys.argv.(3))
and out_set = open_out Sys.argv.(1) in and out_set = open_out Sys.argv.(2)
and ac_id = Sys.argv.(1) in
try try
let xml = start_and_begin xml_file h_name in let xml = start_and_begin xml_file h_name in
fprintf out_h "#define MODULES_IDLE 0\n"; fprintf out_h "#define MODULES_IDLE 0\n";
@@ -446,7 +447,7 @@ let () =
let modules = let modules =
try try
let target = Sys.getenv "TARGET" in let target = Sys.getenv "TARGET" in
GC.get_modules_of_config ~target xml (ExtXml.parse_file fp_file) GC.get_modules_of_config ~target ac_id xml (ExtXml.parse_file fp_file)
with with
| Not_found -> failwith "TARTGET env needs to be specified to generate modules files" | Not_found -> failwith "TARTGET env needs to be specified to generate modules files"
in in