comparison setup.py @ 17709:b7fff47bb128

setup: calculate version more correctly The old calculation code failed to properly identify revs that weren't tagged, leaving us with a version of "unknown" most of the time during development.
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 05 Oct 2012 13:44:52 -0500
parents 318fb32b980e
children 93d97a212559
comparison
equal deleted inserted replaced
17708:4f2f0f367ef6 17709:b7fff47bb128
170 # under Windows. Otherwise, the subprocess will fail with 170 # under Windows. Otherwise, the subprocess will fail with
171 # error 0xc0150004. See: http://bugs.python.org/issue3440 171 # error 0xc0150004. See: http://bugs.python.org/issue3440
172 env['SystemRoot'] = os.environ['SystemRoot'] 172 env['SystemRoot'] = os.environ['SystemRoot']
173 173
174 if os.path.isdir('.hg'): 174 if os.path.isdir('.hg'):
175 cmd = [sys.executable, 'hg', 'id', '-i', '-t'] 175 cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n']
176 l = runhg(cmd, env).split() 176 numerictags = [t for t in runhg(cmd, env).split() if t[0].isdigit()]
177 while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags 177 hgid = runhg([sys.executable, 'hg', 'id', '-i'], env).strip()
178 l.pop() 178 if numerictags: # tag(s) found
179 if len(l) > 1: # tag found 179 version = numerictags[-1]
180 version = l[-1] 180 if hgid.endswith('+'): # propagate the dirty status to the tag
181 if l[0].endswith('+'): # propagate the dirty status to the tag
182 version += '+' 181 version += '+'
183 elif len(l) == 1: # no tag found 182 else: # no tag found
184 cmd = [sys.executable, 'hg', 'parents', '--template', 183 cmd = [sys.executable, 'hg', 'parents', '--template',
185 '{latesttag}+{latesttagdistance}-'] 184 '{latesttag}+{latesttagdistance}-']
186 version = runhg(cmd, env) + l[0] 185 version = runhg(cmd, env) + hgid
187 if version.endswith('+'): 186 if version.endswith('+'):
188 version += time.strftime('%Y%m%d') 187 version += time.strftime('%Y%m%d')
189 elif os.path.exists('.hg_archival.txt'): 188 elif os.path.exists('.hg_archival.txt'):
190 kw = dict([[t.strip() for t in l.split(':', 1)] 189 kw = dict([[t.strip() for t in l.split(':', 1)]
191 for l in open('.hg_archival.txt')]) 190 for l in open('.hg_archival.txt')])