From 2dc4978d8af326c310057ca8fd22a4c7f5d09335 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Sat, 22 Jun 2019 23:13:19 -0400 Subject: 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. --- meson.build | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'meson.build') diff --git a/meson.build b/meson.build index f657f874..eb5039ee 100644 --- a/meson.build +++ b/meson.build @@ -13,8 +13,6 @@ project( add_project_arguments( [ - '-DSWAY_SRC_DIR="@0@"'.format(meson.current_source_dir()), - '-DWL_HIDE_DEPRECATED', '-DWLR_USE_UNSTABLE', @@ -142,6 +140,44 @@ if git.found() endif add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c') +# Compute the relative path used by compiler invocations. +source_root = meson.current_source_dir().split('/') +build_root = meson.build_root().split('/') +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) + '/' + +# 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 + add_project_arguments( + '-DSWAY_REL_SRC_DIR="@0@"'.format(relative_dir), + language: 'c', + ) +endif + + sway_inc = include_directories('include') subdir('include') -- cgit v1.2.3-54-g00ecf