From b1e51c76b449d5e7bf0968ce930cafb83384b375 Mon Sep 17 00:00:00 2001
From: Jiao Lin <linjiao@ornl.gov>
Date: Tue, 16 Aug 2016 17:29:07 -0400
Subject: [PATCH] Refs #17237. use cmake macro for git_rev and detect no-change

---
 buildconfig/CMake/conda-update-recipe.py.in | 54 ++++++++++++---------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/buildconfig/CMake/conda-update-recipe.py.in b/buildconfig/CMake/conda-update-recipe.py.in
index a6b93bc45a6..41e54936783 100644
--- a/buildconfig/CMake/conda-update-recipe.py.in
+++ b/buildconfig/CMake/conda-update-recipe.py.in
@@ -1,32 +1,40 @@
 # -*- Python -*-
 
 version = "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"
+git_rev = "@MtdVersion_WC_LAST_CHANGED_SHA_LONG@"
 
 import subprocess as sp, shlex, os
-git_rev = sp.check_output("git rev-parse HEAD".split(), 
-                          cwd="@CMAKE_SOURCE_DIR@").strip()
 
-# checkout recipe
-if not os.path.exists('conda-recipes'):
-    cmd = 'git clone git@github.com:mantidproject/conda-recipes'
-    sp.check_call(cmd.split())
-else:
-    cmd = 'git pull'
-    sp.check_call(cmd.split(), cwd='conda-recipes')
+def main():
+    # checkout recipe
+    if not os.path.exists('conda-recipes'):
+        cmd = 'git clone git@github.com:mantidproject/conda-recipes'
+        sp.check_call(cmd.split())
+    else:
+        cmd = 'git pull'
+        sp.check_call(cmd.split(), cwd='conda-recipes')
 
-# change framework meta.yaml
-path = 'conda-recipes/framework/meta.yaml'
-header = []
-header.append('{% set version = "' + '%s' % version + '" %}')
-header.append('{% set git_rev = "' + '%s' % git_rev + '" %}')
-body = open(path, 'rt').read().split('\n')
-body = body[2:]
-open(path, 'wt').write('\n'.join(header+body))
+    # change framework meta.yaml
+    path = 'conda-recipes/framework/meta.yaml'
+    header = []
+    header.append('{% set version = "' + '%s' % version + '" %}')
+    header.append('{% set git_rev = "' + '%s' % git_rev + '" %}')
+    content = open(path, 'rt').read().split('\n')
+    old_header = content[:2]
+    body = content[2:]
+    # if nothing changed just exit
+    if header == old_header:
+        print "Nothing changed. Skipping."
+        return
+    open(path, 'wt').write('\n'.join(header+body))
 
-# commit
-cmd = 'git commit -m "update version and git_rev" framework/meta.yaml'
-sp.check_call(shlex.split(cmd), cwd="conda-recipes")
+    # commit
+    cmd = 'git commit -m "update version and git_rev" framework/meta.yaml'
+    sp.check_call(shlex.split(cmd), cwd="conda-recipes")
 
-# push
-cmd = 'git push'
-sp.check_call(cmd.split(), cwd="conda-recipes")
+    # push
+    cmd = 'git push'
+    sp.check_call(cmd.split(), cwd="conda-recipes")
+    return
+
+if __name__ == '__main__': main()
-- 
GitLab