diff --git a/common/GitInfoStamp.cmake b/common/GitInfoStamp.cmake index f2c9ce138..148993a98 100644 --- a/common/GitInfoStamp.cmake +++ b/common/GitInfoStamp.cmake @@ -4,7 +4,22 @@ # reported a hash seventeen commits stale. configure_file leaves the output untouched when nothing # changed, so this costs a recompile only when HEAD moves. Also included at configure time, so the # file exists for the generator and the SHA prints with the configure output. +# A source tree that is not a git checkout of its own - a downloaded tarball, perhaps unpacked inside +# some other repository - has no commit to report: the version from VERSION stands alone and the +# commit reads "unknown", and the build goes on. +SET(GIT_SHA1 "") +SET(GIT_DATE "") if (GIT_EXECUTABLE) + EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" rev-parse --show-toplevel + WORKING_DIRECTORY "${GITINFO_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_TOPLEVEL + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if (GIT_TOPLEVEL) + FILE(REAL_PATH "${GIT_TOPLEVEL}" GIT_TOPLEVEL) + endif () + FILE(REAL_PATH "${GITINFO_SOURCE_DIR}" GITINFO_SOURCE_REAL) +endif () +if (GIT_EXECUTABLE AND GIT_TOPLEVEL STREQUAL GITINFO_SOURCE_REAL) # --dirty: a build from uncommitted changes says so in the hash itself EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=8 --dirty @@ -17,4 +32,7 @@ if (GIT_EXECUTABLE) OUTPUT_VARIABLE GIT_DATE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif () +if (NOT GIT_SHA1) + SET(GIT_SHA1 "unknown") +endif () CONFIGURE_FILE("${GITINFO_TEMPLATE}" "${GITINFO_OUTPUT}" @ONLY) diff --git a/image_analysis/WriteReflections.cpp b/image_analysis/WriteReflections.cpp index 7b49f877a..fba15332c 100644 --- a/image_analysis/WriteReflections.cpp +++ b/image_analysis/WriteReflections.cpp @@ -110,9 +110,10 @@ std::string IsoDate(const std::string ×tamp) { return timestamp.substr(0, 10); } -// The commit this build was made from, with its date; empty when the build does not know it. +// The commit this build was made from, with its date where the build knows it ("unknown" for a source +// tree without git history). std::string GitDescription() { - return jfjoch_git_sha1().empty() ? std::string() : jfjoch_git_sha1() + " " + jfjoch_git_date(); + return jfjoch_git_date().empty() ? jfjoch_git_sha1() : jfjoch_git_sha1() + " " + jfjoch_git_date(); } // The MTZ HISTORY records saying where a file came from, after the one naming the program: the @@ -284,7 +285,7 @@ void WriteMmcifReflections(const std::vector &reflections, // Rugnux integrated the images (data reduction) and scaled and merged them (data scaling), the // two rows the wwPDB asks a data-processing program to be named under; the description is the // commit the build was made from. - const std::string software_description = CifStr(GitDescription().empty() ? "" : "git " + GitDescription()); + const std::string software_description = CifStr("git " + GitDescription()); out << "loop_\n"; out << "_software.pdbx_ordinal\n"; out << "_software.name\n";