|
| 1 | +# this routine is intended to be run from inside meson and creates a |
| 2 | +# file named GSASIIversion.txt with that information |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +import datetime |
| 8 | +source = os.environ.get('MESON_SOURCE_ROOT', |
| 9 | + os.path.dirname(os.path.dirname(__file__))) |
| 10 | +build = os.environ.get('MESON_BUILD_ROOT', |
| 11 | + os.path.dirname(os.path.dirname(__file__))) |
| 12 | + |
| 13 | +if shutil.which('git'): |
| 14 | + out = subprocess.run(['git','tag','-l','--sort=-authordate','v*'], |
| 15 | + stdout=subprocess.PIPE,cwd=source) |
| 16 | + version = out.stdout.decode('latin-1').split('\n')[0].strip() |
| 17 | + out = subprocess.run(['git','tag','-l','--sort=-authordate','[0-9]*'], |
| 18 | + stdout=subprocess.PIPE,cwd=source) |
| 19 | + number = out.stdout.decode('latin-1').split('\n')[0].strip() |
| 20 | + out = subprocess.run(['git','log','HEAD','-1'], |
| 21 | + stdout=subprocess.PIPE,cwd=source) |
| 22 | + githash = out.stdout.decode('latin-1').split('commit')[1].split('\n')[0].strip() |
| 23 | + how = 'git' |
| 24 | +else: |
| 25 | + how = 'git_verinfo' |
| 26 | + try: |
| 27 | + sys.path.insert(0,source) |
| 28 | + from GSASII import git_verinfo |
| 29 | + number = '?' |
| 30 | + githash = git_verinfo.git_version |
| 31 | + version = git_verinfo.git_versiontag |
| 32 | + for item in git_verinfo.git_tags+git_verinfo.git_prevtags: |
| 33 | + if item.isnumeric(): |
| 34 | + number = item |
| 35 | + break |
| 36 | + except: |
| 37 | + sys.exit() |
| 38 | +outfile = os.path.join(build,'sources','GSASIIversion.txt') |
| 39 | +with open(outfile,'w') as fp: |
| 40 | + fp.write(f"{version}\n{number}\ncommit {githash}\n") |
| 41 | + fp.write(f"#created by {__file__} on {datetime.datetime.now()} from {how}\n") |
| 42 | + fp.close() |
| 43 | +print(outfile) |
0 commit comments