From ea8671c2eccbae23d0e92cc20a1571b0b323286e Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Wed, 22 Apr 2015 14:23:39 +0200 Subject: [PATCH] Prevent invoking Jinja templating unecessarily --- Makefile | 6 +++--- libsharp/sharp_legendre.c | 4 +++- libsharp/sharp_legendre.c.in | 1 - runjinja.py | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f44ecfd..a621948 100644 --- a/Makefile +++ b/Makefile @@ -54,10 +54,10 @@ perftest: compile_all $(BINDIR)/sharp_testsuite test gauss 4095 -1 -1 8192 0 1 && \ $(BINDIR)/sharp_testsuite test gauss 8191 -1 -1 16384 0 1 -# Jinja templates - %.c: %.c.in - ./runjinja.py < $< > $@ +# Only do this if the md5sum changed, in order to avoid Python and Jinja +# dependency when not modifying the c.in file + grep `md5sum $< | cut -d ' ' -f 1` $@ || ./runjinja.py < $< > $@ genclean: rm libsharp/sharp_legendre.c || exit 0 diff --git a/libsharp/sharp_legendre.c b/libsharp/sharp_legendre.c index 75518d6..8b4fe4b 100644 --- a/libsharp/sharp_legendre.c +++ b/libsharp/sharp_legendre.c @@ -1,4 +1,4 @@ -/* +/* DO NOT EDIT. md5sum of source: 88eec944ab6fbfdc7f391fbb58df3bf1 *//* NOTE NOTE NOTE @@ -1303,3 +1303,5 @@ void sharp_legendre_transform_s(float *bl, } } + + diff --git a/libsharp/sharp_legendre.c.in b/libsharp/sharp_legendre.c.in index 9862127..e30f787 100644 --- a/libsharp/sharp_legendre.c.in +++ b/libsharp/sharp_legendre.c.in @@ -160,4 +160,3 @@ void sharp_legendre_transform{{T}}({{scalar}} *bl, } } /*{ endfor }*/ - diff --git a/runjinja.py b/runjinja.py index 5269c1a..fd659fa 100755 --- a/runjinja.py +++ b/runjinja.py @@ -5,6 +5,7 @@ Preprocesses foo.c.in to foo.c. Reads STDIN and writes STDOUT. """ import sys +import hashlib from jinja2 import Template, Environment env = Environment(block_start_string='/*{', @@ -13,4 +14,6 @@ env = Environment(block_start_string='/*{', variable_end_string='}}') extra_vars = dict(len=len) -sys.stdout.write(env.from_string(sys.stdin.read()).render(**extra_vars)) +input = sys.stdin.read() +sys.stdout.write('/* DO NOT EDIT. md5sum of source: %s */' % hashlib.md5(input).hexdigest()) +sys.stdout.write(env.from_string(input).render(**extra_vars))