Blame googletest/xcode/Scripts/versiongenerate.py

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