Sha256: 7baf12a21b1dce6e67465d9904efb55cce2ce141fcc4b864ed80df3b7c0f168b

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

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

    # @!visibility private
    attr_reader :path

    # @!visibility private
    def initialize(path)
      @path = path

      if !Otool.valid_path?(path)
        raise ArgumentError,
%Q{File:

#{path}

must exist and not be a directory.
}
      end
    end

    # @!visibility private
    def to_s
      "#<OTOOL: #{path}>"
    end

    # @!visibility private
    def inspect
      to_s
    end

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

    private

    # @!visibility private
    def arch_info
      args = ["otool", "-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

      @arch_info = hash[:out]
    end

    # @!visibility private
    def self.valid_path?(path)
      File.exist?(path) && !File.directory?(path)
    end

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
run_loop_tcc-2.1.6 lib/run_loop/otool.rb
run_loop_tcc-2.1.5 lib/run_loop/otool.rb
run_loop-2.1.6 lib/run_loop/otool.rb
run_loop-2.1.5 lib/run_loop/otool.rb
run_loop-2.1.4 lib/run_loop/otool.rb
run_loop_tcc-2.1.4 lib/run_loop/otool.rb
run_loop_tcc-2.1.3 lib/run_loop/otool.rb