You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2013/07/21 20:04:55 UTC
svn commit: r1505436 -
/subversion/trunk/build/generator/swig/external_runtime.py
Author: rhuijben
Date: Sun Jul 21 18:04:54 2013
New Revision: 1505436
URL: http://svn.apache.org/r1505436
Log:
Stop replacing the swig external runtime file that is included by all swig
files on every gen-make invocation. Keep the existing file if the contents
wasn't modified.
* build/generator/swig/external_runtime.py
(imports): Use standard layout and add filecmp.
(write_external_runtime): Use temporary name. Compare and replace if
necessary.
Modified:
subversion/trunk/build/generator/swig/external_runtime.py
Modified: subversion/trunk/build/generator/swig/external_runtime.py
URL: http://svn.apache.org/viewvc/subversion/trunk/build/generator/swig/external_runtime.py?rev=1505436&r1=1505435&r2=1505436&view=diff
==============================================================================
--- subversion/trunk/build/generator/swig/external_runtime.py (original)
+++ subversion/trunk/build/generator/swig/external_runtime.py Sun Jul 21 18:04:54 2013
@@ -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)