3 # Check for the first line in a file generated with gmmproc,
4 # to see which gmmproc version was used, to see whether
5 # to enable __declspec(dllexport to export symbols). This
6 # is *not* intended for source files that are not generated
9 # Author: Chun-wei Fan April 2, 2020
15 min_required_gmmproc_ver = '2.64.3'
17 parser = argparse.ArgumentParser(description='Check gmmproc version used.')
18 parser.add_argument('--file',
20 help='Generated .cc/.h file to check gmmproc version')
21 parser.add_argument('--gmmprocdir',
23 help='Directory where gmmproc is located')
24 args = parser.parse_args()
26 if args.file is None and args.gmmprocdir is None:
27 raise ValueError('Either --file or --gmmprocdir must be specified')
29 if args.gmmprocdir is not None:
30 # gmmprocdir is specified: Check version string in gmmproc
31 gmmproc_path = os.path.join(args.gmmprocdir, 'gmmproc')
32 if not os.path.exists(gmmproc_path):
33 raise ValueError('A valid directory to locate gmmproc must be ' \
34 'specified with --gmmprocdir=<directory>')
36 gmmproc_ver_str = None
37 with open(gmmproc_path, 'r') as f:
39 if line.startswith(' $main::glibmm_version = '):
40 gmmproc_ver_str = line[line.find('\"') + 1:line.rfind('\"')]
42 if gmmproc_ver_str is None:
43 raise ValueError('The gmmproc at %s is invalid' % gmmproc_path)
45 gmmproc_ver = gmmproc_ver_str.split('.')
47 # A pre-generated file is specified via --file
48 if not os.path.exists(args.file):
49 raise FileNotFoundError('File specified with --file does not exist')
51 # We only allow .h/.cc files to run this check
52 if not args.file.endswith('.cc') and \
53 not args.file.endswith('.h'):
54 raise ValueError('Only .cc/.h files are accepted here')
56 # Now grab the first line of the file we are checking for
58 firstline = f.readline()
61 # Check for gmmproc signature...
62 if not firstline.startswith('// Generated by gmmproc '):
63 raise ValueError('Specified file is not generated by gmmproc')
65 tokens = firstline.split()
66 gmmproc_ver = tokens[tokens.index('gmmproc') + 1].split('.')
68 # Now compare the gmmproc version against the one we want
70 gmmproc_major = int(gmmproc_ver[0])
71 gmmproc_minor = int(gmmproc_ver[1])
72 gmmproc_micro = int(gmmproc_ver[2])
74 min_required_ver = min_required_gmmproc_ver.split('.')
75 min_major_ver = int(min_required_ver[0])
76 min_minor_ver = int(min_required_ver[1])
77 min_micro_ver = int(min_required_ver[2])
79 if gmmproc_major > min_major_ver or \
80 (gmmproc_major == min_major_ver and \
81 gmmproc_minor > min_minor_ver) or \
82 (gmmproc_major == min_major_ver and \
83 gmmproc_minor == min_minor_ver and \
84 gmmproc_micro >= min_micro_ver):