summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-08-01 16:50:33 +0000
committerAlan Conway <aconway@apache.org>2007-08-01 16:50:33 +0000
commit28b22a308cb6cf0232067636fb6676a4c96d82f7 (patch)
tree1f5b4cd32c425ffda3a7295dd47f0aaba3c0ce25 /cpp
parent9235b5d09b3273c7c495ff266e18781fad363a9b (diff)
downloadqpid-python-28b22a308cb6cf0232067636fb6676a4c96d82f7.tar.gz
* src/generate.sh: Moved requirements test to configure.ac
* rubygen: Cleanup and improvements, template for cluster work. * configure.ac: - support for ruby code generator + cleanup. - moved "can generate" tests to configure.ac - removed redundant APR stuff. * bootstrap: Remove codegen from bootstrap, all in config/make. * src/Makefile.am (libqpidcommon_la_LIBADD): - Ruby code generator. - Improvements to existing generator rules. - Removed APR stuff. * configure.ac (CPPUNIT_CXXFLAGS): Removed APR stuff. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@561869 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rwxr-xr-xcpp/bootstrap4
-rw-r--r--cpp/configure.ac39
-rw-r--r--cpp/rubygen/README13
-rwxr-xr-xcpp/rubygen/amqpgen.rb15
-rwxr-xr-xcpp/rubygen/cppgen.rb25
-rwxr-xr-xcpp/rubygen/generate23
-rw-r--r--cpp/rubygen/templates/frame_body_lists.rb31
-rw-r--r--cpp/src/Makefile.am97
-rwxr-xr-xcpp/src/generate.sh20
-rw-r--r--cpp/src/tests/Makefile.am3
-rwxr-xr-xcpp/src/tests/ais_check2
-rw-r--r--cpp/src/tests/cluster.mk1
12 files changed, 185 insertions, 88 deletions
diff --git a/cpp/bootstrap b/cpp/bootstrap
index 4a0d2cf86b..d56ae5bef4 100755
--- a/cpp/bootstrap
+++ b/cpp/bootstrap
@@ -14,13 +14,9 @@ export JAVA JAVAC
perl -ne '/^(include |if |else|endif)/ or print' Makefile.am \
| make -f - abs_srcdir=`dirname $(pwd)` gen.mk > /dev/null )
-# Bootstrap generated code.
-(cd src; ./generate.sh)
-
automake
autoconf
-
if [ "$1" = "-build" -o "$1" = "--build" ] ; then
shift
./configure "$@"
diff --git a/cpp/configure.ac b/cpp/configure.ac
index f94710232a..86a0347248 100644
--- a/cpp/configure.ac
+++ b/cpp/configure.ac
@@ -90,28 +90,7 @@ CPPUNIT_CXXFLAGS=$CPPUNIT_CFLAGS
AC_SUBST(CPPUNIT_LIBS)
AC_SUBST(CPPUNIT_CXXFLAGS)
-AC_ARG_ENABLE([apr-platform],
- [AS_HELP_STRING([--enable-apr-platform],
- [use the Apache Portable Runtime library for platform (default no)])],
- [case $enableval in
- yes|no) enable_APR_PLATFORM=$enableval;;
- *) AC_MSG_ERROR([Invalid value for --enable-apr-platform: $enableval]);;
- esac],
- [enable_APR_PLATFORM=no]
-)
-AM_CONDITIONAL([USE_APR_PLATFORM], [test x$enable_APR_PLATFORM = xyes])
-
-APR_MINIMUM_VERSION=1.2.2
-AC_SUBST(APR_MINIMUM_VERSION)
-AC_SUBST(APR_CXXFLAGS)
-AC_SUBST(USE_APR_PLATFORM)
-
-if test "$enable_APR_PLATFORM" = yes; then
- PKG_CHECK_MODULES([APR], [apr-1 >= $APR_MINIMUM_VERSION])
- APR_CXXFLAGS="$APR_CFLAGS -DUSE_APR_PLATFORM=1"
- USE_APR_PLATFORM=1
-fi
-
+# Enable Valgrind
AC_ARG_ENABLE([valgrind],
[AS_HELP_STRING([--enable-valgrind],
[run valgrind memory checker on tests, if available (default yes)])],
@@ -132,6 +111,22 @@ test "$enable_VALGRIND" = no && VALGRIND=
AC_CHECK_PROG([RPMLINT], [rpmlint], [rpmlint])
AM_CONDITIONAL([HAS_RPMLINT], [test -n "$RPMLINT"])
+# Code generation: generated code is included in the distribution
+# so code generation is only required in an svn checkout.
+# It requires several external tools and files, which we check for here.
+
+AC_CHECK_PROG([RUBY], [ruby], [ruby])
+AC_CHECK_PROG([JAVA], [java], [java])
+AC_CHECK_PROG([JAVAC], [javac], [javc])
+test -n "$RUBY" -a -n "$JAVA" -a -n "$JAVAC" && generate=yes
+
+specdir=`pwd`/$srcdir/../specs
+AMQP_XML=$specdir/amqp-transitional.0-10.xml
+AC_SUBST(AMQP_XML)
+ls $AMQP_XML >/dev/null 2>&1 || generate=no
+
+AM_CONDITIONAL([GENERATE], [test x$generate = xyes])
+
# URL and download URL for the package.
URL=http://rhm.et.redhat.com/qpidc
AC_SUBST(URL)
diff --git a/cpp/rubygen/README b/cpp/rubygen/README
index 43111d4c4f..a1fd6cfec8 100644
--- a/cpp/rubygen/README
+++ b/cpp/rubygen/README
@@ -1,16 +1,13 @@
RUBY CODE GENERATOR
-amqpgen.rb: builds an AMQP model from XML files and provides generic code generation functions (e.g. capitalization of names etc)
+Run ./generate for usage.
+Examples in samples/
-cppgen.rb: C++ specific code generation functions.
+For example:
+ ./generate . ../../specs/amqp.0-9.xml samples/Proxy.rb
+will generate
-A template is a ruby file that generates one or more source files.
-For an example run
- samples/runme test <amqp.xml files>
-
-The first argument is a directory for generated files, remaining arguments
-are xml files.
diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb
index 3fc66525d8..1bd11848a6 100755
--- a/cpp/rubygen/amqpgen.rb
+++ b/cpp/rubygen/amqpgen.rb
@@ -135,12 +135,13 @@ class AmqpRoot < AmqpElement
def classes()
@cache_classes ||= elements.collect("class") { |c| AmqpClass.new(c,self) }.sort_by_name
end
-
+
+ # Return all methods on all classes.
+ def methods() classes.collect { |c| c.methods }.flatten; end
+
# Return all methods on chassis for all classes.
def methods_on(chassis)
- classes.collect { |c|
- c.methods_on(chassis)
- }.flatten
+ classes.collect { |c| c.methods_on(chassis) }.flatten
end
# Merge contents of elements.
@@ -190,6 +191,12 @@ class Generator
@midline = /[^\n]\z/ === str
end
+ # Append str + '\n' to generated code.
+ def genl(str="")
+ gen str
+ gen "\n"
+ end
+
# Generate code with added prefix.
def prefix(add)
save=@prefix
diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb
index 3e3800c4cd..b5f4758411 100755
--- a/cpp/rubygen/cppgen.rb
+++ b/cpp/rubygen/cppgen.rb
@@ -105,6 +105,7 @@ class CppGen < Generator
# Write a header file.
def h_file(path)
+ path = (/\.h$/ === path ? path : path+".h")
guard=path.upcase.tr('./-','_')
file(path) {
gen "#ifndef #{guard}\n"
@@ -122,5 +123,29 @@ class CppGen < Generator
yield
end
end
+
+ def include(header) genl "#include \"#{header}\""; end
+
+ def scope(open="{",close="}", &block)
+ genl open; indent(&block); genl close
+ end
+
+ def namespace(name, &block)
+ names = name.split("::")
+ names.each { |n| genl "namespace #{n} {" }
+ yield
+ genl('}'*names.size+" // "+name)
+ end
+
+ def struct_class(type, name, *bases, &block)
+ gen "#{type} #{name}"
+ gen ": #{bases.join(', ')}" unless bases.empty
+ genl "{"
+ yield
+ genl "};"
+ end
+
+ def struct(name, *bases, &block) struc_class("struct", bases, &block); end
+ def class_(name, *bases, &block) struc_class("struct", bases, &block); end
end
diff --git a/cpp/rubygen/generate b/cpp/rubygen/generate
new file mode 100755
index 0000000000..09b27211af
--- /dev/null
+++ b/cpp/rubygen/generate
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+require 'amqpgen'
+
+#
+# Run a set of code generation templates.
+#
+
+if ARGV.size < 3
+ puts <<EOS
+Usage: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] TEMPLATE.rb [ ... ]
+Parse all SPEC.xml files to create an AMQP model, run each TEMPLATE
+putting the resulting files under OUTDIR. Prints a list of files
+generated to standard output.
+
+If OUTDIR is '-' then just prints file list without generating files.
+EOS
+ exit 1
+end
+outdir=ARGV[0]
+specs=ARGV.grep(/\.xml$/)
+templates=ARGV.grep(/\.rb$/)
+Amqp=AmqpRoot.new(*specs)
+templates.each { |t| require t }
diff --git a/cpp/rubygen/templates/frame_body_lists.rb b/cpp/rubygen/templates/frame_body_lists.rb
new file mode 100644
index 0000000000..33c416fe84
--- /dev/null
+++ b/cpp/rubygen/templates/frame_body_lists.rb
@@ -0,0 +1,31 @@
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class FrameBodyListsGen < CppGen
+
+ def initialize(outdir, amqp)
+ super(outdir, amqp);
+ end
+
+ def generate
+ h_file("qpid/framing/frame_body_lists.h") {
+ gen <<EOS
+/**@file
+ * Macro lists of frame body classes, used to generate Visitors
+ */
+EOS
+ gen "#define METHOD_BODIES() "
+ @amqp.methods.each { |m| gen "\\\n (#{m.body_name}) " }
+ gen <<EOS
+
+
+#define OTHER_BODIES() (AMQContentBody)(AMQHeaderBody)(AMQHeartbeatBody))
+
+EOS
+ }
+ end
+end
+
+FrameBodyListsGen.new(ARGV[0], Amqp).generate;
+
+
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am
index 458f28abd2..d4293b70fd 100644
--- a/cpp/src/Makefile.am
+++ b/cpp/src/Makefile.am
@@ -1,31 +1,75 @@
SUBDIRS = . tests
-# Generated code
--include generate.mk
+## Generated code
-generate.mk $(generated_cpp) $(generated_h): gen/timestamp
+# Note: generated soure and makefiles included in distribution so a
+# distribution can be built without code generation tools and XML
+# sources.
-gen/timestamp: generate.sh $(generator)
- $(srcdir)/generate.sh
- touch $@
+EXTRA_DIST= $(platform_dist)
+
+EXTRA_DIST += gen/generate.mk generate.sh $(generated_cpp) $(generated_h) \
+ rubygen.mk $(rgen_srcs)
+
+# AMQP_XML is defined in ../configure.ac
+specs=@AMQP_XML@ $(top_srcdir)/xml/cluster.xml
+
+# Makefiles are either generated or copied from $srcdir.
+sinclude gen/generate.mk
+sinclude rubygen.mk
+
+DISTCLEANFILES=gen/generate.mk rubygen.mk
+
+if GENERATE
+
+# Java code generator.
+# Must generate into a separate gen directory because otherwise
+# there's no way to figure out which files are generated.
+
+gentools_dir=$(top_srcdir)/gentools
+
+gen/generate.mk: generate.sh $(specs) $(generator)
+ env gentools_dir=$(gentools_dir) specs="$(specs)" $(srcdir)/generate.sh
+
+gen $(generated_cpp) $(generated_h): gen/generate.mk
# Empty rule in case a generator file is renamed/removed.
$(generator):
-DISTCLEANFILES=generate.mk
-
-clean-gen:
+maintainer-clean-local:
rm -rf gen
-maintainer-clean-local:
- clean-gen
+# Ruby generator.
+
+rgen_dir=$(top_srcdir)/rubygen
+rgen_tdir=$(rgen_dir)/templates
+rgen_script=$(rgen_dir)/generate
+rgen_cmd=ruby -I $(rgen_dir) $(rgen_script)
+
+rgen_templates=$(rgen_tdir)/frame_body_lists.rb
+
+rubygen.mk: $(rgen_script) $(specs) $(rgen_templates)
+ echo rgen_srcs=`$(rgen_cmd) - $(specs) $(rgen_templates)` > $@
+ echo rgen_srcs=`$(rgen_cmd) . $(specs) $(rgen_templates)`
-EXTRA_DIST=generate.sh $(generated_cpp) $(generated_h) $(platform_dist)
+$(rgen_srcs): rubygen.mk
-AM_CXXFLAGS = $(WARNING_CFLAGS) $(APR_CXXFLAGS)
+else # !GENERATE
+# If not generating, copy generated makefiles from source dir to build dir.
+gen/generate.mk:
+ cp $(srcdir)/$@ $@
+rubygen.mk:
+ cp $(srcdir)/$@ $@
+endif # GENERATE
+
+## Compiler flags
+
+AM_CXXFLAGS = $(WARNING_CFLAGS)
AM_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO_ARG)
INCLUDES = -Igen -I$(srcdir)/gen
+## Automake macros to build libraries and executables.
+
qpidd_LDADD = \
libqpidbroker.la \
libqpidcommon.la
@@ -33,21 +77,6 @@ qpidd_LDADD = \
sbin_PROGRAMS = qpidd
qpidd_SOURCES = qpidd.cpp
-apr_plat_src = \
- qpid/sys/apr/APRBase.cpp \
- qpid/sys/apr/APRPool.cpp \
- qpid/sys/apr/Socket.cpp \
- qpid/sys/apr/Time.cpp \
- qpid/sys/apr/Thread.cpp \
- qpid/sys/apr/Shlib.cpp
-
-apr_plat_hdr = \
- qpid/sys/apr/APRBase.h \
- qpid/sys/apr/APRPool.h \
- qpid/sys/apr/Condition.h \
- qpid/sys/apr/Mutex.h \
- qpid/sys/apr/Thread.h
-
posix_plat_src = \
qpid/sys/epoll/EpollPoller.cpp \
qpid/sys/posix/check.cpp \
@@ -64,15 +93,8 @@ posix_plat_hdr = \
qpid/sys/posix/Mutex.h \
qpid/sys/posix/Thread.h
-if USE_APR_PLATFORM
- platform_dist=$(posix_plat_src) $(posix_plat_hdr)
- platform_src = $(apr_plat_src)
- platform_hdr = $(apr_plat_hdr)
-else
- platform_dist=$(apr_plat_src) $(apr_plat_hdr)
- platform_src = $(posix_plat_src)
- platform_hdr = $(posix_plat_hdr)
-endif
+platform_src = $(posix_plat_src)
+platform_hdr = $(posix_plat_hdr)
lib_LTLIBRARIES = libqpidcommon.la libqpidbroker.la libqpidclient.la
@@ -91,7 +113,6 @@ libqpidcommon_la_LIBADD = \
-lboost_program_options \
-luuid \
libLogger.la \
- $(APR_LIBS) \
$(LIB_DLOPEN) \
$(LIB_CLOCK_GETTIME)
diff --git a/cpp/src/generate.sh b/cpp/src/generate.sh
index 1d8f946ecd..2cc31ff922 100755
--- a/cpp/src/generate.sh
+++ b/cpp/src/generate.sh
@@ -1,19 +1,19 @@
# !/bin/sh
# Generate code from AMQP specification.
-# srcdir must
+# specs and gentools_dir are set by Makefile
#
-srcdir=`dirname $0`
set -e
-gentools_dir="$srcdir/../gentools"
-specs_dir="$srcdir/../../specs"
-specs="$specs_dir/amqp-transitional.0-10.xml $srcdir/../xml/cluster.xml"
-
test -z "$JAVA" && JAVA=java ;
-test -z "$JAVAC" && JAVAC=javac ;
+test -z "$JAVAC" && JAVAC=javac ;
+
+checkspecs() {
+ for s in $specs; do test -f $s || return 1; done
+ return 0
+}
# Can we generate code?
-if { test -d $gentools_dir && test -d $specs_dir && \
+if { test -d $gentools_dir && checkspecs &&
which $JAVA && which $JAVAC; } > /dev/null;
then
echo "Generating code."
@@ -40,8 +40,8 @@ make_assign() {
make_assign "generator" "" $specs \
`find ../gentools \( -name '*.java' -o -name '*.tmpl' \) -print`
fi
-) > generate.mk-t
-mv generate.mk-t generate.mk
+) > gen/generate.mk-t
+mv gen/generate.mk-t gen/generate.mk
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am
index 82918c1aec..bc173d61d6 100644
--- a/cpp/src/tests/Makefile.am
+++ b/cpp/src/tests/Makefile.am
@@ -14,6 +14,7 @@ check_PROGRAMS=
check_LTLIBRARIES=
TESTS=
EXTRA_DIST=
+CLEANFILES=
#
# Unit test programs.
@@ -171,7 +172,7 @@ all-am: .valgrind.supp .valgrindrc
# ltmain invocations, one may corrupt the temporaries of the other.
.NOTPARALLEL:
-CLEANFILES=valgrind.out *.log *.vglog .valgrindrc .valgrind.supp dummy_test $(unit_wrappers)
+CLEANFILES+=valgrind.out *.log *.vglog .valgrindrc .valgrind.supp dummy_test $(unit_wrappers)
MAINTAINERCLEANFILES=gen.mk
interop_runner_SOURCES = \
diff --git a/cpp/src/tests/ais_check b/cpp/src/tests/ais_check
index 69a0469a26..ce3bbe1b1c 100755
--- a/cpp/src/tests/ais_check
+++ b/cpp/src/tests/ais_check
@@ -34,6 +34,6 @@ fi
FAILED=0
for test in `cat ais_tests`; do
- $srcdir/$test || FAILED=`expr $FAILED + 1`
+ ./$test || FAILED=`expr $FAILED + 1`
done
exit $FAILED
diff --git a/cpp/src/tests/cluster.mk b/cpp/src/tests/cluster.mk
index 8b603efb14..092647c9eb 100644
--- a/cpp/src/tests/cluster.mk
+++ b/cpp/src/tests/cluster.mk
@@ -21,6 +21,7 @@ AIS_TESTS=
ais_check: ais_tests
ais_tests:
echo $(AIS_TESTS) >$@
+CLEANFILES+=ais_tests
AIS_TESTS+=Cpg
check_PROGRAMS+=Cpg