mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-12-15 08:56:26 -05:00
Use -fmacro-prefix-map to strip build path
This commit matches sway's 2dc4978d8af326c310057ca8fd22a4c7f5d09335. To help ensure a reproducible build (when debug info is disabled), the meson build script now uses the -fmacro-prefix-map command line argument supported by GCC to strip the build-path dependent bytes of each __FILE__ string used by wlr_log and related functions. A rather ugly algorithm is used to compute the relative path between the build and source folders, because meson has no specific function for this. When the compiler does not support -fmacro-prefix-map, fall back to shifting the start of each __FILE__ string by the length of the relative path to the source directory.
This commit is contained in:
parent
9e8f952997
commit
bb05617414
4 changed files with 47 additions and 22 deletions
38
meson.build
38
meson.build
|
|
@ -17,7 +17,6 @@ project(
|
|||
so_version = ['3', '4', '1']
|
||||
|
||||
add_project_arguments([
|
||||
'-DWLR_SRC_DIR="@0@"'.format(meson.current_source_dir()),
|
||||
'-DWLR_USE_UNSTABLE',
|
||||
], language: 'c')
|
||||
|
||||
|
|
@ -41,6 +40,43 @@ add_project_arguments(cc.get_supported_arguments([
|
|||
'-Wno-unused-parameter',
|
||||
]), 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(
|
||||
'-DWLR_REL_SRC_DIR="@0@"'.format(relative_dir),
|
||||
language: 'c',
|
||||
)
|
||||
endif
|
||||
|
||||
conf_data = configuration_data()
|
||||
conf_data.set10('WLR_HAS_LIBCAP', false)
|
||||
conf_data.set10('WLR_HAS_SYSTEMD', false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue