diff --git a/docs/en/api-guides/reproducible-builds.rst b/docs/en/api-guides/reproducible-builds.rst index 5919ef8d89..93ef078732 100644 --- a/docs/en/api-guides/reproducible-builds.rst +++ b/docs/en/api-guides/reproducible-builds.rst @@ -13,6 +13,7 @@ When reproducible builds are enabled, the application built with ESP-IDF does no - Directory where the project is located - Directory where ESP-IDF is located (``IDF_PATH``) - Build time +- Toolchain installation path Reasons for Non-Reproducible Builds ----------------------------------- @@ -46,6 +47,7 @@ ESP-IDF achieves reproducible builds using the following measures: - Path to the project is replaced with ``/IDF_PROJECT`` - Path to the build directory is replaced with ``/IDF_BUILD`` - Paths to components are replaced with ``/COMPONENT_NAME_DIR`` (where ``NAME`` is the name of the component) + - Path to the toolchain is replaced with ``/TOOLCHAIN`` - Build date and time are not included into the :ref:`application metadata structure ` and :ref:`bootloader metadata structure ` if :ref:`CONFIG_APP_REPRODUCIBLE_BUILD` is enabled. - ESP-IDF build system ensures that source file lists, component lists and other sequences are sorted before passing them to CMake. Various other parts of the build system, such as the linker script generator also perform sorting to ensure that same output is produced regardless of the environment. diff --git a/docs/zh_CN/api-guides/reproducible-builds.rst b/docs/zh_CN/api-guides/reproducible-builds.rst index ec922e3f55..74d568b0e4 100644 --- a/docs/zh_CN/api-guides/reproducible-builds.rst +++ b/docs/zh_CN/api-guides/reproducible-builds.rst @@ -13,6 +13,7 @@ ESP-IDF 构建系统支持 `可重复构建 ` 和 :ref:`引导加载程序元数据结构 ` 中。 - ESP-IDF 构建系统在将源文件列表、组件列表和其他序列传递给 CMake 之前会对其进行排序。构建系统的其他各个部分,如链接器脚本生成器,也会先排序,从而确保无论环境如何,输出都一致。 diff --git a/tools/cmake/prefix_map.cmake b/tools/cmake/prefix_map.cmake index 440d412b43..6373b6b087 100644 --- a/tools/cmake/prefix_map.cmake +++ b/tools/cmake/prefix_map.cmake @@ -31,6 +31,19 @@ function(__generate_prefix_map compile_options_var) string(APPEND gdbinit_file_lines "set substitute-path ${substituted_path} ${component_dir}\n") endforeach() + # Mapping for toolchain path + execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-sysroot + OUTPUT_VARIABLE compiler_sysroot + ) + if(compiler_sysroot STREQUAL "") + message(FATAL_ERROR "Failed to determine toolchain sysroot") + endif() + string(STRIP "${compiler_sysroot}" compiler_sysroot) + get_filename_component(compiler_sysroot "${compiler_sysroot}/.." REALPATH) + list(APPEND compile_options "-fdebug-prefix-map=${compiler_sysroot}=/TOOLCHAIN") + string(APPEND gdbinit_file_lines "set substitute-path /TOOLCHAIN ${compiler_sysroot}\n") + # Write the final gdbinit file set(gdbinit_path "${BUILD_DIR}/prefix_map_gdbinit") file(WRITE "${gdbinit_path}" "${gdbinit_file_lines}") diff --git a/tools/test_build_system/test_reproducible_build.py b/tools/test_build_system/test_reproducible_build.py index a19a20174d..c5ba093b55 100644 --- a/tools/test_build_system/test_reproducible_build.py +++ b/tools/test_build_system/test_reproducible_build.py @@ -3,6 +3,7 @@ # This test checks the behavior of reproducible builds option. import logging import os +import shutil import subprocess from pathlib import Path @@ -36,6 +37,10 @@ def test_reproducible_builds(app_name: str, idf_py: IdfPyFunc, test_app_copy: Pa idf_path = os.environ['IDF_PATH'] assert str(idf_path) not in strings_output, f'{idf_path} found in {elf_file}' assert str(test_app_copy) not in strings_output, f'{test_app_copy} found in {elf_file}' + compiler_path = shutil.which('xtensa-esp32-elf-gcc') + assert compiler_path is not None, 'failed to determine compiler path' + toolchain_path = Path(compiler_path).parent.parent + assert str(toolchain_path) not in strings_output, f'{toolchain_path} found in {elf_file}' logging.info(f'Building in {build_second} directory') idf_py('-B', str(build_second), 'build')