Skip to content

Commit 1e7c846

Browse files
committed
Fix version number detection
1 parent 49577e2 commit 1e7c846

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323
string(TOLOWER "${BOB_SYSTEM_NAME}-${BOB_SYSTEM_PROCESSOR}-${CMAKE_BUILD_TYPE}" BOB_PLATFORM_STR)
2424
set(BOB_PLATFORM "${BOB_PLATFORM_STR}" CACHE STRING "The name of the platform Bob is being built to")
2525

26-
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/bin/version.py --counter=0 OUTPUT_VARIABLE BOB_DISCOVERED_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
26+
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/bin/version.py --letter=a --counter=0 OUTPUT_VARIABLE BOB_DISCOVERED_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
2727
set(BOB_VERSION_INTERNAL "${BOB_DISCOVERED_VERSION}" CACHE INTERNAL "The version of Bob that is currently being built")
2828
if(NOT BOB_VERSION)
2929
set(BOB_VERSION ${BOB_VERSION_INTERNAL})

bin/version.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
VERSION_RE = re.compile(r'^\d+\.\d+\.\d+$')
2121
BOB_REPOSITORY = 'https://github.com/idiap/bob.git'
2222

23-
def git_remote_version_branches():
23+
def git_remote_version_branches(verbose):
2424
"""Get the branches available on the origin using git ls-remote"""
2525

2626
try:
@@ -34,9 +34,10 @@ def git_remote_version_branches():
3434
return [k for k in cand if BRANCH_RE.match(k)]
3535

3636
except:
37-
print "Warning: could retrieve remote branch list"
37+
if verbose:
38+
print "Warning: could retrieve remote branch list"
3839

39-
def git_version_branches():
40+
def git_version_branches(verbose):
4041
"""Get the branches available on the origin"""
4142

4243
try:
@@ -50,9 +51,10 @@ def git_version_branches():
5051
return [k for k in cand if k and BRANCH_RE.match(k)]
5152

5253
except:
53-
print "Warning: could retrieve branch list"
54+
if verbose:
55+
print "Warning: could retrieve branch list"
5456

55-
def git_current_branch():
57+
def git_current_branch(verbose):
5658
"""Get the current branch we are sitting on"""
5759

5860
try:
@@ -70,9 +72,10 @@ def git_current_branch():
7072
raise RuntimeError
7173

7274
except:
73-
print "Warning: could not determine in which branch I'm on"
75+
if verbose:
76+
print "Warning: could not determine in which branch I'm on"
7477

75-
def git_next_minor_version(branch):
78+
def git_next_minor_version(branch, verbose):
7679
"""Gets the next minor version"""
7780

7881
try:
@@ -93,19 +96,20 @@ def git_next_minor_version(branch):
9396
return '.'.join([str(k) for k in next_version])
9497

9598
except:
96-
print "Warning: could not determine latest tag on branch (%s). Assuming it is %s.0" % (branch, branch)
99+
if verbose:
100+
print "Warning: could not determine latest tag on branch (%s). Assuming it is %s.0" % (branch, branch)
97101
return branch + '.0'
98102

99-
def git_next_major_version():
103+
def git_next_major_version(verbose):
100104
"""Gets the next major version"""
101105

102106
# try local
103-
candidates = sorted([StrictVersion(k) for k in git_version_branches()])
107+
candidates = sorted([StrictVersion(k) for k in git_version_branches(verbose)])
104108

105109
if not candidates:
106110
# try remote
107111
candidates = \
108-
sorted([StrictVersion(k) for k in git_remote_version_branches()])
112+
sorted([StrictVersion(k) for k in git_remote_version_branches(verbose)])
109113

110114
if not candidates:
111115
return None
@@ -118,18 +122,18 @@ def git_next_major_version():
118122

119123
return '.'.join([str(k) for k in next_version])
120124

121-
def git_next_version(branch):
125+
def git_next_version(branch, verbose):
122126
"""Gets the next version given the branch I'm on"""
123127

124128
if BRANCH_RE.match(branch):
125129
# we are on a stable branch
126-
return git_next_minor_version(branch)
130+
return git_next_minor_version(branch, verbose)
127131

128132
else:
129133
# we are on the master tip
130-
return git_next_major_version()
134+
return git_next_major_version(verbose)
131135

132-
def git_count(branch):
136+
def git_count(branch, verbose):
133137
"""Count the number of commits in the repository.
134138
135139
Note: This does not work right for shallow git clones.
@@ -145,14 +149,15 @@ def git_count(branch):
145149
return stdout.count('\n')
146150

147151
except:
148-
print "Warning: could not determine commit count on branch '%s'" % branch
152+
if verbose:
153+
print "Warning: could not determine commit count on branch '%s'" % branch
149154

150-
def package_version():
155+
def package_version(verbose):
151156
"""Interprets the package version from the directory name"""
152157

153158
dirname = os.path.basename(os.path.realpath(os.curdir))
154159

155-
match = re.match(r'^bob[-_](\d+\.\d+\.\d+[abcd]\d+)$', dirname)
160+
match = re.match(r'^bob[-_](\d+\.\d+\.\d+([abcd]\d+)?)$', dirname)
156161

157162
if match: return match.groups()[0]
158163

@@ -164,8 +169,9 @@ def package_version():
164169

165170
parser = optparse.OptionParser()
166171
parser.add_option("-v", "--version", dest="version", metavar='VERSION', help="force version to a given string (format M.m.p; by default calculates the version number of the next build based on the currently existing branch and tags)", type='str')
167-
parser.add_option("-l", "--letter", dest="letter", metavar='LETTER', choices=('a', 'b', 'c'), default='a', help="force the suffix letter to be one of ([a]alpha, [b]beta, [c]candidate; defaults to 'a')")
172+
parser.add_option("-l", "--letter", dest="letter", metavar='LETTER', choices=('a', 'b', 'c'), help="force the suffix letter to be one of ([a]alpha, [b]beta, [c]candidate; defaults to None)")
168173
parser.add_option("-c", "--counter", dest="count", metavar='COUNT', type='int', help="force the counter after the letter (by default use number of commits in the current branch)")
174+
parser.add_option("-V", "--verbose", dest="verbose", default=False, action='store_true', help="be verbose about potential issues (warnings)")
169175

170176
(options, args) = parser.parse_args()
171177

@@ -182,22 +188,27 @@ def package_version():
182188
# change directories to my parent's
183189
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
184190

185-
branch = git_current_branch()
191+
branch = git_current_branch(options.verbose)
186192

187193
if options.version is None:
188-
options.version = package_version()
194+
options.version = package_version(options.verbose)
189195

190196
if not options.version:
191197
if branch is not None:
192-
options.version = git_next_version(branch)
198+
options.version = git_next_version(branch, options.verbose)
193199

194200
if options.count is None:
195-
options.count = git_count(branch)
201+
options.count = git_count(branch, options.verbose)
196202

197-
if not options.version: print 'unknown'
198-
else:
203+
if not options.version:
204+
print 'unknown'
205+
elif options.letter:
199206
final = options.version + options.letter + str(options.count)
200207
StrictVersion(final) #double-checks all is good
201208
print final
209+
else:
210+
final = options.version
211+
StrictVersion(final) #double-checks all is good
212+
print final
202213

203214
sys.exit(0)

0 commit comments

Comments
 (0)