| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import re |
| 11 |
import sys |
| 12 |
import copy |
| 13 |
|
| 14 |
manifest_match = "<version>(\d+)\.(\d+)\.(\d+)</version>" |
| 15 |
|
| 16 |
|
| 17 |
if __name__ == '__main__': |
| 18 |
bump = "patch" |
| 19 |
if len(sys.argv) > 1: |
| 20 |
bump = sys.argv[1] |
| 21 |
if bump not in {"major","minor","patch"}: |
| 22 |
print sys.argv[0]+" [major|minor|patch] (default: patch)" |
| 23 |
exit(-1) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
manifests=["octomap/package.xml","octovis/package.xml","dynamicEDT3D/package.xml"] |
| 28 |
cmakelists=["octomap/CMakeLists.txt","octovis/CMakeLists.txt","dynamicEDT3D/CMakeLists.txt"] |
| 29 |
versions = [] |
| 30 |
|
| 31 |
|
| 32 |
for manifest in manifests: |
| 33 |
with open(manifest, 'r') as f: |
| 34 |
package_str = f.read() |
| 35 |
match = re.search(manifest_match, package_str) |
| 36 |
if match is None: |
| 37 |
print "Error: no version tag found in %s" % manifest |
| 38 |
exit(-1) |
| 39 |
else: |
| 40 |
v= match.groups() |
| 41 |
v = [int(x) for x in v] |
| 42 |
versions.append(v) |
| 43 |
|
| 44 |
|
| 45 |
for cmake in cmakelists: |
| 46 |
with open(cmake, 'r') as f: |
| 47 |
cmake_str = f.read() |
| 48 |
v = [] |
| 49 |
for m in ["MAJOR","MINOR","PATCH"]: |
| 50 |
searchstr = "_%s_VERSION (\d+)\)" % m |
| 51 |
match = re.search(searchstr, cmake_str) |
| 52 |
if match is None: |
| 53 |
print "Error: no version tag %s found in %s" % (searchstr,cmake) |
| 54 |
exit(-1) |
| 55 |
|
| 56 |
v.append(int(match.group(1))) |
| 57 |
|
| 58 |
versions.append(v) |
| 59 |
|
| 60 |
new_version = copy.deepcopy(versions[0]) |
| 61 |
for v in versions: |
| 62 |
if v != versions[0]: |
| 63 |
print "Error: check current versions, mismatch: %d.%d.%d vs. %d.%d.%d" %(tuple(v)+tuple(versions[0])) |
| 64 |
exit(-1) |
| 65 |
|
| 66 |
print "OctoMap component versions found: %d.%d.%d" % tuple(versions[0]) |
| 67 |
|
| 68 |
|
| 69 |
idx = dict(major=0, minor=1, patch=2)[bump] |
| 70 |
|
| 71 |
new_version[idx] += 1 |
| 72 |
|
| 73 |
new_version = new_version[:idx + 1] + [0 for x in new_version[idx + 1:]] |
| 74 |
new_version_str = "%d.%d.%d" % tuple(new_version) |
| 75 |
print 'Updating to new version: %s\n' % new_version_str |
| 76 |
|
| 77 |
|
| 78 |
for cmake in cmakelists: |
| 79 |
with open(cmake, 'r') as f: |
| 80 |
cmake_str = f.read() |
| 81 |
idx = dict(MAJOR=0, MINOR=1, PATCH=2) |
| 82 |
for m in ["MAJOR","MINOR","PATCH"]: |
| 83 |
old_str = "_%s_VERSION %d)" % (m,versions[0][idx[m]]) |
| 84 |
new_str = "_%s_VERSION %d)" % (m,new_version[idx[m]]) |
| 85 |
cmake_str = cmake_str.replace(old_str, new_str) |
| 86 |
|
| 87 |
with open(cmake, 'w') as f: |
| 88 |
f.write(cmake_str) |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
for manifest in manifests: |
| 94 |
with open(manifest, 'r') as f: |
| 95 |
package_str = f.read() |
| 96 |
old_str = "<version>%d.%d.%d</version>" % tuple(versions[0]) |
| 97 |
new_str = "<version>%s</version>" % new_version_str |
| 98 |
new_package_str = package_str.replace(old_str, new_str) |
| 99 |
|
| 100 |
with open(manifest, 'w') as f: |
| 101 |
f.write(new_package_str) |
| 102 |
|
| 103 |
print "Finished writing package.xml and CMakeLists.txt files.\n" |
| 104 |
print "Now check the output, adjust CHANGELOG, and \"git commit\".\nFinally, run:" |
| 105 |
print " git checkout master && git merge --no-ff devel && git tag v%s" % new_version_str |
| 106 |
print " git push origin master devel && git push --tags" |
| 107 |
print "\n(adjust when not on the \"devel\" branch)\n" |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|