Skip to content

Commit

Permalink
[modules] start pimping dependencies
Browse files Browse the repository at this point in the history
Start working on #940

This replaces
```xml
<depend require="foo|bar" conflict="baz"/>
```
with
```xml
<depends>foo,bar</depends>
<conflicts>baz</conflicts>
```

and now allows to specify OR dependencies with | (pipe) similaro to Debian depends:
```xml
<depends>foo,bar,this|that</depends>
```
which would depend on: foo AND bar AND (this OR that)
  • Loading branch information
flixr committed Dec 6, 2014
1 parent fc0a7dd commit 4697a37
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 40 deletions.
3 changes: 1 addition & 2 deletions conf/modules/ahrs_chimu_spi.xml
@@ -1,10 +1,9 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="ins">
<module name="ahrs_chimu_spi" dir="ins">
<doc>
<description>CHimu (SPI)</description>
</doc>
<!-- <depend conflict="ins" -->
<header>
<file name="ins_module.h"/>
</header>
Expand Down
3 changes: 1 addition & 2 deletions conf/modules/ahrs_chimu_uart.xml
@@ -1,13 +1,12 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="ins">
<module name="ahrs_chimu_uart" dir="ins">
<doc>
<description>
CHimu (UART)
For older CHIMU v1.0 you should define CHIMU_BIG_ENDIAN
</description>
</doc>
<!-- <depend conflict="ins" -->
<header>
<file name="ins_module.h"/>
</header>
Expand Down
1 change: 0 additions & 1 deletion conf/modules/airspeed_ads1114.xml
Expand Up @@ -7,7 +7,6 @@
Module to extend the baro_board module with an airspeed sensor using ads1114 adc
</description>
</doc>
<depend require="baro_board.xml"/>
<header>
<file name="airspeed_ads1114.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/cam_segment.xml
Expand Up @@ -4,7 +4,7 @@
<doc>
<description>Camera control to point a segment</description>
</doc>
<!--depend require="cam_point.xml"/-->
<depends>cam_point</depends>
<header>
<file name="cam_segment.h"/>
</header>
Expand Down
2 changes: 2 additions & 0 deletions conf/modules/digital_cam.xml
Expand Up @@ -43,6 +43,8 @@
</dl_settings>
</settings>

<conflicts>digital_cam_i2c,digital_cam_servo,digital_cam_uart</conflicts>

<header>
<file name="gpio_cam_ctrl.h"/>
<file name="dc.h"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/digital_cam_i2c.xml
Expand Up @@ -9,7 +9,7 @@
<define name="DC_SHOOT_ON_BUTTON_RELEASE" />
<define name="DC_SHOT_SYNC_SEND" value="TRUE|FALSE" description="send DC_SHOT message when photo was taken (default: TRUE)"/>
</doc>

<conflicts>digital_cam,digital_cam_servo,digital_cam_uart</conflicts>
<header>
<file name="atmega_i2c_cam_ctrl.h"/>
<file name="dc.h"/
Expand Down
2 changes: 2 additions & 0 deletions conf/modules/digital_cam_servo.xml
Expand Up @@ -12,6 +12,8 @@
<define name="DC_AUTOSHOOT_DISTANCE_INTERVAL" value="50" description="grid in meters"/>
</doc>

<conflicts>digital_cam,digital_cam_i2c,digital_cam_uart</conflicts>

<header>
<file name="servo_cam_ctrl.h"/>
<file name="dc.h"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/digital_cam_shoot_rc.xml
Expand Up @@ -11,7 +11,7 @@
</description>
<define name="DC_RADIO_SHOOT" value="RADIO_xxx" description="specifies the channel to be used to trigger the camera by radio transmiter"/>
</doc>
<depend require="digital_cam"/>
<depends>digital_cam|digital_cam_servo|digital_cam_uart|digital_cam_i2c</depends>
<header>
<file name="dc_shoot_rc.h"/>
</header>
Expand Down
1 change: 1 addition & 0 deletions conf/modules/digital_cam_uart.xml
Expand Up @@ -20,6 +20,7 @@
</dl_settings>
</dl_settings>
</settings>
<conflicts>digital_cam,digital_cam_servo,digital_cam_i2c</conflicts>
<header>
<file name="uart_cam_ctrl.h"/>
<file name="dc.h"/
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/infrared_adc.xml
@@ -1,6 +1,6 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="ir_adc" dir="sensors">
<module name="infrared_adc" dir="sensors">
<doc>
<description>Infrared sensor using ADC</description>
<configure name="ADC_IR1" value="ADC_1" description="ADC for IR horizontal channel 1"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/ins_vn100.xml
Expand Up @@ -6,7 +6,7 @@
<define name="VN100_SPI_DEV" value="spiX" description="select spi peripherals (default spi1)"/>
<define name="VN100_SLAVE_IDX" value="X" description="spi slave index"/>
</doc>
<!-- <depend conflict="ins" -->
<!-- <conflicts>ins</conflicts> -->
<header>
<file name="ins_vn100.h"/>
</header>
Expand Down
1 change: 0 additions & 1 deletion conf/modules/ins_xsens.xml
Expand Up @@ -4,7 +4,6 @@
<doc>
<description>XSens</description>
</doc>
<!-- <depend conflict="ins" -->
<header>
<file name="ins_module.h"/>
</header>
Expand Down
4 changes: 2 additions & 2 deletions conf/modules/ins_xsens_MTiG_Uart0.xml
Expand Up @@ -4,8 +4,8 @@
<doc>
<description>XSens MTiG</description>
</doc>
<!-- <depend conflict="ins" -->
<!-- <depend require="gps_xsens" -->
<!-- <conflicts>ins</conflicts> -->
<!-- <requires>gps_xsens</requires> -->
<header>
<file name="ins_module.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/ins_xsens_MTi_Uart0.xml
Expand Up @@ -4,7 +4,7 @@
<doc>
<description>XSens MTi</description>
</doc>
<!-- <depend conflict="ins" -->
<!-- <conflicts>ins</conflicts> -->
<header>
<file name="ins_module.h"/>
</header>
Expand Down
1 change: 0 additions & 1 deletion conf/modules/mag_hmc5843.xml
Expand Up @@ -4,7 +4,6 @@
<doc>
<description>hmc5843 magnetometer</description>
</doc>
<!-- <depend conflict="ins" -->
<header>
<file name="mag_hmc5843.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/meteo_stick.xml
Expand Up @@ -34,7 +34,7 @@
<define name="SEND_MS" value="TRU|FALSE" description="Send data over telemetry (PAYLOAD_FLOAT message, scaled PTU data)"/>
</section>
</doc>
<depend require="pwm_meas"/>
<depends>pwm_meas</depends>
<header>
<file name="meteo_stick.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/mf_ptu.xml
Expand Up @@ -31,7 +31,7 @@
<define name="SEND_PTU" value="TRU|FALSE" description="Send data over telemetry (PAYLOAD_FLOAT message, scaled PTU data)"/>
</section>
</doc>
<depend require="pwm_meas"/>
<depends>pwm_meas</depends>
<header>
<file name="mf_ptu.h"/>
</header>
Expand Down
9 changes: 3 additions & 6 deletions conf/modules/module.dtd
@@ -1,10 +1,11 @@
<!-- Paparazzi Modules DTD -->

<!ELEMENT module (doc?,settings_file*,settings*,depend?,header,init*,periodic*,event*,datalink*,makefile*)>
<!ELEMENT module (doc?,settings_file*,settings*,depends?,conflicts?,header,init*,periodic*,event*,datalink*,makefile*)>
<!ELEMENT doc (description|define|configure|section)*>
<!ELEMENT settings_file (file*)>
<!ELEMENT settings (dl_settings?)>
<!ELEMENT depend EMPTY>
<!ELEMENT depends (#PCDATA)>
<!ELEMENT conflicts (#PCDATA)>
<!ELEMENT header (file*)>
<!ELEMENT init EMPTY>
<!ELEMENT periodic EMPTY>
Expand All @@ -29,10 +30,6 @@
name CDATA #REQUIRED
dir CDATA #IMPLIED>

<!ATTLIST depend
require CDATA #IMPLIED
conflict CDATA #IMPLIED>

<!ATTLIST header>

<!ATTLIST init
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/px4flow.xml
Expand Up @@ -4,7 +4,7 @@
<doc>
<description>PX4FLOW optical flow sensor</description>
</doc>
<depend require="mavlink_decoder"/>
<depends>mavlink_decoder</depends>
<header>
<file name="px4flow.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/windturbine.xml
Expand Up @@ -4,7 +4,7 @@
<doc>
<description></description>
</doc>
<depend require="trig_test.xml"/>
<depends>trig_test.xml</depends>
<header>
<file name="windturbine.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/xtend_rssi.xml
Expand Up @@ -13,7 +13,7 @@
</description>
<configure name="XTEND_RSSI_PWM_INPUT_CHANNEL" value="input" description="select on which arch dep input the pwm line is connected"/>
</doc>
<depend require="pwm_meas.xml"/>
<depends>pwm_meas</depends>
<header>
<file name="xtend_rssi.h"/>
</header>
Expand Down
2 changes: 1 addition & 1 deletion sw/airborne/modules/digital_cam/dc_shoot_rc.c
Expand Up @@ -31,7 +31,7 @@
#include "dc.h"

#ifndef DC_RADIO_SHOOT
#error "You need to define DC_RADIO_SHOT to a RADIO_xxx channel to use this module"
#error "You need to define DC_RADIO_SHOOT to a RADIO_xxx channel to use this module"
#endif

#define DC_RADIO_SHOOT_THRESHOLD 3000
Expand Down
51 changes: 38 additions & 13 deletions sw/tools/generators/gen_modules.ml
Expand Up @@ -290,28 +290,53 @@ let parse_modules modules =
let test_section_modules = fun xml ->
List.fold_right (fun x r -> ExtXml.tag_is x "modules" || r) (Xml.children xml) false

(** Check dependencies *)
let pipe_regexp = Str.regexp "|"
let dep_of_field = fun field att ->
(** create list of dependencies from string
* returns a nested list, where the second level consists of OR dependencies
*)
let deps_of_string = fun s ->
let comma_regexp = Str.regexp "," in
let pipe_regexp = Str.regexp "|" in
try
(* first get the comma separated deps *)
let deps = Str.split comma_regexp s in
(* split up each dependency in a list of OR deps (separated by |) *)
List.map (fun dep ->
Str.split pipe_regexp dep)
deps;
with
_ -> [[]]

let get_pcdata = fun xml tag ->
try
Str.split pipe_regexp (Xml.attrib field att)
Xml.pcdata (ExtXml.child (ExtXml.child xml tag) "0")
with
_ -> []
Not_found -> ""

(** Check dependencies *)
let check_dependencies = fun modules names ->
List.iter (fun m ->
try
let dep = ExtXml.child m "depend" in
let require = dep_of_field dep "require" in
List.iter (fun req ->
if not (List.exists (fun c -> String.compare c req == 0) names) then
fprintf stderr "\nWARNING: Dependency not satisfied: module %s requires %s\n" (Xml.attrib m "name") req)
let module_name = Xml.attrib m "name" in
let dep_string = get_pcdata m "depends" in
(*fprintf stderr "\n\nWARNING: parsing dep string: %s\n\n" dep_string;
fprintf stderr "\n\nWARNING: names: %s" (String.concat "," names);*)
let require = deps_of_string dep_string in
List.iter (fun deps ->
(* iterate over all dependencies, where the second level contains the OR dependencies *)
let find_common satisfied d = if List.mem d names then d::satisfied else satisfied in
let satisfied = List.fold_left find_common [] deps in
if List.length satisfied == 0 then
begin
fprintf stderr "\nDEPENDENCY WARNING: Module %s requires %s\n" module_name (String.concat " or " deps);
fprintf stderr "Available dependencies are:\n %s\n\n" (String.concat "\n " names)
end)
require;
let conflict = dep_of_field dep "conflict" in
let conflict_string = get_pcdata m "conflicts" in
let conflict_l = List.flatten (deps_of_string conflict_string) in
List.iter (fun con ->
if List.exists (fun c -> String.compare c con == 0) names then
fprintf stderr "\nWARNING: Dependency not satisfied: module %s conflicts with %s\n" (Xml.attrib m "name") con)
conflict
fprintf stderr "\nDEPENDENCY WARNING: Module %s conflicts with %s\n" module_name con)
conflict_l
with _ -> ()
) modules

Expand Down

0 comments on commit 4697a37

Please sign in to comment.