diff options
author | Rob Austein <sra@hactrn.net> | 2016-07-28 12:34:00 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-07-28 12:34:00 -0400 |
commit | 2de6ede47bcff6c8c478cc68ac8e36cfd9f2f166 (patch) | |
tree | 5299f07c2321c657f0b9252f5225a5963aa51d56 /buildtools/make-version.py | |
parent | 87b225aa90a341a20a1b5414a340c18ad45b50e8 (diff) |
First cut at whacking build scripts to work with git instead of subversion.
Diffstat (limited to 'buildtools/make-version.py')
-rw-r--r-- | buildtools/make-version.py | 104 |
1 files changed, 57 insertions, 47 deletions
diff --git a/buildtools/make-version.py b/buildtools/make-version.py index 09d43801..451809e7 100644 --- a/buildtools/make-version.py +++ b/buildtools/make-version.py @@ -1,69 +1,79 @@ #!/usr/bin/env python -# $Id$ -# Copyright (C) 2013 Internet Systems Consortium ("ISC") +# Copyright (C) 2016 Parsons Government Services ("PARSONS") +# Portions copyright (C) 2013 Internet Systems Consortium ("ISC") # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. +# copyright notices and this permission notice appear in all copies. # -# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. +# THE SOFTWARE IS PROVIDED "AS IS" AND PARSONS AND ISC DISCLAIM +# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# PARSONS OR ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# Kludge to extract Subversion revision number from environment at -# build time, if possible, using it to construct the software version -# number that one of our users so desperately wants us to have. This -# is a bit tricky because we want this to be automatic (hence use of -# Subversion revision number, which isn't really intended for this -# purpose), want it to work whether installing from binary package or -# subversion checkout or frozen tarball, and need to be careful both -# to update it whenever the revision changes and not to stomp on it -# when the subversion revision number isn't available. -# -# I did say this was a kludge. - -# One could argue that we should be throwing a fatal error when we -# can't determine the version, rather than just issuing a warning and -# writing a version of "Unknown". Maybe later. +""" +Kludge to extract revision information from environment at build +time, if possible, using it to construct the software version number +that one of our users so desperately wants us to have. This is a +bit tricky because we want this to be automatic, want it to work +whether installing from binary package or git checkout or frozen +tarball, and need to be careful both to update it whenever the +revision changes and not to stomp on it when the git revision +information isn't available. +""" import subprocess +import argparse +import time import sys -unknown = "Unknown" +parser = argparse.ArgumentParser(description = __doc__) +parser.add_argument("--stdout", action = "store_true", help = "write version information to stdout") -try: - v = subprocess.Popen(("svnversion", "-c"), stdout = subprocess.PIPE).communicate()[0] - err = None -except Exception, e: - v = unknown - err = e +# The next two are only for use by other build scripts. Using these directly will +# likely result in version numbering that diverges from the semi-official packaged +# binaries, which is unlikely to be what you want. Because of this, we suppress all +# mention of these options from the --help output. + +parser.add_argument("--build-tag", action = "store_true", help = argparse.SUPPRESS) +parser.add_argument("--major-version", default = "1.0", help = argparse.SUPPRESS) -if any(s in v for s in ("Unversioned", "Uncommitted", unknown)): - v = unknown -else: - v = "0." + v.strip().split(":")[-1].translate(None, "SMP") +args = parser.parse_args() + +if args.build_tag: + try: + subprocess.check_call(("git", "describe", "--match", "buildbot-*", "--exact"), + stdout = open("/dev/null", "w"), stderr = subprocess.STDOUT) + except subprocess.CalledProcessError: + subprocess.check_call(("git", "tag", "-a", "-m", "Build robot", + "buildbot-{}.{}".format(args.major_version, int(time.time())))) + +try: + ver = subprocess.check_output(("git", "describe", "--match", "buildbot-*", "--dirty"), stderr = open("/dev/null", "w")).strip() +except subprocess.CalledProcessError: + ver = None try: old = open("VERSION", "r").read().strip() -except: +except IOError: old = None -if err is not None and (old is None or old == unknown): - sys.stderr.write("Warning: No saved version and svnversion failed: %s\n" % err) +if ver is None: + ver = old -if v == unknown: - if old is not None and old != unknown: - v = old - else: - sys.stderr.write("Warning: Could not determine software version\n") +if ver is None and old is None: + sys.exit("Could not determine software version") -if old is None or v != old: +if ver != old: with open("rpki/version.py", "w") as f: - f.write("VERSION = \"%s\"\n" % v) + f.write("VERSION = \"{}\"\n".format(ver)) with open("VERSION", "w") as f: - f.write(v + "\n") + f.write("{}\n".format(ver)) + +if args.stdout: + sys.stdout.write("{}\n".format(ver)) |