Module: DepWalker
- Extended by:
- DepWalker
- Included in:
- DepWalker
- Defined in:
- lib/dep_walker.rb,
ext/dep_walker/dep_walker.c
Constant Summary collapse
- VERSION =
'1.0.2'
- TRACE_INFO =
Informational messages
0
- TRACE_SUCCESS =
Succes messages
1
- TRACE_ERROR =
Error messages
2
Class Method Summary collapse
Instance Method Summary collapse
-
#check(name_or_spec, version = nil) ⇒ Object
Checks dependencis for a single Gem.
-
#check_all ⇒ Object
Checks dependencies for all installed gems.
-
#dependencies(gem_spec) ⇒ Object
Returns dependencies for all shared libraries found in the Gem’s directories.
-
#dll_dependencies(dll_path = "") ⇒ Object
Returns all dependencies for input shared library.
-
#walk_deps(gem_spec) ⇒ Object
Search dependency dlls for all extension libraries in the Gem.
Class Method Details
.raw_dependencies(path) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'ext/dep_walker/dep_walker.c', line 4
static VALUE raw_dependencies(VALUE self, VALUE path)
{
VALUE mDeps = rb_ary_new();
if (RSTRING_LEN(path) > 0)
{
DumpDllFromPath(mDeps, StringValuePtr(path));
}
return mDeps;
}
|
Instance Method Details
#check(name_or_spec, version = nil) ⇒ Object
Checks dependencis for a single Gem. Returns hash of extension library used by Gem as a key and array of unresolved dependencies as a value.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dep_walker.rb', line 87 def check(name_or_spec, version=nil) gem_deps = {} spec = name_or_spec.is_a?(String) ? Gem::Specification.find_all_by_name(name_or_spec, version) : [name_or_spec] spec.each do |s| spec_deps = {} walk_deps(s).each do |k,v| spec_deps[k] = v[:not_found] unless v[:not_found].empty? end gem_deps[s.full_name] = spec_deps unless spec_deps.empty? end gem_deps end |
#check_all ⇒ Object
Checks dependencies for all installed gems. Returns hash of all unresolved dependencies with the full Gem name in keys and hash of extension libraries and dependencies that are not found in the system.
72 73 74 75 76 77 78 79 80 |
# File 'lib/dep_walker.rb', line 72 def check_all all_deps = {} Gem::Specification.find_all.each do |spec| gem_deps = check(spec) all_deps.merge! gem_deps unless gem_deps.empty? end all_deps end |
#dependencies(gem_spec) ⇒ Object
Returns dependencies for all shared libraries found in the Gem’s directories
139 140 141 142 143 144 145 146 147 |
# File 'lib/dep_walker.rb', line 139 def dependencies(gem_spec) deps = {} Dir.glob(File.join(gem_spec.full_gem_path, "**/*")).select do |f| f if [".so",".dll"].include? File.extname(f) end.each do |ext| deps[ext] = dll_dependencies(ext) end deps end |
#dll_dependencies(dll_path = "") ⇒ Object
Returns all dependencies for input shared library
152 153 154 155 156 |
# File 'lib/dep_walker.rb', line 152 def dll_dependencies(dll_path = "") return [] unless ['.dll', '.so'].include? File.extname dll_path raw_dependencies(dll_path).map {|dep| dep.downcase}.uniq end |
#walk_deps(gem_spec) ⇒ Object
Search dependency dlls for all extension libraries in the Gem. Search is performed across all directories in the system path and the extension library’s directory. Returns hash with a full path to extension library as a key and hash with all dependencies found with the paths from which they will be loade and all dependencies that are not found.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/dep_walker.rb', line 108 def walk_deps(gem_spec) dep_tree = {} if gem_spec.is_a? Gem::Specification trace("Checking #{gem_spec.full_name}", TRACE_INFO) dependencies(gem_spec).each do |k,v| trace(" #{k}", TRACE_INFO) found = {} not_found = [] v.each do |shlib| if found[shlib].nil? || not_found.include?(shlib) shlib_dir = find_shlib_dir(File.dirname(k), shlib) if shlib_dir found[shlib] = shlib_dir trace(" #{shlib} -> Found at #{shlib_dir}", TRACE_SUCCESS) elsif !shlib.start_with?("msvcrt-ruby") not_found << shlib trace(" #{shlib} -> Not found", TRACE_ERROR) end end end dep_tree[k] = {:found => found, :not_found => not_found} end trace("="*40, TRACE_INFO) end dep_tree end |