2009-02-17 02:50:31 +08:00
|
|
|
require 'rubygems'
|
2014-10-31 05:09:38 +08:00
|
|
|
require 'rubygems/package_task'
|
2009-12-24 23:00:45 +08:00
|
|
|
require 'rake/testtask'
|
2009-02-17 02:50:31 +08:00
|
|
|
|
2009-02-17 10:21:45 +08:00
|
|
|
#so we can: ssh host rake -f $hudson_workspace/sigar/Rakefile
|
|
|
|
Dir.chdir(File.dirname(__FILE__))
|
|
|
|
|
2009-02-17 02:50:31 +08:00
|
|
|
props = {}
|
2009-04-05 10:32:20 +08:00
|
|
|
File.open("version.properties").each { |line|
|
2009-02-17 02:50:31 +08:00
|
|
|
next if line =~ /^#/
|
|
|
|
line.chomp!
|
|
|
|
line.strip!
|
|
|
|
next if line.empty?
|
|
|
|
key,val = line.split('=')
|
|
|
|
props[key] = val
|
|
|
|
}
|
|
|
|
|
|
|
|
GEM = props['project.name']
|
2009-02-17 05:51:24 +08:00
|
|
|
MAKE = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
|
2009-02-17 02:50:31 +08:00
|
|
|
|
|
|
|
spec = Gem::Specification.new do |s|
|
|
|
|
s.name = GEM
|
2018-01-22 17:51:37 +08:00
|
|
|
s.version = props['version.major'] + '.' + props['version.minor'] + '.' + props['version.maint']
|
2009-02-17 02:50:31 +08:00
|
|
|
s.summary = props['project.summary']
|
|
|
|
s.description = s.summary
|
|
|
|
s.author = props['project.author']
|
|
|
|
s.email = props['project.email']
|
|
|
|
s.homepage = props['project.homepage']
|
|
|
|
s.platform = Gem::Platform::RUBY
|
|
|
|
s.extensions = 'bindings/ruby/extconf.rb'
|
|
|
|
s.files =
|
2018-05-30 21:24:06 +08:00
|
|
|
%w(LICENSE NOTICE README.md Rakefile version.properties) +
|
2010-01-19 16:04:46 +08:00
|
|
|
%w(bindings/SigarWrapper.pm bindings/SigarBuild.pm) +
|
2012-03-27 07:24:27 +08:00
|
|
|
`git ls-files -- bindings/ruby/*.*`.split("\n") +
|
2009-02-17 02:50:31 +08:00
|
|
|
Dir.glob("include/*.h") +
|
2010-01-19 16:04:46 +08:00
|
|
|
Dir.glob("src/**/*.[ch]") +
|
|
|
|
Dir.glob("src/**/*.in")
|
2009-02-17 02:50:31 +08:00
|
|
|
end
|
|
|
|
|
2014-10-31 05:09:38 +08:00
|
|
|
Gem::PackageTask.new(spec) do |pkg|
|
2009-02-17 02:50:31 +08:00
|
|
|
pkg.gem_spec = spec
|
|
|
|
end
|
|
|
|
|
2009-12-24 23:00:45 +08:00
|
|
|
task :default => :test
|
|
|
|
|
2009-02-17 05:51:24 +08:00
|
|
|
def in_ext()
|
|
|
|
ext = 'bindings/ruby'
|
|
|
|
Dir.chdir(ext) if File.directory? ext
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Build sigar extension'
|
|
|
|
task :build do
|
2010-05-21 07:01:14 +08:00
|
|
|
in_ext()
|
2024-09-10 18:58:09 +08:00
|
|
|
unless File.exist? "Makefile"
|
2009-12-24 23:00:45 +08:00
|
|
|
unless system("ruby extconf.rb")
|
|
|
|
STDERR.puts "Failed to configure"
|
2024-09-10 18:58:09 +08:00
|
|
|
next
|
2009-12-24 23:00:45 +08:00
|
|
|
end
|
2009-02-17 05:51:24 +08:00
|
|
|
end
|
|
|
|
unless system(MAKE)
|
|
|
|
STDERR.puts 'Failed to ' + MAKE
|
2024-09-10 18:58:09 +08:00
|
|
|
next
|
2009-02-17 05:51:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-24 23:00:45 +08:00
|
|
|
Rake::TestTask.new do |t|
|
|
|
|
t.pattern = 'test/*_test.rb'
|
2010-05-21 06:56:42 +08:00
|
|
|
t.libs << "."
|
2009-12-24 23:00:45 +08:00
|
|
|
end
|
|
|
|
|
2010-01-18 10:59:38 +08:00
|
|
|
task :test => [:build] do
|
|
|
|
in_ext()
|
|
|
|
end
|
2009-12-24 23:00:45 +08:00
|
|
|
|
2009-02-17 05:51:24 +08:00
|
|
|
desc 'Clean sigar extension'
|
|
|
|
task :clean do
|
|
|
|
in_ext()
|
2024-09-10 18:58:09 +08:00
|
|
|
system(MAKE + ' clean') if File.exist? "Makefile"
|
2009-02-17 05:51:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Dist Clean sigar extension'
|
|
|
|
task :distclean do
|
|
|
|
in_ext()
|
2024-09-10 18:58:09 +08:00
|
|
|
system(MAKE + ' distclean') if File.exist? "Makefile"
|
2009-02-17 05:51:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Run sigar examples (test)'
|
|
|
|
task :examples => [:build] do
|
|
|
|
in_ext()
|
|
|
|
Dir["examples/*.rb"].each do |file|
|
2010-05-21 06:56:42 +08:00
|
|
|
cmd = "ruby -I. #{file}"
|
2009-02-17 05:51:24 +08:00
|
|
|
print cmd + "\n"
|
|
|
|
system(cmd)
|
|
|
|
end
|
|
|
|
end
|
2010-01-19 16:04:46 +08:00
|
|
|
|
|
|
|
desc "create a gemspec file"
|
|
|
|
task :make_spec do
|
|
|
|
File.open("#{GEM}.gemspec", "w") do |file|
|
|
|
|
file.puts spec.to_ruby
|
|
|
|
end
|
|
|
|
end
|