build: Convert git_sha1_gen script to Python.
authorJose Fonseca <jfonseca@vmware.com>
Tue, 1 Aug 2017 13:36:16 +0000 (14:36 +0100)
committerJose Fonseca <jfonseca@vmware.com>
Tue, 1 Aug 2017 14:24:39 +0000 (15:24 +0100)
Python is the scripting language we've been using for scripts that need
to run across all supported platforms.

Shell is *not* a portable language for scripts.

Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Makefile.am
bin/git_sha1_gen.py [new file with mode: 0755]
bin/git_sha1_gen.sh [deleted file]
src/Makefile.am
src/SConscript
src/mesa/Android.libmesa_git_sha1.mk

index cf52c834aa3baa3ff0c2df81235e734417e9599c..538c38ddebfbe4aa8dee15a5656c3720995dd858 100644 (file)
@@ -53,7 +53,7 @@ EXTRA_DIST = \
        common.py \
        docs \
        doxygen \
-       bin/git_sha1_gen.sh \
+       bin/git_sha1_gen.py \
        scons \
        SConstruct
 
diff --git a/bin/git_sha1_gen.py b/bin/git_sha1_gen.py
new file mode 100755 (executable)
index 0000000..6d13db1
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import os.path
+import subprocess
+import sys
+
+git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git')
+try:
+    git_sha1 = subprocess.check_output([
+        'git',
+        '--git-dir=' + git_dir,
+        'rev-parse',
+        '--short=10',
+        'HEAD',
+    ], stderr=open(os.devnull, 'w'))
+except subprocess.CalledProcessError as e:
+    # don't print anything if git fails
+    pass
+else:
+    sys.stdout.write('#define MESA_GIT_SHA1 "git-%s"\n' % git_sha1.rstrip())
diff --git a/bin/git_sha1_gen.sh b/bin/git_sha1_gen.sh
deleted file mode 100755 (executable)
index 898e590..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-# run git from the sources directory
-cd "$(dirname "$0")"
-
-# don't print anything if git fails
-if ! git_sha1=$(git --git-dir=../.git rev-parse --short=10 HEAD 2>/dev/null)
-then
-  exit
-fi
-
-printf '#define MESA_GIT_SHA1 "git-%s"\n' "$git_sha1"
index 5aee6b01417ab06f4ccf488573168adb12e1ea41..8d7483fc75890da36e260af39100b44523294670 100644 (file)
@@ -21,7 +21,7 @@
 
 .PHONY: git_sha1.h.tmp
 git_sha1.h.tmp:
-       @sh $(top_srcdir)/bin/git_sha1_gen.sh > $@
+       @python $(top_srcdir)/bin/git_sha1_gen.py > $@
 
 git_sha1.h: git_sha1.h.tmp
        @echo "updating git_sha1.h"
index 82bc28518efa2a1113b7325e8a800e33a35ec538..bd20d4e2108b463f450e7636904763eec6c5db90 100644 (file)
@@ -1,6 +1,7 @@
 import filecmp
 import os
 import subprocess
+from sys import executable as python_cmd
 
 Import('*')
 
@@ -25,7 +26,7 @@ def write_git_sha1_h_file(filename):
 
     tempfile = "git_sha1.h.tmp"
     with open(tempfile, "w") as f:
-        args = [ 'sh', Dir('#').abspath + '/bin/git_sha1_gen.sh' ]
+        args = [ python_cmd, Dir('#').abspath + '/bin/git_sha1_gen.py' ]
         try:
             subprocess.Popen(args, stdout=f).wait()
         except:
index 7d64b1c809cc962c4a7949055c478d8fee001f84..f66f88484bc1d112059bf82bc0b0e0c714b797c0 100644 (file)
@@ -46,7 +46,7 @@ LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/, git_sha1.h)
 $(intermediates)/git_sha1.h: $(wildcard $(MESA_TOP)/.git/logs/HEAD)
        @mkdir -p $(dir $@)
        @echo "GIT-SHA1: $(PRIVATE_MODULE) <= git"
-       $(hide) sh $(MESA_TOP)/bin/git_sha1_gen.sh > $@
+       $(hide) python $(MESA_TOP)/bin/git_sha1_gen.py > $@
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)