From f7eb0af9b6fec3d421b45040feb5abb559ddd595 Mon Sep 17 00:00:00 2001 From: Alex Kleb Date: Mon, 18 Apr 2022 15:03:13 -0400 Subject: [PATCH] Working git-hash on adflow --- .gitignore | 1 + adflow/__init__.py | 1 + adflow/fortranVersion.py | 15 +++++++++++++++ src/build/Makefile | 26 +++++++++++++++++++++++++- src/build/directoryList | 1 + src/build/fileList | 2 ++ src/f2py/adflow.pyf | 3 +++ 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 adflow/fortranVersion.py diff --git a/.gitignore b/.gitignore index 03c447853..1617af44d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ src/build/adflow_project.dep src/build/libadflow-f2pywrappers2.f90 src/build/libadflowmodule.c src/build/importTest.py +src/build/version.f90 # Regression test auxiliary files: input_files.tar.gz diff --git a/adflow/__init__.py b/adflow/__init__.py index 1320315f0..e74e48a57 100644 --- a/adflow/__init__.py +++ b/adflow/__init__.py @@ -6,3 +6,4 @@ from .pyADflow_C import ADFLOW_C from .oversetCheck import OversetCheck from .checkZipper import checkZipper +from .fortranVersion import fortranVersion diff --git a/adflow/fortranVersion.py b/adflow/fortranVersion.py new file mode 100644 index 000000000..2c79da1d4 --- /dev/null +++ b/adflow/fortranVersion.py @@ -0,0 +1,15 @@ +from .libadflow import version + + +def fortranVersion(): + """ + Return the version of the compiled Fortran code + + Returns + ------- + ver : str + the value of `git describe --dirty --always --tags` at compile time of the libadflow object. + """ + + ver = version() + return ver.decode("utf-8").strip() diff --git a/src/build/Makefile b/src/build/Makefile index 7ddfcbe20..044437a5c 100644 --- a/src/build/Makefile +++ b/src/build/Makefile @@ -10,6 +10,8 @@ CC_ALL_FLAGS = $(C_FLAGS) -I../c_defines -I../metis-4.0 $(PETSC_CC_INCLUDE LINKER_ALL_FLAGS = $(CGNS_LINKER_FLAGS) $(PETSC_LIB) $(LINKER_FLAGS) +GIT_VERSION = $(shell git describe --dirty --always --tags) + # Include the full filelist include fileList @@ -46,10 +48,32 @@ OFILES=$(f90Files:%.f90=%.o) $(F90Files:%.F90=%.o) $(cFilesNoDir:%.c=%.o) $(f77F DEP_FILE=adflow_project.dep # Not real targets are "phony" -.PHONY: sources lib +.PHONY: version sources lib default: all +version: ../build/version.f90 + +../build/version.f90: + @echo "Making auto-generated version file" + @echo GIT_VERSION is $(GIT_VERSION) +# @echo "module fortranversion" > version.f90 +# @echo " use constants, only : maxStringLen" >> version.f90 +# @echo "contains" >> version.f90 + @echo " subroutine version(ver)" > version.f90 + @echo " ! Automatically generated version function" >> version.f90 + @echo " !" >> version.f90 + @echo " ! Desricption of Arguments" >> version.f90 + @echo " ! Output" >> version.f90 + @echo " ! ver - string, contains git tag and commit hash" >> version.f90 + @echo " use precision" >> version.f90 + @echo " implicit none" >> version.f90 + @echo " character(len=256), intent(out) :: ver" >> version.f90 + @echo " " >> version.f90 + @echo " ver = '$(GIT_VERSION)'" >> version.f90 + @echo " end subroutine version" >> version.f90 +# @echo "end module fortranVersion" >> version.f90 + # The 'source's makes all the .o files. It also depends on the dependence file "DEP_FILE". sources: $(OFILES) $(DEP_FILE) diff --git a/src/build/directoryList b/src/build/directoryList index cd87942bb..43672aa75 100644 --- a/src/build/directoryList +++ b/src/build/directoryList @@ -5,6 +5,7 @@ dirs:= adjoint\ adjoint/ADFirstAidKit\ ADT\ bcdata\ + build\ initFlow\ inputParam\ NKSolver\ diff --git a/src/build/fileList b/src/build/fileList index b1cf99855..59fb85467 100644 --- a/src/build/fileList +++ b/src/build/fileList @@ -13,6 +13,8 @@ fortranFiles= ADT/adtUtils.F90\ \ bcdata/BCData.F90\ \ + build/version.f90\ + \ initFlow/variableReading.F90\ initFlow/initializeFlow.F90\ \ diff --git a/src/f2py/adflow.pyf b/src/f2py/adflow.pyf index a8dbea684..99ac28263 100644 --- a/src/f2py/adflow.pyf +++ b/src/f2py/adflow.pyf @@ -1444,6 +1444,9 @@ python module libadflow end subroutine getfam end module surfacefamilies + subroutine version(ver) ! in :test:version.f90 + character(len=256) intent(out) :: ver + end subroutine version end interface