fastcov icon indicating copy to clipboard operation
fastcov copied to clipboard

Bazel tool adaptation problem: The source file path in the *.info file contains the /proc/self/cwd prefix.

Open xuyinghao opened this issue 7 months ago • 0 comments

1. We use Bazel to build the program root /mnt/data_disk/code/example/DevAI-fast# ll drwxr-xr-x 8 root root 4096 May 8 11:43 app lrwxrwxrwx 1 root root 105 May 8 17:22 bazel-bin -> /root/.cache/bazel/_bazel_root/4db1772f2ccf4e71b9735be1a7c21b3f/execroot/DevAI/bazel-out/k8-fastbuild/bin lrwxrwxrwx 1 root root 78 May 8 17:22 bazel-DevAI-fast -> /root/.cache/bazel/_bazel_root/4db1772f2ccf4e71b9735be1a7c21b3f/execroot/DevAI lrwxrwxrwx 1 root root 88 May 8 17:22 bazel-out -> /root/.cache/bazel/_bazel_root/4db1772f2ccf4e71b9735be1a7c21b3f/execroot/DevAI/bazel-out -rwxr-xr-x 1 root root 7939 May 8 15:10 bazel.sh lrwxrwxrwx 1 root root 110 May 8 17:22 bazel-testlogs -> /root/.cache/bazel/_bazel_root/4db1772f2ccf4e71b9735be1a7c21b3f/execroot/DevAI/bazel-out/k8-fastbuild/testlogs

2. When Bazel compiles in the sandbox, it sets the PWD to /proc/self/cwd (19:55:01) SUBCOMMAND: # //app/kms:test_kms [action 'Compiling test/kms/kms_main_test.cpp', configuration: 18597e44d9bff309c3d5835cda854ed7842d34d5e34330cadd0d6dc3faef32f2, execution platform: @local_config_platform//:host] (cd /root/.cache/bazel/_bazel_root/4db1772f2ccf4e71b9735be1a7c21b3f/execroot/DevAI &&
exec env -
BAZEL_CXXOPTS='-std=c++17'
BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS=1
BAZEL_LINKLIBS=''
BAZEL_LINKOPTS=''
PATH=/opt/buildtools/python/bin/
PWD=/proc/self/cwd
/usr/local/bin/gcc -MD -MF bazel-out/k8-fastbuild/bin/app/kms/_objs/test_kms/kms_main_test.pic.d ... -c test/kms/kms_main_test.cpp -o bazel-out/k8-fastbuild/bin/app/kms/_objs/test_kms/kms_main_test.pic.o)

3. In the .o object file, the path prefix for the gcda file is/doc/setf/cwd. Although the fastcov command uses the --gcov_prefix_zip and --gcov_prefix parameters, the source file for the SF: field in the generated DevAI.info file still has the prefix/doc/setf/cwd root /mnt/data_disk/code/example/DevAI-fast# find bazel-out/ -name kms_main.* bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.gcda bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.o bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.d bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.gcno

root /mnt/data_disk/code/example/DevAI-fast# strings bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.o | grep kms_main app/kms/src/kms_main.c /proc/self/cwd/bazel-out/k8-fastbuild/bin/app/kms/_objs/kms/kms_main.pic.gcda

DevAI.info SF**: /proc/self/cwd**/app/kms/src/kms_main.c

4. The source file path in the DevAI.info file is /proc/self/cwd/app/kms/src/kms_main.c instead of the actual /mnt/data_disk/code/example/DevAI-fast/app/kms/src/kms_main.c. Therefore, when the genhtml command is executed to generate a report, the source file cannot be found. As a result, the report data is not lost. Found 40 entries. Found common filename prefix "/proc/self/cwd/app" Writing .css and .png files. Generating output. Processing file kms/src/kms_main.c genhtml: WARNING: cannot read **/proc/self/cwd/**app/kms/src/kms_main.c!

Therefore, when generating the SF: field of the info file, it need to use the processPrefix function to process the source file path or use the processGcdas function to process the source file path in advance. I'm not sure which way is better.

xuyinghao avatar May 08 '25 12:05 xuyinghao