From 95110bb1108d1813e7ed9ff517133ae68b3eb3ae Mon Sep 17 00:00:00 2001 From: icyleaf Date: Tue, 11 Apr 2023 16:03:48 +0800 Subject: [PATCH] feat: add .files method for proguard parser --- lib/app_info/dsym.rb | 2 ++ lib/app_info/dsym/debug_info.rb | 9 +++++++++ lib/app_info/dsym/macho.rb | 7 +++++++ lib/app_info/proguard.rb | 11 +++++++++++ spec/app_info/dsym_spec.rb | 1 + spec/app_info/proguard_spec.rb | 4 ++++ 6 files changed, 34 insertions(+) diff --git a/lib/app_info/dsym.rb b/lib/app_info/dsym.rb index 3ca1ec1..4646886 100644 --- a/lib/app_info/dsym.rb +++ b/lib/app_info/dsym.rb @@ -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] dsym_files files by alphabetical order def files diff --git a/lib/app_info/dsym/debug_info.rb b/lib/app_info/dsym/debug_info.rb index 63237dc..779c959 100644 --- a/lib/app_info/dsym/debug_info.rb +++ b/lib/app_info/dsym/debug_info.rb @@ -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] def machos @machos ||= case macho_type when ::MachO::MachOFile @@ -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') diff --git a/lib/app_info/dsym/macho.rb b/lib/app_info/dsym/macho.rb index c424f51..b5298fa 100644 --- a/lib/app_info/dsym/macho.rb +++ b/lib/app_info/dsym/macho.rb @@ -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, diff --git a/lib/app_info/proguard.rb b/lib/app_info/proguard.rb index 577e1bf..b942e80 100644 --- a/lib/app_info/proguard.rb +++ b/lib/app_info/proguard.rb @@ -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? diff --git a/spec/app_info/dsym_spec.rb b/spec/app_info/dsym_spec.rb index ef444ed..2c365aa 100644 --- a/spec/app_info/dsym_spec.rb +++ b/spec/app_info/dsym_spec.rb @@ -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 diff --git a/spec/app_info/proguard_spec.rb b/spec/app_info/proguard_spec.rb index ce7c078..b408f95 100644 --- a/spec/app_info/proguard_spec.rb +++ b/spec/app_info/proguard_spec.rb @@ -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