##// END OF EJS Templates
setup: further improve the error path for version retrieval...
marmoute -
r50988:010a1e73 stable
parent child Browse files
Show More
@@ -58,7 +58,7 b' help:'
58 all: build doc
58 all: build doc
59
59
60 local:
60 local:
61 $(PYTHON) setup.py $(PURE) \
61 MERCURIAL_SETUP_MAKE_LOCAL=1 $(PYTHON) setup.py $(PURE) \
62 build_py -c -d . \
62 build_py -c -d . \
63 build_ext $(COMPILERFLAG) -i \
63 build_ext $(COMPILERFLAG) -i \
64 build_hgexe $(COMPILERFLAG) -i \
64 build_hgexe $(COMPILERFLAG) -i \
@@ -21,6 +21,11 b' def sysstr(s):'
21 return s.decode('latin-1')
21 return s.decode('latin-1')
22
22
23
23
24 def eprint(*args, **kwargs):
25 kwargs['file'] = sys.stderr
26 print(*args, **kwargs)
27
28
24 import ssl
29 import ssl
25
30
26 # ssl.HAS_TLSv1* are preferred to check support but they were added in Python
31 # ssl.HAS_TLSv1* are preferred to check support but they were added in Python
@@ -292,10 +297,11 b' def findhg():'
292 if retcode == 0 and not filterhgerr(err):
297 if retcode == 0 and not filterhgerr(err):
293 return hgcommand(hgcmd, hgenv)
298 return hgcommand(hgcmd, hgenv)
294
299
295 raise SystemExit(
300 eprint("/!\\")
296 'Unable to find a working hg binary to extract the '
301 eprint(r"/!\ Unable to find a working hg binary")
297 'version from the repository tags'
302 eprint(r"/!\ Version cannot be extract from the repository")
298 )
303 eprint(r"/!\ Re-run the setup once a first version is built")
304 return None
299
305
300
306
301 def localhgenv():
307 def localhgenv():
@@ -320,33 +326,46 b' def localhgenv():'
320
326
321 version = ''
327 version = ''
322
328
323 if os.path.isdir('.hg'):
329
330 def _try_get_version():
324 hg = findhg()
331 hg = findhg()
332 if hg is None:
333 return ''
334 hgid = None
335 numerictags = []
325 cmd = ['log', '-r', '.', '--template', '{tags}\n']
336 cmd = ['log', '-r', '.', '--template', '{tags}\n']
326 numerictags = [t for t in sysstr(hg.run(cmd)).split() if t[0:1].isdigit()]
337 pieces = sysstr(hg.run(cmd)).split()
338 numerictags = [t for t in pieces if t[0:1].isdigit()]
327 hgid = sysstr(hg.run(['id', '-i'])).strip()
339 hgid = sysstr(hg.run(['id', '-i'])).strip()
328 if not hgid:
340 if not hgid:
329 # Bail out if hg is having problems interacting with this repository,
341 eprint("/!\\")
330 # rather than falling through and producing a bogus version number.
342 eprint(r"/!\ Unable to determine hg version from local repository")
331 # Continuing with an invalid version number will break extensions
343 eprint(r"/!\ Failed to retrieve current revision tags")
332 # that define minimumhgversion.
344 return ''
333 raise SystemExit('Unable to determine hg version from local repository')
334 if numerictags: # tag(s) found
345 if numerictags: # tag(s) found
335 version = numerictags[-1]
346 version = numerictags[-1]
336 if hgid.endswith('+'): # propagate the dirty status to the tag
347 if hgid.endswith('+'): # propagate the dirty status to the tag
337 version += '+'
348 version += '+'
338 else: # no tag found
349 else: # no tag found on the checked out revision
339 ltagcmd = ['parents', '--template', '{latesttag}']
350 ltagcmd = ['parents', '--template', '{latesttag}']
340 ltag = sysstr(hg.run(ltagcmd))
351 ltag = sysstr(hg.run(ltagcmd))
341 if not ltag:
352 if not ltag:
342 ltag = 'null'
353 eprint("/!\\")
354 eprint(r"/!\ Unable to determine hg version from local repository")
355 eprint(
356 r"/!\ Failed to retrieve current revision distance to lated tag"
357 )
358 return ''
343 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag]
359 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag]
344 changessince = len(hg.run(changessincecmd).splitlines())
360 changessince = len(hg.run(changessincecmd).splitlines())
345 if ltag == 'null':
346 ltag = '0.0'
347 version = '%s+hg%s.%s' % (ltag, changessince, hgid)
361 version = '%s+hg%s.%s' % (ltag, changessince, hgid)
348 if version.endswith('+'):
362 if version.endswith('+'):
349 version = version[:-1] + 'local' + time.strftime('%Y%m%d')
363 version = version[:-1] + 'local' + time.strftime('%Y%m%d')
364 return version
365
366
367 if os.path.isdir('.hg'):
368 version = _try_get_version()
350 elif os.path.exists('.hg_archival.txt'):
369 elif os.path.exists('.hg_archival.txt'):
351 kw = dict(
370 kw = dict(
352 [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')]
371 [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')]
@@ -366,21 +385,35 b" elif os.path.exists('mercurial/__version"
366 with open('mercurial/__version__.py') as f:
385 with open('mercurial/__version__.py') as f:
367 data = f.read()
386 data = f.read()
368 version = re.search('version = b"(.*)"', data).group(1)
387 version = re.search('version = b"(.*)"', data).group(1)
369
388 if not version:
370 if version:
389 if os.environ.get("MERCURIAL_SETUP_MAKE_LOCAL") == "1":
371 versionb = version
390 version = "0.0+0"
372 if not isinstance(versionb, bytes):
391 eprint("/!\\")
373 versionb = versionb.encode('ascii')
392 eprint(r"/!\ Using '0.0+0' as the default version")
393 eprint(r"/!\ Re-run make local once that first version is built")
394 eprint("/!\\")
395 else:
396 eprint("/!\\")
397 eprint(r"/!\ Could not determine the Mercurial version")
398 eprint(r"/!\ You need to build a local version first")
399 eprint(r"/!\ Run `make local` and try again")
400 eprint("/!\\")
401 msg = "Run `make local` first to get a working local version"
402 raise SystemExit(msg)
374
403
375 write_if_changed(
404 versionb = version
376 'mercurial/__version__.py',
405 if not isinstance(versionb, bytes):
377 b''.join(
406 versionb = versionb.encode('ascii')
378 [
407
379 b'# this file is autogenerated by setup.py\n'
408 write_if_changed(
380 b'version = b"%s"\n' % versionb,
409 'mercurial/__version__.py',
381 ]
410 b''.join(
382 ),
411 [
383 )
412 b'# this file is autogenerated by setup.py\n'
413 b'version = b"%s"\n' % versionb,
414 ]
415 ),
416 )
384
417
385
418
386 class hgbuild(build):
419 class hgbuild(build):
General Comments 0
You need to be logged in to leave comments. Login now