Skip to content

Commit

Permalink
Xcode backend: better quoting for spaces in HEADER_SEARCH_PATHS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klokik authored and jpakkane committed Dec 16, 2024
1 parent e542901 commit 0b41b36
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions mesonbuild/backend/xcodebackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0b41b36

Please sign in to comment.