Skip to content

Instantly share code, notes, and snippets.

@CrazyCoder
Created May 24, 2011 23:50
Show Gist options
  • Save CrazyCoder/990016 to your computer and use it in GitHub Desktop.
Save CrazyCoder/990016 to your computer and use it in GitHub Desktop.
Patch for Ocra issue #26 (Gem files not detected correctly with recent RubyGems)
Index: bin/ocra
===================================================================
--- bin/ocra (revision 2cb11c915af52197f90abd944d84219305d8c602)
+++ bin/ocra (revision )
@@ -181,7 +181,7 @@
IGNORE_GEMFILES = %r{(
# Auxiliary files in the root of the gem
- ^(\.\/)?(History|Install|Manifest|README|Licen[sc]e|Contributors|ChangeLog|BSD|GPL).*$ |
+ ^(\.\/)?(History|Install|Manifest|README|CHANGES|Licen[sc]e|Contributors|ChangeLog|BSD|GPL).*$ |
# Installation files in the root of the gem
^(\.\/)?(Rakefile|setup.rb|extconf.rb)$ |
# Documentation/test directories in the root of the gem
@@ -505,6 +505,28 @@
return src_prefix, src_files
end
+ # returns all files under dirs, which are located under root
+ def Ocra.get_all_files(dirs, root)
+ require 'find'
+ files = []
+ dirs.each do |dir|
+ dir_path = root / dir
+ Find.find(dir_path) do |path|
+ if FileTest.directory?(path)
+ if File.basename(path)[0] == ?.
+ Find.prune # Don't look any further into this directory.
+ else
+ next
+ end
+ else
+ path[root.to_s + '/'] = '' # trim root directory from paths
+ files << path
+ end
+ end
+ end
+ files
+ end
+
# Searches for features that are loaded from gems, then produces a
# list of files included in those gems' manifests. Also returns a
# list of original features that are caused gems to be
@@ -554,17 +576,21 @@
gems = sort_uniq(gems)
gem_files = []
gems.each do |gempath, fullgemname|
+ gemroot = gempath / "gems" / fullgemname
gemspecpath = gempath / 'specifications' / "#{fullgemname}.gemspec"
@gemspecs << gemspecpath
spec = Gem::Specification.load(gemspecpath)
Ocra.msg "Will include gem #{spec.full_name}"
- # Get list of files
- files = Pathname(spec.files)
+ # Add all files recursively from 'require_paths'
+ files = get_all_files(spec.require_paths, gemroot)
+ # Add extra files from spec 'files'
+ files |= spec.files
+ files = Pathname(files)
# Filter out some unlikely files (Readme, etc.)
files = files.select { |filename| filename !~ IGNORE_GEMFILES } if Ocra.gem_filter
# Find the full path
- files = files.map { |file| (gempath / "gems" / fullgemname / file).expand }
+ files = files.map { |file| (gemroot / file).expand }
# Filter out non-files
files = files.select { |file| file.file? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment