Skip to content

Commit 641e78a

Browse files
committed
Fix #14040 (release script: set versions)
1 parent 2ae38ac commit 641e78a

2 files changed

Lines changed: 97 additions & 15 deletions

File tree

lib/version.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,13 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
// For a release version x.y.z the MAJOR should be x and both MINOR and DEVMINOR should be y.
20-
// After a release the DEVMINOR is incremented. MAJOR=x MINOR=y, DEVMINOR=y+1
2119

2220
#ifndef versionH
2321
#define versionH
2422

25-
#define CPPCHECK_MAJOR_VERSION 2
26-
#define CPPCHECK_MINOR_VERSION 17
27-
#define CPPCHECK_DEVMINOR_VERSION 18
28-
#define CPPCHECK_BUGFIX_VERSION 99
23+
#define CPPCHECK_VERSION_STRING "2.18 dev"
24+
#define CPPCHECK_VERSION 2,19,99,0
2925

30-
#define STRINGIFY(x) STRING(x)
31-
#define STRING(VER) #VER
32-
#if CPPCHECK_BUGFIX_VERSION < 99
33-
#define CPPCHECK_VERSION_STRING STRINGIFY(CPPCHECK_MAJOR_VERSION) "." STRINGIFY(CPPCHECK_MINOR_VERSION) "." STRINGIFY(CPPCHECK_BUGFIX_VERSION)
34-
#define CPPCHECK_VERSION CPPCHECK_MAJOR_VERSION,CPPCHECK_MINOR_VERSION,CPPCHECK_BUGFIX_VERSION,0
35-
#else
36-
#define CPPCHECK_VERSION_STRING STRINGIFY(CPPCHECK_MAJOR_VERSION) "." STRINGIFY(CPPCHECK_DEVMINOR_VERSION) " dev"
37-
#define CPPCHECK_VERSION CPPCHECK_MAJOR_VERSION,CPPCHECK_MINOR_VERSION,99,0
38-
#endif
3926
#define LEGALCOPYRIGHT L"Copyright (C) 2007-2025 Cppcheck team."
4027

4128
#endif

tools/release-set-version.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Update Cppcheck version
4+
#
5+
# Usage:
6+
# release: python3 release-set-version.py 2.18.0
7+
# debug: python3 release-set-version.py 2.18.99
8+
9+
import glob
10+
import re
11+
import subprocess
12+
import sys
13+
14+
15+
def git(args):
16+
return subprocess.check_output(['git'] + args).decode('utf-8').strip()
17+
18+
19+
def sed(args):
20+
return subprocess.check_output(['sed'] + args).decode('utf-8').strip()
21+
22+
23+
def egrep(args):
24+
try:
25+
return subprocess.check_output(['egrep'] + args).decode('utf-8').strip()
26+
except Exception:
27+
return ''
28+
29+
30+
# is there uncommitted changes in folder
31+
def is_uncommitted_changes():
32+
for f in git(['status', '--short']).split('\n'):
33+
if not f.startswith('??'):
34+
return True
35+
return False
36+
37+
38+
# get current git branch
39+
def get_current_branch():
40+
return git(['branch', '--show-current'])
41+
42+
43+
def set_version(new_version:str):
44+
if re.match(r'2[.][0-9][0-9][.][0-9]{1,2}([.][0-9])?', new_version) is None:
45+
print(f'Aborting, invalid version {new_version}')
46+
return
47+
48+
v = new_version.split('.')
49+
50+
if is_uncommitted_changes():
51+
print('Aborting, there are uncommitted changes')
52+
return
53+
54+
is_dev_version = (len(v) == 3 and v[-1] == '99')
55+
56+
if not is_dev_version:
57+
expected_branch = v[0] + '.' + v[1] + '.x'
58+
if get_current_branch() != expected_branch:
59+
print(f'Aborting, must be executed from {expected_branch} branch')
60+
return
61+
62+
v2 = '.'.join(v[:2])
63+
v3 = '.'.join(v[:3])
64+
65+
cppcheck_version_string = (v[0] + '.' + str(int(v[1])+1) + ' dev') if is_dev_version else new_version
66+
cppcheck_version = ','.join((v+['0','0','0','0'])[:4])
67+
68+
def check_sed(args):
69+
file = args[-1]
70+
res = re.match(r's/([^/]+)/.*', args[-2])
71+
if res is None:
72+
raise Exception('Failed to verify sed call argument ' + args[-2])
73+
pattern = res.group(1)
74+
if len(egrep([pattern, file])) < 4:
75+
print(f"WARNING: pattern '{pattern}' not found in file {file}")
76+
sed(args)
77+
78+
check_sed(['-i', '-r', f's/version 2[.][0-9]+([.][0-9]+)*/version {new_version}/', 'cli/main.cpp'])
79+
check_sed(['-i', '-r', f's/VERSION 2[.][0-9]+[.]99/VERSION {v3}/', 'CMakeLists.txt']) # version must have 3 parts.
80+
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION_STRING .*/#define CPPCHECK_VERSION_STRING "{cppcheck_version_string}"/', 'lib/version.h'])
81+
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION .*/#define CPPCHECK_VERSION {cppcheck_version}/', 'lib/version.h'])
82+
check_sed(['-i', '-r', f's/<[?]define ProductName[ ]*=.*/<?define ProductName = "Cppcheck $(var.Platform) {cppcheck_version_string}" ?>/', 'win_installer/productInfo.wxi'])
83+
check_sed(['-i', '-r', f's/<[?]define ProductVersion[ ]*=.*/<?define ProductVersion = "{new_version}" ?>/', 'win_installer/productInfo.wxi'])
84+
for g in glob.glob('man/*.md'):
85+
check_sed(['-i', '-r', f's/subtitle: Version 2\.[0-9].*/subtitle: Version {cppcheck_version_string}/', g])
86+
print("Versions have been changed. Please double check output of 'git diff'")
87+
commit_message = f'bumped version to {new_version}' if is_dev_version else f'{new_version}: Set version'
88+
print(f"git commit -a -m {commit_message}")
89+
90+
if len(sys.argv) != 2:
91+
print('Syntax: python3 release-set-version.py [version]')
92+
sys.exit(1)
93+
94+
set_version(sys.argv[-1])
95+

0 commit comments

Comments
 (0)