File: increase_version.py

package info (click to toggle)
octomap 1.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 2,880 kB
  • ctags: 1,391
  • sloc: cpp: 9,871; python: 71; xml: 59; makefile: 47
file content (113 lines) | stat: -rwxr-xr-x 3,451 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python

# Increases the version number of package.xml and CMakeLists.txt files in
# subfolders. The first argument specifies the version increase:
# major, minor, or patch (default, e.g. 1.6.2 --> 1.6.3)
#
# Borrows heaviliy from ROS / catkin release tools


import re
import sys
import copy

manifest_match = "<version>(\d+)\.(\d+)\.(\d+)</version>"


if __name__ == '__main__':
  bump = "patch"
  if len(sys.argv) > 1:
    bump = sys.argv[1]
    if bump not in {"major","minor","patch"}:
      print sys.argv[0]+" [major|minor|patch] (default: patch)"
      exit(-1)
  
  
  
  manifests=["octomap/package.xml","octovis/package.xml","dynamicEDT3D/package.xml"]
  cmakelists=["octomap/CMakeLists.txt","octovis/CMakeLists.txt","dynamicEDT3D/CMakeLists.txt"]
  versions = []

  # find versions in package.xml
  for manifest in manifests:
    with open(manifest, 'r') as f:
      package_str = f.read()
    match = re.search(manifest_match, package_str)
    if match is None:
      print "Error: no version tag found in %s" % manifest
      exit(-1)
    else:
      v= match.groups()
      v = [int(x) for x in v]
      versions.append(v)

  # find version in CMakeLists:
  for cmake in cmakelists:
    with open(cmake, 'r') as f:
      cmake_str = f.read()
    v = []
    for m in ["MAJOR","MINOR","PATCH"]:
      searchstr = "_%s_VERSION (\d+)\)" % m
      match = re.search(searchstr, cmake_str)
      if match is None:
        print "Error: no version tag %s found in %s" % (searchstr,cmake)
        exit(-1)
      
      v.append(int(match.group(1)))

    versions.append(v)
  
  new_version = copy.deepcopy(versions[0])
  for v in versions:
    if v != versions[0]:
      print "Error: check current versions, mismatch: %d.%d.%d vs. %d.%d.%d" %(tuple(v)+tuple(versions[0]))
      exit(-1)

  print "OctoMap component versions found: %d.%d.%d" % tuple(versions[0])
  # "bump version" from catkin:
  # find the desired index
  idx = dict(major=0, minor=1, patch=2)[bump]
  # increment the desired part
  new_version[idx] += 1
  # reset all parts behind the bumped part
  new_version = new_version[:idx + 1] + [0 for x in new_version[idx + 1:]]
  new_version_str = "%d.%d.%d" % tuple(new_version)
  print 'Updating to new version: %s\n' % new_version_str

  # adjust CMakeLists
  for cmake in cmakelists:
    with open(cmake, 'r') as f:
      cmake_str = f.read()
    idx = dict(MAJOR=0, MINOR=1, PATCH=2)
    for m in ["MAJOR","MINOR","PATCH"]:      
      old_str = "_%s_VERSION %d)" % (m,versions[0][idx[m]])
      new_str = "_%s_VERSION %d)" % (m,new_version[idx[m]])
      cmake_str = cmake_str.replace(old_str, new_str)

    with open(cmake, 'w') as f:
      f.write(cmake_str)

    

  # adjust package.xml
  for manifest in manifests:
    with open(manifest, 'r') as f:
      package_str = f.read()
    old_str = "<version>%d.%d.%d</version>" % tuple(versions[0])
    new_str = "<version>%s</version>" % new_version_str
    new_package_str = package_str.replace(old_str, new_str)

    with open(manifest, 'w') as f:
      f.write(new_package_str)

  print "Finished writing package.xml and CMakeLists.txt files.\n"
  print "Now check the output, adjust CHANGELOG, and \"git commit\".\nFinally, run:"
  print "  git checkout master && git merge --no-ff devel && git tag v%s" % new_version_str
  print "  git push origin master devel && git push --tags"
  print "\n(adjust when not on the \"devel\" branch)\n"