Skip to content

Commit f021b9c

Browse files
slipherVReaperV
authored andcommitted
path stripping flags
1 parent 3bc9452 commit f021b9c

File tree

2 files changed

+20
-37
lines changed

2 files changed

+20
-37
lines changed

cmake/DaemonFlags.cmake

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,13 @@ if(USE_CPP23)
9898
set(CPP23SupportLibrary "")
9999
else()
100100
add_definitions(-DDAEMON_CPP23_SUPPORT_LIBRARY_ENABLED=1)
101-
# FIXME: Doesn't work?
102-
add_compile_options("-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/src=.")
103101

104102
if (CPP23SupportLibraryOldLibrary)
105103
message(STATUS "Using <stacktrace>: found ${CPP23SupportLibrary} (recommended to use libc++exp on this compiler version instead, but it wasn't found)")
106104
else()
107105
message(STATUS "Using <stacktrace>: found ${CPP23SupportLibrary}")
108106
endif()
109107
endif()
110-
elseif (MSVC)
111-
# FIXME: Doesn't work in sgame/cgame?
112-
string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/src)
113-
add_compile_options("/d1trimfile:${backslashed_dir}")
114-
115-
string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/daemon/src)
116-
add_compile_options("/d1trimfile:${backslashed_dir}")
117108
endif()
118109
endif()
119110

@@ -226,6 +217,24 @@ macro(try_exe_linker_flag PROP FLAG)
226217
endif()
227218
endmacro()
228219

220+
# Stripping of absolute paths for __FILE__ / source_location
221+
# Also do without src/ to get libs/
222+
set(FILENAME_STRIP_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}")
223+
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL DAEMON_DIR)
224+
set(FILENAME_STRIP_DIRS ${FILENAME_STRIP_DIRS} "${DAEMON_DIR}/src" "${DAEMON_DIR}")
225+
endif()
226+
foreach(strip_dir ${FILENAME_STRIP_DIRS})
227+
if (MSVC)
228+
string(REPLACE "/" "\\" backslashed_dir ${strip_dir})
229+
# set_c_cxx_flag can't be used because macros barf if the input contains backslashes
230+
# https://gitlab.kitware.com/cmake/cmake/-/issues/19281
231+
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}")
232+
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}")
233+
else()
234+
try_c_cxx_flag(PREFIX_MAP "-fmacro-prefix-map=${strip_dir}=.")
235+
endif()
236+
endforeach()
237+
229238
if (BE_VERBOSE)
230239
set(WARNMODE "no-error=")
231240
else()

src/common/StackTrace.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,10 @@ inline std::string FormatStackTrace( const std::stacktrace& stackTrace,
5757
continue;
5858
}
5959

60-
std::string file = entry.source_file();
61-
62-
#if defined( _MSC_VER )
63-
size_t pos = file.find( "src\\n" );
64-
#else
65-
size_t pos = file.find( "src/" );
66-
#endif
67-
68-
if ( pos != std::string::npos ) {
69-
file = file.substr( pos + 4 );
70-
}
71-
72-
if ( compact ) {
73-
#if defined( _MSC_VER )
74-
pos = file.find( "engine\\renderer-vulkan" );
75-
#else
76-
pos = file.find( "engine/renderer-vulkan" );
77-
#endif
78-
79-
if ( pos == std::string::npos ) {
80-
continue;
81-
}
82-
83-
file = file.substr( pos + 23 );
84-
}
85-
8660
if( compact ) {
87-
out += Str::Format( addLineEnd ? "\n%s:%u" : "%s:%u", file, entry.source_line() );
61+
out += Str::Format( addLineEnd ? "\n%s:%u" : "%s:%u", entry.source_file(), entry.source_line());
8862
} else {
89-
out += Str::Format( addLineEnd ? "\n%s:%u: %s" : "%s:%u: %s", file, entry.source_line(), entry.description() );
63+
out += Str::Format( addLineEnd ? "\n%s:%u: %s" : "%s:%u: %s", entry.source_file(), entry.source_line(), entry.description());
9064
}
9165
addLineEnd = true;
9266
}

0 commit comments

Comments
 (0)