source: gtest-1.7.0/xcode/Scripts/versiongenerate.py@ 12747

Last change on this file since 12747 was 12746, checked in by hock@…, 11 years ago

integrated the Google Testing Framework (gtest)

and wrote an Hello World test, to ensure the framework is working..

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