summaryrefslogtreecommitdiff
path: root/build/generator/swig/external_runtime.py
diff options
context:
space:
mode:
Diffstat (limited to 'build/generator/swig/external_runtime.py')
-rwxr-xr-xbuild/generator/swig/external_runtime.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/build/generator/swig/external_runtime.py b/build/generator/swig/external_runtime.py
index bbf58fc..c37c225 100755
--- a/build/generator/swig/external_runtime.py
+++ b/build/generator/swig/external_runtime.py
@@ -24,7 +24,12 @@
# external_runtime.py: Generate external runtime files for SWIG
#
-import sys, os, re, fileinput
+import sys
+import os
+import re
+import fileinput
+import filecmp
+
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) ]
@@ -63,8 +68,10 @@ class Generator(generator.swig.Generator):
"python": "pyrun.swg", "perl":"perlrun.swg", "ruby":"rubydef.swg"
}
- # Build runtime files
- out = self._output_file(lang)
+ # Build runtime files to temporary location
+ dest = self._output_file(lang)
+ out = dest + '.tmp'
+
if self.version() == (1, 3, 24):
out_file = open(out, "w")
out_file.write(open("%s/swigrun.swg" % self.proxy_dir).read())
@@ -99,6 +106,26 @@ class Generator(generator.swig.Generator):
sys.stdout.write(
re.sub(r"SWIG_GetModule\(\)", "SWIG_GetModule(NULL)", line)
)
+
+ # Did the output change?
+ try:
+ if filecmp.cmp(dest, out):
+ identical = True
+ else:
+ identical = False
+ except:
+ identical = False
+
+ # Only overwrite file if changed
+ if identical:
+ os.remove(out)
+ else:
+ try:
+ os.remove(dest)
+ except: pass
+ os.rename(out, dest)
+ print('Wrote %s' % (dest,))
+
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)