root/trunk/tools/rakehelp.rb

Revision 84, 2.4 kB (checked in by e.@brainspl.at, 2 years ago)

add tolls

Line 
1 def make(makedir)
2   Dir.chdir(makedir) do
3     sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
4   end
5 end
6
7
8 def extconf(dir)
9   Dir.chdir(dir) do ruby "extconf.rb" end
10 end
11
12
13 def setup_tests
14   Rake::TestTask.new do |t|
15     t.libs << "test"
16     t.test_files = FileList['test/test*.rb']
17     t.verbose = true
18   end
19 end
20
21
22 def setup_clean otherfiles
23   files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
24   CLEAN.include(files)
25 end
26
27
28 def setup_rdoc files
29   Rake::RDocTask.new do |rdoc|
30     rdoc.rdoc_dir = 'doc/rdoc'
31     rdoc.options << '--line-numbers'
32     rdoc.rdoc_files.add(files)
33   end
34 end
35
36
37 def setup_extension(dir, extension)
38   ext = "ext/#{dir}"
39   ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
40   ext_files = FileList[
41     "#{ext}/*.c",
42     "#{ext}/*.h",
43     "#{ext}/extconf.rb",
44     "#{ext}/Makefile",
45     "lib"
46   ]
47
48   task "lib" do
49     directory "lib"
50   end
51
52   desc "Builds just the #{extension} extension"
53   task extension.to_sym => ["#{ext}/Makefile", ext_so ]
54
55   file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
56     extconf "#{ext}"
57   end
58
59   file ext_so => ext_files do
60     make "#{ext}"
61     cp ext_so, "lib"
62   end
63 end
64
65
66 def base_gem_spec(pkg_name, pkg_version)
67   rm_rf "test/coverage"
68   pkg_version = pkg_version
69   pkg_name    = pkg_name
70   pkg_file_name = "#{pkg_name}-#{pkg_version}"
71   Gem::Specification.new do |s|
72     s.name = pkg_name
73     s.version = pkg_version
74     s.platform = Gem::Platform::RUBY
75     s.has_rdoc = true
76     s.extra_rdoc_files = [ "README" ]
77
78     s.files = %w(COPYING LICENSE README Rakefile) +
79       Dir.glob("{bin,doc/rdoc,test}/**/*") +
80       Dir.glob("ext/**/*.{h,c,rb,rl}") +
81       Dir.glob("{examples,tools,lib}/**/*.rb")
82
83     s.require_path = "lib"
84     s.extensions = FileList["ext/**/extconf.rb"].to_a
85     s.bindir = "bin"
86   end
87 end
88
89 def setup_gem(pkg_name, pkg_version)
90   spec = base_gem_spec(pkg_name, pkg_version)
91   yield spec if block_given?
92
93   Rake::GemPackageTask.new(spec) do |p|
94     p.gem_spec = spec
95     p.need_tar = true if RUBY_PLATFORM !~ /mswin/
96   end
97 end
98
99 def sub_project(project, *targets)
100   targets.each do |target|
101     Dir.chdir "projects/#{project}" do
102       sh %{rake --trace #{target.to_s} }
103     end
104   end
105 end
106
107 # Conditional require rcov/rcovtask if present
108 begin
109   require 'rcov/rcovtask'
110  
111   Rcov::RcovTask.new do |t|
112     t.test_files = FileList['test/test*.rb']
113     t.rcov_opts << "-x /usr"
114     t.output_dir = "test/coverage"
115   end
116 rescue Object
117 end
Note: See TracBrowser for help on using the browser.