FIX: Remove undistributable CHEMKIN files
[freefoam.git] / data / utilities / checkVersionInfo.py.in
blobb1371d53533563189d9a29c7898211c486480074
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
31 # Script
32 # checkVersionInfo [--warn]
34 # Description
35 # Verifies the version information contained in various files.
37 # Requires the source directory to be a git checkout
39 #------------------------------------------------------------------------------
41 """Usage: checkVersionInfo.py
43 Verifies the version information contained in various files.
45 Options
46 -------
47 --warn Only warn about version information issues, don't treat them as errors.
49 """
51 import sys
52 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
53 from FreeFOAM.compat import *
54 import os
55 import os.path as op
56 import re
57 import subprocess
59 # parse --warn argument if present
60 warnOnly = False
61 errText = 'ERROR:'
62 if len(sys.argv) == 2:
63 if sys.argv[1] == '--warn':
64 warnOnly = True
65 errText = 'WARNING:'
66 else:
67 echo('ERROR: unknown option "%s"'%sys.argv[1], file=sys.stderr)
68 sys.exit(1)
69 elif len(sys.argv) > 2:
70 echo('ERROR: too many arguments', file=sys.stderr)
71 sys.exit(1)
74 SOURCE_DIR = '@CMAKE_SOURCE_DIR@'
75 GIT_EXECUTABLE = '@GIT_EXECUTABLE@'
76 UPSTREAM_VERSION = '1.7.x'
78 os.chdir(SOURCE_DIR)
80 # get version info, output is of the form vX.Y.Z
81 v = subprocess.check_output(
82 [GIT_EXECUTABLE, 'describe', '--abbrev=0'])[1:].decode().strip()
83 major, minor, patch = v.split('.')
84 rc = ''
85 idx = patch.find('rc', 1)
86 if idx > 0:
87 rc = patch[idx:]
88 patch = patch[:idx]
90 # get upstream info
91 h = subprocess.check_output(
92 [GIT_EXECUTABLE, 'merge-base', 'HEAD',
93 'origin/upstream/OpenFOAM-'+UPSTREAM_VERSION]).decode().strip()
94 u = UPSTREAM_VERSION+'-'+subprocess.check_output(
95 [GIT_EXECUTABLE, 'log', '-1', '--pretty=format:%h', h]).decode().strip()
97 # checks to perform
98 retcode = 0
99 checks = {
100 op.join(SOURCE_DIR, 'CMakeLists.txt'): {
101 'FOAM_VERSION_MAJOR': {
102 'regex': re.compile(r'set\(FOAM_VERSION_MAJOR\s+"?(\d+)'),
103 'value': major,
104 'found': False,
106 'FOAM_VERSION_MINOR': {
107 'regex': re.compile(r'set\(FOAM_VERSION_MINOR\s+"?(\d+)'),
108 'value': minor,
109 'found': False,
111 'FOAM_VERSION_PATCH': {
112 'regex': re.compile(r'set\(FOAM_VERSION_PATCH\s+"?(\d+)'),
113 'value': patch,
114 'found': False,
116 'FOAM_VERSION_SUFFIX': {
117 'regex': re.compile(r'set\(FOAM_VERSION_SUFFIX\s*"?([^\")]*)'),
118 'value': rc,
119 'found': False,
122 op.join(SOURCE_DIR, 'data', 'asciidoc', 'common.conf'): {
123 'shortver': {
124 'regex': re.compile(r'^shortver=(\d+\.\d+)$'),
125 'value': '%s.%s'%(major, minor),
126 'found': False,
128 'ver': {
129 'regex': re.compile(r'^ver=(\d+\.\d+\.\d+)$'),
130 'value': '%s.%s.%s'%(major, minor, patch),
131 'found': False,
133 'fullver': {
134 'regex': re.compile(r'^fullver=(\d+\.\d+\.\d+\S*)$'),
135 'value': '%s.%s.%s%s'%(major, minor, patch, rc),
136 'found': False,
141 # run checks
142 for fname, items in checks.items():
143 for l in open(fname, 'rt'):
144 for var, ctrl in items.items():
145 m = ctrl['regex'].search(l)
146 if m is not None:
147 ctrl['found'] = True
148 if m.group(1) != ctrl['value']:
149 retcode = 1
150 echo('%s: %s in file %s is out of date. Should be "%s".'%(
151 errText, var, fname, ctrl['value']), file=sys.stderr)
153 # verify that we found all version info
154 for fname, items in checks.items():
155 for var, ctrl in items.items():
156 if not ctrl['found']:
157 retcode = 1
158 echo('%s: Failed to parse %s in file %s.'%(errText, var, fname))
160 if(not warnOnly):
161 sys.exit(retcode)
163 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file