Skip to content

Commit

Permalink
feat: add .files method for proguard parser
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf committed Apr 11, 2023
1 parent ab28136 commit 95110bb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/app_info/dsym.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def manufacturer
Manufacturer::APPLE
end

# @return [nil]
def each_file(&block)
files.each { |file| block.call(file) }
end
alias each_objects each_file

# @return [Array<DebugInfo>] dsym_files files by alphabetical order
def files
Expand Down
9 changes: 9 additions & 0 deletions lib/app_info/dsym/debug_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ def initialize(path)
@path = path
end

# @return [String]
def object
@object ||= ::File.basename(bin_path)
end

# @return [::MachO::MachOFile, ::MachO::FatFile]
def macho_type
@macho_type ||= ::MachO.open(bin_path)
end

# @return [Array<AppInfo::DSYM::MachO>]
def machos
@machos ||= case macho_type
when ::MachO::MachOFile
Expand All @@ -37,29 +40,35 @@ def machos
end
end

# @return [String, nil]
def release_version
info.try(:[], 'CFBundleShortVersionString')
end

# @return [String, nil]
def build_version
info.try(:[], 'CFBundleVersion')
end

# @return [String, nil]
def identifier
info.try(:[], 'CFBundleIdentifier').sub('com.apple.xcode.dsym.', '')
end
alias bundle_id identifier

# @return [CFPropertyList]
def info
return nil unless ::File.exist?(info_path)

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

# @return [String]
def info_path
@info_path ||= ::File.join(path, 'Contents', 'Info.plist')
end

# @return [String]
def bin_path
@bin_path ||= lambda {
dwarf_path = ::File.join(path, 'Contents', 'Resources', 'DWARF')
Expand Down
7 changes: 7 additions & 0 deletions lib/app_info/dsym/macho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ def initialize(file, size = 0)
@size = size
end

# @return [String]
def cpu_name
@file.cpusubtype
end

# @return [String]
def cpu_type
@file.cputype
end

# @return [String]
def type
@file.filetype
end

# @return [String, Integer]
def size(human_size: false)
return number_to_human_size(@size) if human_size

@size
end

# @return [String]
def uuid
@file[:LC_UUID][0].uuid_string
end
alias debug_id uuid

# @return [::MachO::Headers]
def header
@header ||= @file.header
end

# @return [Hash{Symbol => String, Integer}]
def to_h
{
uuid: uuid,
Expand Down
11 changes: 11 additions & 0 deletions lib/app_info/proguard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def version_code
end
alias build_version version_code

def files
Dir.children(contents).each_with_object([]) do |filename, obj|
path = ::File.join(contents, filename)
obj << {
name: filename,
path: path,
size: ::File.size(path)
}
end
end

# @return [REXML::Document]
def manifest
return unless manifest?
Expand Down
1 change: 1 addition & 0 deletions spec/app_info/dsym_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
it { expect(subject.files[0].machos[0].size).to eq data[:size] }
it { expect(subject.files[0].machos[0].size(human_size: true)).to eq data[:human_size] }
it { expect(subject.files[0].machos[0].to_h).to eq data }
it { expect(subject.objects).to eq subject.files }
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/app_info/proguard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
it { expect(subject.version_code).to eq '1' }
it { expect(subject.release_version).to eq '1.0' }
it { expect(subject.build_version).to eq '1' }

it { expect(subject.files[0]).to have_key :name }
it { expect(subject.files[0]).to have_key :path }
it { expect(subject.files[0]).to have_key :size }
end
end

Expand Down

0 comments on commit 95110bb

Please sign in to comment.