Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

targets.delete corrupts the project file? #462

Closed
JanC opened this issue Jan 23, 2017 · 2 comments
Closed

targets.delete corrupts the project file? #462

JanC opened this issue Jan 23, 2017 · 2 comments

Comments

@JanC
Copy link
Contributor

JanC commented Jan 23, 2017

Hi,
I've updated to xcodeproj 1.4.2 and I have troubled removing a target from a project. This same code works fine in version 1.3.0

@d360_kit_project_path = "MyKit.xcodeproj"

@xcp_project = Xcodeproj::Project.open(@d360_kit_project_path)
target_name = "MyKitTests"
@xcp_target = @xcp_project.targets.select { |target| target.name == target_name }.first

if @xcp_target
    puts "Removing target #{@xcp_target.name}"
    @xcp_project.targets.delete(@xcp_target)
end
@xcp_project.save(@xcp_project.path)

The result is

Removing target MyKitTests
/Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project/object/configuration_list.rb:101:in `ascii_plist_annotation': undefined method `isa' for nil:NilClass (NoMethodError)
Did you mean?  is_a?
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:286:in `block in to_ascii_plist'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:285:in `each'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:285:in `to_ascii_plist'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `block in save'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `open'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `save'
	from remove_target.rb:14:in `<main>'

In attachment is a sample project to reproduce it

bundle exec ruby remove_target.rb 

Any ideas?

cheers
MyKit.zip

@oscahie
Copy link

oscahie commented Feb 3, 2017

I just ran into the same issue... While I'm not familiar with Xcodeproj, nor with Ruby, I made a quick & dirty patch anyway just to get it working and move on for now. Simply changed the method ascii_plist_annotation located at $HOME/.rvm/gems/ruby-2.0.0-p0/gems/xcodeproj-1.4.2/lib/xcodeproj/project/object/configuration_list.rb, line 100, to this:

        def ascii_plist_annotation
            unless target.nil?
                " Build configuration list for #{target.isa} \"#{target}\" "
            else
                " Build configuration list for <deleted target> "
            end
        end

A proper fix would be required, since it seems like a XCConfigurationList object for the deleted target is not being removed from the project file in 1.4.2.

@JanC
Copy link
Contributor Author

JanC commented Mar 28, 2018

I tried again with xcodeproj (1.5.7) but the behaviour is still the same. The fix above works fine so I created a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants