Index: build.conf =================================================================== --- build.conf (revision 17838) +++ build.conf (working copy) @@ -99,6 +99,9 @@ subversion/bindings/swig/proxy swig-proxy-dir = subversion/bindings/swig/proxy +swig-checkout-files = common.swg swigrun.swg runtime.swg + ruby/rubydef.swg ruby/rubyhead.swg ruby/rubytracking.swg + perl5/perlrun.swg python/pyrun.swg python/python.swg # ---------------------------------------------------------------------------- # Index: build/generator/gen_make.py =================================================================== --- build/generator/gen_make.py (revision 17843) +++ build/generator/gen_make.py (working copy) @@ -8,6 +8,7 @@ import gen_base import generator.swig.header_wrappers +import generator.swig.checkout_swig_header import generator.swig.external_runtime import generator.util.executable _exec = generator.util.executable @@ -133,6 +134,7 @@ if not self.release_mode: for swig in (generator.swig.header_wrappers, + generator.swig.checkout_swig_header, generator.swig.external_runtime): gen = swig.Generator(self.conf, "swig") gen.write_makefile_rules(self.ofile) Index: build/generator/swig/__init__.py =================================================================== --- build/generator/swig/__init__.py (revision 17838) +++ build/generator/swig/__init__.py (working copy) @@ -20,8 +20,9 @@ # Read configuration options self.proxy_dir = parser.get('options', 'swig-proxy-dir') - self.includes = \ - _collect_paths(parser.get('options', 'includes')) + self.includes = _collect_paths(parser.get('options', 'includes')) + self.swig_checkout_files = \ + _collect_paths(parser.get('options', 'swig-checkout-files')) # Calculate build options self.opts = {} @@ -47,13 +48,3 @@ pass return 0 - def checkout(self, dir, file): - """Checkout a specific header file from SWIG""" - out = "%s/%s" % (self.proxy_dir, file) - if os.path.exists(out): - os.remove(out) - if self.version() == 103024: - shutil.copy("%s/%s/%s" % (self.swig_libdir, dir, file), out) - else: - _exec.run("%s -o %s -co %s/%s" % (self.swig_path, out, dir, file)) - Index: build/generator/swig/external_runtime.py =================================================================== --- build/generator/swig/external_runtime.py (revision 17843) +++ build/generator/swig/external_runtime.py (working copy) @@ -16,9 +16,9 @@ """Generate external runtime files for SWIG""" def write(self): - """Generate external runtime and long long fix""" - self.write_external_runtime() - self.write_long_long_fix() + """Generate external runtimes""" + for lang in self.langs: + self.write_external_runtime(lang) def write_makefile_rules(self, makefile): """Write the makefile rules for generating external runtimes""" @@ -30,94 +30,61 @@ out = self._output_file(lang) makefile.write( 'autogen-swig-%s: %s\n' % (self.short[lang], out) + - '%s:\n' % out + - '\t$(GEN_SWIG_RUNTIME)\n\n' + '%s: $(SWIG_CHECKOUT_FILES)\n' % out + + '\t$(GEN_SWIG_RUNTIME) %s\n\n' % lang ) makefile.write('\n') - def write_external_runtime(self): + def write_external_runtime(self, lang): """Generate external runtime header files for each SWIG language""" - # Gather necessary header files - self.checkout(".","swigrun.swg") - if self.version() == 103024: - self.checkout(".","common.swg") - self.checkout(".","runtime.swg") - self.checkout("python","pyrun.swg") - self.checkout("perl5","perlrun.swg") - self.checkout("ruby","rubydef.swg") - self.checkout("ruby", "rubyhead.swg") - if self.version() >= 103026: - self.checkout("ruby", "rubytracking.swg") - # Runtime library names runtime_library = { "python": "pyrun.swg", "perl":"perlrun.swg", "ruby":"rubydef.swg" } # Build runtime files - for lang in self.langs: - out = "%s/swig_%s_external_runtime.swg" % (self.proxy_dir, lang) - if self.version() == 103024: - out_file = open(out, "w") - out_file.write(open("%s/swigrun.swg" % self.proxy_dir).read()) - out_file.write(open("%s/common.swg" % self.proxy_dir).read()) - out_file.write( - open("%s/%s" % (self.proxy_dir, runtime_library[lang])).read()) - if lang != "ruby": - out_file.write(open("%s/runtime.swg" % self.proxy_dir).read()) - out_file.close() - else: - _exec.run("%s -%s -external-runtime %s" % (self.swig_path, lang, out)) + out = self._output_file(lang) + if self.version() == 103024: + out_file = open(out, "w") + out_file.write(open("%s/swigrun.swg" % self.proxy_dir).read()) + out_file.write(open("%s/common.swg" % self.proxy_dir).read()) + out_file.write( + open("%s/%s" % (self.proxy_dir, runtime_library[lang])).read()) + if lang != "ruby": + out_file.write(open("%s/runtime.swg" % self.proxy_dir).read()) + out_file.close() + else: + _exec.run("%s -%s -external-runtime %s" % (self.swig_path, lang, out)) - if lang == "ruby" and self.version() >= 103026: - # SWIG 1.3.26-27 should include rubytracking.swg in their - # external runtime, but they don't. - # TODO: Find out whether this bug will be fixed in later versions - # of SWIG. - runtime = open(out, "r").read() - tracking = open("%s/rubytracking.swg" % self.proxy_dir,"r").read() - out_file = open(out, "w") - out_file.write(tracking) - out_file.write(runtime) - out_file.close() + if lang == "ruby" and self.version() >= 103026: + # SWIG 1.3.26-27 should include rubytracking.swg in their + # external runtime, but they don't. + # TODO: Find out whether this bug will be fixed in later versions + # of SWIG. + runtime = open(out).read() + tracking = open("%s/rubytracking.swg" % self.proxy_dir).read(); + out_file = open(out, "w") + out_file.write(tracking) + out_file.write(runtime) + out_file.close() - # SWIG 1.3.25 and earlier use the wrong number of arguments in calls to - # SWIG_GetModule. We fix this below. - if self.version() <= 103025: - for line in fileinput.input(out, inplace=1): - sys.stdout.write( - re.sub(r"SWIG_GetModule\(\)", "SWIG_GetModule(NULL)", line) - ) - - def write_long_long_fix(self): - """Hide the SWIG implementation of 'long long' converters so that - Visual C++ won't get confused by it.""" - - self.checkout("python","python.swg") - - python_swg_filename = "%s/python.swg" % self.proxy_dir - python_swg = open(python_swg_filename).read() - file = open(python_swg_filename,"w") - file.write(""" - %fragment("SWIG_AsVal_" {long long},"header") { - } - %fragment("SWIG_Check_" {long long},"header") { - } - %fragment("SWIG_From_" {long long},"header") { - }\n""") - file.write(python_swg) - file.close() - + # SWIG 1.3.25 and earlier use the wrong number of arguments in calls to + # SWIG_GetModule. We fix this below. + if self.version() <= 103025: + for line in fileinput.input(out, inplace=1): + sys.stdout.write( + re.sub(r"SWIG_GetModule\(\)", "SWIG_GetModule(NULL)", line) + ) def _output_file(self, lang): """Return the output filename of the runtime for the given language""" return '%s/swig_%s_external_runtime.swg' % (self.proxy_dir, lang) if __name__ == "__main__": - if len(sys.argv) < 3: + if len(sys.argv) != 4: print "Usage: %s build.conf swig" print "Generates external runtime files for SWIG" else: gen = Generator(sys.argv[1], sys.argv[2]) - gen.write() + gen.write_external_runtime(sys.argv[3]) Index: build/generator/swig/checkout_swig_header.py =================================================================== --- build/generator/swig/checkout_swig_header.py (revision 0) +++ build/generator/swig/checkout_swig_header.py (revision 0) @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# +# Checkout files from the SWIG library into Subversion's proxy directory +# + +import sys, os, re, fileinput +if __name__ == "__main__": + parent_dir = os.path.dirname(os.path.abspath(os.path.dirname(sys.argv[0]))) + sys.path[0:0] = [ parent_dir, os.path.dirname(parent_dir) ] +import generator.swig +from gen_base import build_path_splitfile, build_path_join +from generator.util.executable import run + +class Generator(generator.swig.Generator): + + def write(self): + """Checkout all files""" + for path in self.swig_checkout_files: + self.checkout(path) + + def write_makefile_rules(self, makefile): + """Write makefile rules to checkout files""" + script_path = 'build/generator/swig/checkout_swig_header.py' + conf = '$(abs_srcdir)/build.conf' + makefile.write('CHECKOUT_SWIG = cd $(top_srcdir) && $(PYTHON)' + + ' %s %s $(SWIG)\n\n' % (script_path, conf)) + checkout_locations = [] + for path in self.swig_checkout_files: + out = self._output_file(path) + checkout_locations.append(out) + makefile.write('%s: %s\n' % (out, script_path) + + '\t$(CHECKOUT_SWIG) %s\n\n' % path) + makefile.write('SWIG_CHECKOUT_FILES = %s\n\n\n' + % " ".join(checkout_locations)) + + def checkout(self, path): + """Checkout a specific header file from SWIG""" + out = self._output_file(path) + if os.path.exists(out): + os.remove(out) + if self._skip_checkout(path): + open(out, "w") + elif self.version() == 103024: + shutil.copy(build_path_join(self.swig_libdir, path), out) + else: + run("%s -o %s -co %s" % (self.swig_path, out, path)) + + # Fix generated SWIG files to never use "long long", which is not portable + if path == "python/python.swg": + python_swg = open(out).read() + file = open(out, "w") + file.write(""" + %fragment("SWIG_AsVal_" {long long},"header") { + } + %fragment("SWIG_Check_" {long long},"header") { + } + %fragment("SWIG_From_" {long long},"header") { + }\n""") + file.write(python_swg) + file.close() + + def _skip_checkout(self, path): + """Should we skip this checkout?""" + return (path == "ruby/rubytracking.swg" and self.version() < 103026 or + path == "common.swg" and self.version() > 103024) + + def _output_file(self, path): + """Get output filename""" + dir, filename = build_path_splitfile(path) + return build_path_join(self.proxy_dir, filename) + +if __name__ == "__main__": + if len(sys.argv) != 4: + print "Usage: %s build.conf swig file.swg" + print "Checkout a specific header file from SWIG's library into" + print "the Subversion proxy directory." + else: + gen = Generator(sys.argv[1], sys.argv[2]) + gen.checkout(sys.argv[3]) Property changes on: build/generator/swig/checkout_swig_header.py ___________________________________________________________________ Name: svn:executable + * Index: build/generator/gen_win.py =================================================================== --- build/generator/gen_win.py (revision 17838) +++ build/generator/gen_win.py (working copy) @@ -195,17 +195,11 @@ self.configs = ['Debug','Release'] if self.swig_libdir: - - # Generate SWIG header wrappers - header_wrappers = \ - generator.swig.header_wrappers.Generator("build.conf", self.swig_exe) - header_wrappers.write() - - # Generate external runtime - runtime = \ - generator.swig.external_runtime.Generator("build.conf", self.swig_exe) - runtime.write() - + # Generate SWIG header wrappers and external runtime + for swig in (generator.swig.header_wrappers, + generator.swig.checkout_swig_header, + generator.swig.external_runtime): + swig.Generator(self.conf, self.swig_exe).write() else: print "%s not found; skipping SWIG file generation..." % self.swig_exe