Sha256: 82d0217083f0495a811f37303c087540af2a5f6a113e88763348162eba4ac16b

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

require 'app_info/dsym/macho'

module AppInfo
  class DSYM < File
    # DSYM Debug Information Format Struct
    class DebugInfo
      attr_reader :path

      def initialize(path)
        @path = path
      end

      def object
        @object ||= ::File.basename(bin_path)
      end

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

      def machos
        @machos ||= case macho_type
                    when ::MachO::MachOFile
                      [MachO.new(macho_type, ::File.size(bin_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

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

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

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

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

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

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

      def bin_path
        @bin_path ||= lambda {
          dwarf_path = ::File.join(path, 'Contents', 'Resources', 'DWARF')
          name = Dir.children(dwarf_path)[0]
          ::File.join(dwarf_path, name)
        }.call
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
app-info-3.0.0.beta3 lib/app_info/dsym/debug_info.rb
app-info-3.0.0.beta2 lib/app_info/dsym/debug_info.rb
app-info-3.0.0.beta1 lib/app_info/dsym/debug_info.rb