From f889a2a1c4f59351f451a6dd121e9d41a014ac8a Mon Sep 17 00:00:00 2001 From: Nick <0xb000@gmail.com> Date: Mon, 4 Nov 2024 18:33:41 +0200 Subject: [PATCH] Xcode backend: better quoting for spaces in HEADER_SEARCH_PATHS Xcode treats this dict value as a space-separated string, any spaces in the path will make the path invalid by splitting it into pieces. Split out header path processing into a helper function. --- mesonbuild/backend/xcodebackend.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 5c03c715720e..0e40d0239e5a 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -1756,19 +1756,12 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non settings_dict.add_item('GCC_PREFIX_HEADER', f'$(PROJECT_DIR)/{relative_pch_path}') settings_dict.add_item('GCC_PREPROCESSOR_DEFINITIONS', '') settings_dict.add_item('GCC_SYMBOLS_PRIVATE_EXTERN', 'NO') - header_arr = PbxArray() - unquoted_headers = [] - unquoted_headers.append(self.get_target_private_dir_abs(target)) + unquoted_headers = [self.get_target_private_dir_abs(target)] if target.implicit_include_directories: unquoted_headers.append(os.path.join(self.environment.get_build_dir(), target.get_subdir())) unquoted_headers.append(os.path.join(self.environment.get_source_dir(), target.get_subdir())) - if headerdirs: - for i in headerdirs: - i = os.path.normpath(i) - unquoted_headers.append(i) - for i in unquoted_headers: - header_arr.add_item(f'"{i}"') - settings_dict.add_item('HEADER_SEARCH_PATHS', header_arr) + unquoted_headers += headerdirs + settings_dict.add_item('HEADER_SEARCH_PATHS', self.normalize_header_search_paths(unquoted_headers)) settings_dict.add_item('INSTALL_PATH', install_path) settings_dict.add_item('LIBRARY_SEARCH_PATHS', '') if isinstance(target, build.SharedModule): @@ -1796,6 +1789,15 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non warn_array.add_item('"$(inherited)"') bt_dict.add_item('name', buildtype) + def normalize_header_search_paths(self, header_dirs) -> PbxArray: + header_arr = PbxArray() + for i in header_dirs: + np = os.path.normpath(i) + # Make sure Xcode will not split single path into separate entries, escaping space with a slash is not enought + item = f'"\\\"{np}\\\""' if ' ' in np else f'"{np}"' + header_arr.add_item(item) + return header_arr + def add_otherargs(self, settings_dict, langargs): for langname, args in langargs.items(): if args: