From: nobuyoshi nakada Date: 2005-08-26T17:04:04+09:00 Subject: [PATCH] native extention by rubygems Hi, Rubygems 0.8.11 fails to compile a native extention which needs optional configurations. $ ruby18 /usr/bin/gem install mysql -- --with-mysql-dir=/usr/lib/mysql Attempting local installation of 'mysql' Local gem file not found: mysql*.gem Attempting remote installation of 'mysql' Building native extensions. This could take a while... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --with-opt-include=${opt-dir}/include --with-opt-lib=${opt-dir}/lib --with-make-prog=make --srcdir=. --curdir --ruby=/usr/bin/ruby --with-mysql-config --with-mysql-dir=/usr/local --with-mysql-include=${mysql-dir}/include --with-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib=mysqlclient --with-mlib=m --with-mysqlclientlib=mysqlclient --with-zlib=z --with-mysqlclientlib=mysqlclient --with-socketlib=socket --with-mysqlclientlib=mysqlclient --with-nsllib=nsl --with-mysqlclientlib=mysqlclient ERROR: While executing gem ... (RuntimeError) ERROR: Failed to build gem native extension. Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.6 for inspection. ruby extconf.rb install mysql -- --with-mysql-dir=/usr/lib/mysql\nchecking for mysql_query() in -lmysqlclient... no Note that also arguments to gem command itself are passed to extconf.rb. And, gem doesn't work with ruby 1.9. $ ruby19 /usr/bin/gem install mysql -- --with-mysql-dir=/usr/lib/mysql Attempting local installation of 'mysql' Local gem file not found: mysql*.gem Attempting remote installation of 'mysql' ERROR: While executing gem ... (NoMethodError) undefined method `close' for nil:NilClass Because Zlib::GzipReader in 1.9 uses readpartial method. But subsequent exception is hiding it. --- bin/gem.orig 2005-08-10 13:28:10.567750000 +0900 +++ bin/gem 2005-08-26 15:33:18.054250000 +0900 @@ -9,9 +9,4 @@ exit(1) end -# We need to preserve the original ARGV to use for passing gem options -# to source gems. If there is a -- in the line, strip all options after -# it...its for the source building process. -args = !ARGV.include?("--") ? ARGV.clone : ARGV[0...ARGV.index("--")] - -Gem::GemRunner.new.run(args) +Gem::GemRunner.new.run(ARGV) --- lib/rubygems/gem_commands.rb.orig 2005-08-10 13:28:11.395875000 +0900 +++ lib/rubygems/gem_commands.rb 2005-08-26 15:55:43.226125000 +0900 @@ -146,11 +146,19 @@ ENV['GEM_PATH'] = options[:install_dir] # TODO: If a dependency isn't met, first check to see if it's in # the install list - if(options[:args].empty?) + args = options[:args] + gems = [] + until args.empty? or /^-/ =~ args.first + gems << args.shift + end + if args.first == '--' + args.shift + end + if gems.empty? fail Gem::CommandLineError, "Please specify a gem name on the command line (e.g. gem build GEMNAME)" end - options[:args].each do |gem_name| + gems.each do |gem_name| if local? begin say "Attempting local installation of '#{gem_name}'" --- lib/rubygems/installer.rb.orig 2005-08-10 13:28:11.130250000 +0900 +++ lib/rubygems/installer.rb 2005-08-26 16:02:25.913625000 +0900 @@ -286,8 +286,8 @@ dest_path = File.join(directory, spec.require_paths[0]) spec.extensions.each do |extension| Dir.chdir File.join(directory, File.dirname(extension)) - results = ["#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}"] - results << `#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}` + results = [[Gem.ruby, File.basename(extension), *@options[:args]].join(" ")] + results << `#{results.last}` if File.exist?('Makefile') mf = File.read('Makefile') mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$.*/, "RUBYARCHDIR = #{dest_path}") @@ -303,8 +303,8 @@ results << `#{make_program} install` say results.join("\n") else - File.open(File.join(Dir.pwd, 'gem_make.out'), 'wb') {|f| f.puts results.join("\n")} - raise "ERROR: Failed to build gem native extension.\nGem files will remain installed in #{directory} for inspection.\n #{results.join('\n')}\n\nResults logged to #{File.join(Dir.pwd, 'gem_make.out')}" + File.open(File.join(Dir.pwd, 'gem_make.out'), 'wb') {|f| f.puts results} + raise "ERROR: Failed to build gem native extension.\nGem files will remain installed in #{directory} for inspection.\n #{results.join("\n")}\n\nResults logged to #{File.join(Dir.pwd, 'gem_make.out')}" end File.open('gem_make.out', 'wb') {|f| f.puts results.join("\n")} end @@ -417,7 +417,7 @@ return if executables.size == 0 answer = @force_executables || ask_yes_no( "Remove executables and scripts for\n" + - "'#{gemspec.executables.join(", ")}' in addition to the gem?", + "'#{gemspec.executables.join(", ")}' in addition to the gem\?", true) unless answer say "Executables and scripts will remain installed." --- lib/rubygems/package.rb.orig 2005-08-10 13:28:11.192750000 +0900 +++ lib/rubygems/package.rb 2005-08-26 14:43:19.245875000 +0900 @@ -350,6 +350,8 @@ ret end + alias readpartial read + def getc return nil if @read >= @size ret = @io.getc @@ -486,18 +488,18 @@ has_meta = true break when "metadata.gz" - begin - # if we have a security_policy, then pre-read the - # metadata file and calculate it's digest - sio = nil - if security_policy - Gem.ensure_ssl_available - sio = StringIO.new(entry.read) - meta_dgst = dgst_algo.digest(sio.string) - sio.rewind - end + # if we have a security_policy, then pre-read the + # metadata file and calculate it's digest + sio = nil + if security_policy + Gem.ensure_ssl_available + sio = StringIO.new(entry.read) + meta_dgst = dgst_algo.digest(sio.string) + sio.rewind + end - gzis = Zlib::GzipReader.new(sio || entry) + gzis = Zlib::GzipReader.new(sio || entry) + begin # YAML wants an instance of IO # (GS) Changed to line below: @metadata = YAML.load(gzis) rescue nil @metadata = load_gemspec(gzis) --- lib/rubygems/specification.rb.orig 2005-08-10 13:28:11.005250000 +0900 +++ lib/rubygems/specification.rb 2005-08-26 14:13:42.955875000 +0900 @@ -404,8 +404,8 @@ unless Specification === spec raise Gem::Exception, "YAML data doesn't evaluate to gem specification" end - unless spec.instance_variable_get :@specification_version - spec.instance_variable_set :@specification_version, NONEXISTENT_SPECIFICATION_VERSION + spec.instance_eval do + @specification_version ||= NONEXISTENT_SPECIFICATION_VERSION end spec end -- Nobu Nakada