1#/usr/bin/python 2 3"""A script to prepare version informtion for use the gtest Info.plist file. 4 5 This script extracts the version information from the configure.ac file and 6 uses it to generate a header file containing the same information. The 7 #defines in this header file will be included in during the generation of 8 the Info.plist of the framework, giving the correct value to the version 9 shown in the Finder. 10 11 This script makes the following assumptions (these are faults of the script, 12 not problems with the Autoconf): 13 1. The AC_INIT macro will be contained within the first 1024 characters 14 of configure.ac 15 2. The version string will be 3 integers separated by periods and will be 16 surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first 17 segment represents the major version, the second represents the minor 18 version and the third represents the fix version. 19 3. No ")" character exists between the opening "(" and closing ")" of 20 AC_INIT, including in comments and character strings. 21""" 22 23import sys 24import re 25 26# Read the command line argument (the output directory for Version.h) 27if (len(sys.argv) < 3): 28 print "Usage: /usr/bin/python versiongenerate.py input_dir output_dir" 29 sys.exit(1) 30else: 31 input_dir = sys.argv[1] 32 output_dir = sys.argv[2] 33 34# Read the first 1024 characters of the configure.ac file 35config_file = open("%s/configure.ac" % input_dir, 'r') 36buffer_size = 1024 37opening_string = config_file.read(buffer_size) 38config_file.close() 39 40# Extract the version string from the AC_INIT macro 41# The following init_expression means: 42# Extract three integers separated by periods and surrounded by squre 43# brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy 44# (*? is the non-greedy flag) since that would pull in everything between 45# the first "(" and the last ")" in the file. 46version_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)", 47 re.DOTALL) 48version_values = version_expression.search(opening_string) 49major_version = version_values.group(1) 50minor_version = version_values.group(2) 51fix_version = version_values.group(3) 52 53# Write the version information to a header file to be included in the 54# Info.plist file. 55file_data = """// 56// DO NOT MODIFY THIS FILE (but you can delete it) 57// 58// This file is autogenerated by the versiongenerate.py script. This script 59// is executed in a "Run Script" build phase when creating gtest.framework. This 60// header file is not used during compilation of C-source. Rather, it simply 61// defines some version strings for substitution in the Info.plist. Because of 62// this, we are not not restricted to C-syntax nor are we using include guards. 63// 64 65#define GTEST_VERSIONINFO_SHORT %s.%s 66#define GTEST_VERSIONINFO_LONG %s.%s.%s 67 68""" % (major_version, minor_version, major_version, minor_version, fix_version) 69version_file = open("%s/Version.h" % output_dir, 'w') 70version_file.write(file_data) 71version_file.close() 72