build,log: make __FILE__ produce concise and consistent filenames
The output of __FILE__ previously depended on where the build directory is and was needlessly verbose. With this change, all filenames are relative to the src/ directory. Logging of source file names is now also enabled for release builds (although this is not used yet).
This commit is contained in:
parent
dca1aefbd8
commit
21c3aebce5
7 changed files with 56 additions and 11 deletions
39
meson.build
39
meson.build
|
@ -515,6 +515,45 @@ use_testing_stages = is_developer_build
|
|||
config.set('TAISEI_BUILDCONF_DYNSTAGE', stages_live_reload)
|
||||
config.set('TAISEI_BUILDCONF_TESTING_STAGES', use_testing_stages)
|
||||
|
||||
# Stolen from Sway
|
||||
# Compute the relative path used by compiler invocations.
|
||||
source_root = meson.current_source_dir().split('/')
|
||||
build_root = meson.build_root().split('/')
|
||||
if build_machine.system() == 'windows'
|
||||
source_root = source_root.replace('\\', '/')
|
||||
build_root = build_root.replace('\\', '/')
|
||||
endif
|
||||
relative_dir_parts = []
|
||||
i = 0
|
||||
in_prefix = true
|
||||
foreach p : build_root
|
||||
if i >= source_root.length() or not in_prefix or p != source_root[i]
|
||||
in_prefix = false
|
||||
relative_dir_parts += '..'
|
||||
endif
|
||||
i += 1
|
||||
endforeach
|
||||
i = 0
|
||||
in_prefix = true
|
||||
foreach p : source_root
|
||||
if i >= build_root.length() or not in_prefix or build_root[i] != p
|
||||
in_prefix = false
|
||||
relative_dir_parts += p
|
||||
endif
|
||||
i += 1
|
||||
endforeach
|
||||
relative_dir = join_paths(relative_dir_parts) + '/src/'
|
||||
|
||||
# Strip relative path prefixes from the code if possible, otherwise hide them.
|
||||
if cc.has_argument('-fmacro-prefix-map=/prefix/to/hide=')
|
||||
add_project_arguments(
|
||||
'-fmacro-prefix-map=@0@='.format(relative_dir),
|
||||
language: 'c',
|
||||
)
|
||||
else
|
||||
config.set('TAISEI_BUILDCONF_REL_SRC_DIR', relative_dir)
|
||||
endif
|
||||
|
||||
subdir('misc')
|
||||
subdir('emscripten')
|
||||
subdir('switch')
|
||||
|
|
|
@ -120,16 +120,16 @@ void log_sync(void);
|
|||
#if defined(DEBUG) && !defined(__EMSCRIPTEN__)
|
||||
#define log_debug(...) log_custom(LOG_DEBUG, __VA_ARGS__)
|
||||
#undef UNREACHABLE
|
||||
#define UNREACHABLE log_fatal("This code should never be reached (%s:%i)", __FILE__, __LINE__)
|
||||
#define UNREACHABLE log_fatal("This code should never be reached (%s:%i)", _TAISEI_SRC_FILE, __LINE__)
|
||||
#else
|
||||
#define log_debug(...) ((void)0)
|
||||
#define LOG_NO_FILENAMES
|
||||
// #define LOG_NO_FILENAMES
|
||||
#endif
|
||||
|
||||
#ifdef LOG_NO_FILENAMES
|
||||
#define _do_log(func, lvl, ...) (func)(lvl, __func__, "<unknown>", 0, __VA_ARGS__)
|
||||
#else
|
||||
#define _do_log(func, lvl, ...) (func)(lvl, __func__, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define _do_log(func, lvl, ...) (func)(lvl, __func__, _TAISEI_SRC_FILE, __LINE__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define log_custom(lvl, ...) _do_log(_taisei_log, lvl, __VA_ARGS__)
|
||||
|
|
10
src/random.h
10
src/random.h
|
@ -162,10 +162,10 @@ uint64_t _tsrand64_a(int idx, const char *file, uint line) RNG_DEPRECATED;
|
|||
double _afrand(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
double _anfrand(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
|
||||
#define tsrand_fill_p(rnd,amount) _tsrand_fill_p(rnd, amount, __FILE__, __LINE__)
|
||||
#define tsrand_fill(amount) _tsrand_fill(amount, __FILE__, __LINE__)
|
||||
#define tsrand_a(idx) _tsrand_a(idx, __FILE__, __LINE__)
|
||||
#define afrand(idx) _afrand(idx, __FILE__, __LINE__)
|
||||
#define anfrand(idx) _anfrand(idx, __FILE__, __LINE__)
|
||||
#define tsrand_fill_p(rnd,amount) _tsrand_fill_p(rnd, amount, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define tsrand_fill(amount) _tsrand_fill(amount, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define tsrand_a(idx) _tsrand_a(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define afrand(idx) _afrand(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define anfrand(idx) _anfrand(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
|
||||
#define TSRAND_ARRAY_LIMIT 16
|
||||
|
|
|
@ -45,7 +45,7 @@ void _ts_assert_fail(const char *cond, const char *func, const char *file, int l
|
|||
#define _assert(cond, uselog)
|
||||
#define _assume(cond, uselog) ASSUME(cond)
|
||||
#else
|
||||
#define _assert(cond, uselog) (LIKELY(cond) ? (void)0 : (_ts_assert_fail(#cond, __func__, __FILE__, __LINE__, uselog), TRAP()))
|
||||
#define _assert(cond, uselog) (LIKELY(cond) ? (void)0 : (_ts_assert_fail(#cond, __func__, _TAISEI_SRC_FILE, __LINE__, uselog), TRAP()))
|
||||
#define _assume(cond, uselog) _assert(cond, uselog)
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,6 +24,12 @@
|
|||
#include <stdnoreturn.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef TAISEI_BUILDCONF_REL_SRC_DIR
|
||||
#define _TAISEI_SRC_FILE ((const char *)__FILE__ + sizeof(TAISEI_BUILDCONF_REL_SRC_DIR) - 1)
|
||||
#else
|
||||
#define _TAISEI_SRC_FILE __FILE__
|
||||
#endif
|
||||
|
||||
#include "util/assert.h"
|
||||
|
||||
#ifdef __FAST_MATH__
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
uint line;
|
||||
} DebugInfo;
|
||||
|
||||
#define _DEBUG_INFO_INITIALIZER_ { __FILE__, __func__, __LINE__ }
|
||||
#define _DEBUG_INFO_INITIALIZER_ { _TAISEI_SRC_FILE, __func__, __LINE__ }
|
||||
#define _DEBUG_INFO_ ((DebugInfo) _DEBUG_INFO_INITIALIZER_)
|
||||
#define _DEBUG_INFO_PTR_ (&_DEBUG_INFO_)
|
||||
#define set_debug_info(debug) _set_debug_info(debug, _DEBUG_INFO_PTR_)
|
||||
|
|
|
@ -51,7 +51,7 @@ static void _vfs_set_error_win32(const char *file, int line) {
|
|||
free(errstr);
|
||||
}
|
||||
|
||||
#define vfs_set_error_win32() _vfs_set_error_win32(__FILE__, __LINE__)
|
||||
#define vfs_set_error_win32() _vfs_set_error_win32(_TAISEI_SRC_FILE, __LINE__)
|
||||
|
||||
static VFSInfo vfs_syspath_query(VFSNode *node) {
|
||||
VFSInfo i = {0};
|
||||
|
|
Loading…
Reference in a new issue