Skip to content

Commit 1e7ee6f

Browse files
authored
Fix #14040 (release script: set versions) (danmar#7711)
1 parent b78a8c0 commit 1e7ee6f

File tree

3 files changed

+107
-22
lines changed

3 files changed

+107
-22
lines changed

createrelease

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@
5050
# - empty the releasenotes.txt in main branch
5151
#
5252
# Update version numbers in:
53-
# sed -i -r "s/version 2[.][0-9]+([.]99)*/version 2.13.0/" cli/main.cpp
54-
# sed -i -r "s|VERSION 2[.][0-9]+[.]99|VERSION 2.13.0|" CMakeLists.txt # version must have 3 parts.
55-
# sed -i -r "s/CPPCHECK_MINOR_VERSION [0-9]+/CPPCHECK_MINOR_VERSION 13/" lib/version.h
56-
# sed -i -r "s/CPPCHECK_BUGFIX_VERSION 99/CPPCHECK_BUGFIX_VERSION 0/" lib/version.h
57-
# sed -i -r "s/2[.][0-9]+([.]99)*( dev)*/2.13.0/" win_installer/productInfo.wxi
58-
# sed -i -r "s/subtitle: Version 2\.[0-9]+.*/subtitle: Version 2.13/" man/*.md
59-
# Ensure that "-rc1" is added in productInfo.wxi and lib/version.h
53+
# python3 tools/release-set-version.py 2.19.0
6054
# Verify:
6155
# grep '\.99' */*.[ch]* && grep '[0-9][0-9] dev' */*.[ch]*
6256
# egrep "2\.[0-9]+" */*.h */*.cpp man/*.md | grep -v "test/test" | less

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.19 dev"
24+
#define CPPCHECK_VERSION 2,18,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: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
v3 = '.'.join(v[:3])
63+
64+
cppcheck_version_string = (v[0] + '.' + str(int(v[1])+1) + ' dev') if is_dev_version else new_version
65+
cppcheck_version = ','.join((v+['0','0','0','0'])[:4])
66+
67+
def check_sed(args):
68+
file = args[-1]
69+
res = re.match(r's/([^/]+)/.*', args[-2])
70+
if res is None:
71+
raise Exception('Failed to verify sed call argument ' + args[-2])
72+
pattern = res.group(1)
73+
if len(egrep([pattern, file])) < 4:
74+
print(f"WARNING: pattern '{pattern}' not found in file {file}")
75+
sed(args)
76+
77+
check_sed(['-i', '-r', f's/version 2[.][0-9]+([.][0-9]+)*/version {new_version}/', 'cli/main.cpp'])
78+
check_sed(['-i', '-r', f's/VERSION 2[.][0-9]+[.]99/VERSION {v3}/', 'CMakeLists.txt']) # version must have 3 parts.
79+
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION_STRING .*/#define CPPCHECK_VERSION_STRING "{cppcheck_version_string}"/', 'lib/version.h'])
80+
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION .*/#define CPPCHECK_VERSION {cppcheck_version}/', 'lib/version.h'])
81+
check_sed(['-i', '-r', f's/<[?]define ProductName[ ]*=.*/<?define ProductName = "Cppcheck $(var.Platform) {cppcheck_version_string}" ?>/', 'win_installer/productInfo.wxi'])
82+
check_sed(['-i', '-r', f's/<[?]define ProductVersion[ ]*=.*/<?define ProductVersion = "{new_version}" ?>/', 'win_installer/productInfo.wxi'])
83+
for g in glob.glob('man/*.md'):
84+
check_sed(['-i', '-r', f's/subtitle: Version 2\.[0-9].*/subtitle: Version {cppcheck_version_string}/', g])
85+
print('Versions have been changed.')
86+
print('')
87+
print('Please double check these results below:')
88+
for p in ('[^.0-9]2[.][0-9]+[.][0-9]', '2[.][0-9]+ dev'):
89+
for ext in ('cpp', 'h', 'md'):
90+
for g in glob.glob(f'*/*.{ext}'):
91+
s = egrep([p, g])
92+
if s != '':
93+
print(f'{g}: {s}')
94+
print('')
95+
print("Please double check output of 'git diff'")
96+
commit_message = f'bumped version to {new_version}' if is_dev_version else f'{new_version}: Set version'
97+
print(f"git commit -a -m {commit_message}")
98+
99+
if len(sys.argv) != 2:
100+
print('Syntax: python3 release-set-version.py [version]')
101+
sys.exit(1)
102+
103+
set_version(sys.argv[-1])
104+

0 commit comments

Comments
 (0)