[master] a29fca7 Move the production of vcs_version.h and vmod_abi.h to libvcc/generate.py

Poul-Henning Kamp phk at FreeBSD.org
Mon Jan 16 12:22:04 CET 2017


commit a29fca70f7ccc75964bcfffb8c8ab1617fcf2bba
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jan 16 10:45:57 2017 +0000

    Move the production of vcs_version.h and vmod_abi.h to libvcc/generate.py

diff --git a/include/Makefile.am b/include/Makefile.am
index 34ca265..3c01782 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -102,59 +102,21 @@ nobase_noinst_HEADERS = \
 	vut.h \
 	vut_options.h
 
-tbl/vrt_stv_var.h tbl/vcl_returns.h tbl/vcc_types.h vrt_obj.h: vcl.h
-vcl.h: $(top_srcdir)/lib/libvcc/generate.py $(top_srcdir)/include/vrt.h
+GENERATED_H = \
+	tbl/vrt_stv_var.h \
+	tbl/vcl_returns.h \
+	tbl/vcc_types.h \
+	vrt_obj.h \
+	vcl.h \
+	vcs_version.h \
+	vmod_abi.h 
+
+$(GENERATED_H): $(top_srcdir)/lib/libvcc/generate.py $(top_srcdir)/include/vrt.h
 	mkdir -p tbl
 	@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py $(top_srcdir) $(top_builddir)
 
 BUILT_SOURCES = vcs_version.h vmod_abi.h
 MAINTAINERCLEANFILES = vcs_version.h
-vcs_version.h: FORCE
-	@if [ -d "$(top_srcdir)/.git" ]; then \
-		V="$$(git --git-dir=$(top_srcdir)/.git show -s --pretty=format:%h)" \
-		B="$$(git --git-dir=$(top_srcdir)/.git rev-parse --abbrev-ref HEAD)" \
-		H="$$(head -n 1 vcs_version.h 2>/dev/null || true)"; \
-		if [ "/* $$V */" != "$$H" ]; then \
-		( \
-		  echo "/* $$V */" ;\
-		  echo '/*' ;\
-		  echo ' * NB:  This file is machine generated, DO NOT EDIT!' ;\
-		  echo ' *' ;\
-		  echo ' * Run make to regenerate' ;\
-		  echo ' *'  ;\
-		  echo ' */' ;\
-		  echo "/* $$V */" ;\
-		  echo '' ;\
-		  echo "#define VCS_Version \"$$V\"" ; \
-		  echo "#define VCS_Branch \"$$B\"" \
-		) > vcs_version.h ; \
-		fi \
-	else \
-		if [ ! -f vcs_version.h ]; then \
-		( \
-		  echo "/* NOGIT */" ; \
-		  echo '/* No git commit ID available, see include/Makefile.am for explanation */' ; \
-		  echo '#define VCS_Version "NOGIT"' ; \
-		  echo '#define VCS_Branch "NOGIT"' \
-		) >  vcs_version.h ; \
-		fi \
-	fi
-FORCE:
-
-# If vcs_version contains NOGIT, Varnish has not been built from a
-# tarball made with make dist, nor from a git checkout, so there's no
-# way for us to give strong guarantees about what version you're
-# actually running.
-#
-# The way to fix this is to either build Varnish from a tarball made
-# with `make dist` or a git checkout.
-
-vmod_abi.h: vcs_version.h
-	@GITID=$$(sed 's/[^0-9a-f]//g;q' vcs_version.h) ; \
-	if [ -z "$$GITID" ]; then \
-		echo "warning: weak VMOD ABI checking, see include/Makefile.am" ; \
-	fi ; \
-	echo "#define VMOD_ABI_Version \"@PACKAGE_STRING@ $$GITID\"" > vmod_abi.h
 
 CLEANFILES = \
 	tbl/vcl_returns.h \
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 55bb359..9797273 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -30,6 +30,11 @@
 # Generate various .c and .h files for the VCL compiler and the interfaces
 # for it.
 
+from __future__ import print_function
+
+import subprocess
+import os
+
 #######################################################################
 # These are our tokens
 
@@ -984,7 +989,7 @@ def file_header(fo):
 	fo.write("""/*
  * NB:  This file is machine generated, DO NOT EDIT!
  *
- * Edit and run generate.py instead.
+ * Edit and run lib/libvcc/generate.py instead.
  */
 
 """)
@@ -1371,3 +1376,43 @@ for i in stv_variables:
 		fp_vclvar.write("\t%s\n" % j.strip())
 
 fp_vclvar.close()
+
+#######################################################################
+
+if os.path.isdir(os.path.join(srcroot, ".git")):
+	v = subprocess.check_output([
+		"git --git-dir=" + os.path.join(srcroot, ".git") + 
+		" show -s --pretty=format:%h"
+	], shell=True, universal_newlines=True)
+	b = subprocess.check_output([
+		"git --git-dir=" + os.path.join(srcroot, ".git") + 
+	 	" rev-parse --abbrev-ref HEAD"
+	], shell=True, universal_newlines=True)
+	b = b.strip()
+else:
+	b = "NOGIT"
+	v = "NOGIT"
+		
+vcsfn = os.path.join(srcroot, "include", "vcs_version.h")
+
+try:
+	i = open(vcsfn).readline()
+except IOError:
+	i = ""
+
+if i != "/* " + v + " */":
+	fo = open(vcsfn, "w")
+	file_header(fo)
+	fo.write('#define VCS_Version "%s"\n' % v)
+	fo.write('#define VCS_Branch "%s"\n' % b)
+	fo.close()
+
+	for i in open(os.path.join(srcroot, "Makefile")):
+		if i[:14] == "PACKAGE_STRING":
+			break
+	i = i.split("=")[1].strip()
+
+	fo = open(os.path.join(srcroot, "include", "vmod_abi.h"), "w")
+	file_header(fo)
+	fo.write('#define VMOD_ABI_Version "%s %s"\n' % (i, v))
+	fo.close()



More information about the varnish-commit mailing list