build: do not relink every single binary just for a timestamp

Summary:
Prior to this change, "make check" would always waste a lot of
time relinking 60+ binaries. With this change, it does that
only when the generated file, util/build_version.cc, changes,
and that happens only when the date changes or when the
current git SHA changes.

This change makes some other improvements: before, there was no
rule to build a deleted util/build_version.cc. If it was somehow
removed, any attempt to link a program would fail.
There is no longer any need for the separate file,
build_tools/build_detect_version.  Its functionality is
now in the Makefile.

* Makefile (DEPFILES): Don't filter-out util/build_version.cc.
No need, and besides, removing that dependency was wrong.
(date, git_sha, gen_build_version): New helper variables.
(util/build_version.cc): New rule, to create this file
and update it only if it would contain new information.
* build_tools/build_detect_platform: Remove file.
* db/db_impl.cc: Now, print only date (not the time).
* util/build_version.h (rocksdb_build_compile_time): Remove
declaration.  No longer used.

Test Plan:
- Run "make check" twice, and note that the second time no linking is performed.
- Remove util/build_version.cc and ensure that any "make"
command regenerates it before doing anything else.
- Run this: strings librocksdb.a|grep _build_.
That prints output including the following:

  rocksdb_build_git_date:2015-02-19
  rocksdb_build_git_sha:2.8.fb-1792-g3cb6cc0

Reviewers: ljin, sdong, igor

Reviewed By: igor

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D33591
main
Jim Meyering 10 years ago
parent d45a6a4002
commit a42324e370
  1. 23
      Makefile
  2. 12
      build_tools/build_detect_platform
  3. 22
      build_tools/build_detect_version
  4. 4
      db/db_impl.cc
  5. 5
      util/build_version.h

@ -130,6 +130,27 @@ CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverl
LDFLAGS += $(PLATFORM_LDFLAGS) LDFLAGS += $(PLATFORM_LDFLAGS)
date := $(shell date +%F)
git_sha := $(shell git describe HEAD 2>/dev/null)
gen_build_version = \
printf '%s\n' \
'\#include "build_version.h"' \
'const char* rocksdb_build_git_sha = \
"rocksdb_build_git_sha:$(git_sha)";' \
'const char* rocksdb_build_git_date = \
"rocksdb_build_git_date:$(date)";' \
'const char* rocksdb_build_compile_date = __DATE__;'
# Record the version of the source that we are compiling.
# We keep a record of the git revision in this file. It is then built
# as a regular source file as part of the compilation process.
# One can run "strings executable_filename | grep _build_" to find
# the version of the source that we used to build the executable file.
util/build_version.cc:
$(AM_V_GEN)$(gen_build_version) > $@.tmp
$(AM_V_at)if test -f $@; then \
cmp -s $@.tmp $@ && : || mv -f $@.tmp $@; else mv -f $@.tmp $@; fi
LIBOBJECTS = $(SOURCES:.cc=.o) LIBOBJECTS = $(SOURCES:.cc=.o)
MOCKOBJECTS = $(MOCK_SOURCES:.cc=.o) MOCKOBJECTS = $(MOCK_SOURCES:.cc=.o)
@ -751,7 +772,7 @@ endif
@$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \ @$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \
-MM -MT'$@' -MT'$(<:.cc=.o)' "$<" -o '$@' -MM -MT'$@' -MT'$(<:.cc=.o)' "$<" -o '$@'
DEPFILES = $(filter-out util/build_version.d,$(SOURCES:.cc=.d)) DEPFILES = $(SOURCES:.cc=.d)
depend: $(DEPFILES) depend: $(DEPFILES)

@ -165,11 +165,7 @@ esac
JAVA_LDFLAGS="$PLATFORM_LDFLAGS" JAVA_LDFLAGS="$PLATFORM_LDFLAGS"
if test -z "$DO_NOT_RUN_BUILD_DETECT_VERSION"; then # We want to make a list of all cc files in $DIRS,
"$PWD/build_tools/build_detect_version"
fi
# We want to make a list of all cc files within util, db and table
# except for the test and benchmark files. By default, find will output a list # except for the test and benchmark files. By default, find will output a list
# of all files matching either rule, so we need to append -print to make the # of all files matching either rule, so we need to append -print to make the
# prune take effect. # prune take effect.
@ -183,6 +179,12 @@ PORTABLE_FILES=`cd "$ROCKSDB_ROOT"; find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o $P
MOCK_SOURCES=`cd "$ROCKSDB_ROOT"; find $DIRS -name '*mock*.cc' -print | grep -v "test" | sort | tr "\n" " "` MOCK_SOURCES=`cd "$ROCKSDB_ROOT"; find $DIRS -name '*mock*.cc' -print | grep -v "test" | sort | tr "\n" " "`
set +f # re-enable globbing set +f # re-enable globbing
# If the generated util/build_version.cc is not on the list, add it:
case $PORTABLE_FILES in
*util/build_version.cc*) ;;
*) PORTABLE_FILES="$PORTABLE_FILES util/build_version.cc" ;;
esac
# The sources consist of the portable files, plus the platform-specific port # The sources consist of the portable files, plus the platform-specific port
# file. # file.
echo "SOURCES=$PORTABLE_FILES $GENERIC_PORT_FILES $PORT_FILES" >> "$OUTPUT" echo "SOURCES=$PORTABLE_FILES $GENERIC_PORT_FILES $PORT_FILES" >> "$OUTPUT"

@ -1,22 +0,0 @@
#!/bin/sh
#
# Record the version of the source that we are compiling.
# We keep a record of the git revision in util/version.cc. This source file
# is then built as a regular source file as part of the compilation process.
# One can run "strings executable_filename | grep _build_" to find the version of
# the source that we used to build the executable file.
OUTFILE="$PWD/util/build_version.cc"
GIT_SHA=""
if command -v git >/dev/null 2>&1; then
GIT_SHA=$(git rev-parse HEAD 2>/dev/null)
fi
cat > "${OUTFILE}" <<EOF
#include "build_version.h"
const char* rocksdb_build_git_sha = "rocksdb_build_git_sha:${GIT_SHA}";
const char* rocksdb_build_git_datetime = "rocksdb_build_git_datetime:$(date)";
const char* rocksdb_build_compile_date = __DATE__;
const char* rocksdb_build_compile_time = __TIME__;
EOF

@ -4047,8 +4047,8 @@ void DumpRocksDBBuildVersion(Logger * log) {
"RocksDB version: %d.%d.%d\n", ROCKSDB_MAJOR, ROCKSDB_MINOR, "RocksDB version: %d.%d.%d\n", ROCKSDB_MAJOR, ROCKSDB_MINOR,
ROCKSDB_PATCH); ROCKSDB_PATCH);
Log(InfoLogLevel::INFO_LEVEL, log, "Git sha %s", rocksdb_build_git_sha); Log(InfoLogLevel::INFO_LEVEL, log, "Git sha %s", rocksdb_build_git_sha);
Log(InfoLogLevel::INFO_LEVEL, log, "Compile time %s %s", Log(InfoLogLevel::INFO_LEVEL, log, "Compile date %s",
rocksdb_build_compile_time, rocksdb_build_compile_date); rocksdb_build_compile_date);
#endif #endif
} }

@ -7,10 +7,9 @@
#if !defined(IOS_CROSS_COMPILE) #if !defined(IOS_CROSS_COMPILE)
// if we compile with Xcode, we don't run build_detect_vesion, so we don't // if we compile with Xcode, we don't run build_detect_vesion, so we don't
// generate these variables // generate these variables
// these variables tell us about the git config and time // this variable tells us about the git revision
extern const char* rocksdb_build_git_sha; extern const char* rocksdb_build_git_sha;
// these variables tell us when the compilation occurred // Date on which the code was compiled:
extern const char* rocksdb_build_compile_time;
extern const char* rocksdb_build_compile_date; extern const char* rocksdb_build_compile_date;
#endif #endif

Loading…
Cancel
Save