Method: EmergeCLI::XcodeSimulator#install_app

Defined in:
lib/utils/xcode_simulator.rb

#install_app(ipa_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/utils/xcode_simulator.rb', line 21

def install_app(ipa_path)
  raise "Non-IPA file provided: #{ipa_path}" unless ipa_path.end_with?('.ipa')

  Dir.mktmpdir do |tmp_dir|
    Logger.debug "Extracting .app from .ipa in temporary directory: #{tmp_dir}"

    Zip::File.open(ipa_path) do |zip_file|
      # Debug: List all entries to see what's in the IPA
      Logger.debug 'IPA contents:'
      zip_file.each do |entry|
        Logger.debug "  #{entry.name}"
      end

      # Try different patterns to find the .app directory
      app_entry = zip_file.glob('**/*.app/').first ||
                  zip_file.glob('**/*.app').first ||
                  zip_file.find { |entry| entry.name.end_with?('.app/') || entry.name.end_with?('.app') }

      raise 'No .app found in .ipa file' unless app_entry
      Logger.debug "Found app entry: #{app_entry.name}"

      # Extract the .app directory and its contents
      app_dir = app_entry.name.end_with?('/') ? app_entry.name.chomp('/') : app_entry.name
      pattern = "#{File.dirname(app_dir)}/#{File.basename(app_dir)}/**/*"
      Logger.debug "Using glob pattern: #{pattern}"

      zip_file.glob(pattern).each do |entry|
        entry_path = File.join(tmp_dir, entry.name)
        FileUtils.mkdir_p(File.dirname(entry_path))
        zip_file.extract(entry, entry_path) unless File.exist?(entry_path)
      end

      extracted_app = Dir.glob(File.join(tmp_dir, '**/*.app')).first
      raise 'Failed to extract .app from .ipa' unless extracted_app
      Logger.debug "Extracted app at: #{extracted_app}"

      install_extracted_app(extracted_app)
    end
  end
end