Sha256: d513dc05a426871968066011d0439b73b0f127d90988db1fc29a3ba9cc7dd4e7

Contents?: true

Size: 1.59 KB

Versions: 56

Compression:

Stored size: 1.59 KB

Contents

module RunLoop
  # @!visibility private
  #
  # A class for interacting with otool
  class Otool

    # @!visibility private
    # @param [RunLoop::Xcode] xcode An instance of Xcode
    def initialize(xcode)
      @xcode = xcode
    end

    # @!visibility private
    def to_s
      "#<OTOOL: Xcode #{xcode.version.to_s}>"
    end

    # @!visibility private
    def inspect
      to_s
    end

    # @!visibility private
    def executable?(path)
      expect_valid_path!(path)
      !arch_info(path)[/is not an object file/, 0]
    end

    private

    # @!visibility private
    attr_reader :xcode, :command_name

    # @!visibility private
    def arch_info(path)
      args = [command_name, "-hv", "-arch", "all", path]
      opts = { :log_cmd => false }

      hash = xcrun.run_command_in_context(args, opts)

      if hash[:exit_status] != 0
        raise RuntimeError,
%Q{Could not get arch info from file:

#{path}

#{args.join(" ")}

exited #{hash[:exit_status]} with the following output:

#{hash[:out]}
}
      end

      hash[:out]
    end

    # @!visibility private
    def expect_valid_path!(path)
      return true if File.exist?(path) && !File.directory?(path)
      raise ArgumentError, %Q[
File:

#{path}

must exist and not be a directory.

]
    end

    # @!visibility private
    def xcrun
      @xcrun ||= RunLoop::Xcrun.new
    end

    # @!visibility private
    def xcode
      @xcode
    end

    # @!visibility private
    def command_name
      @command_name ||= begin
        if xcode.version_gte_8?
          "otool-classic"
        else
          "otool"
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
run_loop-4.9.1 lib/run_loop/otool.rb
run_loop-4.9.0 lib/run_loop/otool.rb
run_loop-4.8.1 lib/run_loop/otool.rb
run_loop-4.8.0 lib/run_loop/otool.rb
run_loop-4.7.0 lib/run_loop/otool.rb
run_loop-4.6.3 lib/run_loop/otool.rb
run_loop-4.6.1 lib/run_loop/otool.rb
run_loop-4.6.0 lib/run_loop/otool.rb
run_loop-4.5.7 lib/run_loop/otool.rb
run_loop-4.5.6 lib/run_loop/otool.rb
run_loop-4.5.5 lib/run_loop/otool.rb
run_loop-4.5.4 lib/run_loop/otool.rb
run_loop-4.5.3 lib/run_loop/otool.rb
run_loop-4.5.2 lib/run_loop/otool.rb
run_loop-4.5.1 lib/run_loop/otool.rb
run_loop-4.5.0 lib/run_loop/otool.rb
run_loop-4.4.2 lib/run_loop/otool.rb
run_loop-4.4.1 lib/run_loop/otool.rb
run_loop-2.3.2 lib/run_loop/otool.rb
run_loop-4.3.0 lib/run_loop/otool.rb