Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find safer way to get date and git info during build #190

Open
tkoskela opened this issue May 24, 2023 · 5 comments
Open

Find safer way to get date and git info during build #190

tkoskela opened this issue May 24, 2023 · 5 comments
Assignees
Labels
area: main-source Relating to the src/ directory (main Conquest source code) improves: stability Fix or enhance issues with stability or robustness time: hours type: bug

Comments

@tkoskela
Copy link
Contributor

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.

sed "s/BBB/"`git symbolic-ref HEAD | cut -b 12-`"/" $(COMMENT) | sed "s/RRR/"`git describe --tags`"/" >> datestamp.f90

@tkoskela tkoskela added area: main-source Relating to the src/ directory (main Conquest source code) improves: stability Fix or enhance issues with stability or robustness type: bug labels May 24, 2023
@tkoskela tkoskela self-assigned this May 24, 2023
@tkoskela
Copy link
Contributor Author

tkoskela commented May 24, 2023

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

@davidbowler
Copy link
Contributor

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
Copy link
Contributor

davidbowler commented May 26, 2023

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: main-source Relating to the src/ directory (main Conquest source code) improves: stability Fix or enhance issues with stability or robustness time: hours type: bug
Projects
None yet
Development

No branches or pull requests

2 participants