为测试构建ruby c扩展的推荐方法
我正在使用为测试构建ruby c扩展的推荐方法,ruby,ruby-c-extension,Ruby,Ruby C Extension,我正在使用 gem build $gemname.gemspec && gem install $gemname-0.0.1.gem 然而,这似乎不是测试gem的最佳方法,因为它将gem移出本地环境并进入rubygems路径 建议使用 cd ext/$gemname && ruby extconf.rb && make ??或者有更好的实践吗?我猜像下面这样的Rakefile也可以工作(并且比上面的命令更简单)。然而,这对于测试来说并不是必需的
gem build $gemname.gemspec && gem install $gemname-0.0.1.gem
然而,这似乎不是测试gem的最佳方法,因为它将gem移出本地环境并进入rubygems路径
建议使用
cd ext/$gemname && ruby extconf.rb && make
??或者有更好的实践吗?我猜像下面这样的Rakefile也可以工作(并且比上面的命令更简单)。然而,这对于测试来说并不是必需的
require 'rake/testtask'
require 'rake/clean'
NAME = 'hola'
# rule to build the extension: this says
# that the extension should be rebuilt
# after any change to the files in ext
file "lib/#{NAME}/#{NAME}.so" =>
Dir.glob("ext/#{NAME}/*{.rb,.c}") do
Dir.chdir("ext/#{NAME}") do
# this does essentially the same thing
# as what RubyGems does
ruby "extconf.rb"
sh "make"
end
cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}"
end
# make the :test task depend on the shared
# object, so it will be built automatically
# before running the tests
task :test => "lib/#{NAME}/#{NAME}.so"
# use 'rake clean' and 'rake clobber' to
# easily delete generated files
CLEAN.include('ext/**/*{.o,.log,.so}')
CLEAN.include('ext/**/Makefile')
CLOBBER.include('lib/**/*.so')
# the same as before
Rake::TestTask.new do |t|
t.libs << 'test'
end
desc "Run tests"
task :default => :test
需要“rake/testtask”
需要“耙/清洁”
NAME='hola'
#构建扩展的规则:如下所示
#应该重建扩展
#对ext中的文件进行任何更改后
文件“lib/#{NAME}/#{NAME}.so”=>
Dir.glob(“ext/#{NAME}/*{.rb.c}”)do
Dir.chdir(“ext/#{NAME}”)do
#这基本上是一样的
#就像RubyGems做的那样
ruby“extconf.rb”
sh“制造”
结束
cp“ext/#{NAME}/#{NAME}.so”,“lib/#{NAME}”
结束
#使:测试任务依赖于共享
#对象,因此它将自动生成
#在运行测试之前
任务:test=>“lib/#{NAME}/#{NAME}.so”
#使用“rake clean”和“rake clobber”来
#轻松删除生成的文件
CLEAN.include('ext/***{.o、.log、.so}'))
CLEAN.include('ext/**/Makefile')
CLOBBER.include('lib/***/.so')
#和以前一样
Rake::TestTask.new do|t|
t、 libs:测试