versiongenerate.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. """A script to prepare version informtion for use the gtest Info.plist file.
  32. This script extracts the version information from the configure.ac file and
  33. uses it to generate a header file containing the same information. The
  34. #defines in this header file will be included in during the generation of
  35. the Info.plist of the framework, giving the correct value to the version
  36. shown in the Finder.
  37. This script makes the following assumptions (these are faults of the script,
  38. not problems with the Autoconf):
  39. 1. The AC_INIT macro will be contained within the first 1024 characters
  40. of configure.ac
  41. 2. The version string will be 3 integers separated by periods and will be
  42. surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first
  43. segment represents the major version, the second represents the minor
  44. version and the third represents the fix version.
  45. 3. No ")" character exists between the opening "(" and closing ")" of
  46. AC_INIT, including in comments and character strings.
  47. """
  48. import sys
  49. import re
  50. # Read the command line argument (the output directory for Version.h)
  51. if (len(sys.argv) < 3):
  52. print "Usage: versiongenerate.py input_dir output_dir"
  53. sys.exit(1)
  54. else:
  55. input_dir = sys.argv[1]
  56. output_dir = sys.argv[2]
  57. # Read the first 1024 characters of the configure.ac file
  58. config_file = open("%s/configure.ac" % input_dir, 'r')
  59. buffer_size = 1024
  60. opening_string = config_file.read(buffer_size)
  61. config_file.close()
  62. # Extract the version string from the AC_INIT macro
  63. # The following init_expression means:
  64. # Extract three integers separated by periods and surrounded by squre
  65. # brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy
  66. # (*? is the non-greedy flag) since that would pull in everything between
  67. # the first "(" and the last ")" in the file.
  68. version_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)",
  69. re.DOTALL)
  70. version_values = version_expression.search(opening_string)
  71. major_version = version_values.group(1)
  72. minor_version = version_values.group(2)
  73. fix_version = version_values.group(3)
  74. # Write the version information to a header file to be included in the
  75. # Info.plist file.
  76. file_data = """//
  77. // DO NOT MODIFY THIS FILE (but you can delete it)
  78. //
  79. // This file is autogenerated by the versiongenerate.py script. This script
  80. // is executed in a "Run Script" build phase when creating gtest.framework. This
  81. // header file is not used during compilation of C-source. Rather, it simply
  82. // defines some version strings for substitution in the Info.plist. Because of
  83. // this, we are not not restricted to C-syntax nor are we using include guards.
  84. //
  85. #define GTEST_VERSIONINFO_SHORT %s.%s
  86. #define GTEST_VERSIONINFO_LONG %s.%s.%s
  87. """ % (major_version, minor_version, major_version, minor_version, fix_version)
  88. version_file = open("%s/Version.h" % output_dir, 'w')
  89. version_file.write(file_data)
  90. version_file.close()