2 """Extract the FreeType version numbers from `<freetype/freetype.h>`.
4 This script parses the header to extract the version number defined there.
5 By default, the full dotted version number is printed, but `--major`,
6 `--minor` or `--patch` can be used to only print one of these values
10 from __future__ import print_function
20 # #define FREETYPE_MAJOR 2
21 # #define FREETYPE_MINOR 10
22 # #define FREETYPE_PATCH 2
25 RE_MAJOR = re.compile(r"^ \#define \s+ FREETYPE_MAJOR \s+ (.*) $", re.X)
26 RE_MINOR = re.compile(r"^ \#define \s+ FREETYPE_MINOR \s+ (.*) $", re.X)
27 RE_PATCH = re.compile(r"^ \#define \s+ FREETYPE_PATCH \s+ (.*) $", re.X)
30 def parse_freetype_header(header):
35 for line in header.splitlines():
37 m = RE_MAJOR.match(line)
39 assert major == None, "FREETYPE_MAJOR appears more than once!"
43 m = RE_MINOR.match(line)
45 assert minor == None, "FREETYPE_MINOR appears more than once!"
49 m = RE_PATCH.match(line)
51 assert patch == None, "FREETYPE_PATCH appears more than once!"
56 major and minor and patch
57 ), "This header is missing one of FREETYPE_MAJOR, FREETYPE_MINOR or FREETYPE_PATCH!"
59 return (major, minor, patch)
63 parser = argparse.ArgumentParser(description=__doc__)
65 group = parser.add_mutually_exclusive_group()
69 help="Only print the major version number.",
74 help="Only print the minor version number.",
79 help="Only print the patch version number.",
85 help="The input freetype.h header to parse.",
88 args = parser.parse_args()
89 with open(args.input) as f:
92 version = parse_freetype_header(header)
101 print("%s.%s.%s" % version)
106 if __name__ == "__main__":