Class: FastlaneCore::IpaFileAnalyser

Inherits:
Object
  • Object
show all
Defined in:
fastlane_core/lib/fastlane_core/ipa_file_analyser.rb

Class Method Summary collapse

Class Method Details

.fetch_app_build(path) ⇒ Object

Fetches the app build number from the given ipa file.



25
26
27
28
29
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 25

def self.fetch_app_build(path)
  plist = self.fetch_info_plist_file(path)
  return plist['CFBundleVersion'] if plist
  return nil
end

.fetch_app_identifier(path) ⇒ Object

Fetches the app identifier (e.g. com.facebook.Facebook) from the given ipa file.



11
12
13
14
15
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 11

def self.fetch_app_identifier(path)
  plist = self.fetch_info_plist_file(path)
  return plist['CFBundleIdentifier'] if plist
  return nil
end

.fetch_app_platform(path) ⇒ Object

Fetches the app platform from the given ipa file.



32
33
34
35
36
37
38
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 32

def self.fetch_app_platform(path)
  plist = self.fetch_info_plist_file(path)
  platform = "ios"
  platform = plist['DTPlatformName'] if plist
  platform = "ios" if platform == "iphoneos" # via https://github.com/fastlane/fastlane/issues/3484
  return platform
end

.fetch_app_version(path) ⇒ Object

Fetches the app version from the given ipa file.



18
19
20
21
22
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 18

def self.fetch_app_version(path)
  plist = self.fetch_info_plist_file(path)
  return plist['CFBundleShortVersionString'] if plist
  return nil
end

.fetch_info_plist_file(path) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 40

def self.fetch_info_plist_file(path)
  UI.user_error!("Could not find file at path '#{path}'") unless File.exist?(path)
  plist_data = self.fetch_info_plist_with_rubyzip(path)
  if plist_data.nil?
    # Xcode produces invalid zip files for IPAs larger than 4GB. RubyZip
    # can't read them, but the unzip command is able to work around this.
    plist_data = self.fetch_info_plist_with_unzip(path)
  end
  return nil if plist_data.nil?

  result = CFPropertyList.native_types(CFPropertyList::List.new(data: plist_data).value)
  if result['CFBundleIdentifier'] || result['CFBundleVersion']
    return result
  end
  return nil
end

.fetch_info_plist_with_rubyzip(path) ⇒ Object



57
58
59
60
61
62
63
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 57

def self.fetch_info_plist_with_rubyzip(path)
  Zip::File.open(path, "rb") do |zipfile|
    file = zipfile.glob('**/Payload/*.app/Info.plist').first
    return nil unless file
    zipfile.read(file)
  end
end

.fetch_info_plist_with_unzip(path) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'fastlane_core/lib/fastlane_core/ipa_file_analyser.rb', line 65

def self.fetch_info_plist_with_unzip(path)
  entry, error, = Open3.capture3("unzip", "-Z", "-1", path, "*Payload/*.app/Info.plist")

  # unzip can return multiple Info.plist files if is an embedded app bundle (a WatchKit app)
  #   - ContainsWatchApp/Payload/Sample.app/Watch/Sample WatchKit App.app/Info.plist
  #   - ContainsWatchApp/Payload/Sample.app/Info.plist
  #
  # we can determine the main Info.plist by the shortest path
  entry = entry.lines.map(&:chomp).min_by(&:size)

  UI.command_output(error) unless error.empty?
  return nil if entry.nil? || entry.empty?
  data, error, = Open3.capture3("unzip", "-p", path, entry)
  UI.command_output(error) unless error.empty?
  return nil if data.empty?
  data
end