Skip to content

Commit

Permalink
[#2979] Allow controlling ccache directory location with an environme…
Browse files Browse the repository at this point in the history
…nt variable

Summary:
Allow controlling ccache directory location with an environment variable. Before this change, we are using the default ~/.ccache directory, except on Jenkins.

Also remove the `--gen-compilation-db` flag from `yb_build.sh` as it has been superseded by the `compilecmds` build type.

Test Plan:
Jenkins: compile only

`export YB_CCACHE_DIR=/some/directory; ./yb_build.sh`

Reviewers: jason, timur

Reviewed By: timur

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D7595
  • Loading branch information
mbautin committed Nov 20, 2019
1 parent 2cae6c9 commit d030aa0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
4 changes: 3 additions & 1 deletion build-support/common-build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ declare -i -r YB_DOWNLOAD_LOCK_TIMEOUT_SEC=120

readonly YB_DOWNLOAD_LOCKS_DIR=/tmp/yb_download_locks

readonly YB_NFS_PATH_RE="^/(n|z|u|net|Volumes/net)/"

# -------------------------------------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1419,7 +1421,7 @@ is_jenkins_phabricator_build() {

# Check if we're using an NFS partition in YugaByte's build environment.
is_src_root_on_nfs() {
if [[ $YB_SRC_ROOT =~ ^/(n|z|u|net|Volumes/net)/ ]]; then
if [[ $YB_SRC_ROOT =~ $YB_NFS_PATH_RE ]]; then
return 0
fi
return 1
Expand Down
32 changes: 19 additions & 13 deletions build-support/compiler-wrappers/compiler-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -604,22 +604,28 @@ if which ccache >/dev/null && ! "$compiling_pch" && [[ -z ${YB_NO_CCACHE:-} ]];
export CCACHE_CC="$compiler_executable"
export CCACHE_SLOPPINESS="file_macro,pch_defines,time_macros"
export CCACHE_BASEDIR=$YB_SRC_ROOT
if is_jenkins; then
# Enable reusing cache entries from builds in different directories, potentially with incorrect
# file paths in debug information. This is OK for Jenkins because we probably won't be running
# these builds in the debugger.
export CCACHE_NOHASHDIR=1
fi

# Ensure CCACHE puts temporary files on the local disk.
export CCACHE_TEMPDIR=${CCACHE_TEMPDIR:-/tmp/ccache_tmp_$USER}
jenkins_ccache_dir=/n/jenkins/ccache
if [[ $USER == "jenkins" && -d $jenkins_ccache_dir ]] && is_src_root_on_nfs; then
if [[ ${YB_DEBUG_CCACHE:-0} == "1" ]] && ! is_jenkins; then
log "is_jenkins (based on JOB_NAME) is false for some reason, even though" \
"the user is 'jenkins'. Setting CCACHE_DIR to '$jenkins_ccache_dir' anyway." \
"This is host $HOSTNAME, and current directory is $PWD."
if [[ -n ${YB_CCACHE_DIR:-} ]]; then
export CCACHE_DIR=$YB_CCACHE_DIR
else
jenkins_ccache_dir=/n/jenkins/ccache
if [[ $USER == "jenkins" && -d $jenkins_ccache_dir ]] && is_src_root_on_nfs; then
# Enable reusing cache entries from builds in different directories, potentially with
# incorrect file paths in debug information. This is OK for Jenkins because we probably won't
# be running these builds in the debugger.
export CCACHE_NOHASHDIR=1

if [[ ${YB_DEBUG_CCACHE:-0} == "1" ]] && ! is_jenkins; then
log "is_jenkins (based on JOB_NAME) is false for some reason, even though" \
"the user is 'jenkins'. Setting CCACHE_DIR to '$jenkins_ccache_dir' anyway." \
"This is host $HOSTNAME, and current directory is $PWD."
fi
export CCACHE_DIR=$jenkins_ccache_dir
fi
export CCACHE_DIR=$jenkins_ccache_dir
fi
if [[ ${CCACHE_DIR:-} =~ $YB_NFS_PATH_RE ]]; then
# Do not update the stats file, because that involves locking and might be problematic/slow
# on NFS.
export CCACHE_NOSTATS=1
Expand Down
21 changes: 7 additions & 14 deletions yb_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ java_test_name=""
show_report=true
running_any_tests=false
clean_postgres=false
export_compile_commands=false
make_ninja_extra_args=""
java_lint=false

Expand Down Expand Up @@ -918,9 +917,6 @@ while [[ $# -gt 0 ]]; do
--no-postgres|--skip-postgres|--np|--sp)
export YB_SKIP_POSTGRES_BUILD=1
;;
--gen-compilation-db|--gcdb)
export_compile_commands=true
;;
--run-java-test-methods-separately|--rjtms)
export YB_RUN_JAVA_TEST_METHODS_SEPARATELY=1
;;
Expand Down Expand Up @@ -1056,16 +1052,6 @@ if "$use_nfs_shared_thirdparty" && "$no_shared_thirdparty"; then
fatal "--use-shared-thirdparty and --no-shared-thirdparty cannot be specified at the same time"
fi

if "$export_compile_commands" && ! "$force_no_run_cmake"; then
force_run_cmake=true
fi

if "$export_compile_commands"; then
log "Will export compile commands (create a compilation database JSON file)"
export CMAKE_EXPORT_COMPILE_COMMANDS=1
export YB_EXPORT_COMPILE_COMMANDS=1
fi

configure_remote_compilation
do_not_use_local_thirdparty_flag_path=$YB_SRC_ROOT/thirdparty/.yb_thirdparty_do_not_use

Expand All @@ -1086,6 +1072,13 @@ if "$java_lint"; then
lint_java_code
exit
fi

if ! is_jenkins && is_src_root_on_nfs && \
[[ -z ${YB_CCACHE_DIR:-} && $HOME =~ $YB_NFS_PATH_RE ]]; then
export YB_CCACHE_DIR=$HOME/.ccache
log "Setting YB_CCACHE_DIR=$YB_CCACHE_DIR by default for NFS-based builds"
fi

# -------------------------------------------------------------------------------------------------
# Recursively invoke this script in order to save the log to a file.
# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit d030aa0

Please sign in to comment.