build_info.txt generated from script
This commit is contained in:
parent
05a6fb92d5
commit
2613041d53
4 changed files with 50 additions and 31 deletions
|
|
@ -1,8 +1,18 @@
|
|||
|
||||
import os, sys
|
||||
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("term_file", help="name of file containing postprocessing term spec")
|
||||
parser.add_argument("-b", "--build-info", action="store_true", help="print build_info instead of code")
|
||||
args = parser.parse_args()
|
||||
|
||||
from lark import Lark, Visitor, Transformer, v_args, Token
|
||||
|
||||
from post import *
|
||||
|
||||
from resources.m_template import mod_form
|
||||
|
||||
calc_grammar = """
|
||||
?varlist: "[" [NAME ("," NAME)*] "]"
|
||||
|
|
@ -63,35 +73,39 @@ class VersionInfo(object):
|
|||
import os, datetime
|
||||
import subprocess as sp
|
||||
|
||||
bd = 'character (len=*), parameter :: build_date="{}"'
|
||||
bb = 'character (len=*), parameter :: build_base="{}"'
|
||||
bd = 'build date: {}'
|
||||
bb = 'build base: {}'
|
||||
|
||||
self.build_date = bd.format(datetime.datetime.today().ctime())
|
||||
|
||||
try:
|
||||
self.build_base = bb.format(sp.check_output(["git", "rev-parse", "HEAD"]).strip())
|
||||
except subprocess.CalledProcessError:
|
||||
except sp.CalledProcessError:
|
||||
self.build_base = "None"
|
||||
|
||||
tinfo = 'character (len=*), parameter :: term_info={}'
|
||||
try:
|
||||
sp.check_output("git diff --exit-code".split())
|
||||
sp.check_output("git diff --cached --exit-code".split())
|
||||
self.off_base = ""
|
||||
except sp.CalledProcessError:
|
||||
self.off_base = "built with changes not commited"
|
||||
|
||||
self.lines = input_raw.split(os.linesep)
|
||||
tinfo = '''
|
||||
================================================================================
|
||||
************************************ terms *************************************
|
||||
--------------------------------------------------------------------------------
|
||||
{}
|
||||
================================================================================
|
||||
'''
|
||||
|
||||
nl = len(self.lines)
|
||||
|
||||
self.term_info = tinfo.format("//char(10)//".join(map('"{}"'.format, self.lines)))
|
||||
self.term_info = tinfo.format(input_raw)
|
||||
|
||||
def fparams (self):
|
||||
return "\n".join([self.build_date, self.build_base, self.term_info])
|
||||
return "\n".join([self.build_date, self.build_base, self.off_base, self.term_info])
|
||||
|
||||
def test():
|
||||
|
||||
with open("resources/m_template.f90") as template_file:
|
||||
mod_form = template_file.read()
|
||||
|
||||
with open("terms.input") as inputfile:
|
||||
terms_raw = ((inputfile.read()))
|
||||
|
||||
def test(terms_raw):
|
||||
|
||||
tree = Lark(calc_grammar, parser='lalr' ).parse(terms_raw)
|
||||
|
||||
|
|
@ -107,13 +121,24 @@ def test():
|
|||
|
||||
print mod_form.format( cdict )
|
||||
|
||||
# print mod_form.format( ir4.print_program() )
|
||||
|
||||
# print mod_form.format( ir3.print_program() )
|
||||
|
||||
# ir4.save_ir()
|
||||
|
||||
|
||||
|
||||
def build_info(terms_raw):
|
||||
|
||||
vinfo = VersionInfo(terms_raw)
|
||||
|
||||
print vinfo.fparams()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
|
||||
with open(args.term_file) as inputfile:
|
||||
terms_raw = ((inputfile.read()))
|
||||
|
||||
if args.build_info:
|
||||
build_info(terms_raw)
|
||||
else:
|
||||
test(terms_raw)
|
||||
|
|
|
|||
0
code/code_gen/resources/__init__.py
Normal file
0
code/code_gen/resources/__init__.py
Normal file
|
|
@ -1,4 +1,4 @@
|
|||
module m_{0[module_name]}
|
||||
mod_form='''module m_{0[module_name]}
|
||||
|
||||
use m_openmpi
|
||||
use m_parameters
|
||||
|
|
@ -77,3 +77,4 @@ end subroutine m_{0[module_name]}_write_result
|
|||
|
||||
|
||||
end module m_{0[module_name]}
|
||||
'''
|
||||
|
|
@ -39,8 +39,8 @@ x-edge-cold-bc-uPrime-hybrid : ${MODULES} ${OBJ} print_build_info.o build_info.o
|
|||
|
||||
${OBJ} : ${MODULES}
|
||||
|
||||
m_terms.f90 : code_gen/code_gen.py code_gen/terms.input code_gen/resources/m_template.f90
|
||||
cd code_gen && python code_gen.py > ../$@
|
||||
m_terms.f90 : code_gen/code_gen.py code_gen/terms.input code_gen/resources/m_template.py
|
||||
python code_gen/code_gen.py code_gen/terms.input > $@
|
||||
|
||||
%.o: %.f90
|
||||
${compiler} -c ${flags} $<
|
||||
|
|
@ -62,11 +62,4 @@ build_info.o : build_info.txt
|
|||
ld -r -b binary -o build_info.o build_info.txt
|
||||
|
||||
build_info.txt : code_gen/terms.input
|
||||
echo "<<build date>>" > build_info.txt
|
||||
date >> build_info.txt
|
||||
echo "<<build base revision>>" >> build_info.txt
|
||||
git rev-parse HEAD >> build_info.txt
|
||||
echo "<<git status>>" >> build_info.txt
|
||||
git status >> build_info.txt
|
||||
echo "<<terms>>" >> build_info.txt
|
||||
cat code_gen/terms.input >> build_info.txt
|
||||
python code_gen/code_gen.py -b code_gen/terms.input > build_info.txt
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue