Skip to content

Commit

Permalink
BLD: output friendlier error messages from scons.
Browse files Browse the repository at this point in the history
Replace assertion failures with a gentler scons termination.
  • Loading branch information
pavoljuhas committed Jun 21, 2017
1 parent 0e048ce commit 3329f73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 9 additions & 4 deletions site_scons/libdiffpybuildutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

MYDIR = os.path.dirname(os.path.abspath(__file__))

GIT_MISSING_ERROR_MSG = """
EMSG_GIT_MISSING = """
Cannot determine libdiffpy version. Compile from a git repository
or use a source archive from
https://github.com/diffpy/libdiffpy/releases
"""

EMSG_BAD_FALLBACK_VERSION = """
Inconsistent FALLBACK_VERSION {} vs {} from git tag.
"""


def gitinfo():
'Extract dictionary of version data from git records.'
Expand Down Expand Up @@ -65,12 +69,13 @@ def getversion():
if gi:
afb = FALLBACK_VERSION
gfb = gi['version'].split('.post')[0] + '.post0'
emsg = "Inconsistent FALLBACK_VERSION {!r}. Git tag suggests {!r}."
assert gfb == afb, emsg.format(afb, gfb)
if gfb != afb:
raise RuntimeError(EMSG_BAD_FALLBACK_VERSION.format(afb, gfb))
rv.update(gi)
else:
# Not a git repository. Require that gitarchive.cfg is expanded.
assert '$Format:' not in ga['commit'], GIT_MISSING_ERROR_MSG
if '$Format:' in ga['commit']:
raise RuntimeError(EMSG_GIT_MISSING)
rv['commit'] = ga['commit']
rv['date'] = ga['date']
# First assume we have an undetermined post-release. Keep version
Expand Down
13 changes: 11 additions & 2 deletions src/diffpy/SConscript.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import string
Import('env')


def get_version_or_die():
from libdiffpybuildutils import getversion
try:
rv = getversion()
except RuntimeError as e:
print(e)
Exit(1)
return rv


def parsemajorminor(hcode):
'Extract major and minor version from a C++ header file.'
mx = re.search(r'(?m)^#define *DIFFPY_VERSION_MAJOR *(\d+)', hcode)
Expand Down Expand Up @@ -69,9 +79,8 @@ vhpp = File('version.hpp')
if os.path.isfile(str(vhpp.srcnode())):
majorminor = parsemajorminor(vhpp.srcnode().get_contents())
else:
from libdiffpybuildutils import getversion
vtpl = File('version.tpl')
gver = getversion()
gver = get_version_or_die()
vhpp, = env.BuildVersionCode(['version.hpp'], vtpl)
env.Depends(vhpp, env.Value(gver['version'] + gver['commit']))
majorminor = (gver['major'], gver['minor'])
Expand Down

0 comments on commit 3329f73

Please sign in to comment.