##// 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 58 all: build doc
59 59
60 60 local:
61 $(PYTHON) setup.py $(PURE) \
61 MERCURIAL_SETUP_MAKE_LOCAL=1 $(PYTHON) setup.py $(PURE) \
62 62 build_py -c -d . \
63 63 build_ext $(COMPILERFLAG) -i \
64 64 build_hgexe $(COMPILERFLAG) -i \
@@ -21,6 +21,11 b' def sysstr(s):'
21 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 29 import ssl
25 30
26 31 # ssl.HAS_TLSv1* are preferred to check support but they were added in Python
@@ -292,10 +297,11 b' def findhg():'
292 297 if retcode == 0 and not filterhgerr(err):
293 298 return hgcommand(hgcmd, hgenv)
294 299
295 raise SystemExit(
296 'Unable to find a working hg binary to extract the '
297 'version from the repository tags'
298 )
300 eprint("/!\\")
301 eprint(r"/!\ Unable to find a working hg binary")
302 eprint(r"/!\ Version cannot be extract from the repository")
303 eprint(r"/!\ Re-run the setup once a first version is built")
304 return None
299 305
300 306
301 307 def localhgenv():
@@ -320,33 +326,46 b' def localhgenv():'
320 326
321 327 version = ''
322 328
323 if os.path.isdir('.hg'):
329
330 def _try_get_version():
324 331 hg = findhg()
332 if hg is None:
333 return ''
334 hgid = None
335 numerictags = []
325 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 339 hgid = sysstr(hg.run(['id', '-i'])).strip()
328 340 if not hgid:
329 # Bail out if hg is having problems interacting with this repository,
330 # rather than falling through and producing a bogus version number.
331 # Continuing with an invalid version number will break extensions
332 # that define minimumhgversion.
333 raise SystemExit('Unable to determine hg version from local repository')
341 eprint("/!\\")
342 eprint(r"/!\ Unable to determine hg version from local repository")
343 eprint(r"/!\ Failed to retrieve current revision tags")
344 return ''
334 345 if numerictags: # tag(s) found
335 346 version = numerictags[-1]
336 347 if hgid.endswith('+'): # propagate the dirty status to the tag
337 348 version += '+'
338 else: # no tag found
349 else: # no tag found on the checked out revision
339 350 ltagcmd = ['parents', '--template', '{latesttag}']
340 351 ltag = sysstr(hg.run(ltagcmd))
341 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 359 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag]
344 360 changessince = len(hg.run(changessincecmd).splitlines())
345 if ltag == 'null':
346 ltag = '0.0'
347 361 version = '%s+hg%s.%s' % (ltag, changessince, hgid)
348 362 if version.endswith('+'):
349 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 369 elif os.path.exists('.hg_archival.txt'):
351 370 kw = dict(
352 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 385 with open('mercurial/__version__.py') as f:
367 386 data = f.read()
368 387 version = re.search('version = b"(.*)"', data).group(1)
369
370 if version:
371 versionb = version
372 if not isinstance(versionb, bytes):
373 versionb = versionb.encode('ascii')
388 if not version:
389 if os.environ.get("MERCURIAL_SETUP_MAKE_LOCAL") == "1":
390 version = "0.0+0"
391 eprint("/!\\")
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(
376 'mercurial/__version__.py',
377 b''.join(
378 [
379 b'# this file is autogenerated by setup.py\n'
380 b'version = b"%s"\n' % versionb,
381 ]
382 ),
383 )
404 versionb = version
405 if not isinstance(versionb, bytes):
406 versionb = versionb.encode('ascii')
407
408 write_if_changed(
409 'mercurial/__version__.py',
410 b''.join(
411 [
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 419 class hgbuild(build):
General Comments 0
You need to be logged in to leave comments. Login now