michael@0: #!/usr/bin/env python michael@0: # michael@0: # Copyright 2008, Google Inc. michael@0: # All rights reserved. michael@0: # michael@0: # Redistribution and use in source and binary forms, with or without michael@0: # modification, are permitted provided that the following conditions are michael@0: # met: michael@0: # michael@0: # * Redistributions of source code must retain the above copyright michael@0: # notice, this list of conditions and the following disclaimer. michael@0: # * Redistributions in binary form must reproduce the above michael@0: # copyright notice, this list of conditions and the following disclaimer michael@0: # in the documentation and/or other materials provided with the michael@0: # distribution. michael@0: # * Neither the name of Google Inc. nor the names of its michael@0: # contributors may be used to endorse or promote products derived from michael@0: # this software without specific prior written permission. michael@0: # michael@0: # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: """A script to prepare version informtion for use the gtest Info.plist file. michael@0: michael@0: This script extracts the version information from the configure.ac file and michael@0: uses it to generate a header file containing the same information. The michael@0: #defines in this header file will be included in during the generation of michael@0: the Info.plist of the framework, giving the correct value to the version michael@0: shown in the Finder. michael@0: michael@0: This script makes the following assumptions (these are faults of the script, michael@0: not problems with the Autoconf): michael@0: 1. The AC_INIT macro will be contained within the first 1024 characters michael@0: of configure.ac michael@0: 2. The version string will be 3 integers separated by periods and will be michael@0: surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first michael@0: segment represents the major version, the second represents the minor michael@0: version and the third represents the fix version. michael@0: 3. No ")" character exists between the opening "(" and closing ")" of michael@0: AC_INIT, including in comments and character strings. michael@0: """ michael@0: michael@0: import sys michael@0: import re michael@0: michael@0: # Read the command line argument (the output directory for Version.h) michael@0: if (len(sys.argv) < 3): michael@0: print "Usage: versiongenerate.py input_dir output_dir" michael@0: sys.exit(1) michael@0: else: michael@0: input_dir = sys.argv[1] michael@0: output_dir = sys.argv[2] michael@0: michael@0: # Read the first 1024 characters of the configure.ac file michael@0: config_file = open("%s/configure.ac" % input_dir, 'r') michael@0: buffer_size = 1024 michael@0: opening_string = config_file.read(buffer_size) michael@0: config_file.close() michael@0: michael@0: # Extract the version string from the AC_INIT macro michael@0: # The following init_expression means: michael@0: # Extract three integers separated by periods and surrounded by squre michael@0: # brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy michael@0: # (*? is the non-greedy flag) since that would pull in everything between michael@0: # the first "(" and the last ")" in the file. michael@0: version_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)", michael@0: re.DOTALL) michael@0: version_values = version_expression.search(opening_string) michael@0: major_version = version_values.group(1) michael@0: minor_version = version_values.group(2) michael@0: fix_version = version_values.group(3) michael@0: michael@0: # Write the version information to a header file to be included in the michael@0: # Info.plist file. michael@0: file_data = """// michael@0: // DO NOT MODIFY THIS FILE (but you can delete it) michael@0: // michael@0: // This file is autogenerated by the versiongenerate.py script. This script michael@0: // is executed in a "Run Script" build phase when creating gtest.framework. This michael@0: // header file is not used during compilation of C-source. Rather, it simply michael@0: // defines some version strings for substitution in the Info.plist. Because of michael@0: // this, we are not not restricted to C-syntax nor are we using include guards. michael@0: // michael@0: michael@0: #define GTEST_VERSIONINFO_SHORT %s.%s michael@0: #define GTEST_VERSIONINFO_LONG %s.%s.%s michael@0: michael@0: """ % (major_version, minor_version, major_version, minor_version, fix_version) michael@0: version_file = open("%s/Version.h" % output_dir, 'w') michael@0: version_file.write(file_data) michael@0: version_file.close()