implement various suggestions to improve the use of git information gathered

This commit is contained in:
Axel Kohlmeyer 2019-03-05 17:29:34 -05:00
parent 1c7d191988
commit c5a3b034ce
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
5 changed files with 52 additions and 37 deletions

View File

@ -1332,22 +1332,38 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HE
# Generate lmpgitversion.h # Generate lmpgitversion.h
###################################### ######################################
set(temp "#ifndef LMP_GIT_VERSION_H\n#define LMP_GIT_VERSION_H\n") set(temp "#ifndef LMP_GIT_VERSION_H\n#define LMP_GIT_VERSION_H\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_version[] =") set(temp_git_commit "(unknown)")
set(temp_git_branch "(unknown)")
set(temp_git_describe "(unknown)")
set(temp_git_info "false")
if(GIT_FOUND) if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe HEAD execute_process(COMMAND ${GIT_EXECUTABLE} describe HEAD
OUTPUT_VARIABLE temp_git_version RESULT_VARIABLE temp_in_git_checkout
ERROR_QUIET ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD if(temp_in_git_checkout EQUAL 0)
OUTPUT_VARIABLE temp_git_branch set(temp_git_info "true")
ERROR_QUIET execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE temp_git_commit
set(temp_git "${temp_git_branch} / ${temp_git_version}") ERROR_QUIET
else() OUTPUT_STRIP_TRAILING_WHITESPACE)
set(temp_git "") execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE temp_git_branch
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty=-modified
OUTPUT_VARIABLE temp_git_describe
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif() endif()
set(temp "${temp} \"${temp_git}\";\n#endif\n\n") set(temp "${temp}const bool LAMMPS_NS::LAMMPS::has_git_info = ${temp_git_info};\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_commit[] = \"${temp_git_commit}\";\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_branch[] = \"${temp_git_branch}\";\n")
set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"${temp_git_describe}\";\n")
set(temp "${temp}#endif\n\n")
message(STATUS "Generating lmpgitversion.h...") message(STATUS "Generating lmpgitversion.h...")
file(WRITE "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${temp}" ) file(WRITE "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${temp}" )
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h") execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h")

View File

@ -171,13 +171,21 @@ gitversion:
@echo 'Gathering git version information' @echo 'Gathering git version information'
@echo '#ifndef LMP_GIT_VERSION_H' > ${TMPNAME}.lmpgitversion @echo '#ifndef LMP_GIT_VERSION_H' > ${TMPNAME}.lmpgitversion
@echo '#define LMP_GIT_VERSION_H' >> ${TMPNAME}.lmpgitversion @echo '#define LMP_GIT_VERSION_H' >> ${TMPNAME}.lmpgitversion
@echo 'const char LAMMPS_NS::LAMMPS::git_version[] = ' >> ${TMPNAME}.lmpgitversion
@if (type git && git describe HEAD ) >> /dev/null 2>> /dev/null ; then \ @if (type git && git describe HEAD ) >> /dev/null 2>> /dev/null ; then \
export v1=$$(git rev-parse --abbrev-ref HEAD); export v2=$$(git describe HEAD); \ git='true'; \
echo "\"$${v1} / $${v2}\";" >> ${TMPNAME}.lmpgitversion ; \ commit=$$(git rev-parse HEAD); \
branch=$$(git rev-parse --abbrev-ref HEAD); \
describe=$$(git describe --dirty=-modified); \
else \ else \
echo '"";' >> ${TMPNAME}.lmpgitversion ; \ git='false' ; \
fi commit='(unknown)' ; \
branch='(unknown)' ; \
describe='(unknown)' ; \
fi ; \
echo "const bool LAMMPS_NS::LAMMPS::has_git_info = $${git};" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_commit[] = \"$${commit}\";" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_branch[] = \"$${branch}\";" >> ${TMPNAME}.lmpgitversion ; \
echo "const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"$${describe}\";" >> ${TMPNAME}.lmpgitversion
@echo '#endif' >> ${TMPNAME}.lmpgitversion @echo '#endif' >> ${TMPNAME}.lmpgitversion
@if [ -f lmpgitversion.h ]; \ @if [ -f lmpgitversion.h ]; \
then test "`diff --brief ${TMPNAME}.lmpgitversion lmpgitversion.h`" != "" && \ then test "`diff --brief ${TMPNAME}.lmpgitversion lmpgitversion.h`" != "" && \

View File

@ -260,9 +260,10 @@ void Info::command(int narg, char **arg)
fprintf(out,"Printed on %s\n",ctime(&now)); fprintf(out,"Printed on %s\n",ctime(&now));
if (flags & CONFIG) { if (flags & CONFIG) {
if (strlen(lmp->git_version) > 0) { if (lmp->has_git_info) {
fprintf(out,"\nLAMMPS version: %s / %s\nGit revision: %s\n\n", fprintf(out,"\nLAMMPS version: %s / %s\nGit info: %s / %s / %s\n\n",
universe->version, universe->num_ver,lmp->git_version); universe->version, universe->num_ver,lmp->git_branch,
lmp->git_descriptor,lmp->git_commit);
} else { } else {
fprintf(out,"\nLAMMPS version: %s / %s\n\n", fprintf(out,"\nLAMMPS version: %s / %s\n\n",
universe->version, universe->num_ver); universe->version, universe->num_ver);

View File

@ -419,10 +419,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
if ((universe->me == 0) && !helpflag) { if ((universe->me == 0) && !helpflag) {
if (screen) fprintf(screen,"LAMMPS (%s)\n",universe->version); if (screen) fprintf(screen,"LAMMPS (%s)\n",universe->version);
if (logfile) fprintf(logfile,"LAMMPS (%s)\n",universe->version); if (logfile) fprintf(logfile,"LAMMPS (%s)\n",universe->version);
if (strlen(git_version) > 0) {
if (screen) fprintf(screen,"Git revision (%s)\n",git_version);
if (logfile) fprintf(logfile,"Git revision (%s)\n",git_version);
}
} }
// universe is one or more worlds, as setup by partition switch // universe is one or more worlds, as setup by partition switch
@ -497,15 +493,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
if ((universe->me == 0) && (!helpflag)) { if ((universe->me == 0) && (!helpflag)) {
if (universe->uscreen) { if (universe->uscreen) {
fprintf(universe->uscreen,"LAMMPS (%s)\n",universe->version); fprintf(universe->uscreen,"LAMMPS (%s)\n",universe->version);
if (strlen(git_version) > 0)
fprintf(universe->uscreen,"Git revision (%s)\n",git_version);
fprintf(universe->uscreen,"Running on %d partitions of processors\n", fprintf(universe->uscreen,"Running on %d partitions of processors\n",
universe->nworlds); universe->nworlds);
} }
if (universe->ulogfile) { if (universe->ulogfile) {
fprintf(universe->ulogfile,"LAMMPS (%s)\n",universe->version); fprintf(universe->ulogfile,"LAMMPS (%s)\n",universe->version);
if (strlen(git_version) > 0)
fprintf(universe->ulogfile,"Git revision (%s)\n",git_version);
fprintf(universe->ulogfile,"Running on %d partitions of processors\n", fprintf(universe->ulogfile,"Running on %d partitions of processors\n",
universe->nworlds); universe->nworlds);
} }
@ -514,14 +506,10 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
if ((me == 0) && (!helpflag)) { if ((me == 0) && (!helpflag)) {
if (screen) { if (screen) {
fprintf(screen,"LAMMPS (%s)\n",universe->version); fprintf(screen,"LAMMPS (%s)\n",universe->version);
if (strlen(git_version) > 0)
fprintf(screen,"Git revision (%s)\n",git_version);
fprintf(screen,"Processor partition = %d\n",universe->iworld); fprintf(screen,"Processor partition = %d\n",universe->iworld);
} }
if (logfile) { if (logfile) {
fprintf(logfile,"LAMMPS (%s)\n",universe->version); fprintf(logfile,"LAMMPS (%s)\n",universe->version);
if (strlen(git_version) > 0)
fprintf(logfile,"Git revision (%s)\n",git_version);
fprintf(logfile,"Processor partition = %d\n",universe->iworld); fprintf(logfile,"Processor partition = %d\n",universe->iworld);
} }
} }
@ -911,13 +899,11 @@ void LAMMPS::help()
// general help message about command line and flags // general help message about command line and flags
if (strlen(git_version) > 0) { if (has_git_info) {
fprintf(fp, fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - "
"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - " LAMMPS_VERSION "\nGit info (%s / %s)\n\n",git_branch, git_descriptor);
LAMMPS_VERSION "\nGit revision (%s)\n\n",git_version);
} else { } else {
fprintf(fp, fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - "
"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - "
LAMMPS_VERSION "\n\n"); LAMMPS_VERSION "\n\n");
} }
fprintf(fp, fprintf(fp,

View File

@ -64,7 +64,11 @@ class LAMMPS {
class CiteMe *citeme; // citation info class CiteMe *citeme; // citation info
static const char * installed_packages[]; static const char * installed_packages[];
static const char git_version[];
static const bool has_git_info;
static const char git_commit[];
static const char git_branch[];
static const char git_descriptor[];
LAMMPS(int, char **, MPI_Comm); LAMMPS(int, char **, MPI_Comm);
~LAMMPS(); ~LAMMPS();