Skip to content

Commit

Permalink
Merge pull request #407 from CocoaPods/xcode-8-devtoolscore-workaroun…
Browse files Browse the repository at this point in the history
…d-subprocess-exec

Xcode 8 devtoolscore workaround subprocess exec
  • Loading branch information
orta authored Sep 6, 2016
2 parents 0e803d9 + 177a325 commit ac5cdd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
26 changes: 21 additions & 5 deletions lib/xcodeproj/plist/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def attempt_to_load!
def write_to_path(hash, path)
raise ThreadError, 'Can only write plists from the main thread.' unless Thread.current == Thread.main

if DevToolsCore.load_xcode_frameworks && path.end_with?('pbxproj')
ruby_hash_write_xcode(hash, path)
else
path = File.expand_path(path)
success = ruby_hash_write_xcode(hash, path)

unless success
CoreFoundation.RubyHashPropertyListWrite(hash, path)
fix_encoding(path)
end
Expand Down Expand Up @@ -96,7 +97,22 @@ def fix_encoding(filename)
# The path of the file.
#
def ruby_hash_write_xcode(hash, path)
path = File.expand_path(path)
return false unless path.end_with?('pbxproj')
require 'open3'
_output, status = Open3.capture2e(Gem.ruby, '-e', <<-RUBY, path, :stdin_data => Marshal.dump(hash))
$LOAD_PATH.replace #{$LOAD_PATH}
path = ARGV.first
hash = Marshal.load(STDIN)
require "xcodeproj"
require "xcodeproj/plist/ffi"
ffi = Xcodeproj::Plist::FFI
success = ffi::DevToolsCore.load_xcode_frameworks && ffi.send(:ruby_hash_write_devtoolscore, hash, path)
exit(success ? 0 : 1)
RUBY
status.success?
end

def ruby_hash_write_devtoolscore(hash, path)
success = true

begin
Expand All @@ -111,7 +127,7 @@ def ruby_hash_write_xcode(hash, path)
success = false
end

CoreFoundation.RubyHashPropertyListWrite(hash, path) unless success
success
end
end
end
Expand Down
13 changes: 5 additions & 8 deletions lib/xcodeproj/plist/ffi/dev_tools_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ module Plist
module FFI
module DevToolsCore
def self.silence_stderr
begin
orig_stderr = $stderr.clone
$stderr.reopen File.new('/dev/null', 'w')
retval = yield
ensure
$stderr.reopen orig_stderr
end
retval
orig_stderr = $stderr.clone
$stderr.reopen File.new('/dev/null', 'w')
yield
ensure
$stderr.reopen orig_stderr
end

# rubocop:disable Style/MethodName
Expand Down
2 changes: 1 addition & 1 deletion spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ module ProjectSpecs
end

it 'escapes non ASCII characters in the project' do
Plist::FFI::DevToolsCore.stubs(:load_xcode_frameworks).returns(nil)
Plist::FFI.stubs(:ruby_hash_write_xcode).returns(false)

file_ref = @project.new_file('わくわく')
file_ref.name = 'わくわく'
Expand Down

0 comments on commit ac5cdd7

Please sign in to comment.