🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.8 KiB

  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2020-2021 by
  4. # David Turner, Robert Wilhelm, and Werner Lemberg.
  5. #
  6. # This file is part of the FreeType project, and may only be used, modified,
  7. # and distributed under the terms of the FreeType project license,
  8. # LICENSE.TXT. By continuing to use, modify, or distribute this file you
  9. # indicate that you have read the license and understand and accept it
  10. # fully.
  11. """Extract the libtool version from `configure.raw`.
  12. This script parses the `configure.raw` file to extract the libtool version
  13. number. By default, the full dotted version number is printed, but
  14. `--major`, `--minor` or `--patch` can be used to only print one of these
  15. values instead.
  16. """
  17. from __future__ import print_function
  18. import argparse
  19. import os
  20. import re
  21. import sys
  22. # Expected input:
  23. #
  24. # ...
  25. # version_info='23:2:17'
  26. # ...
  27. RE_VERSION_INFO = re.compile(r"^version_info='(\d+):(\d+):(\d+)'")
  28. def parse_configure_raw(header):
  29. major = None
  30. minor = None
  31. patch = None
  32. for line in header.splitlines():
  33. line = line.rstrip()
  34. m = RE_VERSION_INFO.match(line)
  35. if m:
  36. assert major == None, "version_info appears more than once!"
  37. major = m.group(1)
  38. minor = m.group(2)
  39. patch = m.group(3)
  40. continue
  41. assert (
  42. major and minor and patch
  43. ), "This input file is missing a version_info definition!"
  44. return (major, minor, patch)
  45. def main():
  46. parser = argparse.ArgumentParser(description=__doc__)
  47. group = parser.add_mutually_exclusive_group()
  48. group.add_argument(
  49. "--major",
  50. action="store_true",
  51. help="Only print the major version number.",
  52. )
  53. group.add_argument(
  54. "--minor",
  55. action="store_true",
  56. help="Only print the minor version number.",
  57. )
  58. group.add_argument(
  59. "--patch",
  60. action="store_true",
  61. help="Only print the patch version number.",
  62. )
  63. group.add_argument(
  64. "--soversion",
  65. action="store_true",
  66. help="Only print the libtool library suffix.",
  67. )
  68. parser.add_argument(
  69. "input",
  70. metavar="CONFIGURE_RAW",
  71. help="The input configure.raw file to parse.",
  72. )
  73. args = parser.parse_args()
  74. with open(args.input) as f:
  75. raw_file = f.read()
  76. version = parse_configure_raw(raw_file)
  77. if args.major:
  78. print(version[0])
  79. elif args.minor:
  80. print(version[1])
  81. elif args.patch:
  82. print(version[2])
  83. elif args.soversion:
  84. # Convert libtool version_info to the library suffix.
  85. # (current,revision, age) -> (current - age, age, revision)
  86. print(
  87. "%d.%s.%s"
  88. % (int(version[0]) - int(version[2]), version[2], version[1])
  89. )
  90. else:
  91. print("%s.%s.%s" % version)
  92. return 0
  93. if __name__ == "__main__":
  94. sys.exit(main())