Skip to content

Commit 1d92e8e

Browse files
jajanuszlgirdwood
authored andcommitted
sof: use RELATIVE_FILE instead of __FILE__
Use RELATIVE_FILE because __FILE__ makes binary output dependent on project location. Signed-off-by: Janusz Jankowski <[email protected]>
1 parent 24f3160 commit 1d92e8e

File tree

13 files changed

+48
-14
lines changed

13 files changed

+48
-14
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ if(BUILD_LIBRARY)
126126

127127
add_subdirectory(src)
128128

129+
sof_append_relative_path_definitions(sof)
130+
129131
get_target_property(incdirs sof_public_headers INTERFACE_INCLUDE_DIRECTORIES)
130132

131133
# we append slash at the end to make CMake copy contents of directories
@@ -176,3 +178,5 @@ target_link_libraries(sof PRIVATE sof_static_libraries)
176178
sof_add_build_counter_rule()
177179

178180
add_subdirectory(src)
181+
182+
sof_append_relative_path_definitions(sof)

src/arch/xtensa/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ if(build_bootloader)
231231
target_link_libraries(bootloader PRIVATE "-lgcc")
232232
target_link_libraries(bootloader PRIVATE "-T${PROJECT_BINARY_DIR}/${platform_bootldr_ld_script}")
233233
sof_add_ld_script(bootloader ${platform_bootldr_ld_script})
234+
sof_append_relative_path_definitions(bootloader)
234235

235236
add_custom_target(
236237
bootloader_dump

src/audio/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function(sof_audio_add_module lib_name compile_flags)
7474
target_link_libraries(${lib_name} PRIVATE -Wl,--export-dynamic)
7575
target_compile_options(${lib_name} PRIVATE ${compile_flags})
7676
add_local_sources(${lib_name} ${ARGN})
77+
sof_append_relative_path_definitions(${lib_name})
7778
install(TARGETS ${lib_name} DESTINATION lib)
7879
endfunction()
7980

src/include/sof/debug/debug.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include <stddef.h>
2222
#include <stdint.h>
2323

24+
#ifndef RELATIVE_FILE
25+
#error "This file requires RELATIVE_FILE to be defined. " \
26+
"Add it to CMake's target with sof_append_relative_path_definitions."
27+
#endif
28+
2429
#if CONFIG_DEBUG
2530

2631
#include <sof/lib/mailbox.h>
@@ -37,8 +42,9 @@
3742
#define dbg() \
3843
do { \
3944
volatile uint32_t *__m = (uint32_t *)mailbox_get_debug_base(); \
40-
*(__m++) = (__FILE__[0] << 24) + (__FILE__[1] << 16) +\
41-
(__FILE__[2] << 8) + (__FILE__[3]); \
45+
*(__m++) = (RELATIVE_FILE[0] << 24) + \
46+
(RELATIVE_FILE[1] << 16) + \
47+
(RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
4248
*(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
4349
(__func__[2] << 8) + (__func__[3]); \
4450
*__m = __LINE__; \
@@ -49,8 +55,9 @@
4955
do { \
5056
volatile uint32_t *__m = \
5157
(uint32_t *)mailbox_get_debug_base() + __x; \
52-
*(__m++) = (__FILE__[0] << 24) + (__FILE__[1] << 16) +\
53-
(__FILE__[2] << 8) + (__FILE__[3]); \
58+
*(__m++) = (RELATIVE_FILE[0] << 24) + \
59+
(RELATIVE_FILE[1] << 16) + \
60+
(RELATIVE_FILE[2] << 8) + (RELATIVE_FILE[3]); \
5461
*(__m++) = (__func__[0] << 24) + (__func__[1] << 16) + \
5562
(__func__[2] << 8) + (__func__[3]); \
5663
*__m = __LINE__; \

src/include/sof/debug/panic.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
#include <ipc/trace.h>
1313
#include <stdint.h>
1414

15+
#ifndef RELATIVE_FILE
16+
#error "This file requires RELATIVE_FILE to be defined. " \
17+
"Add it to CMake's target with sof_append_relative_path_definitions."
18+
#endif
19+
1520
void dump_panicinfo(void *addr, struct sof_ipc_panic_info *panic_info);
1621
void panic_rewind(uint32_t p, uint32_t stack_rewind_frames,
1722
struct sof_ipc_panic_info *panic_info, uintptr_t *data);
1823
void __panic(uint32_t p, char *filename, uint32_t linenum);
1924

2025
/* panic dump filename and linenumber of the call */
21-
#define panic(x) __panic((x), (__FILE__), (__LINE__))
26+
#define panic(x) __panic((x), (RELATIVE_FILE), (__LINE__))
2227

2328
/* runtime assertion */
2429
#define assert(cond) (void)((cond) || (panic(SOF_IPC_PANIC_ASSERT), 0))

src/include/sof/trace/trace.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#ifndef __SOF_TRACE_TRACE_H__
1111
#define __SOF_TRACE_TRACE_H__
1212

13+
#ifndef RELATIVE_FILE
14+
#error "This file requires RELATIVE_FILE to be defined. " \
15+
"Add it to CMake's target with sof_append_relative_path_definitions."
16+
#endif
17+
1318
#if CONFIG_TRACE
1419
#include <platform/trace/trace.h>
1520
#endif
@@ -229,17 +234,17 @@ void trace_init(struct sof *sof);
229234
uint32_t line_idx; \
230235
uint32_t file_name_len; \
231236
uint32_t text_len; \
232-
const char file_name[sizeof(__FILE__)]; \
237+
const char file_name[sizeof(RELATIVE_FILE)]; \
233238
const char text[sizeof(format)]; \
234239
} log_entry = { \
235240
lvl, \
236241
comp_class, \
237242
ids, \
238243
params, \
239244
__LINE__, \
240-
sizeof(__FILE__), \
245+
sizeof(RELATIVE_FILE), \
241246
sizeof(format), \
242-
__FILE__, \
247+
RELATIVE_FILE, \
243248
format \
244249
}
245250

@@ -282,17 +287,17 @@ do { \
282287
uint32_t line_idx; \
283288
uint32_t file_name_len; \
284289
uint32_t text_len; \
285-
const char file_name[sizeof(__FILE__)]; \
290+
const char file_name[sizeof(RELATIVE_FILE)]; \
286291
const char text[sizeof(format)]; \
287292
} log_entry = { \
288293
lvl, \
289294
comp_class, \
290295
ids, \
291296
params, \
292297
__LINE__, \
293-
sizeof(__FILE__), \
298+
sizeof(RELATIVE_FILE), \
294299
sizeof(format), \
295-
__FILE__, \
300+
RELATIVE_FILE, \
296301
format \
297302
}
298303
#endif

test/cmocka/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ SET(arch_src ${PROJECT_SOURCE_DIR}/src/arch/xtensa/idc.c)
5757
add_library(universal_mock STATIC ${PROJECT_SOURCE_DIR}/test/cmocka/src/universal_mocks.c)
5858
target_link_libraries(universal_mock PRIVATE sof_options)
5959
link_libraries(universal_mock)
60+
sof_append_relative_path_definitions(universal_mock)
6061

6162
# creates exectuable for new test and adds it as test for ctest
6263
function(cmocka_test test_name)
@@ -74,6 +75,8 @@ function(cmocka_test test_name)
7475
target_compile_definitions(${test_name} PRIVATE -D_UINTPTR_T_DEFINED)
7576

7677
add_test(NAME ${test_name} COMMAND xt-run --exit_with_target_code ${test_name})
78+
79+
sof_append_relative_path_definitions(${test_name})
7780
endfunction()
7881

7982
add_subdirectory(src)

test/cmocka/src/audio/mux/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_library(
1313
${PROJECT_SOURCE_DIR}/src/audio/mux/mux_generic.c
1414
${PROJECT_SOURCE_DIR}/src/audio/component.c
1515
)
16+
sof_append_relative_path_definitions(audio_mux)
1617

1718
target_link_libraries(audio_mux PRIVATE sof_options)
1819

test/cmocka/src/audio/pipeline/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if(CONFIG_SMP)
1010
link_libraries(-Wl,--gc-sections)
1111

1212
add_library(pipeline_lib STATIC ${arch_src})
13+
sof_append_relative_path_definitions(pipeline_lib)
1314

1415
target_link_libraries(pipeline_lib PRIVATE sof_options)
1516

test/cmocka/src/audio/selector/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_library(audio_for_selector STATIC
1212
${PROJECT_SOURCE_DIR}/src/audio/selector/selector.c
1313
${PROJECT_SOURCE_DIR}/src/audio/selector/selector_generic.c
1414
)
15+
sof_append_relative_path_definitions(audio_for_selector)
1516

1617
target_link_libraries(audio_for_selector PRIVATE sof_options)
1718

test/cmocka/src/audio/volume/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_library(audio_for_volume STATIC
1313
${PROJECT_SOURCE_DIR}/src/audio/volume/volume_generic.c
1414
${PROJECT_SOURCE_DIR}/src/audio/volume/volume_hifi3.c
1515
)
16+
sof_append_relative_path_definitions(audio_for_volume)
1617

1718
target_link_libraries(audio_for_volume PRIVATE sof_options)
1819

test/cmocka/src/debugability/macros.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ static void test_debugability_macros_declare_log_entry(void **state)
4242
"uint32_t line_idx; "
4343
"uint32_t file_name_len; "
4444
"uint32_t text_len; "
45-
"const char file_name[sizeof(\"" __FILE__ "\")]; "
45+
"const char file_name[sizeof(\"" RELATIVE_FILE "\")]; "
4646
"const char text[sizeof(\"Message\")]; "
4747
"} log_entry = { "
4848
"1"
4949
"(6 << 24)"
5050
"1"
5151
"1"
5252
"32"
53-
"sizeof(\"" __FILE__ "\")"
53+
"sizeof(\"" RELATIVE_FILE "\")"
5454
"sizeof(\"Message\")"
55-
"\"" __FILE__ "\""
55+
"\"" RELATIVE_FILE "\""
5656
"\"Message\" "
5757
"}";
5858
(void)state;

tools/testbench/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.10)
44

55
project(SOF_TESTBENCH C)
66

7+
include(../../scripts/cmake/misc.cmake)
8+
79
add_executable(testbench
810
testbench.c
911
alloc.c
@@ -18,6 +20,8 @@ add_executable(testbench
1820
trace.c
1921
)
2022

23+
sof_append_relative_path_definitions(testbench)
24+
2125
target_include_directories(testbench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
2226

2327
target_compile_options(testbench PRIVATE -g -O3 -Wall -Werror -Wl,-EL -Wmissing-prototypes -Wimplicit-fallthrough=3)

0 commit comments

Comments
 (0)