CONQUEST-release icon indicating copy to clipboard operation
CONQUEST-release copied to clipboard

Find safer way to get date and git info during build

Open tkoskela opened this issue 2 years ago • 5 comments

Currently the makefile extracts the current date and time and the git branch and hash via a mixture of sed and shell commands. I found this fails, e.g. when I have a / in the git branch name. There might be a safer way to get this information.

https://github.com/OrderN/CONQUEST-release/blob/3a6e1f697e0bd3fd1101715e56bf3c7b7a7fde63/src/Makefile#L61

tkoskela avatar May 24 '23 11:05 tkoskela

I think this should be doable without sed by passing the date, time and the git information through preprocessor variables and then having some #ifdef blocks in the code that grab the value. This would have the advantage of

  1. Not having to deal with special characters in sed
  2. Not relying on writing source files from the Makefile
  3. Being able to default to something meaningful if something fails.
  4. Improving the readability

tkoskela avatar May 24 '23 12:05 tkoskela

https://stackoverflow.com/questions/1704907/how-can-i-get-my-c-code-to-automatically-print-out-its-git-version-hash/

tkoskela avatar May 25 '23 13:05 tkoskela

Yes, but also see the linked answer on how to sort out dependencies and updates:

https://stackoverflow.com/questions/3236145/force-gnu-make-to-rebuild-objects-affected-by-compiler-definition

davidbowler avatar May 25 '23 13:05 davidbowler

How about this? It creates a source file but from within Make (which I think is more reliable than sed!)

deps.obj.inc: $(SRCS_NODS) system.make
	touch $(COMMENT)
	$(ECHOSTR) "module datestamp" > datestamp.f90
	$(ECHOSTR) "  implicit none" >> datestamp.f90
	$(ECHOSTR) '  character(len=*), parameter :: datestr="'`date "+%Y/%m/%d at %H:%M %z"`'"' >> datestamp.f90
	$(ECHOSTR) '  character(len=*), parameter :: commentver="'`git describe --abbrev=4 --dirty --always --tags`'"' >> datestamp.f90
	$(ECHOSTR) "end module datestamp" >> datestamp.f90
	./makedeps makedeps.txt $^
	sed /"^mpi.o"/D makedeps.txt > deps.obj.inc

davidbowler avatar May 26 '23 14:05 davidbowler

The alternative would be to create a file datestamp.fpp or something which had DATE and VERSION within it, and to run that through a preprocessor to create datestamp.f90.

davidbowler avatar May 26 '23 14:05 davidbowler

This has been resolved as far as I can tell.

davidbowler avatar Feb 12 '25 16:02 davidbowler