]> git.puffer.fish Git - mirror/frr.git/commitdiff
python/clippy: make output file writing less weird
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 15:33:17 +0000 (17:33 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 23 Aug 2017 22:18:53 +0000 (00:18 +0200)
This should stomp out any parallel build issues in this regard.

Fixes: #971
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
common.am
python/clidef.py
python/clippy/__init__.py

index b115a871b9797d05b518a35f6a24b489ec07221e..c0094b1b88bbe6d7bcc36ce81eed9f4c758d64c4 100644 (file)
--- a/common.am
+++ b/common.am
@@ -13,8 +13,7 @@ CLIPPY_DEPS = $(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py
 SUFFIXES = _clippy.c .proto .pb-c.c .pb-c.h .pb.h
 .c_clippy.c:
        @{ test -x $(top_builddir)/$(HOSTTOOLS)lib/clippy || $(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy; }
-       $(AM_V_CLIPPY)$(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py $< > $@.tmp
-       @{ test -f $@ && diff $@.tmp $@ >/dev/null 2>/dev/null; } && rm $@.tmp || mv $@.tmp $@
+       $(AM_V_CLIPPY)$(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py -o $@ $<
 
 ## automake's "ylwrap" is a great piece of GNU software... not. 
 .l.c:
index 8e3c7595b792adcfaed1f207696709f7d33a5764..aa6cd18b8b4000d2d32ed1481c237c59120927b2 100644 (file)
@@ -257,4 +257,4 @@ if __name__ == '__main__':
     process_file(args.cfile, ofd, dumpfd, args.all_defun)
 
     if args.o is not None:
-        clippy.wrdiff(args.o, ofd)
+        clippy.wrdiff(args.o, ofd, [args.cfile, os.path.realpath(__file__)])
index 82aa9495d44476f7935c64114fd8e065414f7ddb..41aeae6b4d8da09b58051ba4e0b8018954af5886 100644 (file)
@@ -16,6 +16,7 @@
 # with this program; see the file COPYING; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
+import os, stat
 import _clippy
 from _clippy import parse, Graph, GraphNode
 
@@ -47,7 +48,7 @@ def dump(graph):
     for i, depth in graph_iterate(graph):
         print('\t%s%s %r' % ('  ' * (depth * 2), i.type, i.text))
 
-def wrdiff(filename, buf):
+def wrdiff(filename, buf, reffiles = []):
     '''write buffer to file if contents changed'''
 
     expl = ''
@@ -57,8 +58,16 @@ def wrdiff(filename, buf):
     try:    old = open(filename, 'r').read()
     except: pass
     if old == buf:
+        for reffile in reffiles:
+            # ensure output timestamp is newer than inputs, for make
+            reftime = os.stat(reffile)[stat.ST_MTIME]
+            outtime = os.stat(filename)[stat.ST_MTIME]
+            if outtime <= reftime:
+                os.utime(filename, (reftime + 1, reftime + 1))
         # sys.stderr.write('%s unchanged, not written\n' % (filename))
         return
-    with open('.new.' + filename, 'w') as out:
+
+    newname = '%s.new-%d' % (filename, os.getpid())
+    with open(newname, 'w') as out:
         out.write(buf)
-    os.rename('.new.' + filename, filename)
+    os.rename(newname, filename)