Skip to content

Commit 965197d

Browse files
committed
add version for binaries to meson build; show binary version on startup; create meson install commands
1 parent dfbbf9b commit 965197d

File tree

9 files changed

+101
-2
lines changed

9 files changed

+101
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ __pycache__
2828

2929
# from Spyder
3030
.spyproject
31+
3132
# GSAS binaries
3233
GSASII/bindist
34+
GSASII/bin
3335

3436
# Local dev env files
3537
.vscode

GSASII/GSASIIpath.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,20 @@ def TestSPG():
11541154
'''Test if pyspg.[so,.pyd] can be run from a location in the existing path
11551155
Do not modify the path if not.
11561156
'''
1157+
def showVersion():
1158+
try:
1159+
f = os.path.join(os.path.dirname(pyspg.__file__),'GSASIIversion.txt')
1160+
with open(f,'r') as fp:
1161+
version = fp.readline().strip()
1162+
vnum = fp.readline().strip()
1163+
print(f' Binary ver: {vnum}, {version}')
1164+
except:
1165+
if GetConfigValue('debug'):
1166+
print(' Binaries: undated')
11571167
try:
11581168
from . import pyspg
11591169
pyspg
1170+
showVersion()
11601171
return True
11611172
except ImportError:
11621173
pass
@@ -1172,6 +1183,7 @@ def TestSPG():
11721183
print(f'Module pyspg in {pyspg.__file__} could not be run\nerror msg: {err}')
11731184
print(70*'=')
11741185
return False
1186+
showVersion()
11751187
return True
11761188

11771189
def pathhack_TestSPG(fpth):

sources/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
21
*module.c
3-
*-f2pywrappers.f
2+
*-f2pywrappers.f
3+
GSASIIversion.txt

sources/install.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set OUTDIR=%USERPROFILE%\.GSASII\bin
2+
copy /y "%MESON_BUILD_ROOT%\sources\"*.so ${OUTDIR}\
3+
copy /y "%MESON_BUILD_ROOT%\sources\"*/*.so ${OUTDIR}\
4+
copy /y "%MESON_BUILD_ROOT%\sources\"LATTIC ${OUTDIR}\
5+
copy /y "%MESON_BUILD_ROOT%\sources\"convcell ${OUTDIR}\
6+
copy /y "%MESON_BUILD_ROOT%\sources\"GSAS*.txt ${OUTDIR}\

sources/install.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
OUTDIR=~/.GSASII/bin
3+
mkdir -p ${OUTDIR}
4+
cp -v "${MESON_BUILD_ROOT}/sources/"*.so ${OUTDIR}/
5+
cp -v "${MESON_BUILD_ROOT}/sources/"*/*.so ${OUTDIR}/
6+
cp -v "${MESON_BUILD_ROOT}/sources/"LATTIC ${OUTDIR}/
7+
cp -v "${MESON_BUILD_ROOT}/sources/"convcell ${OUTDIR}/
8+
cp -v "${MESON_BUILD_ROOT}/sources/"GSAS*.txt ${OUTDIR}/

sources/meson.build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,17 @@ executable('convcell', files('convcell.f'), install:true)
203203
#executable('LATTIC', files('LATTIC.f'), link_with:NISTlatsubs_lib, install:true)
204204
executable('LATTIC', files('LATTIC.f','NISTlatsubs/BLOCKDATA1.f'), link_with:NISTlatsubs_lib, install:true)
205205
subdir('k_vec_cython')
206+
207+
# create text file with version info
208+
r = run_command(py, 'tagbinaries.py', check:true)
209+
210+
if host_machine.system() == 'windows'
211+
install = files('install.bat')
212+
sysinstall = files('sysinstall.bat')
213+
else
214+
install = files('install.sh')
215+
sysinstall = files('sysinstall.sh')
216+
endif
217+
218+
r = run_target('local-install', command: install)
219+
r = run_target('system-install', command: sysinstall)

sources/sysinstall.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set OUTDIR=%MESON_SOURCE_ROOT%\GSASII\bin
2+
copy /y "%MESON_BUILD_ROOT%\sources\"*.so ${OUTDIR}\
3+
copy /y "%MESON_BUILD_ROOT%\sources\"*/*.so ${OUTDIR}\
4+
copy /y "%MESON_BUILD_ROOT%\sources\"LATTIC ${OUTDIR}\
5+
copy /y "%MESON_BUILD_ROOT%\sources\"convcell ${OUTDIR}\
6+
copy /y "%MESON_BUILD_ROOT%\sources\"GSAS*.txt ${OUTDIR}\

sources/sysinstall.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
OUTDIR=${MESON_SOURCE_ROOT}/GSASII/bin
3+
mkdir -p ${OUTDIR}
4+
cp -v "${MESON_BUILD_ROOT}/sources/"*.so ${OUTDIR}/
5+
cp -v "${MESON_BUILD_ROOT}/sources/"*/*.so ${OUTDIR}/
6+
cp -v "${MESON_BUILD_ROOT}/sources/"LATTIC ${OUTDIR}/
7+
cp -v "${MESON_BUILD_ROOT}/sources/"convcell ${OUTDIR}/
8+
cp -v "${MESON_BUILD_ROOT}/sources/"GSAS*.txt ${OUTDIR}/

sources/tagbinaries.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)