fix(build_system): fix toolchain sysroot directory affecting builds

Closes https://github.com/espressif/esp-idf/issues/13680
This commit is contained in:
Ivan Grokhotkov 2024-08-12 13:28:15 +02:00
parent 1c343d8923
commit bef4cb05ff
No known key found for this signature in database
GPG Key ID: 1E050E141B280628
4 changed files with 22 additions and 0 deletions

View File

@ -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 the project is located
- Directory where ESP-IDF is located (``IDF_PATH``) - Directory where ESP-IDF is located (``IDF_PATH``)
- Build time - Build time
- Toolchain installation path
Reasons for Non-Reproducible Builds 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 project is replaced with ``/IDF_PROJECT``
- Path to the build directory is replaced with ``/IDF_BUILD`` - 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) - 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 <app-image-format-application-description>` and :ref:`bootloader metadata structure <image-format-bootloader-description>` if :ref:`CONFIG_APP_REPRODUCIBLE_BUILD` is enabled. - Build date and time are not included into the :ref:`application metadata structure <app-image-format-application-description>` and :ref:`bootloader metadata structure <image-format-bootloader-description>` 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. - 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.

View File

@ -13,6 +13,7 @@ ESP-IDF 构建系统支持 `可重复构建 <https://reproducible-builds.org/doc
- 项目所在目录 - 项目所在目录
- ESP-IDF 所在目录 (``IDF_PATH``) - ESP-IDF 所在目录 (``IDF_PATH``)
- 构建时间 - 构建时间
- 工具链安装路径
构建不可重复的原因 构建不可重复的原因
------------------ ------------------
@ -46,6 +47,7 @@ ESP-IDF 可通过以下方式实现可重复构建:
- 替换项目路径为 ``/IDF_PROJECT`` - 替换项目路径为 ``/IDF_PROJECT``
- 替换构建目录的路径为 ``/IDF_BUILD`` - 替换构建目录的路径为 ``/IDF_BUILD``
- 替换组件路径为 ``/COMPONENT_NAME_DIR`` (其中 ``NAME`` 指的是组件的名称) - 替换组件路径为 ``/COMPONENT_NAME_DIR`` (其中 ``NAME`` 指的是组件的名称)
- 替换工具链的路径为 ``/TOOLCHAIN``
- 如果启用 :ref:`CONFIG_APP_REPRODUCIBLE_BUILD`,则不会将构建日期和时间包括在 :ref:`应用程序元数据结构 <app-image-format-application-description>`:ref:`引导加载程序元数据结构 <image-format-bootloader-description>` 中。 - 如果启用 :ref:`CONFIG_APP_REPRODUCIBLE_BUILD`,则不会将构建日期和时间包括在 :ref:`应用程序元数据结构 <app-image-format-application-description>`:ref:`引导加载程序元数据结构 <image-format-bootloader-description>` 中。
- ESP-IDF 构建系统在将源文件列表、组件列表和其他序列传递给 CMake 之前会对其进行排序。构建系统的其他各个部分,如链接器脚本生成器,也会先排序,从而确保无论环境如何,输出都一致。 - ESP-IDF 构建系统在将源文件列表、组件列表和其他序列传递给 CMake 之前会对其进行排序。构建系统的其他各个部分,如链接器脚本生成器,也会先排序,从而确保无论环境如何,输出都一致。

View File

@ -31,6 +31,19 @@ function(__generate_prefix_map compile_options_var)
string(APPEND gdbinit_file_lines "set substitute-path ${substituted_path} ${component_dir}\n") string(APPEND gdbinit_file_lines "set substitute-path ${substituted_path} ${component_dir}\n")
endforeach() 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 # Write the final gdbinit file
set(gdbinit_path "${BUILD_DIR}/prefix_map_gdbinit") set(gdbinit_path "${BUILD_DIR}/prefix_map_gdbinit")
file(WRITE "${gdbinit_path}" "${gdbinit_file_lines}") file(WRITE "${gdbinit_path}" "${gdbinit_file_lines}")

View File

@ -3,6 +3,7 @@
# This test checks the behavior of reproducible builds option. # This test checks the behavior of reproducible builds option.
import logging import logging
import os import os
import shutil
import subprocess import subprocess
from pathlib import Path 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'] idf_path = os.environ['IDF_PATH']
assert str(idf_path) not in strings_output, f'{idf_path} found in {elf_file}' 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}' 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') logging.info(f'Building in {build_second} directory')
idf_py('-B', str(build_second), 'build') idf_py('-B', str(build_second), 'build')