diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-02-03 11:00:27 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-02-09 20:36:50 -0500 |
commit | a6fcd567f6aa01746471fd639db63fecadbf166b (patch) | |
tree | bcdc273c61aa32335b6733cc0e560ae3ec69e429 | |
parent | 2a9f934aae45b7d4fab93ccbd761d39600bdf385 (diff) | |
download | phosphor-inventory-manager-a6fcd567f6aa01746471fd639db63fecadbf166b.tar.gz phosphor-inventory-manager-a6fcd567f6aa01746471fd639db63fecadbf166b.zip |
build: split app/test pimgen invocation
Run pimgen twice, once for the application with the real YAML
and once for the testcase with the example YAML so that the
testcase can run and build sucessfully when an alternate YAML
tree is provided.
Move extra interface rule generation from pimgen to a makefile
generating script.
Change-Id: Ib0c01bd2207007b815019232a466fa16889f2005
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | Makefile.am | 41 | ||||
-rw-r--r-- | Makefile.extra.in | 1 | ||||
-rw-r--r-- | configure.ac | 19 | ||||
-rwxr-xr-x | generate_makefile.sh | 61 | ||||
-rwxr-xr-x | pimgen.py | 81 | ||||
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 29 | ||||
-rw-r--r-- | test/Makefile.extra.in | 1 | ||||
-rw-r--r-- | test/test.cpp | 8 |
10 files changed, 148 insertions, 102 deletions
@@ -4,10 +4,8 @@ *.sw* phosphor-inventory generated.cpp -xyz.openbmc_project.Example.Iface1.cpp -xyz.openbmc_project.Example.Iface2.cpp -xyz/openbmc_project/Example/Iface1/server.hpp -xyz/openbmc_project/Example/Iface2/server.hpp +xyz.openbmc_project.Example.*.cpp +xyz/openbmc_project/Example/ Makefile Makefile.in configure @@ -29,3 +27,5 @@ install-sh ltmain.sh missing stamp-h1 +Makefile.extra +extra_ifaces.cpp diff --git a/Makefile.am b/Makefile.am index fb4ecb2..1673362 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,34 +1,33 @@ -EXTRAIFACES_C=@EXTRAIFACES_C@ -EXTRAIFACES_LO=@EXTRAIFACES_LO@ -BUILT_SOURCES=generated.cpp +BUILT_SOURCES=generated.cpp extra_ifaces.cpp -CLEANFILES=$(BUILT_SOURCES) $(EXTRAIFACES_C) libextra.la +CLEANFILES=$(BUILT_SOURCES) sbin_PROGRAMS = phosphor-inventory +noinst_LTLIBRARIES = libmanagercommon.la libmanager.la + +extra_yamldir=$(YAML_PATH)/extra_interfaces.d + phosphor_inventory_SOURCES = app.cpp phosphor_inventory_LDADD = libmanager.la -phosphor_inventory_LDFLAGS = $(SYSTEMD_LIBS) -phosphor_inventory_CFLAGS = $(SYSTEMD_CFLAGS) +phosphor_inventory_LDFLAGS = $(SDBUSPLUS_LIBS) +phosphor_inventory_CFLAGS = $(SDBUSPLUS_CFLAGS) -noinst_LTLIBRARIES = libmanager.la -libmanager_la_SOURCES = \ +libmanagercommon_la_SOURCES = \ xyz.openbmc_project.Inventory.Manager.cpp \ - generated.cpp \ events.cpp \ manager.cpp -libmanager_la_LIBADD = libextra.la $(SDBUSPLUS_LIBS) +libmanagercommon_la_LIBADD = $(SDBUSPLUS_LIBS) -# Automake does not allow autoconf substituted variables -# in _SOURCES variables. Work around this by providing -# our own target. -# -# Typically the recommendation is conditional compilation -# but here the generated source files are completely -# arbitrary and not known making that approach difficult. -libextra.la: $(EXTRAIFACES_LO) - $(AM_V_CXXLD)$(CXXLINK) $(EXTRAIFACES_LO) +libmanager_la_SOURCES = \ + extra_ifaces.cpp \ + generated.cpp +libmanager_la_LIBADD = libmanagercommon.la $(SDBUSPLUS_LIBS) + +clean-local: clean-extra -$(EXTRAIFACES_C) generated.cpp: - $(AM_V_GEN)@PIMGEN@ -o $(top_builddir) generate-cpp +generated.cpp: + $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-cpp SUBDIRS = . test + +-include Makefile.extra diff --git a/Makefile.extra.in b/Makefile.extra.in new file mode 100644 index 0000000..128a178 --- /dev/null +++ b/Makefile.extra.in @@ -0,0 +1 @@ +# Empty file so that 'configure' attempts to generate Makefile.extra. diff --git a/configure.ac b/configure.ac index 8101911..e9b30fe 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,9 @@ AM_PROG_AR AC_PROG_INSTALL AC_PROG_MAKE_SET AC_PROG_AWK +AC_CHECK_PROG([FIND], find, find) +AC_CHECK_PROG([BASENAME], basename, basename) +AC_CHECK_PROG([DIRNAME], dirname, dirname) AM_PATH_PYTHON([2.7], [AC_SUBST([PYTHON], [echo "$PYTHON"])], [AC_MSG_ERROR([Could not find python-2.7 installed...python-2.7 is required])]) @@ -53,6 +56,10 @@ AS_IF([test "x$enable_oe_sdk" == "xyes"], AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags]) ) +AC_PATH_PROG([SDBUSPLUSPLUS], [sdbus++]) +AS_IF([test "x$SDBUSPLUSPLUS" == "x"], + AC_MSG_ERROR([Cannot find sdbus++])) + AC_ARG_VAR(BUSNAME, [The DBus busname to own.]) AC_ARG_VAR(INVENTORY_ROOT, [The DBus inventory namespace root.]) AC_ARG_VAR(IFACE, [The manager DBus interface.]) @@ -64,13 +71,13 @@ AS_IF([test "x$YAML_PATH" == "x"], [YAML_PATH="$srcdir/example"]) AC_DEFINE_UNQUOTED([BUSNAME], ["$BUSNAME"], [The DBus busname to own.]) AC_DEFINE_UNQUOTED([INVENTORY_ROOT], ["$INVENTORY_ROOT"], [The DBus inventory namespace root.]) AC_DEFINE_UNQUOTED([IFACE], ["$IFACE"], [The manager DBus interface.]) -PIMGEN="$PYTHON $srcdir/pimgen.py -d $YAML_PATH" -EXTRAIFACES_LO="`$PIMGEN list-interfaces|awk '{ for(i=1;i<=NF;i++){printf $i".lo ";}}'`" -EXTRAIFACES_C="`$PIMGEN list-interfaces|awk '{ for(i=1;i<=NF;i++){printf $i".cpp ";}}'`" -AC_SUBST(EXTRAIFACES_LO) -AC_SUBST(EXTRAIFACES_C) -AC_SUBST(PIMGEN) # Create configured output +AC_CONFIG_FILES([Makefile.extra], + [${srcdir}/generate_makefile.sh $yaml > Makefile.extra], + [yaml=${YAML_PATH}/extra_interfaces.d]) +AC_CONFIG_FILES([test/Makefile.extra], + [${srcdir}/generate_makefile.sh $test_yaml > test/Makefile.extra], + [test_yaml=$srcdir/example/extra_interfaces.d]) AC_CONFIG_FILES([Makefile test/Makefile]) AC_OUTPUT diff --git a/generate_makefile.sh b/generate_makefile.sh new file mode 100755 index 0000000..17236a7 --- /dev/null +++ b/generate_makefile.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +yaml_top=$1 +toplevel_dirs=xyz +interfaces= + +if [ -d $yaml_top/$toplevel_dirs ]; then + cd $yaml_top + interfaces=`find $toplevel_dirs -name "*.interface.yaml"` +fi + +for i in ${interfaces}; +do + iface_path=`dirname $i`/`basename $i .interface.yaml` + iface=`echo $iface_path | sed 's/\//./g'` + cat <<MAKEFILE +${i%.interface.yaml}/server.cpp: \$(extra_yamldir)/${i} ${i%.interface.yaml}/server.hpp + @mkdir -p \`dirname \$@\` + \$(AM_V_GEN)\$(SDBUSPLUSPLUS) -r \$(extra_yamldir) interface server-cpp ${iface} > \$@ + +${i%.interface.yaml}/server.hpp: \$(extra_yamldir)/${i} + @mkdir -p \`dirname \$@\` + \$(AM_V_GEN)\$(SDBUSPLUSPLUS) -r \$(extra_yamldir) interface server-header ${iface} > \$@ + +MAKEFILE + +done + +echo "extra_ifaces_cpp_SOURCES = \\" +for i in ${interfaces}; +do + echo " ${i%.interface.yaml}/server.cpp \\" +done +echo + +echo "extra_ifaces_hpp_SOURCES = \\" +for i in ${interfaces}; +do + echo " ${i%.interface.yaml}/server.hpp \\" +done +echo + +echo "extra_ifaces.cpp: \$(extra_ifaces_cpp_SOURCES)" +if [ "$interfaces" ]; then + echo " \$(AM_V_GEN)cat \$^ > \$@" +else + echo " \$(AM_V_GEN)touch \$@" +fi + +cat << MAKEFILE + +.PHONY: clean-extra +clean-extra: + for i in \$(extra_ifaces_cpp_SOURCES) \\ + \$(extra_ifaces_hpp_SOURCES); \\ + do \\ + test -e \$\$i && rm \$\$i ; \\ + test -d \`dirname \$\$i\` && rmdir -p \`dirname \$\$i\` ; \\ + true; \\ + done +MAKEFILE @@ -431,61 +431,21 @@ class Everything(Renderer): @staticmethod def load(args): - # Invoke sdbus++ to generate any extra interface bindings for - # extra interfaces that aren't defined externally. - yaml_files = [] - extra_ifaces_dir = os.path.join(args.inputdir, 'extra_interfaces.d') - if os.path.exists(extra_ifaces_dir): - for directory, _, files in os.walk(extra_ifaces_dir): - if not files: - continue - - yaml_files += map( - lambda f: os.path.relpath( - os.path.join(directory, f), - extra_ifaces_dir), - filter(lambda f: f.endswith('.interface.yaml'), files)) - - genfiles = { - 'server-cpp': lambda x: '%s.cpp' % ( - x.replace(os.sep, '.')), - 'server-header': lambda x: os.path.join( - os.path.join( - *x.split('.')), 'server.hpp') - } - - for i in yaml_files: - iface = i.replace('.interface.yaml', '').replace(os.sep, '.') - for process, f in genfiles.iteritems(): - - dest = os.path.join(args.outputdir, f(iface)) - parent = os.path.dirname(dest) - if parent and not os.path.exists(parent): - os.makedirs(parent) - - with open(dest, 'w') as fd: - subprocess.call([ - 'sdbus++', - '-r', - extra_ifaces_dir, - 'interface', - process, - iface], - stdout=fd) - # Aggregate all the event YAML in the events.d directory # into a single list of events. + events = [] events_dir = os.path.join(args.inputdir, 'events.d') - yaml_files = filter( - lambda x: x.endswith('.yaml'), - os.listdir(events_dir)) - events = [] - for x in yaml_files: - with open(os.path.join(events_dir, x), 'r') as fd: - for e in yaml.safe_load(fd.read()).get('events', {}): - events.append(e) + if os.path.exists(events_dir): + yaml_files = filter( + lambda x: x.endswith('.yaml'), + os.listdir(events_dir)) + + for x in yaml_files: + with open(os.path.join(events_dir, x), 'r') as fd: + for e in yaml.safe_load(fd.read()).get('events', {}): + events.append(e) return Everything( *events, @@ -496,16 +456,17 @@ class Everything(Renderer): '''Aggregate all the interface YAML in the interfaces.d directory into a single list of interfaces.''' + interfaces = [] interfaces_dir = os.path.join(args.inputdir, 'interfaces.d') - yaml_files = filter( - lambda x: x.endswith('.yaml'), - os.listdir(interfaces_dir)) + if os.path.exists(interfaces_dir): + yaml_files = filter( + lambda x: x.endswith('.yaml'), + os.listdir(interfaces_dir)) - interfaces = [] - for x in yaml_files: - with open(os.path.join(interfaces_dir, x), 'r') as fd: - for i in yaml.safe_load(fd.read()): - interfaces.append(i) + for x in yaml_files: + with open(os.path.join(interfaces_dir, x), 'r') as fd: + for i in yaml.safe_load(fd.read()): + interfaces.append(i) return interfaces @@ -516,9 +477,6 @@ class Everything(Renderer): self.class_map[x['type']](**x) for x in a] super(Everything, self).__init__(**kw) - def list_interfaces(self, *a): - print ' '.join([str(i) for i in self.interfaces]) - def generate_cpp(self, loader): '''Render the template with the provided events and interfaces.''' with open(os.path.join( @@ -537,7 +495,6 @@ if __name__ == '__main__': script_dir = os.path.dirname(os.path.realpath(__file__)) valid_commands = { 'generate-cpp': 'generate_cpp', - 'list-interfaces': 'list_interfaces' } parser = argparse.ArgumentParser( diff --git a/test/.gitignore b/test/.gitignore index 65c2e9e..1520cd8 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,2 @@ phosphor-inventory-test +xyz diff --git a/test/Makefile.am b/test/Makefile.am index 1f6470d..07f8453 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,8 +1,27 @@ +BUILT_SOURCES=generated.cpp extra_ifaces.cpp +CLEANFILES=$(BUILT_SOURCES) + +AM_CPPFLAGS = -iquote$(top_srcdir) + check_PROGRAMS = noinst_PROGRAMS = phosphor-inventory-test +noinst_LTLIBRARIES = libtest.la + +extra_yamldir=$(top_srcdir)/example/extra_interfaces.d + +phosphor_inventory_test_SOURCES = test.cpp +phosphor_inventory_test_LDADD = libtest.la +phosphor_inventory_test_LDFLAGS = $(SDBSUPLUS_LIBS) $(PTHREAD_CFLAGS) +phosphor_inventory_test_CFLAGS = $(SDBUSPLUS_CFLAGS) + +libtest_la_SOURCES = \ + extra_ifaces.cpp \ + generated.cpp +libtest_la_LIBADD = $(top_builddir)/libmanagercommon.la $(SDBUSPLUS_LIBS) + +clean-local: clean-extra + +generated.cpp: + $(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-cpp -phosphor_inventory_test_SOURCES = \ - test.cpp -phosphor_inventory_test_LDFLAGS = $(SYSTEMD_LIBS) $(PTHREAD_CFLAGS) -phosphor_inventory_test_CFLAGS = $(SYSTEMD_CFLAGS) -phosphor_inventory_test_LDADD = ${top_builddir}/libmanager.la +-include Makefile.extra diff --git a/test/Makefile.extra.in b/test/Makefile.extra.in new file mode 100644 index 0000000..128a178 --- /dev/null +++ b/test/Makefile.extra.in @@ -0,0 +1 @@ +# Empty file so that 'configure' attempts to generate Makefile.extra. diff --git a/test/test.cpp b/test/test.cpp index 3f39fa9..6ffad51 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "../manager.hpp" -#include "../config.h" +#include "manager.hpp" +#include "config.h" #include <cassert> #include <iostream> #include <algorithm> #include <thread> #include <chrono> -#include <xyz/openbmc_project/Example/Iface1/server.hpp> -#include <xyz/openbmc_project/Example/Iface2/server.hpp> +#include "xyz/openbmc_project/Example/Iface1/server.hpp" +#include "xyz/openbmc_project/Example/Iface2/server.hpp" using namespace std::literals::chrono_literals; using namespace std::literals::string_literals; |