Skip to content

[BUG] Missing support for handling productRef file references #283

Description

@davidohyer

Describe the bug
When using Swift Packages in a project, running this tool crashes due to the library being unsure of how to handle productRef file references. Below is an example line from a .pbxproj file that contains Swift Packages:

58AFD9DF24D2077900331519 /* Core in Frameworks */ = {isa = PBXBuildFile; productRef = 58AFD9DE24D2077900331519 /* Core */; };

And here is the trace error:

Traceback (most recent call last):
  File "modpbx.py", line 57, in <module>
    resultClasses = project.remove_group_by_id(classesGroup.get_id(), True)
  File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectGroups.py", line 65, in remove_group_by_id
  File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectGroups.py", line 70, in remove_group_by_id
  File "/usr/local/lib/python3.7/site-packages/pbxproj-2.9.0-py3.7.egg/pbxproj/pbxextensions/ProjectFiles.py", line 317, in remove_file_by_id
AttributeError: 'PBXBuildFile' object has no attribute 'fileRef'

System information

  1. pbxproj version used: latest code from master
  2. python version used: 3.7.6
  3. Xcode version used: 11.5

To Reproduce
Steps to reproduce the behavior:

  1. Add a Swift Package to your project
  2. Add the framework to the targets frameworks area
  3. Run the following script:
#! /usr/bin/env python3
import os
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import *

from pbxproj.pbxextensions.ProjectFiles import FileOptions
ProjectFiles._FILE_TYPES[u'.icalls'] = (u'library.icalls', u'PBXResourcesBuildPhase')
del ProjectFiles._FILE_TYPES['.h'] # to prevent header files from being attached to a

project = XcodeProject.load('./App/App.xcodeproj/project.pbxproj')

rootGroup = project._get_parent_group( None )

unityGroup = None
unityGroups = project.get_groups_by_name('Unity', rootGroup)

if unityGroups.__len__() > 0:
	unityGroup = unityGroups[0]

classesGroups = project.get_groups_by_name('Classes', unityGroup)
classesGroup = None

if classesGroups.__len__() > 0:
	classesGroup = classesGroups[0]

librariesGroups = project.get_groups_by_name('Libraries', unityGroup)
librariesGroup = None

if librariesGroups.__len__() > 0:
	librariesGroup = librariesGroups[0]

if classesGroup is not None:
	resultClasses = project.remove_group_by_id(classesGroup.get_id(), True)

Expected behavior
Remove the specified groups.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions