build: General build refactoring
Add vars.mk for variable sharing across makefiles.
Stub and rename example YAML file and template.
Content to be re-introduced as support is added.
Move generated C++ to a header file.
Add input YAML path option to configure.
Change-Id: Ia06e392e8b120b1e1d8614046064fa432a6f9e18
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/.gitignore b/.gitignore
index 0bc0878..d1d026c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@
missing
stamp-h1
phosphor-dbus-monitor
+generated.hpp
diff --git a/configure.ac b/configure.ac
index 38e8d79..e738f3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,5 +50,8 @@
AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
)
+AC_ARG_VAR(YAML_PATH, [The path to the yaml config files.])
+AS_IF([test "x$YAML_PATH" == "x"], [YAML_PATH="$srcdir/example"])
+
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
diff --git a/src/Makefile.am b/src/Makefile.am
index fcb79e0..3fc5554 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,5 @@
+include ${top_srcdir}/vars.mk
+
AM_DEFAULT_SOURCE_EXT = .cpp
AM_CPPFLAGS = -iquote ${top_srcdir}
@@ -6,8 +8,7 @@
phosphor_dbus_monitor_SOURCES = \
functor.cpp \
main.cpp \
- monitor.cpp \
- generated.cpp
+ monitor.cpp
phosphor_dbus_monitor_LDADD = \
$(SDBUSPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS)
@@ -15,13 +16,16 @@
$(SDBUSPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS)
-BUILT_SOURCES = generated.cpp
-CLEANFILES = generated.cpp
+BUILT_SOURCES = generated.hpp
+CLEANFILES = generated.hpp
-generated.cpp:
- $(AM_V_GEN)$(PYTHON) ${top_srcdir}/src/pdmgen.py \
- -t generated.mako.cpp \
- -p "${srcdir}" \
+TEMPLATES = \
+ templates/generated.mako.hpp
+
+generated.hpp: $(PDMGEN) $(YAML_PATH) $(TEMPLATES)
+ $(AM_V_GEN)$(PYTHON) ${PDMGEN} \
+ -t generated.mako.hpp \
+ -p "${TEMPLATESEARCH}" \
-d ${srcdir}/example \
-o ${builddir}/$@ \
generate-cpp
diff --git a/src/example/example.yaml b/src/example/example.yaml
new file mode 100644
index 0000000..5a798e9
--- /dev/null
+++ b/src/example/example.yaml
@@ -0,0 +1 @@
+# Example PDM configuration file.
diff --git a/src/example/monitoring_defs.yaml b/src/example/monitoring_defs.yaml
deleted file mode 100644
index 04629db..0000000
--- a/src/example/monitoring_defs.yaml
+++ /dev/null
@@ -1,55 +0,0 @@
-# Example sensor monitoring definition
-groups:
- - name: fan_zone_group
- description: Group of fan tach sensors
- type: fan_tach
- members:
- - fan0
- - fan1
- - fan2
- - fan3
-
-triggers:
- - name: app_start
- description: The sensor group manager application started
- type: start
- - name: properties_changed
- description: A property change dbus signal
- type: signal
- signature:
- interface: org.freedesktop.DBus.Properties
- member: PropertiesChanged
-
-conditions:
- - name: fans_at_or_above_speed
- type: countAtOrAbove
- interface: xyz.openbmc_project.Sensor.Value
- property: Value
- parameters:
- group: name
- group: member
- count: 3
- value:
- value: 8000
- type: int64
-
-actions:
- - name: log_error
- type: log_error
- parameters:
- message: string
-
-events:
- - name: fans_over_speed
- groups:
- - fan_zone_group
- triggers:
- - name: app_start
- conditions:
- - fans_at_or_above_speed
- - name: properties_changed
- conditions:
- - fans_at_or_above_speed
- actions:
- - name: log_error
- message: "ERROR: Number of fans at or above 8000rpms reached"
diff --git a/src/generated.cpp b/src/generated.cpp
deleted file mode 100644
index 6ef7cd1..0000000
--- a/src/generated.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-#include "data_types.hpp"
-#include "functor.hpp"
-#include "monitor.hpp"
-#include "conditions.hpp"
-#include "actions.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-// Example vector of sensors constructing a group
-static Group fan_zone_group = {
- std::make_tuple(
- "/xyz/openbmc_project/sensors/fan_tach/fan0",
- static_cast<int64_t>(0)
- ),
- std::make_tuple(
- "/xyz/openbmc_project/sensors/fan_tach/fan1",
- static_cast<int64_t>(0)
- ),
- std::make_tuple(
- "/xyz/openbmc_project/sensors/fan_tach/fan2",
- static_cast<int64_t>(0)
- ),
- std::make_tuple(
- "/xyz/openbmc_project/sensors/fan_tach/fan3",
- static_cast<int64_t>(0)
- )
-};
-
-const std::vector<std::tuple<std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>>
- Monitor::events
-{ // Example vector of Events with START trigger
- {std::make_tuple(std::vector<std::shared_ptr<Event>>(
- { // Example vector of StartEvent
- std::make_shared<StartEvent>(
- std::vector<Condition>(
- { // Example vector of StartEvent conditions
- make_condition(propertyStart<int64_t>(
- "/xyz/openbmc_project/sensors/fan_tach/fan0",
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan0",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- )),
- make_condition(propertyStart<int64_t>(
- "/xyz/openbmc_project/sensors/fan_tach/fan1",
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan1",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- )),
- make_condition(propertyStart<int64_t>(
- "/xyz/openbmc_project/sensors/fan_tach/fan2",
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan2",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- )),
- make_condition(propertyStart<int64_t>(
- "/xyz/openbmc_project/sensors/fan_tach/fan3",
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan3",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- )),
- }
- )
- ),
- std::make_shared<SignalEvent>(
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged',"
- "type='signal',"
- "path='/xyz/openbmc_project/sensors/fan_tach/fan0'",
- std::vector<Condition>(
- { // Example vector of SignalEvent conditions
- make_condition(propertySignal<int64_t>(
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan0",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- ))
- }
- )
- ),
- std::make_shared<SignalEvent>(
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged',"
- "type='signal',"
- "path='/xyz/openbmc_project/sensors/fan_tach/fan1'",
- std::vector<Condition>(
- { // Example vector of SignalEvent conditions
- make_condition(propertySignal<int64_t>(
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan1",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- ))
- }
- )
- ),
- std::make_shared<SignalEvent>(
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged',"
- "type='signal',"
- "path='/xyz/openbmc_project/sensors/fan_tach/fan2'",
- std::vector<Condition>(
- { // Example vector of SignalEvent conditions
- make_condition(propertySignal<int64_t>(
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan2",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- ))
- }
- )
- ),
- std::make_shared<SignalEvent>(
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged',"
- "type='signal',"
- "path='/xyz/openbmc_project/sensors/fan_tach/fan3'",
- std::vector<Condition>(
- { // Example vector of SignalEvent conditions
- make_condition(propertySignal<int64_t>(
- "xyz.openbmc_project.Sensor.Value",
- "Value",
- condition::countAtOrAbove(
- fan_zone_group,
- "/xyz/openbmc_project/sensors/fan_tach/fan3",
- static_cast<size_t>(3),
- static_cast<int64_t>(8000ll)
- )
- ))
- }
- )
- )
- }),
- std::vector<Action>(
- {
- make_action(
- action::log_error(
- "ERROR: Number of fans at or above 8000rpms reached"
- )
- )
- })
- )}
-};
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/generated.mako.cpp b/src/generated.mako.cpp
deleted file mode 100644
index a8f6d60..0000000
--- a/src/generated.mako.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-## This file is a template, the comment below is emitted into the generated file
-/* This is an auto generated file. Do not edit. */
-#include "data_types.hpp"
-#include "monitor.hpp"
-#include "functor.hpp"
-#include "conditions.hpp"
-#include "actions.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-const std::vector<std::tuple<std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>>
- Monitor::events
-{
-
-};
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/main.cpp b/src/main.cpp
index a82bb1d..885d843 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <sdbusplus/bus.hpp>
+#include "generated.hpp"
#include "monitor.hpp"
int main(void)
diff --git a/src/monitor.cpp b/src/monitor.cpp
index 9e517fb..2d4d649 100644
--- a/src/monitor.cpp
+++ b/src/monitor.cpp
@@ -98,6 +98,11 @@
}
}
+const std::vector<
+ std::tuple<
+ std::vector<std::shared_ptr<Event>>,
+ std::vector<Action>>> Monitor::events;
+
} // namespace monitoring
} // namespace dbus
} // namespace phosphor
diff --git a/src/pdmgen.py b/src/pdmgen.py
index 1ff5c51..6476a95 100755
--- a/src/pdmgen.py
+++ b/src/pdmgen.py
@@ -85,7 +85,7 @@
help="Generated output file name and path.")
parser.add_argument(
'-t', '--template', dest='template',
- default='generated.mako.cpp',
+ default='generated.mako.hpp',
help='The top level template to render.')
parser.add_argument(
'-p', '--template-path', dest='template_search',
diff --git a/src/templates/generated.mako.hpp b/src/templates/generated.mako.hpp
new file mode 100644
index 0000000..a2e1adf
--- /dev/null
+++ b/src/templates/generated.mako.hpp
@@ -0,0 +1,14 @@
+## This file is a template, the comment below is emitted into the generated file
+/* This is an auto generated file. Do not edit. */
+#pragma once
+
+namespace phosphor
+{
+namespace dbus
+{
+namespace monitoring
+{
+
+} // namespace monitoring
+} // namespace dbus
+} // namespace phosphor
diff --git a/vars.mk b/vars.mk
new file mode 100644
index 0000000..8002262
--- /dev/null
+++ b/vars.mk
@@ -0,0 +1,2 @@
+PDMGEN=${top_srcdir}/src/pdmgen.py
+TEMPLATESEARCH=${top_srcdir}/src/templates