Skip to content

Commit

Permalink
Updated detection implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ark-konopacki committed May 23, 2016
1 parent 87a39e1 commit fc369cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
16 changes: 9 additions & 7 deletions lib/run_loop/detect_aut/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,23 @@ def xcode_preferences_plist
end

# @!visibility private
def pbuddy
def self.pbuddy
@pbuddy ||= RunLoop::PlistBuddy.new
end

# @!visibility private
def self.detect_selected_device
file_name = find_user_state_file
selected_device = `/usr/libexec/PlistBuddy -c Print "#{file_name}"`
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
.split("\n")
.select { |v| v =~ /dvtdevice.*:/ }[0]
selected_device = @pbuddy.plist_find_device(file_name)

udid = selected_device.split(':')[1]
RunLoop::Device.device_with_identifier(udid)

selected_device = RunLoop::Device.device_with_identifier(udid)
#TODO now only returning detected device if simulator detected
if selected_device.simulator?
selected_device
else
nil
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/run_loop/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def self.device_with_identifier(udid_or_name, options={})
# @raise [ArgumentError] If DEVICE_TARGET or options specify an identifier
# that does not match an iOS Simulator or physical device.
def self.detect_device(options, xcode, simctl, instruments)
device = self.device_from_opts_or_env(options)
device = RunLoop::DetectAUT::Xcode.detect_selected_device ||
self.device_from_opts_or_env(options)

# Passed an instance of RunLoop::Device
return device if device && device.is_a?(RunLoop::Device)
Expand Down
10 changes: 10 additions & 0 deletions lib/run_loop/plist_buddy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def plist_read(key, file, opts={})
end
end

# !!Experimental!! find device in xcuserstate file.
# @param [String] file the plist to read
# @return [String] the UDID of device
def plist_find_device(file)
`#{plist_buddy} -c Print "#{file}"`
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
.split("\n")
.select { |v| v =~ /dvtdevice.*:/ }[0]
end

# Checks if the key exists in plist.
# @param [String] key the key to inspect (may not be nil or empty)
# @param [String] file the plist to read
Expand Down

0 comments on commit fc369cf

Please sign in to comment.