mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
build: create BUILD_DIR/prefix_map_gdbinit when enable reproducible build
add project property BUILD_COMPONENT_DIRS
This commit is contained in:
parent
9919b75ec1
commit
ea1005b740
@ -154,6 +154,32 @@ if(NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 8.0.0)
|
|||||||
list(APPEND compile_options "-fdebug-prefix-map=${IDF_PATH}=/IDF")
|
list(APPEND compile_options "-fdebug-prefix-map=${IDF_PATH}=/IDF")
|
||||||
list(APPEND compile_options "-fdebug-prefix-map=${PROJECT_DIR}=/IDF_PROJECT")
|
list(APPEND compile_options "-fdebug-prefix-map=${PROJECT_DIR}=/IDF_PROJECT")
|
||||||
list(APPEND compile_options "-fdebug-prefix-map=${BUILD_DIR}=/IDF_BUILD")
|
list(APPEND compile_options "-fdebug-prefix-map=${BUILD_DIR}=/IDF_BUILD")
|
||||||
|
|
||||||
|
# component dirs
|
||||||
|
idf_build_get_property(python PYTHON)
|
||||||
|
idf_build_get_property(idf_path IDF_PATH)
|
||||||
|
idf_build_get_property(component_dirs BUILD_COMPONENT_DIRS)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${python}
|
||||||
|
"${idf_path}/tools/generate_debug_prefix_map.py"
|
||||||
|
"${BUILD_DIR}"
|
||||||
|
"${component_dirs}"
|
||||||
|
OUTPUT_VARIABLE result
|
||||||
|
RESULT_VARIABLE ret
|
||||||
|
)
|
||||||
|
if(NOT ret EQUAL 0)
|
||||||
|
message(FATAL_ERROR "This is a bug. Please report to https://github.com/espressif/esp-idf/issues")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
spaces2list(result)
|
||||||
|
list(LENGTH component_dirs length)
|
||||||
|
math(EXPR max_index "${length} - 1")
|
||||||
|
foreach(index RANGE ${max_index})
|
||||||
|
list(GET component_dirs ${index} folder)
|
||||||
|
list(GET result ${index} after)
|
||||||
|
list(APPEND compile_options "-fdebug-prefix-map=${folder}=${after}")
|
||||||
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
3
Kconfig
3
Kconfig
@ -206,7 +206,8 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
|||||||
default n
|
default n
|
||||||
select COMPILER_HIDE_PATHS_MACROS
|
select COMPILER_HIDE_PATHS_MACROS
|
||||||
help
|
help
|
||||||
If enabled, all date, time, and path information would be eliminated.
|
If enabled, all date, time, and path information would be eliminated. A .gdbinit file would be create
|
||||||
|
automatically. (or will be append if you have one already)
|
||||||
|
|
||||||
endmenu # Build type
|
endmenu # Build type
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@ for path in \
|
|||||||
"examples/bluetooth/nimble/blecent"; do
|
"examples/bluetooth/nimble/blecent"; do
|
||||||
cd "${IDF_PATH}/${path}"
|
cd "${IDF_PATH}/${path}"
|
||||||
|
|
||||||
echo "CONFIG_APP_REPRODUCIBLE_BUILD=y" >>sdkconfig.defaults
|
echo "CONFIG_APP_REPRODUCIBLE_BUILD=y" >sdkconfig
|
||||||
rm -f sdkconfig
|
|
||||||
|
|
||||||
idf.py -B build_first fullclean build
|
idf.py -B build_first fullclean build
|
||||||
idf.py -B build_second fullclean build
|
idf.py -B build_second fullclean build
|
||||||
@ -23,4 +22,12 @@ for path in \
|
|||||||
"*.map"; do
|
"*.map"; do
|
||||||
diff -s build_first/${item} build_second/${item} # use glob, don't use double quotes
|
diff -s build_first/${item} build_second/${item} # use glob, don't use double quotes
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# test gdb
|
||||||
|
rm -f gdb.txt
|
||||||
|
elf_file=$(find build_first -maxdepth 1 -iname '*.elf')
|
||||||
|
xtensa-esp32-elf-gdb -x build_first/prefix_map_gdbinit -ex 'set logging on' -ex 'set pagination off' -ex 'list' -ex 'quit' "$elf_file"
|
||||||
|
if grep "No such file or directory" gdb.txt; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
@ -189,6 +189,9 @@ function(__component_add component_dir prefix)
|
|||||||
|
|
||||||
# Set Kconfig related properties on the component
|
# Set Kconfig related properties on the component
|
||||||
__kconfig_component_init(${component_target})
|
__kconfig_component_init(${component_target})
|
||||||
|
|
||||||
|
# set BUILD_COMPONENT_DIRS build property
|
||||||
|
idf_build_set_property(BUILD_COMPONENT_DIRS ${component_dir} APPEND)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -17,5 +17,6 @@
|
|||||||
"COMPONENT_KCONFIGS_PROJBUILD" : "${COMPONENT_KCONFIGS_PROJBUILD}"
|
"COMPONENT_KCONFIGS_PROJBUILD" : "${COMPONENT_KCONFIGS_PROJBUILD}"
|
||||||
},
|
},
|
||||||
"build_components" : ${build_components_json},
|
"build_components" : ${build_components_json},
|
||||||
"build_component_paths" : ${build_component_paths_json}
|
"build_component_paths" : ${build_component_paths_json},
|
||||||
|
"debug_prefix_map_gdbinit": "${BUILD_DIR}/prefix_map_gdbinit"
|
||||||
}
|
}
|
||||||
|
45
tools/generate_debug_prefix_map.py
Normal file
45
tools/generate_debug_prefix_map.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# General Workflow:
|
||||||
|
# 1. read all components dirs, a semicolon-separated string (cmake list)
|
||||||
|
# 2. map the component dir with a unique prefix /COMPONENT_<NAME>_DIR
|
||||||
|
# 2. write the prefix mapping file to $BUILD_DIR/prefix_map_gdbinit
|
||||||
|
# 3. print the unique prefix out, a space-separated string, will be used by the build system to add compile options.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def component_name(component_dir: str) -> str:
|
||||||
|
return '/COMPONENT_{}_DIR'.format(os.path.basename(component_dir).upper())
|
||||||
|
|
||||||
|
|
||||||
|
GDB_SUBSTITUTE_PATH_FMT = 'set substitute-path {} {}\n'
|
||||||
|
|
||||||
|
|
||||||
|
def write_gdbinit(build_dir: str, folders: List[str]) -> None:
|
||||||
|
gdb_init_filepath = os.path.join(build_dir, 'prefix_map_gdbinit')
|
||||||
|
|
||||||
|
with open(gdb_init_filepath, 'w') as fw:
|
||||||
|
for folder in folders:
|
||||||
|
fw.write(f'{GDB_SUBSTITUTE_PATH_FMT.format(component_name(folder), folder)}')
|
||||||
|
|
||||||
|
|
||||||
|
def main(build_dir: str, folders: List[str]) -> None:
|
||||||
|
write_gdbinit(build_dir, folders)
|
||||||
|
print(' '.join([component_name(folder) for folder in folders]), end='')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='print the debug-prefix-map and write to '
|
||||||
|
'$BUILD_DIR/prefix_map_gdbinit file')
|
||||||
|
|
||||||
|
parser.add_argument('build_dir',
|
||||||
|
help='build dir')
|
||||||
|
parser.add_argument('folders',
|
||||||
|
help='component folders, semicolon separated string')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(args.build_dir, args.folders.split(';'))
|
Loading…
Reference in New Issue
Block a user