Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions createrelease
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@
# - empty the releasenotes.txt in main branch
#
# Update version numbers in:
# sed -i -r "s/version 2[.][0-9]+([.]99)*/version 2.13.0/" cli/main.cpp
# sed -i -r "s|VERSION 2[.][0-9]+[.]99|VERSION 2.13.0|" CMakeLists.txt # version must have 3 parts.
# sed -i -r "s/CPPCHECK_MINOR_VERSION [0-9]+/CPPCHECK_MINOR_VERSION 13/" lib/version.h
# sed -i -r "s/CPPCHECK_BUGFIX_VERSION 99/CPPCHECK_BUGFIX_VERSION 0/" lib/version.h
# sed -i -r "s/2[.][0-9]+([.]99)*( dev)*/2.13.0/" win_installer/productInfo.wxi
# sed -i -r "s/subtitle: Version 2\.[0-9]+.*/subtitle: Version 2.13/" man/*.md
# Ensure that "-rc1" is added in productInfo.wxi and lib/version.h
# python3 tools/release-set-version.py 2.19.0
# Verify:
# grep '\.99' */*.[ch]* && grep '[0-9][0-9] dev' */*.[ch]*
# egrep "2\.[0-9]+" */*.h */*.cpp man/*.md | grep -v "test/test" | less
Expand Down
17 changes: 2 additions & 15 deletions lib/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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

#ifndef versionH
#define versionH

#define CPPCHECK_MAJOR_VERSION 2
#define CPPCHECK_MINOR_VERSION 17
#define CPPCHECK_DEVMINOR_VERSION 18
#define CPPCHECK_BUGFIX_VERSION 99
#define CPPCHECK_VERSION_STRING "2.19 dev"
#define CPPCHECK_VERSION 2,18,99,0

#define STRINGIFY(x) STRING(x)
#define STRING(VER) #VER
#if CPPCHECK_BUGFIX_VERSION < 99
#define CPPCHECK_VERSION_STRING STRINGIFY(CPPCHECK_MAJOR_VERSION) "." STRINGIFY(CPPCHECK_MINOR_VERSION) "." STRINGIFY(CPPCHECK_BUGFIX_VERSION)
#define CPPCHECK_VERSION CPPCHECK_MAJOR_VERSION,CPPCHECK_MINOR_VERSION,CPPCHECK_BUGFIX_VERSION,0
#else
#define CPPCHECK_VERSION_STRING STRINGIFY(CPPCHECK_MAJOR_VERSION) "." STRINGIFY(CPPCHECK_DEVMINOR_VERSION) " dev"
#define CPPCHECK_VERSION CPPCHECK_MAJOR_VERSION,CPPCHECK_MINOR_VERSION,99,0
#endif
#define LEGALCOPYRIGHT L"Copyright (C) 2007-2025 Cppcheck team."

#endif
104 changes: 104 additions & 0 deletions tools/release-set-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
#
# Update Cppcheck version
#
# Usage:
# release: python3 release-set-version.py 2.18.0
# debug: python3 release-set-version.py 2.18.99

import glob
import re
import subprocess
import sys


def git(args):
return subprocess.check_output(['git'] + args).decode('utf-8').strip()


def sed(args):
return subprocess.check_output(['sed'] + args).decode('utf-8').strip()


def egrep(args):
try:
return subprocess.check_output(['egrep'] + args).decode('utf-8').strip()
except Exception:
return ''


# is there uncommitted changes in folder
def is_uncommitted_changes():
for f in git(['status', '--short']).split('\n'):
if not f.startswith('??'):
return True
return False


# get current git branch
def get_current_branch():
return git(['branch', '--show-current'])


def set_version(new_version:str):
if re.match(r'2[.][0-9][0-9][.][0-9]{1,2}([.][0-9])?', new_version) is None:
print(f'Aborting, invalid version {new_version}')
return

v = new_version.split('.')

if is_uncommitted_changes():
print('Aborting, there are uncommitted changes')
#return

is_dev_version = (len(v) == 3 and v[-1] == '99')

if not is_dev_version:
expected_branch = v[0] + '.' + v[1] + '.x'
if get_current_branch() != expected_branch:
print(f'Aborting, must be executed from {expected_branch} branch')
return

v3 = '.'.join(v[:3])

cppcheck_version_string = (v[0] + '.' + str(int(v[1])+1) + ' dev') if is_dev_version else new_version
cppcheck_version = ','.join((v+['0','0','0','0'])[:4])

def check_sed(args):
file = args[-1]
res = re.match(r's/([^/]+)/.*', args[-2])
if res is None:
raise Exception('Failed to verify sed call argument ' + args[-2])
pattern = res.group(1)
if len(egrep([pattern, file])) < 4:
print(f"WARNING: pattern '{pattern}' not found in file {file}")
sed(args)

check_sed(['-i', '-r', f's/version 2[.][0-9]+([.][0-9]+)*/version {new_version}/', 'cli/main.cpp'])
check_sed(['-i', '-r', f's/VERSION 2[.][0-9]+[.]99/VERSION {v3}/', 'CMakeLists.txt']) # version must have 3 parts.
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION_STRING .*/#define CPPCHECK_VERSION_STRING "{cppcheck_version_string}"/', 'lib/version.h'])
check_sed(['-i', '-r', f's/#define CPPCHECK_VERSION .*/#define CPPCHECK_VERSION {cppcheck_version}/', 'lib/version.h'])
check_sed(['-i', '-r', f's/<[?]define ProductName[ ]*=.*/<?define ProductName = "Cppcheck $(var.Platform) {cppcheck_version_string}" ?>/', 'win_installer/productInfo.wxi'])
check_sed(['-i', '-r', f's/<[?]define ProductVersion[ ]*=.*/<?define ProductVersion = "{new_version}" ?>/', 'win_installer/productInfo.wxi'])
for g in glob.glob('man/*.md'):
check_sed(['-i', '-r', f's/subtitle: Version 2\.[0-9].*/subtitle: Version {cppcheck_version_string}/', g])
print('Versions have been changed.')
print('')
print('Please double check these results below:')
for p in ('[^.0-9]2[.][0-9]+[.][0-9]', '2[.][0-9]+ dev'):
for ext in ('cpp', 'h', 'md'):
for g in glob.glob(f'*/*.{ext}'):
s = egrep([p, g])
if s != '':
print(f'{g}: {s}')
print('')
print("Please double check output of 'git diff'")
commit_message = f'bumped version to {new_version}' if is_dev_version else f'{new_version}: Set version'
print(f"git commit -a -m {commit_message}")

if len(sys.argv) != 2:
print('Syntax: python3 release-set-version.py [version]')
sys.exit(1)

set_version(sys.argv[-1])