buildsys: move file regeneration logic to the script itself
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>
This commit is contained in:
@@ -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)
|
||||
|
@@ -19,17 +19,10 @@
|
||||
# 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)
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user