buildsys: move file regeneration logic to the script itself
authorEric Engestrom <eric.engestrom@imgtec.com>
Wed, 25 Oct 2017 13:04:35 +0000 (14:04 +0100)
committerEric Engestrom <eric.engestrom@imgtec.com>
Fri, 27 Oct 2017 12:38:37 +0000 (13:38 +0100)
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
bin/git_sha1_gen.py
src/Makefile.am
src/SConscript
src/mesa/Android.libmesa_git_sha1.mk

index c75dba101acf4ffc85fb0bc3ec9290690bf91f7c..7b9267b59e9d1d897cc46b9b5779ab5334bba368 100755 (executable)
@@ -6,6 +6,7 @@ The output of this script goes to stdout.
 """
 
 
+import argparse
 import os
 import os.path
 import subprocess
@@ -27,10 +28,20 @@ def get_git_sha1():
         git_sha1 = ''
     return git_sha1
 
+parser = argparse.ArgumentParser()
+parser.add_argument('--output', help='File to write the #define in',
+        required=True)
+args = parser.parse_args()
 
 git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10]
 if git_sha1:
     git_sha1_h_in_path = os.path.join(os.path.dirname(sys.argv[0]),
             '..', 'src', 'git_sha1.h.in')
     with open(git_sha1_h_in_path , 'r') as git_sha1_h_in:
-        sys.stdout.write(git_sha1_h_in.read().replace('@VCS_TAG@', git_sha1))
+        new_sha1 = git_sha1_h_in.read().replace('@VCS_TAG@', git_sha1)
+        if os.path.isfile(args.output):
+            with open(args.output, 'r') as git_sha1_h:
+                if git_sha1_h.read() == new_sha1:
+                    quit()
+        with open(args.output, 'w') as git_sha1_h:
+            git_sha1_h.write(new_sha1)
index 5ef2d4f55eacc470a7a904987d9caa511248bfec..1de4fca6a1216e7662b17b0ad8698d9c88014565 100644 (file)
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
-.PHONY: git_sha1.h.tmp
-git_sha1.h.tmp:
-       @$(PYTHON2) $(top_srcdir)/bin/git_sha1_gen.py > $@
-
-git_sha1.h: git_sha1.h.tmp
-       @echo "updating git_sha1.h"
-       @if ! cmp -s git_sha1.h.tmp git_sha1.h; then \
-               mv git_sha1.h.tmp git_sha1.h ;\
-       else \
-               rm git_sha1.h.tmp ;\
-       fi
+.PHONY: git_sha1.h
+git_sha1.h: $(top_srcdir)/src/git_sha1.h.in
+       @echo "updating $@"
+       @$(PYTHON2) $(top_srcdir)/bin/git_sha1_gen.py --output $@
 
 BUILT_SOURCES = git_sha1.h
 CLEANFILES = $(BUILT_SOURCES)
index a277e8b79254588e8fd4dc5e1d8fad2e4ef340a3..95ea061c4bba124c855a50b931b8e8974123e93c 100644 (file)
@@ -24,22 +24,12 @@ def write_git_sha1_h_file(filename):
     to retrieve the git hashid and write the header file.  An empty file
     will be created if anything goes wrong."""
 
-    tempfile = "git_sha1.h.tmp"
-    with open(tempfile, "w") as f:
-        args = [ python_cmd, Dir('#').abspath + '/bin/git_sha1_gen.py' ]
-        try:
-            subprocess.Popen(args, stdout=f).wait()
-        except:
-            print("Warning: exception in write_git_sha1_h_file()")
-            return
-
-    if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
-        # The filename does not exist or it's different from the new file,
-        # so replace old file with new.
-        if os.path.exists(filename):
-            os.remove(filename)
-        os.rename(tempfile, filename)
-    return
+    args = [ python_cmd, Dir('#').abspath + '/bin/git_sha1_gen.py', '--output', filename ]
+    try:
+        subprocess.call(args)
+    except:
+        print("Warning: exception in write_git_sha1_h_file()")
+        return
 
 
 # Create the git_sha1.h header file
index ddb30c428af739ee9fe507e19bf38a030bff1295..d27923074dd289a115de2db9a3707ce23cff22c6 100644 (file)
@@ -43,10 +43,10 @@ $(intermediates)/dummy.c:
 
 LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/, git_sha1.h)
 
-$(intermediates)/git_sha1.h: $(wildcard $(MESA_TOP)/.git/logs/HEAD)
+$(intermediates)/git_sha1.h: $(MESA_TOP)/src/git_sha1.h.in $(wildcard $(MESA_TOP)/.git/logs/HEAD)
        @mkdir -p $(dir $@)
        @echo "GIT-SHA1: $(PRIVATE_MODULE) <= git"
-       $(hide) $(MESA_PYTHON2) $(MESA_TOP)/bin/git_sha1_gen.py > $@
+       $(hide) $(MESA_PYTHON2) $(MESA_TOP)/bin/git_sha1_gen.py --output $@
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)