Commit 9305a2d4 authored by Nils Goroll's avatar Nils Goroll

pull out vcs_version.h / vmod_abi.h generation to own file again

This basically reverts a29fca70,
except that we are using python instead of make-inlined shell code to
do the work.

Reason: vcs_version.h needs to be up-to-date under all circumstances,
otherwise we will end up with wrong version information in binary
builds, which would divert developer resources into unproductive
confusion compensation.

With an all-in-one generate.py, we basically have the choice between:

- running it with each build, which breaks incremental builds as
  generate.py rewrites central includes like vcl.h

- adding version information to all generate.py-build files or similar
  mechanisms to avoid re-writing them unless they have actually
  changed.

- contradicting the argument given above

I think that, unless there are strong reasons for a single
generate.py, avoiding these issues by splitting functions is the best
option.
parent d731f473
......@@ -101,7 +101,7 @@ nobase_noinst_HEADERS = \
vus.h
## keep in sync with lib/libvcc/Makefile.am
vmod_abi.h: \
vcl.h: \
$(top_srcdir)/lib/libvcc/generate.py \
$(top_srcdir)/include/vdef.h \
$(top_srcdir)/include/vrt.h \
......@@ -114,15 +114,31 @@ GEN_H = \
tbl/vrt_stv_var.h \
tbl/vcl_returns.h \
tbl/vcc_types.h \
vrt_obj.h \
vcl.h \
vcs_version.h
vrt_obj.h
$(GEN_H): vcl.h
GENERATED_H = vcl.h $(GEN_H)
$(GEN_H): vmod_abi.h
## vcs_version.h / vmod_abi.h need to be up-to-date with every build
## except when building from a distribution
GENERATED_H = vmod_abi.h $(GEN_H)
vcs_version.h:
if test -d $(top_srcdir)/.git ; then \
@PYTHON@ $(srcdir)/generate.py \
$(top_srcdir) $(top_builddir) ; \
fi
BUILT_SOURCES = $(GENERATED_H)
vmod_abi.h: vcs_version.h
.PHONY: vcs_version.h
##
BUILT_SOURCES = \
$(GENERATED_H) \
vcs_version.h \
vmod_abi.h
MAINTAINERCLEANFILES = $(GENERATED_H)
......
#!/usr/bin/env python
#
# Copyright (c) 2006 Verdens Gang AS
# Copyright (c) 2006-2015 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Generate vcs_version.h vmod_abi.h
from __future__ import print_function
import subprocess
import collections
import os
import sys
srcroot = "../.."
buildroot = "../.."
if len(sys.argv) == 3:
srcroot = sys.argv[1]
buildroot = sys.argv[2]
elif len(sys.argv) != 1:
print("Two arguments or none")
exit(2)
#######################################################################
def file_header(fo):
fo.write("""/*
* NB: This file is machine generated, DO NOT EDIT!
*
* Edit and run lib/libvcc/generate.py instead.
*/
""")
#######################################################################
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)
v = v.strip()
else:
v = "NOGIT"
vcsfn = os.path.join(srcroot, "include", "vcs_version.h")
try:
i = open(vcsfn).readline()
except IOError:
i = ""
ident = "/* " + v + " */\n"
if i != ident:
fo = open(vcsfn, "w")
fo.write(ident)
file_header(fo)
fo.write('#define VCS_Version "%s"\n' % v)
fo.close()
for i in open(os.path.join(buildroot, "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()
......@@ -818,40 +818,3 @@ for i in stv_variables:
fo.write("#undef VRTSTVVAR\n")
lint_end(fo)
fo.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)
v = v.strip()
else:
v = "NOGIT"
vcsfn = os.path.join(srcroot, "include", "vcs_version.h")
try:
i = open(vcsfn).readline()
except IOError:
i = ""
ident = "/* " + v + " */\n"
if i != ident:
fo = open(vcsfn, "w")
fo.write(ident)
file_header(fo)
fo.write('#define VCS_Version "%s"\n' % v)
fo.close()
for i in open(os.path.join(buildroot, "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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment