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