diff options
author | Alan Conway <aconway@apache.org> | 2009-07-27 21:32:16 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-07-27 21:32:16 +0000 |
commit | 77e93f5453f3b9878c3e27b0e99a365356c5264c (patch) | |
tree | c6e72c764dab31648c39de97ec7154e893662eb5 /cpp/rubygen | |
parent | bcf89b1af8b1d4a0262530b50e5433cdaffb91f0 (diff) | |
download | qpid-python-77e93f5453f3b9878c3e27b0e99a365356c5264c.tar.gz |
Separate generated public header files from non-public headers, generated code re-organization.
The gen/ directory has been removed, code is now generated into:
$(builddir)/src - all .cpp files and non-public .h files.
$(builddir)/include - all public .h files.
The gen/ directory was originally intended to separate generated code
from hand-written code. However both automake and cmake allow you to
direct all build output, including generated code, into a separate
build directory. In fact both recommend you build this way.
Keeping the gen/ directory meant there would have been a total of 8
places to look for header files, all the combinations of
builddir/srcdir, src/include and gen/no-gen. This was a mess, 4 is bad
enough.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@798291 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rwxr-xr-x | cpp/rubygen/amqpgen.rb | 31 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/Operations.rb | 6 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/OperationsInvoker.rb | 6 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/Session.rb | 12 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/constants.rb | 10 | ||||
-rw-r--r-- | cpp/rubygen/framing.0-10/frame_body_lists.rb | 2 | ||||
-rwxr-xr-x | cpp/rubygen/framing.0-10/structs.rb | 6 | ||||
-rwxr-xr-x | cpp/rubygen/generate | 23 |
8 files changed, 54 insertions, 42 deletions
diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb index 802f934c7a..69e65a4056 100755 --- a/cpp/rubygen/amqpgen.rb +++ b/cpp/rubygen/amqpgen.rb @@ -318,7 +318,7 @@ class AmqpFakeMethod < AmqpMethod def content() return "1" if @action.is_a? AmqpCommand and @action.segments end def index() @action.code end def code() @action.code end - def synchronous() end # FIXME aconway 2008-04-10: ??? + def synchronous() end def on_chassis?(chassis) @action.received_by?(chassis) end @@ -464,9 +464,12 @@ end # Collect information about generated files. class GenFiles - @@files = Set.new - def GenFiles.add(f) @@files.add f; end + @@files = Set.new + @@public_api = [] + def GenFiles.add(f) @@files.add(f); end def GenFiles.get() @@files; end + def GenFiles.public_api(file) @@public_api << file; end + def GenFiles.public_api?(file) @@public_api.find { |f| f == file }; end end # Base class for code generators. @@ -476,27 +479,27 @@ class Generator # Takes directory for output or "-", meaning print file names that # would be generated. def initialize (outdir, amqp) + @outdir=outdir[0] + @apidir=outdir[1] @amqp=amqp - @outdir=outdir + raise "outdir is not an array" unless outdir.class == Array @prefix=[''] # For indentation or comments. @indentstr=' ' # One indent level. @outdent=2 - Pathname.new(@outdir).mkpath unless @outdir=="-" end + # Declare next file to be public API + def public_api(file) GenFiles.public_api(file); end + # Create a new file, set @out. def file(file, &block) - GenFiles.add file - if (@outdir != "-") - @path=Pathname.new "#{@outdir}/#{file}" + GenFiles.add(file) + dir = GenFiles.public_api?(file) ? @apidir : @outdir + if (dir != "-") + @path=Pathname.new "#{dir}/#{file}" @path.parent.mkpath @out=String.new # Generate in memory first - if block then yield; endfile; end - end - end - - def endfile() - if @outdir != "-" + yield if block if @path.exist? and @path.read == @out puts "Skipped #{@path} - unchanged" # Dont generate if unchanged else diff --git a/cpp/rubygen/framing.0-10/Operations.rb b/cpp/rubygen/framing.0-10/Operations.rb index c217926a66..cd6a363c56 100755 --- a/cpp/rubygen/framing.0-10/Operations.rb +++ b/cpp/rubygen/framing.0-10/Operations.rb @@ -115,7 +115,7 @@ EOS end end -OperationsGen.new("client",ARGV[0], $amqp).generate() -OperationsGen.new("server",ARGV[0], $amqp).generate() -OperationsGen.new("all",ARGV[0], $amqp).generate() +OperationsGen.new("client",$outdir, $amqp).generate() +OperationsGen.new("server",$outdir, $amqp).generate() +OperationsGen.new("all",$outdir, $amqp).generate() diff --git a/cpp/rubygen/framing.0-10/OperationsInvoker.rb b/cpp/rubygen/framing.0-10/OperationsInvoker.rb index 6e3b79e51e..f9b6cac76b 100755 --- a/cpp/rubygen/framing.0-10/OperationsInvoker.rb +++ b/cpp/rubygen/framing.0-10/OperationsInvoker.rb @@ -112,6 +112,6 @@ class OperationsInvokerGen < CppGen end end -OperationsInvokerGen.new("client",ARGV[0], $amqp).generate() -OperationsInvokerGen.new("server",ARGV[0], $amqp).generate() -OperationsInvokerGen.new("all",ARGV[0], $amqp).generate() +OperationsInvokerGen.new("client",$outdir, $amqp).generate() +OperationsInvokerGen.new("server",$outdir, $amqp).generate() +OperationsInvokerGen.new("all",$outdir, $amqp).generate() diff --git a/cpp/rubygen/framing.0-10/Session.rb b/cpp/rubygen/framing.0-10/Session.rb index 7b92a17f41..61f0e03a8b 100755 --- a/cpp/rubygen/framing.0-10/Session.rb +++ b/cpp/rubygen/framing.0-10/Session.rb @@ -136,6 +136,7 @@ class SessionNoKeywordGen < CppGen end def generate() + public_api("#{@file}.h") h_file(@file) { include "qpid/client/#{@version_base}.h" include "qpid/client/ClientImportExport.h" @@ -222,6 +223,7 @@ class SessionGen < CppGen keyword_methods=session_methods(sync_default).reject { |m| m.fields_c.empty? } max_arity = keyword_methods.map{ |m| m.fields_c.size }.max + public_api("qpid/client/arg.h") h_file("qpid/client/arg.h") { # Generate keyword tag declarations. genl "#define BOOST_PARAMETER_MAX_ARITY #{max_arity}" @@ -231,7 +233,7 @@ class SessionGen < CppGen genl "BOOST_PARAMETER_KEYWORD(keyword_tags, #{k})" }} } - + public_api("#{@fqclass.file}.h") h_file(@fqclass.file) { include @fqbase.file include "qpid/client/arg" @@ -408,8 +410,8 @@ EOS end end -SessionNoKeywordGen.new(ARGV[0], $amqp, true).generate() -SessionNoKeywordGen.new(ARGV[0], $amqp, false).generate() -SessionGen.new(ARGV[0], $amqp, true).generate() -SessionGen.new(ARGV[0], $amqp, false).generate() +SessionNoKeywordGen.new($outdir, $amqp, true).generate() +SessionNoKeywordGen.new($outdir, $amqp, false).generate() +SessionGen.new($outdir, $amqp, true).generate() +SessionGen.new($outdir, $amqp, false).generate() diff --git a/cpp/rubygen/framing.0-10/constants.rb b/cpp/rubygen/framing.0-10/constants.rb index ea74c82f73..5c1c1047f7 100755 --- a/cpp/rubygen/framing.0-10/constants.rb +++ b/cpp/rubygen/framing.0-10/constants.rb @@ -29,7 +29,8 @@ class ConstantsGen < CppGen end def constants_h() - h_file("#{@dir}/constants") { + public_api("#{@dir}/constants.h") + h_file("#{@dir}/constants.h") { namespace(@namespace) { # Constants for class/method names. scope("enum AmqpConstant {","};") { @@ -50,6 +51,7 @@ class ConstantsGen < CppGen def typecode_h_cpp path="#{@dir}/TypeCode" + public_api(path+".h") h_file(path) { include("<iosfwd>") include("\"qpid/sys/IntegerTypes.h\"") @@ -104,7 +106,8 @@ EOS end def enum_h() - h_file("#{@dir}/enum") { + public_api("#{@dir}/enum.h") + h_file("#{@dir}/enum.h") { # Constants for enum domains. namespace(@namespace) { @amqp.domains.each { |d| declare_enum(d.enum) if d.enum } @@ -161,7 +164,8 @@ EOS end def reply_exceptions_h() - h_file("#{@dir}/reply_exceptions") { + public_api("#{@dir}/reply_exceptions.h") + h_file("#{@dir}/reply_exceptions.h") { include "qpid/Exception" include "qpid/sys/ExceptionHolder" include "qpid/framing/enum" diff --git a/cpp/rubygen/framing.0-10/frame_body_lists.rb b/cpp/rubygen/framing.0-10/frame_body_lists.rb index 541fddbca2..4f1b976032 100644 --- a/cpp/rubygen/framing.0-10/frame_body_lists.rb +++ b/cpp/rubygen/framing.0-10/frame_body_lists.rb @@ -44,6 +44,6 @@ EOS end end -FrameBodyListsGen.new(ARGV[0], $amqp).generate; +FrameBodyListsGen.new($outdir, $amqp).generate; diff --git a/cpp/rubygen/framing.0-10/structs.rb b/cpp/rubygen/framing.0-10/structs.rb index 823d062dd5..809e453381 100755 --- a/cpp/rubygen/framing.0-10/structs.rb +++ b/cpp/rubygen/framing.0-10/structs.rb @@ -383,7 +383,8 @@ EOS end end - h_file("qpid/framing/#{classname}.h") { + public_api("qpid/framing/#{classname}.h") + h_file("qpid/framing/#{classname}.h") { if (s.kind_of? AmqpMethod) gen <<EOS #include "qpid/framing/AMQMethodBody.h" @@ -604,9 +605,10 @@ EOS structs.each { |s| define_struct(s) } @amqp.methods_.each { |m| define_struct(m) } #generate a single include file containing the list of structs for convenience + public_api("qpid/framing/amqp_structs.h") h_file("qpid/framing/amqp_structs.h") { structs.each { |s| genl "#include \"qpid/framing/#{s.cppname}.h\"" } } end end -StructGen.new(ARGV[0], $amqp).generate() +StructGen.new($outdir, $amqp).generate() diff --git a/cpp/rubygen/generate b/cpp/rubygen/generate index 0ce1fec46a..89b9b99520 100755 --- a/cpp/rubygen/generate +++ b/cpp/rubygen/generate @@ -25,15 +25,14 @@ require 'amqpgen' # if ARGV.size < 3 puts <<EOS -Usage: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] TEMPLATE.rb [ ... ] -or: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] all [ makefragment.mk | - makefragment.cmake ] +Usage: #{ARGV[0]} SRCDIR APIDIR SPEC.xml [ ... ] TEMPLATE.rb [ ... ] +or: #{ARGV[0]} SRCDIR APIDIR SPEC.xml [ ... ] all [ makefragment.mk | makefragment.cmake ] 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. +putting the resulting files under SRCDIR, public API files in APIdir. +Prints a list of files generated to standard output. -If OUTDIR is '-' then just prints file list without generating files. +If SRCDIR and APIDIR are '-' then just prints file list without generating files. EOS exit 1 end @@ -58,15 +57,16 @@ gendir=File.dirname(__FILE__) if ARGV.any? { |arg| arg=="all" } templates=Dir["#{gendir}/*/*.rb"] else - templates=ARGV.grep(/\.rb$/) +templates=ARGV.grep(/\.rb$/) ARGV.each { |arg| d=File.join gendir,arg templates += Dir["#{d}/*.rb"] if File.directory? d } end -$outdir=ARGV[0] +$outdir=[ ARGV[0], ARGV[1] ] $models=parse_specs(ARGV.grep(/\.xml$/)) + templates.each { |t| ver=Pathname.new(t).dirname.basename.to_s.split('.')[-1] $amqp=$models[ver] @@ -84,17 +84,18 @@ def make_continue(lines) lines.join(" \\\n "); end makefile=ARGV.grep(/.mk$/)[0] cmakefile=ARGV.grep(/.cmake$/)[0] if cmakefile || makefile + srcdir,apidir=$outdir dir=Dir.getwd Dir.chdir File.dirname(__FILE__) generator_files=Dir["**/*.rb"] << File.basename(__FILE__) Dir.chdir dir rgen_generator=generator_files.map{ |f| "$(rgen_dir)/#{f}" } cmake_rgen_generator=generator_files.map{ |f| "${rgen_dir}/#{f}" } - rgen_srcs=GenFiles.get.map{ |f| "#{$outdir}/#{f}" } + rgen_srcs=GenFiles.get.map{ |f| "#{GenFiles.public_api?(f) ? apidir : srcdir}/#{f}" } rgen_subdirs={} rgen_srcs.each { |src| - if src.match(%r{#{$outdir}/qpid/([^/]+)/}) - subdir=$1 + if src.match(%r{(#{srcdir}|#{apidir})/qpid/([^/]+)/}) + subdir=$2 rgen_subdirs[subdir] ||= [] rgen_subdirs[subdir] << src end |