11b362b15af34006e6a11974088a46d42b903418eJohann#!/usr/bin/env python 21b362b15af34006e6a11974088a46d42b903418eJohann# 31b362b15af34006e6a11974088a46d42b903418eJohann# Copyright 2008, Google Inc. 41b362b15af34006e6a11974088a46d42b903418eJohann# All rights reserved. 51b362b15af34006e6a11974088a46d42b903418eJohann# 61b362b15af34006e6a11974088a46d42b903418eJohann# Redistribution and use in source and binary forms, with or without 71b362b15af34006e6a11974088a46d42b903418eJohann# modification, are permitted provided that the following conditions are 81b362b15af34006e6a11974088a46d42b903418eJohann# met: 91b362b15af34006e6a11974088a46d42b903418eJohann# 101b362b15af34006e6a11974088a46d42b903418eJohann# * Redistributions of source code must retain the above copyright 111b362b15af34006e6a11974088a46d42b903418eJohann# notice, this list of conditions and the following disclaimer. 121b362b15af34006e6a11974088a46d42b903418eJohann# * Redistributions in binary form must reproduce the above 131b362b15af34006e6a11974088a46d42b903418eJohann# copyright notice, this list of conditions and the following disclaimer 141b362b15af34006e6a11974088a46d42b903418eJohann# in the documentation and/or other materials provided with the 151b362b15af34006e6a11974088a46d42b903418eJohann# distribution. 161b362b15af34006e6a11974088a46d42b903418eJohann# * Neither the name of Google Inc. nor the names of its 171b362b15af34006e6a11974088a46d42b903418eJohann# contributors may be used to endorse or promote products derived from 181b362b15af34006e6a11974088a46d42b903418eJohann# this software without specific prior written permission. 191b362b15af34006e6a11974088a46d42b903418eJohann# 201b362b15af34006e6a11974088a46d42b903418eJohann# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 211b362b15af34006e6a11974088a46d42b903418eJohann# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 221b362b15af34006e6a11974088a46d42b903418eJohann# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 231b362b15af34006e6a11974088a46d42b903418eJohann# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 241b362b15af34006e6a11974088a46d42b903418eJohann# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 251b362b15af34006e6a11974088a46d42b903418eJohann# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 261b362b15af34006e6a11974088a46d42b903418eJohann# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 271b362b15af34006e6a11974088a46d42b903418eJohann# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 281b362b15af34006e6a11974088a46d42b903418eJohann# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291b362b15af34006e6a11974088a46d42b903418eJohann# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 301b362b15af34006e6a11974088a46d42b903418eJohann# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311b362b15af34006e6a11974088a46d42b903418eJohann 321b362b15af34006e6a11974088a46d42b903418eJohann"""A script to prepare version informtion for use the gtest Info.plist file. 331b362b15af34006e6a11974088a46d42b903418eJohann 341b362b15af34006e6a11974088a46d42b903418eJohann This script extracts the version information from the configure.ac file and 351b362b15af34006e6a11974088a46d42b903418eJohann uses it to generate a header file containing the same information. The 361b362b15af34006e6a11974088a46d42b903418eJohann #defines in this header file will be included in during the generation of 371b362b15af34006e6a11974088a46d42b903418eJohann the Info.plist of the framework, giving the correct value to the version 381b362b15af34006e6a11974088a46d42b903418eJohann shown in the Finder. 391b362b15af34006e6a11974088a46d42b903418eJohann 401b362b15af34006e6a11974088a46d42b903418eJohann This script makes the following assumptions (these are faults of the script, 411b362b15af34006e6a11974088a46d42b903418eJohann not problems with the Autoconf): 421b362b15af34006e6a11974088a46d42b903418eJohann 1. The AC_INIT macro will be contained within the first 1024 characters 431b362b15af34006e6a11974088a46d42b903418eJohann of configure.ac 441b362b15af34006e6a11974088a46d42b903418eJohann 2. The version string will be 3 integers separated by periods and will be 451b362b15af34006e6a11974088a46d42b903418eJohann surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first 461b362b15af34006e6a11974088a46d42b903418eJohann segment represents the major version, the second represents the minor 471b362b15af34006e6a11974088a46d42b903418eJohann version and the third represents the fix version. 481b362b15af34006e6a11974088a46d42b903418eJohann 3. No ")" character exists between the opening "(" and closing ")" of 491b362b15af34006e6a11974088a46d42b903418eJohann AC_INIT, including in comments and character strings. 501b362b15af34006e6a11974088a46d42b903418eJohann""" 511b362b15af34006e6a11974088a46d42b903418eJohann 521b362b15af34006e6a11974088a46d42b903418eJohannimport sys 531b362b15af34006e6a11974088a46d42b903418eJohannimport re 541b362b15af34006e6a11974088a46d42b903418eJohann 551b362b15af34006e6a11974088a46d42b903418eJohann# Read the command line argument (the output directory for Version.h) 561b362b15af34006e6a11974088a46d42b903418eJohannif (len(sys.argv) < 3): 571b362b15af34006e6a11974088a46d42b903418eJohann print "Usage: versiongenerate.py input_dir output_dir" 581b362b15af34006e6a11974088a46d42b903418eJohann sys.exit(1) 591b362b15af34006e6a11974088a46d42b903418eJohannelse: 601b362b15af34006e6a11974088a46d42b903418eJohann input_dir = sys.argv[1] 611b362b15af34006e6a11974088a46d42b903418eJohann output_dir = sys.argv[2] 621b362b15af34006e6a11974088a46d42b903418eJohann 631b362b15af34006e6a11974088a46d42b903418eJohann# Read the first 1024 characters of the configure.ac file 641b362b15af34006e6a11974088a46d42b903418eJohannconfig_file = open("%s/configure.ac" % input_dir, 'r') 651b362b15af34006e6a11974088a46d42b903418eJohannbuffer_size = 1024 661b362b15af34006e6a11974088a46d42b903418eJohannopening_string = config_file.read(buffer_size) 671b362b15af34006e6a11974088a46d42b903418eJohannconfig_file.close() 681b362b15af34006e6a11974088a46d42b903418eJohann 691b362b15af34006e6a11974088a46d42b903418eJohann# Extract the version string from the AC_INIT macro 701b362b15af34006e6a11974088a46d42b903418eJohann# The following init_expression means: 711b362b15af34006e6a11974088a46d42b903418eJohann# Extract three integers separated by periods and surrounded by squre 721b362b15af34006e6a11974088a46d42b903418eJohann# brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy 731b362b15af34006e6a11974088a46d42b903418eJohann# (*? is the non-greedy flag) since that would pull in everything between 741b362b15af34006e6a11974088a46d42b903418eJohann# the first "(" and the last ")" in the file. 751b362b15af34006e6a11974088a46d42b903418eJohannversion_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)", 761b362b15af34006e6a11974088a46d42b903418eJohann re.DOTALL) 771b362b15af34006e6a11974088a46d42b903418eJohannversion_values = version_expression.search(opening_string) 781b362b15af34006e6a11974088a46d42b903418eJohannmajor_version = version_values.group(1) 791b362b15af34006e6a11974088a46d42b903418eJohannminor_version = version_values.group(2) 801b362b15af34006e6a11974088a46d42b903418eJohannfix_version = version_values.group(3) 811b362b15af34006e6a11974088a46d42b903418eJohann 821b362b15af34006e6a11974088a46d42b903418eJohann# Write the version information to a header file to be included in the 831b362b15af34006e6a11974088a46d42b903418eJohann# Info.plist file. 841b362b15af34006e6a11974088a46d42b903418eJohannfile_data = """// 851b362b15af34006e6a11974088a46d42b903418eJohann// DO NOT MODIFY THIS FILE (but you can delete it) 861b362b15af34006e6a11974088a46d42b903418eJohann// 871b362b15af34006e6a11974088a46d42b903418eJohann// This file is autogenerated by the versiongenerate.py script. This script 881b362b15af34006e6a11974088a46d42b903418eJohann// is executed in a "Run Script" build phase when creating gtest.framework. This 891b362b15af34006e6a11974088a46d42b903418eJohann// header file is not used during compilation of C-source. Rather, it simply 901b362b15af34006e6a11974088a46d42b903418eJohann// defines some version strings for substitution in the Info.plist. Because of 911b362b15af34006e6a11974088a46d42b903418eJohann// this, we are not not restricted to C-syntax nor are we using include guards. 921b362b15af34006e6a11974088a46d42b903418eJohann// 931b362b15af34006e6a11974088a46d42b903418eJohann 941b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_VERSIONINFO_SHORT %s.%s 951b362b15af34006e6a11974088a46d42b903418eJohann#define GTEST_VERSIONINFO_LONG %s.%s.%s 961b362b15af34006e6a11974088a46d42b903418eJohann 971b362b15af34006e6a11974088a46d42b903418eJohann""" % (major_version, minor_version, major_version, minor_version, fix_version) 981b362b15af34006e6a11974088a46d42b903418eJohannversion_file = open("%s/Version.h" % output_dir, 'w') 991b362b15af34006e6a11974088a46d42b903418eJohannversion_file.write(file_data) 1001b362b15af34006e6a11974088a46d42b903418eJohannversion_file.close() 101