kronenthaler / mod-pbxproj

A python module to manipulate XCode projects
MIT License
1.2k stars 294 forks source link

[BUG] Added files aren't copied to Compile Sources #287

Closed osfunapps closed 3 years ago

osfunapps commented 3 years ago

Hey,

I'm adding the extension files like so:

extensions_arr = ['.zip', '.xml', '.plist', '.swift']
  for ext in extensions_arr:
        ProjectFiles._FILE_TYPES[ext] = (ext[1:] + ext, u'PBXResourcesBuildPhase')

and am adding the file like this: project.add_file(file_path, force=True, parent=group)

Now, the file does appearing in the Copy Bundle Resources but not in the Compile Sources.

I have to add that I do have spaces in my Library Search Path but even when using escaping the .swift files isn't moved to the Compile Sources of the project.

Thanks, Oz.

kronenthaler commented 3 years ago

Thanks for your question. Let break it down in parts.

First, .swift is a file extension that is already defined and set to add the source code files into the right phase PBXSourcesBuildPhase, which will add the swift files into the compile sources. You are overriding such behavior by telling the library to add them as resources as opposed of source files. If you remove from such list it would do as you expect.

Second, .plist is also predefined, no need to added again.

Lastly, for those resource files that might not be defined AND are resources, you could simply add them separately and specify a proper FileOptions(ignore_unknown_type=True), in your add_file call, to default and add everything that's unknown as a resource. Something like this:

project.add_file(file_path, force=True, parent=group, file_options=FileOptions(ignore_unknown_type=True))

TL;DR: default to add unknown files as resources (if they could be resources), and avoid overriding the already defined types.