tools and utilities for working with xcode/ios projects
Apache License 2.0
226
stars
105
forks
source link
If a file is added by addToPbxFileReferenceSection, project.pbxproj is then saved by Xcode 6.2, removeFromPbxFileReferenceSection will fail to remove it. #44
I have already debugged this issue, so please allow me to explain. When a file is added by addToPbxFileReferenceSection, its record in project.pbxproj will look like this:
However if user opens this Xcode project with Xcode 6.2, then saves it (for whatever reason, does not have to be related to the file in question), its record will now look like this:
The important thing to notice here is that quotes (") are stripped around name and path. This causes removeFromPbxFileReferenceSection to fail. See pbxProject.js line 279, where on the left hand side name and path are unquoted, while on the right hand side name and path are quoted. So if you debug this line you can see that it's comparing: somepath/somefile.m to "somepath/somefile.m", which will never equal.
This issue in turn causes a chain of issues, most important of which is when a file is removed by removeSourceFile, it successfully removes it from PBXBuildFile and PBXSourcesBuildPhase but fails to remove it from PBXFileReference. So the next time when you call addSourceFile on the same file, it will fail to add it to PBXBuildFile and PBXSourcesBuildPhase due to pbxProject.js line 114, where if a file is already found in PBXFileReference, it returns without adding it to PBXBuildFile and PBXSourcesBuildPhase.
This in turn screws up Cordova's plugin upgrade script, which removes bunch of files, update them, then add them again. I understand that Cordova is not this project's responsibility, however I leave this bit of information here just for FYI.
I propose either unquote both side of pbxProject.js line 279, or use || comparison similar to hasFile's implementation. I'm already preparing a pull request with the later strategy, which keeps the code base more consistent. Please consider.
I have already debugged this issue, so please allow me to explain. When a file is added by
addToPbxFileReferenceSection
, its record in project.pbxproj will look like this:However if user opens this Xcode project with Xcode 6.2, then saves it (for whatever reason, does not have to be related to the file in question), its record will now look like this:
The important thing to notice here is that quotes (
"
) are stripped aroundname
andpath
. This causesremoveFromPbxFileReferenceSection
to fail. See pbxProject.js line 279, where on the left hand sidename
andpath
are unquoted, while on the right hand sidename
andpath
are quoted. So if you debug this line you can see that it's comparing:somepath/somefile.m
to"somepath/somefile.m"
, which will never equal.This issue in turn causes a chain of issues, most important of which is when a file is removed by
removeSourceFile
, it successfully removes it fromPBXBuildFile
andPBXSourcesBuildPhase
but fails to remove it fromPBXFileReference
. So the next time when you calladdSourceFile
on the same file, it will fail to add it toPBXBuildFile
andPBXSourcesBuildPhase
due to pbxProject.js line 114, where if a file is already found inPBXFileReference
, it returns without adding it toPBXBuildFile
andPBXSourcesBuildPhase
.This in turn screws up Cordova's plugin upgrade script, which removes bunch of files, update them, then add them again. I understand that Cordova is not this project's responsibility, however I leave this bit of information here just for FYI.
I propose either unquote both side of pbxProject.js line 279, or use
||
comparison similar tohasFile
's implementation. I'm already preparing a pull request with the later strategy, which keeps the code base more consistent. Please consider.EDIT: Pull request #45 is created for this issue.