Class: AppInfo::DSYM

Inherits:
Object show all
Defined in:
lib/app_info/dsym.rb

Overview

DSYM parser

Defined Under Namespace

Classes: MachO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ DSYM

Returns a new instance of DSYM.



11
12
13
# File 'lib/app_info/dsym.rb', line 11

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/app_info/dsym.rb', line 9

def file
  @file
end

Instance Method Details

#app_pathObject



67
68
69
70
71
72
73
74
75
# File 'lib/app_info/dsym.rb', line 67

def app_path
  unless @app_path
    path = File.join(contents, 'Contents', 'Resources', 'DWARF')
    name = Dir.entries(path).reject { |f| ['.', '..'].include?(f) }.first
    @app_path = File.join(path, name)
  end

  @app_path
end

#build_versionObject



48
49
50
# File 'lib/app_info/dsym.rb', line 48

def build_version
  info.try(:[], 'CFBundleVersion')
end

#clear!Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/app_info/dsym.rb', line 77

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

  @contents = nil
  @app_path = nil
  @info = nil
  @object = nil
  @macho_type = nil
end

#contentsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/app_info/dsym.rb', line 89

def contents
  unless @contents
    if File.directory?(@file)
      @contents = @file
    else
      dsym_dir = nil
      @contents = Util.unarchive(@file, path: 'dsym') do |path, zip_file|
        zip_file.each do |f|
          unless dsym_dir
            dsym_dir = f.name
            dsym_dir = dsym_dir.split('/')[0] # fix filename is xxx.app.dSYM/Contents
          end

          f_path = File.join(path, f.name)
          zip_file.extract(f, f_path) unless File.exist?(f_path)
        end
      end

      @contents = File.join(@contents, dsym_dir)
    end
  end

  @contents
end

#file_typeObject



15
16
17
# File 'lib/app_info/dsym.rb', line 15

def file_type
  AppInfo::Platform::DSYM
end

#identifierObject Also known as: bundle_id



52
53
54
# File 'lib/app_info/dsym.rb', line 52

def identifier
  info.try(:[], 'CFBundleIdentifier').sub('com.apple.xcode.dsym.', '')
end

#infoObject



57
58
59
60
61
# File 'lib/app_info/dsym.rb', line 57

def info
  return nil unless File.exist?(info_path)

  @info ||= CFPropertyList.native_types(CFPropertyList::List.new(file: info_path).value)
end

#info_pathObject



63
64
65
# File 'lib/app_info/dsym.rb', line 63

def info_path
  @info_path ||= File.join(contents, 'Contents', 'Info.plist')
end

#macho_typeObject



23
24
25
# File 'lib/app_info/dsym.rb', line 23

def macho_type
  @macho_type ||= ::MachO.open(app_path)
end

#machosObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/app_info/dsym.rb', line 27

def machos
  @machos ||= case macho_type
              when ::MachO::MachOFile
                [MachO.new(macho_type, File.size(app_path))]
              else
                size = macho_type.fat_archs.each_with_object([]) do |arch, obj|
                  obj << arch.size
                end

                machos = []
                macho_type.machos.each_with_index do |file, i|
                  machos << MachO.new(file, size[i])
                end
                machos
              end
end

#objectObject



19
20
21
# File 'lib/app_info/dsym.rb', line 19

def object
  @object ||= File.basename(app_path)
end

#release_versionObject



44
45
46
# File 'lib/app_info/dsym.rb', line 44

def release_version
  info.try(:[], 'CFBundleShortVersionString')
end