Class: RunLoop::Lipo

Inherits:
Object
  • Object
show all
Defined in:
lib/run_loop/lipo.rb

Overview

Note:

All lipo commands are run in the context of `xcrun`.

A class for interacting with the lipo command-line tool to verify that an executable is valid for the test target (device or simulator).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle_path) ⇒ Lipo

Returns a new instance of Lipo



20
21
22
23
# File 'lib/run_loop/lipo.rb', line 20

def initialize(bundle_path)
  @bundle_path = bundle_path
  @plist_buddy = RunLoop::PlistBuddy.new
end

Instance Attribute Details

#bundle_pathString

The path to the application bundle we are inspecting.

Returns:

  • (String)

    The path to the application bundle (.app).



18
19
20
# File 'lib/run_loop/lipo.rb', line 18

def bundle_path
  @bundle_path
end

Instance Method Details

#expect_compatible_arch(device) ⇒ Object

Note:

At the moment, we are focusing on simulator compatibility. Since we don't have an automated way of installing an .ipa on local device, we don't require an .ipa path. Without an .ipa path, we cannot verify the architectures. Further, we would need to adopt a third-party tool like ideviceinfo to find the target device's instruction set.

Inspect the `CFBundleExecutable` in the app bundle path with `lipo` and compare the result with the target device's instruction set.

*Simulators*

If the target is a simulator and the binary contains an i386 slice, the app will launch on the 64-bit simulators.

If the target is a simulator and the binary contains only an x86_64 slice, the app will not launch on these simulators:

“` iPhone 4S, iPad 2, iPhone 5, and iPad Retina. “`

All other simulators are 64-bit.

*Devices*

“` armv7 <== 3gs, 4s, iPad 2, iPad mini, iPad 3, iPod 3, iPod 4, iPod 5 armv7s <== 5, 5c, iPad 4 arm64 <== 5s, 6, 6 Plus, Air, Air 2, iPad Mini Retina, iPad Mini 3 “`

Parameters:

Raises:

  • (RuntimeError)

    Raises an error if the device is a physical device.

  • (RunLoop::IncompatibleArchitecture)

    Raises an error if the instruction set of the target device is not compatible with the executable in the application.

See Also:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/run_loop/lipo.rb', line 71

def expect_compatible_arch(device)
  if device.physical_device?
    raise 'Ensuring compatible arches for physical devices is NYI'
  else
    arches = self.info
    # An i386 binary will run on any simulator.
    return true if arches.include?('i386')

    instruction_set = device.instruction_set
    unless arches.include?(instruction_set)
      raise RunLoop::IncompatibleArchitecture,
            ['Binary at:',
             binary_path,
             'does not contain a compatible architecture for target device.',
             "Expected '#{instruction_set}' but found #{arches}."].join("\n")
    end
  end
end

#infoArray<String>

Returns a list of architecture in the binary.

Returns:

  • (Array<String>)

    A list of architecture.

Raises:

  • (RuntimeError)

    If the output of lipo cannot be parsed.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/run_loop/lipo.rb', line 93

def info
  execute_lipo("-info \"#{binary_path}\"") do |stdout, stderr, wait_thr|
    output = stdout.read.strip
    begin
      output.split(':')[-1].strip.split
    rescue StandardError => e
      msg = ['Expected to be able to parse the output of lipo.',
             "cmd:    'lipo -info \"#{binary_path}\"'",
             "stdout: '#{output}'",
             "stderr: '#{stderr.read.strip}'",
             "exit code: '#{wait_thr.value}'",
             e.message]
      raise msg.join("\n")
    end
  end
end