Class: AppInfo::DSYM

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

Overview

DSYM parser

Defined Under Namespace

Classes: MachO

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Archive

#tempdir, #unarchive

Constructor Details

#initialize(file) ⇒ DSYM

Returns a new instance of DSYM.



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

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

Instance Method Details

#app_pathObject



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

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



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

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

#clear!Object



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

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

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

#contentsObject



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

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

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

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

  @contents
end

#file_typeObject



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

def file_type
  Platform::DSYM
end

#identifierObject Also known as: bundle_id



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

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

#infoObject



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

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

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

#info_pathObject



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

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

#macho_typeObject



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

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

#machosObject



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

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



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

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

#release_versionObject



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

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