media/webrtc/trunk/testing/gtest/xcode/Scripts/versiongenerate.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/testing/gtest/xcode/Scripts/versiongenerate.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +#!/usr/bin/env python
     1.5 +#
     1.6 +# Copyright 2008, Google Inc.
     1.7 +# All rights reserved.
     1.8 +#
     1.9 +# Redistribution and use in source and binary forms, with or without
    1.10 +# modification, are permitted provided that the following conditions are
    1.11 +# met:
    1.12 +#
    1.13 +#     * Redistributions of source code must retain the above copyright
    1.14 +# notice, this list of conditions and the following disclaimer.
    1.15 +#     * Redistributions in binary form must reproduce the above
    1.16 +# copyright notice, this list of conditions and the following disclaimer
    1.17 +# in the documentation and/or other materials provided with the
    1.18 +# distribution.
    1.19 +#     * Neither the name of Google Inc. nor the names of its
    1.20 +# contributors may be used to endorse or promote products derived from
    1.21 +# this software without specific prior written permission.
    1.22 +#
    1.23 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +
    1.35 +"""A script to prepare version informtion for use the gtest Info.plist file.
    1.36 +
    1.37 +  This script extracts the version information from the configure.ac file and
    1.38 +  uses it to generate a header file containing the same information. The
    1.39 +  #defines in this header file will be included in during the generation of
    1.40 +  the Info.plist of the framework, giving the correct value to the version
    1.41 +  shown in the Finder.
    1.42 +
    1.43 +  This script makes the following assumptions (these are faults of the script,
    1.44 +  not problems with the Autoconf):
    1.45 +    1. The AC_INIT macro will be contained within the first 1024 characters
    1.46 +       of configure.ac
    1.47 +    2. The version string will be 3 integers separated by periods and will be
    1.48 +       surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first
    1.49 +       segment represents the major version, the second represents the minor
    1.50 +       version and the third represents the fix version.
    1.51 +    3. No ")" character exists between the opening "(" and closing ")" of
    1.52 +       AC_INIT, including in comments and character strings.
    1.53 +"""
    1.54 +
    1.55 +import sys
    1.56 +import re
    1.57 +
    1.58 +# Read the command line argument (the output directory for Version.h)
    1.59 +if (len(sys.argv) < 3):
    1.60 +  print "Usage: versiongenerate.py input_dir output_dir"
    1.61 +  sys.exit(1)
    1.62 +else:
    1.63 +  input_dir = sys.argv[1]
    1.64 +  output_dir = sys.argv[2]
    1.65 +
    1.66 +# Read the first 1024 characters of the configure.ac file
    1.67 +config_file = open("%s/configure.ac" % input_dir, 'r')
    1.68 +buffer_size = 1024
    1.69 +opening_string = config_file.read(buffer_size)
    1.70 +config_file.close()
    1.71 +
    1.72 +# Extract the version string from the AC_INIT macro
    1.73 +#   The following init_expression means:
    1.74 +#     Extract three integers separated by periods and surrounded by squre
    1.75 +#     brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy
    1.76 +#     (*? is the non-greedy flag) since that would pull in everything between
    1.77 +#     the first "(" and the last ")" in the file.
    1.78 +version_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)",
    1.79 +                                re.DOTALL)
    1.80 +version_values = version_expression.search(opening_string)
    1.81 +major_version = version_values.group(1)
    1.82 +minor_version = version_values.group(2)
    1.83 +fix_version = version_values.group(3)
    1.84 +
    1.85 +# Write the version information to a header file to be included in the
    1.86 +# Info.plist file.
    1.87 +file_data = """//
    1.88 +// DO NOT MODIFY THIS FILE (but you can delete it)
    1.89 +//
    1.90 +// This file is autogenerated by the versiongenerate.py script. This script
    1.91 +// is executed in a "Run Script" build phase when creating gtest.framework. This
    1.92 +// header file is not used during compilation of C-source. Rather, it simply
    1.93 +// defines some version strings for substitution in the Info.plist. Because of
    1.94 +// this, we are not not restricted to C-syntax nor are we using include guards.
    1.95 +//
    1.96 +
    1.97 +#define GTEST_VERSIONINFO_SHORT %s.%s
    1.98 +#define GTEST_VERSIONINFO_LONG %s.%s.%s
    1.99 +
   1.100 +""" % (major_version, minor_version, major_version, minor_version, fix_version)
   1.101 +version_file = open("%s/Version.h" % output_dir, 'w')
   1.102 +version_file.write(file_data)
   1.103 +version_file.close()

mercurial