diff options
author | Manuel Stoeckl <code@mstoeckl.com> | 2019-06-22 23:13:19 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-15 16:35:50 -0400 |
commit | 2dc4978d8af326c310057ca8fd22a4c7f5d09335 (patch) | |
tree | e49b4d10481309d90bd5330b7bbeec588f4de88c /include/log.h | |
parent | Layout tiled using a width/height fraction (diff) | |
download | sway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.tar.gz sway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.tar.zst sway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.zip |
Use -fmacro-prefix-map to strip build path
Because meson does not provide a simple way to get the relative build
path, it is computed with a pair of foreach loops. As meson does not
have a simple way to compute string length (except via underscorify
and 63 split operations), the build script uses a shell command
instead.
If the compiler does not suppot -fmacro-prefix-map, then fall back
to passing in the relative path prefix, and use its length to offset
the uses of __FILE__ in log messages so that the build path is at
least still not included in the logs. This is significantly more
efficient than calling _sway_strip_path.
Diffstat (limited to 'include/log.h')
-rw-r--r-- | include/log.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/include/log.h b/include/log.h index adf431ab..41399a9f 100644 --- a/include/log.h +++ b/include/log.h | |||
@@ -33,22 +33,26 @@ void _sway_vlog(sway_log_importance_t verbosity, const char *format, va_list arg | |||
33 | void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); | 33 | void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); |
34 | bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3); | 34 | bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3); |
35 | 35 | ||
36 | // TODO: get meson to precompute this, for better reproducibility/less overhead | 36 | #ifdef SWAY_REL_SRC_DIR |
37 | const char *_sway_strip_path(const char *filepath); | 37 | // strip prefix from __FILE__, leaving the path relative to the project root |
38 | #define _SWAY_FILENAME ((const char *)__FILE__ + sizeof(SWAY_REL_SRC_DIR) - 1) | ||
39 | #else | ||
40 | #define _SWAY_FILENAME __FILE__ | ||
41 | #endif | ||
38 | 42 | ||
39 | #define sway_log(verb, fmt, ...) \ | 43 | #define sway_log(verb, fmt, ...) \ |
40 | _sway_log(verb, "[%s:%d] " fmt, _sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) | 44 | _sway_log(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__) |
41 | 45 | ||
42 | #define sway_vlog(verb, fmt, args) \ | 46 | #define sway_vlog(verb, fmt, args) \ |
43 | _sway_vlog(verb, "[%s:%d] " fmt, _sway_strip_path(__FILE__), __LINE__, args) | 47 | _sway_vlog(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, args) |
44 | 48 | ||
45 | #define sway_log_errno(verb, fmt, ...) \ | 49 | #define sway_log_errno(verb, fmt, ...) \ |
46 | sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) | 50 | sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) |
47 | 51 | ||
48 | #define sway_abort(FMT, ...) \ | 52 | #define sway_abort(FMT, ...) \ |
49 | _sway_abort("[%s:%d] " FMT, _sway_strip_path(__FILE__), __LINE__, ##__VA_ARGS__) | 53 | _sway_abort("[%s:%d] " FMT, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__) |
50 | 54 | ||
51 | #define sway_assert(COND, FMT, ...) \ | 55 | #define sway_assert(COND, FMT, ...) \ |
52 | _sway_assert(COND, "[%s:%d] %s:" FMT, _sway_strip_path(__FILE__), __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__) | 56 | _sway_assert(COND, "[%s:%d] %s:" FMT, _SWAY_FILENAME, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__) |
53 | 57 | ||
54 | #endif | 58 | #endif |