Skip to content

Commit

Permalink
Fix determining what has loaded on ruby 1.9
Browse files Browse the repository at this point in the history
In ruby 1.9 it appears that LOADED_FEATURES does a full expand path on the contents which is
different than the LOADED_FEATURES on 1.8.  So we need to strip off LOAD_PATH prefixes from 
the LOADED_FEATURES in order to compare it to Amalgalite::Packer.amalgalite_require_order
  • Loading branch information
copiousfreetime committed Mar 27, 2011
1 parent 1214c8c commit b55e4e7
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions bin/amalgalite-pack
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'rubygems'

#
# add relative paths to the load path if we are not a gem and calculate what the
Expand All @@ -16,14 +15,36 @@ if ".." == rel_path.to_s.split( File::SEPARATOR ).first then
$:.unshift File.join( File.dirname( __FILE__ ), "../ext" )
end

#
#
# snapshot of what is needed for amalgalite requires, this info may only be used
# when packing amalgalite itself
#
loaded_features_before = $LOADED_FEATURES.dup
require 'amalgalite/packer'
loaded_features_after = $LOADED_FEATURES.dup
amalgalite_needs = loaded_features_after - loaded_features_before
load_diff = loaded_features_after - loaded_features_before

#
# strip off any LOAD_PATH elements from the front of load_diff since that
# will conflict with Amalgalite::Packer.amalgalite_require_order. Also
# strip out any 'rubygems' items since those are not used by Amalgalite
# and show as a side effect fo the "require 'amalgalite/packer'"
#
strip_paths = $LOAD_PATH.sort.reverse
amalgalite_needs = []
load_diff.each do |f|
next if f.split( File::SEPARATOR ).include?( "rubygems" )
appended = false
strip_paths.each do |path|
if 0 == f.index(path ) then
rel_path = f.sub( path, '' ).sub(%r{\A#{File::SEPARATOR}},'')
amalgalite_needs << rel_path
appended = true
break
end
end
amalgalite_needs << f unless appended
end

#
# Commandline parser
Expand Down Expand Up @@ -77,17 +98,17 @@ begin
require 'amalgalite/packer'
file_list = ARGV.dup


if options[:self] then
options[:table_name] = Amalgalite::Requires::Bootstrap::DEFAULT_BOOTSTRAP_TABLE
core_libs = (amalgalite_needs - Amalgalite::Packer.amalgalite_require_order).delete_if { |l| l.index(".rb").nil? }

#
# check and make sure nothing is missed
#
core_libs.each do |l|
if l.index("malgalite") then
STDERR.puts "ERROR! require_order needs an update #{l}"
core_libs.each do |l|
if l.index("amalgalite") then
STDERR.puts "ERROR! require_order needs an update #{l}"
exit 2
end
end
Expand Down Expand Up @@ -116,7 +137,7 @@ Packing complete. To utilize the bootstrapping in #{dbfile} you must do
one of the following:

* statically compile the amalgalite C extension into your application
* require 'amalgalite/amalgalite3'
* require 'amalgalite/#{RUBY_VERSION.sub(/\.\d$/,'')}/amalgalite3'

Once one of those is working you can boostrap the Amalgalite library with
this line in your code:
Expand Down

0 comments on commit b55e4e7

Please sign in to comment.