This is an automated email from the ASF dual-hosted git repository.

zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e8331ec220 [Enhancement](build) support ccache hits across different 
directories (#61234)
6e8331ec220 is described below

commit 6e8331ec220b3c0a664634e24641edcc9079dbdf
Author: zclllyybb <[email protected]>
AuthorDate: Thu Mar 12 16:51:31 2026 +0800

    [Enhancement](build) support ccache hits across different directories 
(#61234)
    
    Normal Hit Rate:
    ```
    cache hit (direct)                  1303
    cache hit (preprocessed)              20
    cache miss                           219
    cache hit rate                     85.80 %
    ```
    Previously, when we opened a worktree, the first compilation:
    ```
    cache hit (direct)                     0
    cache hit (preprocessed)               0
    cache miss                          1404
    cache hit rate                      0.00 %
    ```
    Now (using another different directory name, plus the current patch):
    ```
    cache hit (direct)                  4665
    cache hit (preprocessed)            2517
    cache miss                             0
    cache hit rate                    100.00 %
    ```
    
    see more in
    https://ccache.dev/manual/4.7.4.html#_compiling_in_different_directories
    docs: https://github.com/apache/doris-website/pull/3452
---
 be/CMakeLists.txt       | 13 +++++++++++--
 build.sh                |  6 ++++--
 env.sh                  | 24 +++++++++++++++++++++---
 hooks/setup_worktree.sh |  1 +
 4 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index 550bf10d77a..907c916fdc8 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -123,7 +123,11 @@ endif()
 
 # Set dirs
 set(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
-set(ENV{DORIS_HOME} "${BASE_DIR}/..")
+if (DEFINED ENV{DORIS_HOME})
+    message(STATUS "DORIS_HOME is $ENV{DORIS_HOME}")
+else()
+    message(FATAL_ERROR "DORIS_HOME is not defined")
+endif()
 set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 set(GENSRC_DIR "${BASE_DIR}/../gensrc/build/")
 set(COMMON_SRC_DIR "${BASE_DIR}/../common")
@@ -297,6 +301,10 @@ endif()
 set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_C_STANDARD 17)
 
+add_compile_options(
+  "-ffile-prefix-map=$ENV{DORIS_HOME}=."
+)
+
 add_compile_options(-g
                     -gdwarf-5
                     -Wall
@@ -419,7 +427,8 @@ endif()
 #   -O3: Enable all compiler optimizations
 #   -DNDEBUG: Turn off dchecks/asserts/debug only code.
 set(CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
-set(CXX_FLAGS_ASAN "-O0 -fsanitize=address -fsanitize=undefined 
-fno-sanitize=float-cast-overflow  
-fsanitize-ignorelist=${BASE_DIR}/../conf/ubsan_ignorelist.txt 
-DUNDEFINED_BEHAVIOR_SANITIZER -DADDRESS_SANITIZER")
+message(STATUS "UBSAN_IGNORELIST is ${UBSAN_IGNORELIST}")
+set(CXX_FLAGS_ASAN "-O0 -fsanitize=address -fsanitize=undefined 
-fno-sanitize=float-cast-overflow -fsanitize-ignorelist=${UBSAN_IGNORELIST} 
-DUNDEFINED_BEHAVIOR_SANITIZER -DADDRESS_SANITIZER")
 set(CXX_FLAGS_LSAN "-O0 -fsanitize=leak -DLEAK_SANITIZER")
 ## Use for BE-UT
 set(CXX_FLAGS_ASAN_UT "-O0 -fsanitize=address -DADDRESS_SANITIZER")
diff --git a/build.sh b/build.sh
index 18ba1c46335..b4268e0d306 100755
--- a/build.sh
+++ b/build.sh
@@ -329,7 +329,7 @@ else
         BUILD_META_TOOL='ON'
         BUILD_FILE_CACHE_MICROBENCH_TOOL='OFF'
         BUILD_INDEX_TOOL='ON'
-       BUILD_TASK_EXECUTOR_SIMULATOR='OFF'
+           BUILD_TASK_EXECUTOR_SIMULATOR='OFF'
         BUILD_HIVE_UDF=1
         BUILD_BE_JAVA_EXTENSIONS=1
         BUILD_BE_CDC_CLIENT=1
@@ -669,7 +669,9 @@ if [[ "${BUILD_BE}" -eq 1 ]]; then
         -DBUILD_FS_BENCHMARK="${BUILD_FS_BENCHMARK}" \
         -DBUILD_TASK_EXECUTOR_SIMULATOR="${BUILD_TASK_EXECUTOR_SIMULATOR}" \
         -DBUILD_FILE_CACHE_LRU_TOOL="${BUILD_FILE_CACHE_LRU_TOOL}" \
-        ${CMAKE_USE_CCACHE:+${CMAKE_USE_CCACHE}} \
+        ${CMAKE_USE_CCACHE_CXX:+${CMAKE_USE_CCACHE_CXX}} \
+        ${CMAKE_USE_CCACHE_C:+${CMAKE_USE_CCACHE_C}} \
+        -DUBSAN_IGNORELIST="${UBSAN_IGNORELIST}" \
         -DUSE_LIBCPP="${USE_LIBCPP}" \
         -DBUILD_META_TOOL="${BUILD_META_TOOL}" \
         
-DBUILD_FILE_CACHE_MICROBENCH_TOOL="${BUILD_FILE_CACHE_MICROBENCH_TOOL}" \
diff --git a/env.sh b/env.sh
index 79120eb5066..d9226d5cf01 100755
--- a/env.sh
+++ b/env.sh
@@ -17,9 +17,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# check DORIS_HOME
-export LC_ALL=C
+# Explicitly set to prevent ccache misses caused by terminal differences
+export LANG=en_US.utf8
+export LC_ALL=en_US.utf8
+export LC_CTYPE=en_US.utf8
+export LC_MESSAGES=en_US.utf8
 
+# check DORIS_HOME
 if [[ -z "${DORIS_HOME}" ]]; then
     echo "Error: DORIS_HOME is not set"
     exit 1
@@ -353,10 +357,24 @@ if NINJA_VERSION="$(ninja --version 2>/dev/null)"; then
     BUILD_SYSTEM="ninja"
 fi
 
+# for worktree build, use ubsan_ignorelist.txt from main branch to avoid 
ccache miss.
+if [[ -z "${UBSAN_IGNORELIST}" ]]; then
+    export UBSAN_IGNORELIST="${DORIS_HOME}/conf/ubsan_ignorelist.txt"
+fi
+
 if CCACHE_VERSION="$(ccache --version 2>/dev/null)"; then
     echo "${CCACHE_VERSION}" | head -n 1
     # shellcheck disable=2034
-    CMAKE_USE_CCACHE="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
+    CMAKE_USE_CCACHE_CXX="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
+    CMAKE_USE_CCACHE_C="-DCMAKE_C_COMPILER_LAUNCHER=ccache"
+
+    export CCACHE_BASEDIR=${DORIS_HOME}
+    export CCACHE_NOHASHDIR=1
+    export CCACHE_COMPRESS=1
+    export CCACHE_IGNOREOPTIONS='-ffile-prefix-map=*' # we remap path in 
different repo to one. the item itself could be ignore.
+    # for debug. when debug enabled, will generate text fingerprint file 
*.ccache-input-text
+    # export CCACHE_LOGFILE=
+    # export CCACHE_DEBUG=1
 fi
 
 export GENERATOR
diff --git a/hooks/setup_worktree.sh b/hooks/setup_worktree.sh
index 869caac5cbf..4a59d7acde7 100755
--- a/hooks/setup_worktree.sh
+++ b/hooks/setup_worktree.sh
@@ -17,6 +17,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# should have UBSAN_IGNORELIST in it to enable ccache
 cp "$ROOT_WORKSPACE_PATH/custom_env.sh" custom_env.sh
 echo "Copied custom_env.sh"
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to