1#!/usr/bin/python 2 3# This script is used to bump the bjam version. It takes a single argument, e.g 4# 5# ./bump_version.py 3.1.9 6# 7# and updates all the necessary files. 8# 9# Copyright 2006 Rene Rivera. 10# Copyright 2005-2006 Vladimir Prus. 11# Distributed under the Boost Software License, Version 1.0. 12# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 13 14 15import os 16import os.path 17import re 18import string 19import sys 20 21srcdir = os.path.abspath(os.path.dirname(__file__)) 22docdir = os.path.abspath(os.path.join(srcdir, "..", "doc")) 23 24 25def edit(file, *replacements): 26 print(" '%s'..." % file) 27 f = open(file, 'r') 28 text = f.read() 29 f.close() 30 for (source, target) in replacements: 31 text, n = re.compile(source, re.MULTILINE).subn(target, text) 32 assert n > 0 33 f = open(file, 'w') 34 f.write(text) 35 f.close() 36 37 38def make_edits(ver): 39 ver03 = (list(ver) + [0] * 3)[0:3] 40 ver02 = ver03[0:2] 41 42 join = lambda v, s : s.join(str(x) for x in v) 43 dotJoin = lambda v : join(v, ".") 44 45 print("Setting version to %s" % str(ver03)) 46 47 edit(os.path.join(srcdir, "boost-jam.spec"), 48 ('^(Version:) .*$', '\\1 %s' % dotJoin(ver03))) 49 50 edit(os.path.join(srcdir, "build.jam"), 51 ('^(_VERSION_ =).* ;$', '\\1 %s ;' % join(ver03, " "))) 52 53 edit(os.path.join(docdir, "bjam.qbk"), 54 ('(\[version).*(\])', '\\1: %s\\2' % dotJoin(ver03)), 55 ('(\[def :version:).*(\])', '\\1 %s\\2' % dotJoin(ver03))) 56 57 edit(os.path.join(srcdir, "patchlevel.h"), 58 ('^(#define VERSION_MAJOR) .*$', '\\1 %s' % ver03[0]), 59 ('^(#define VERSION_MINOR) .*$', '\\1 %s' % ver03[1]), 60 ('^(#define VERSION_PATCH) .*$', '\\1 %s' % ver03[2]), 61 ('^(#define VERSION_MAJOR_SYM) .*$', '\\1 "%02d"' % ver03[0]), 62 ('^(#define VERSION_MINOR_SYM) .*$', '\\1 "%02d"' % ver03[1]), 63 ('^(#define VERSION_PATCH_SYM) .*$', '\\1 "%02d"' % ver03[2]), 64 ('^(#define VERSION) .*$', '\\1 "%s"' % dotJoin(ver)), 65 ('^(#define JAMVERSYM) .*$', '\\1 "JAMVERSION=%s"' % dotJoin(ver02))) 66 67 68def main(): 69 if len(sys.argv) < 2: 70 print("Expect new version as argument.") 71 sys.exit(1) 72 if len(sys.argv) > 3: 73 print("Too many arguments.") 74 sys.exit(1) 75 76 version = sys.argv[1].split(".") 77 if len(version) > 3: 78 print("Expect version argument in the format: <MAJOR>.<MINOR>.<PATCH>") 79 sys.exit(1) 80 81 try: 82 version = list(int(x) for x in version) 83 except ValueError: 84 print("Version values must be valid integers.") 85 sys.exit(1) 86 87 while version and version[-1] == 0: 88 version.pop() 89 90 if not version: 91 print("At least one of the version values must be positive.") 92 sys.exit() 93 94 make_edits(version) 95 96 97if __name__ == '__main__': 98 main() 99