kronenthaler / mod-pbxproj

A python module to manipulate XCode projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] add_folder always resolves paths as absolute

u8-xiaohei opened this issue · comments

Describe the bug
add_folder method in class ProjectFiles add absolute path to PBXGroup.

I used the new script to provide a method like the old "apply_mods" , I found the add_folder method in class ProjectFiles add wrong path to PBXGroup, which expect the relpath,but absolute path wrote.

System information

  1. pbxproj version used: 2.11
  2. python version used: python 3.8
  3. Xcode version used: 11.2.1

Thank you for your report. Can you provide:

  • Exact steps to reproduce
  • A initial sample project
  • A sample expected end state project

@kronenthaler Thank you for reply. But I can't provide the sample project now, I will test it in my spare time.

I found the add_folder() method in old mod_pbxproj.py coverts the path to relpath before call get_or_create_group like this:

grp = self.get_or_create_group(folder_name, path=self.get_relative_path(grp_path), parent=parent)

But the code in add_folder() method to call get_or_create_group in pbxproj/pbxextensions/ProjectFiles.py now is:

path = os.path.abspath(path)
if not create_groups and os.path.splitext(path)[1] not in ProjectFiles._SPECIAL_FOLDERS:
   return self.add_file(path, parent, target_name=target_name, force=False, file_options=file_options)
parent = self.get_or_create_group(os.path.split(path)[1], path, parent)

The path in the above code was converted to absolute path, and then passed to the get_or_create_group method directly.

I now fixed this temporarily by modifing the get_or_create_group method in pbxproj/pbxextensions/ProjectGroups.py like the following:

  def get_or_create_group(self, name, path=None, parent=None):
        if not name:
            return None
        groups = self.get_groups_by_name(name, parent)
        if groups.__len__() > 0:
            return groups[0]
        # temp fix path begin:
        if path is not None:
            abs_path, path, tree = ProjectFiles._get_path_and_tree(self._source_root, path, TreeType.SOURCE_ROOT)
        # temp fix path end
        return self.add_group(name, path, parent)

I just call the _get_path_and_tree method to convert the path to relpath. But I'm not show whether it's the right way.

Thank you.

Thanks for the examples, i will take a look when i have some spare time.

@kronenthaler tks !
I found an another bug about the add_file method of ProjectFiles class in pbxproj/pbxextensions/ProjectFiles.py:

       if os.path.isfile(abs_path):
            self.add_library_search_paths([library_path], recursive=False)
        else:
            self.add_framework_search_paths([library_path, '$(inherited)'], recursive=False)

if the library_path has space, the path added to XCBuildConfiguration will be splited by space and result in two wrong path. for instance, I want to add a file in path :

$(SRCROOT)/../../../../../../../../Library/Application Support/Test/SDK

the result in library search paths will be :

QQ图片20200602163612

The add_library_search_paths and add_framework_search_paths method has a param named "escape", but the default value is set to False。

I now fixed this temporarily by modifing the above code like this:

        escape = False
        if " " in library_path:
            escape = True

        if os.path.isfile(abs_path):
            self.add_library_search_paths([library_path], recursive=False, escape=escape)
        else:
            self.add_framework_search_paths([library_path, '$(inherited)'], recursive=False, escape=escape)

Waiting for your testing and fix, thank you!

@u8-xiaohei i have created a new issue for the last comment: #280

@kronenthaler thank you for your fix.👍

This issue has become stale, the required information has not been provided and it is been marked for closure in the next 5 days