From 6e97ead181f04c5cb4953e5e3316d7d8caf0a1ec Mon Sep 17 00:00:00 2001
From: Kelly Washington <kelly@lindenlab.com>
Date: Thu, 3 Mar 2011 12:05:40 -0800
Subject: [PATCH] Add early exit to message template check if it hasn't
 changed.

---
 indra/cmake/TemplateCheck.cmake |  6 +++---
 scripts/template_verifier.py    | 22 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/indra/cmake/TemplateCheck.cmake b/indra/cmake/TemplateCheck.cmake
index fa4e387dd5c..24805b42149 100644
--- a/indra/cmake/TemplateCheck.cmake
+++ b/indra/cmake/TemplateCheck.cmake
@@ -5,10 +5,10 @@ include(Python)
 macro (check_message_template _target)
   add_custom_command(
       TARGET ${_target}
-      POST_BUILD
+      PRE_LINK
       COMMAND ${PYTHON_EXECUTABLE}
       ARGS ${SCRIPTS_DIR}/template_verifier.py
-           --mode=development --cache_master
-      COMMENT "Verifying message template"
+           --mode=development --cache_master ${TEMPLATE_VERIFIER_OPTIONS}
+      COMMENT "Verifying message template - See http://wiki.secondlife.com/wiki/Template_verifier.py"
       )
 endmacro (check_message_template)
diff --git a/scripts/template_verifier.py b/scripts/template_verifier.py
index ddb050fbbbb..d01750ffc69 100644
--- a/scripts/template_verifier.py
+++ b/scripts/template_verifier.py
@@ -66,6 +66,7 @@ def add_indra_lib_path():
 import optparse
 import os
 import urllib
+import hashlib
 
 from indra.ipc import compatibility
 from indra.ipc import tokenstream
@@ -233,6 +234,9 @@ def run(sysargs):
     parser.add_option(
         '-c', '--cache_master', action='store_true', dest='cache_master',
         default=False,  help="""Set to true to attempt use local cached copy of the master template.""")
+    parser.add_option(
+        '-f', '--force', action='store_true', dest='force_verification',
+        default=False, help="""Set to true to skip the sha_1 check and force template verification.""")
 
     options, args = parser.parse_args(sysargs)
 
@@ -269,8 +273,18 @@ def run(sysargs):
         print "current:", current_filename
         current_url = 'file://%s' % current_filename
 
-    # retrieve the contents of the local template and check for syntax
+    # retrieve the contents of the local template
     current = fetch(current_url)
+    hexdigest = hashlib.sha1(current).hexdigest()
+    if not options.force_verification:
+        # Early exist if the template hasn't changed.
+        sha_url = "%s.sha1" % current_url
+        current_sha = fetch(sha_url)
+        if hexdigest == current_sha:
+            print "Message template SHA_1 has not changed."
+            sys.exit(0)
+
+    # and check for syntax
     current_parsed = llmessage.parseTemplateString(current)
 
     if options.cache_master:
@@ -301,6 +315,12 @@ def explain(header, compat):
 
     if acceptable:
         explain("--- PASS ---", compat)
+        if options.force_verification == False:
+            print "Updating sha1 to %s" % hexdigest
+            sha_filename = "%s.sha1" % current_filename
+            sha_file = open(sha_filename, 'w')
+            sha_file.write(hexdigest)
+            sha_file.close()
     else:
         explain("*** FAIL ***", compat)
         return 1
-- 
GitLab