MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / set_version

Function set_version

tools/release-set-version.py:43–97  ·  view source on GitHub ↗
(new_version:str)

Source from the content-addressed store, hash-verified

41
42
43def 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
99if len(sys.argv) != 2:
100 print('Syntax: python3 release-set-version.py [version]')

Callers 1

Calls 7

is_uncommitted_changesFunction · 0.85
get_current_branchFunction · 0.85
strFunction · 0.85
check_sedFunction · 0.85
egrepFunction · 0.85
matchMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected