3
# Checkout files from the SWIG library into Subversion's proxy directory
6
import sys, os, re, fileinput, shutil
7
if __name__ == "__main__":
8
parent_dir = os.path.dirname(os.path.abspath(os.path.dirname(sys.argv[0])))
9
sys.path[0:0] = [ parent_dir, os.path.dirname(parent_dir) ]
11
from gen_base import build_path_splitfile, build_path_join
12
from generator.util.executable import run
14
class Generator(generator.swig.Generator):
17
"""Checkout all files"""
18
for path in self.swig_checkout_files:
21
def write_makefile_rules(self, makefile):
22
"""Write makefile rules to checkout files"""
23
script_path = 'build/generator/swig/checkout_swig_header.py'
24
conf = '$(abs_srcdir)/build.conf'
25
makefile.write('CHECKOUT_SWIG = cd $(top_srcdir) && $(PYTHON)' +
26
' %s %s $(SWIG)\n\n' % (script_path, conf))
27
checkout_locations = []
28
for path in self.swig_checkout_files:
29
out = self._output_file(path)
30
checkout_locations.append(out)
31
makefile.write('%s: %s\n' % (out, script_path) +
32
'\t$(CHECKOUT_SWIG) %s\n\n' % path)
33
makefile.write('SWIG_CHECKOUT_FILES = %s\n\n\n'
34
% " ".join(checkout_locations))
36
def checkout(self, path):
37
"""Checkout a specific header file from SWIG"""
38
out = self._output_file(path)
39
if os.path.exists(out):
41
if self._skip_checkout(path):
43
elif self.version() == 103024:
44
shutil.copy(build_path_join(self.swig_libdir, path), out)
46
run("%s -o %s -co %s" % (self.swig_path, out, path))
48
# Fix generated SWIG files to never use "long long", which is not portable
49
if path == "python/python.swg":
50
python_swg = open(out).read()
53
%fragment("SWIG_AsVal_" {long long},"header") {
55
%fragment("SWIG_Check_" {long long},"header") {
57
%fragment("SWIG_From_" {long long},"header") {
59
file.write(python_swg)
62
def _skip_checkout(self, path):
63
"""Should we skip this checkout?"""
64
return (path == "ruby/rubytracking.swg" and self.version() < 103026 or
65
path == "common.swg" and self.version() > 103024)
67
def _output_file(self, path):
68
"""Get output filename"""
69
dir, filename = build_path_splitfile(path)
70
return build_path_join(self.proxy_dir, filename)
72
if __name__ == "__main__":
73
if len(sys.argv) != 4:
74
print "Usage: %s build.conf swig file.swg"
75
print "Checkout a specific header file from SWIG's library into"
76
print "the Subversion proxy directory."
78
gen = Generator(sys.argv[1], sys.argv[2])
79
gen.checkout(sys.argv[3])