1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#!/usr/bin/env python 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Copyright 2008, Google Inc. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# All rights reserved. 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Redistribution and use in source and binary forms, with or without 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# modification, are permitted provided that the following conditions are 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# met: 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# * Redistributions of source code must retain the above copyright 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# notice, this list of conditions and the following disclaimer. 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# * Redistributions in binary form must reproduce the above 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# copyright notice, this list of conditions and the following disclaimer 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# in the documentation and/or other materials provided with the 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# distribution. 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# * Neither the name of Google Inc. nor the names of its 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# contributors may be used to endorse or promote products derived from 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# this software without specific prior written permission. 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch"""A script to prepare version informtion for use the gtest Info.plist file. 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch This script extracts the version information from the configure.ac file and 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch uses it to generate a header file containing the same information. The 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch #defines in this header file will be included in during the generation of 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch the Info.plist of the framework, giving the correct value to the version 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch shown in the Finder. 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch This script makes the following assumptions (these are faults of the script, 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch not problems with the Autoconf): 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 1. The AC_INIT macro will be contained within the first 1024 characters 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch of configure.ac 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 2. The version string will be 3 integers separated by periods and will be 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch segment represents the major version, the second represents the minor 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch version and the third represents the fix version. 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 3. No ")" character exists between the opening "(" and closing ")" of 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch AC_INIT, including in comments and character strings. 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch""" 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochimport sys 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochimport re 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Read the command line argument (the output directory for Version.h) 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochif (len(sys.argv) < 3): 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch print "Usage: versiongenerate.py input_dir output_dir" 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch sys.exit(1) 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochelse: 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch input_dir = sys.argv[1] 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch output_dir = sys.argv[2] 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Read the first 1024 characters of the configure.ac file 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconfig_file = open("%s/configure.ac" % input_dir, 'r') 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochbuffer_size = 1024 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochopening_string = config_file.read(buffer_size) 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconfig_file.close() 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Extract the version string from the AC_INIT macro 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# The following init_expression means: 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Extract three integers separated by periods and surrounded by squre 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# (*? is the non-greedy flag) since that would pull in everything between 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# the first "(" and the last ")" in the file. 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochversion_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)", 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch re.DOTALL) 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochversion_values = version_expression.search(opening_string) 78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochmajor_version = version_values.group(1) 79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochminor_version = version_values.group(2) 80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochfix_version = version_values.group(3) 81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Write the version information to a header file to be included in the 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch# Info.plist file. 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochfile_data = """// 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// DO NOT MODIFY THIS FILE (but you can delete it) 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This file is autogenerated by the versiongenerate.py script. This script 88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// is executed in a "Run Script" build phase when creating gtest.framework. This 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// header file is not used during compilation of C-source. Rather, it simply 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// defines some version strings for substitution in the Info.plist. Because of 91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// this, we are not not restricted to C-syntax nor are we using include guards. 92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define GTEST_VERSIONINFO_SHORT %s.%s 95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define GTEST_VERSIONINFO_LONG %s.%s.%s 96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch""" % (major_version, minor_version, major_version, minor_version, fix_version) 98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochversion_file = open("%s/Version.h" % output_dir, 'w') 99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochversion_file.write(file_data) 100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochversion_file.close() 101