module XamarinTestCloud # TODO validate dsym against the current application. # https://github.com/xamarinhq/test-cloud-command-line/issues/91 # # TODO dsym-file can be relative to workspace # https://github.com/xamarinhq/test-cloud-command-line/issues/92 class Dsym attr_reader :path # Caller should rescue RuntimeError and re-raise. # @raise RuntimeError If the dSYM at path is invalid. def initialize(path) @path = path validate! end def to_s "#" end def inspect to_s end def validate! extension = File.extname(path) if extension != ".dSYM" raise RuntimeError, %Q[Invalid dSYM directory. The --dsym-file must have a dSYM extension. Found: #{path} ] end if !File.exist?(path) raise RuntimeError, %Q[Invalid dSYM directory. The --dsym-file does not exist: #{path} ] end if !File.directory?(path) raise RuntimeError, %Q[Invalid dSYM directory. The --dsym-file is not a directory: #{path} ] end if dwarf_symbol_files.count > 1 raise RuntimeError, %Q[Invalid dSYM directory. The --dsym-file contains more than one symbol file. Check the contents of #{File.join("Contents", "Resources", "DWARF")} in: #{path} ] end if dwarf_symbol_files.count < 1 raise RuntimeError, %Q[Invalid dSYM directory. The --dsym-file contains no symbol file. Check the contents of #{File.join("Contents", "Resources", "DWARF")} in: #{path} #{Dir.glob(File.join(path, "Contents", "Resources", "DWARF", "*" ))} ] end true end def remote_path(path_to_app) "#{File.basename(path_to_app)}_dSym" end def symbol_file File.expand_path(dwarf_symbol_files[0]) end # Cannot use Dir.glob # https://github.com/xamarinhq/test-cloud-command-line/issues/52 def dwarf_symbol_files @dwarf_symbol_files ||= begin base = File.join(path, "Contents", "Resources", "DWARF") Dir.entries(base).select do |entry| !(entry.end_with?('..') || entry.end_with?('.')) end.map { |entry| File.join(base, entry) } end end end end