-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
160 lines (140 loc) · 4.63 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
require 'rubygems'
require 'rake/testtask'
require 'rdoc/task'
require 'rake/packagetask'
DISTEM_VERSION='1.4'
begin
require 'rake/extensiontask'
Rake::ExtensionTask.new do |ext|
ext.name = 'cpuhogs'
ext.ext_dir = 'ext/distem/cpuhogs'
ext.lib_dir = 'lib/ext'
end
Rake::ExtensionTask.new do |ext|
ext.name = 'cpugov'
ext.ext_dir = 'ext/distem/cpugov'
ext.lib_dir = 'lib/ext'
end
Rake::ExtensionTask.new do |ext|
ext.name = 'rngstream'
ext.ext_dir = 'ext/distem/rngstream'
ext.lib_dir = 'lib/ext'
end
rescue LoadError
puts "You need the 'rake-compiler' to build extensions from the Rakefile"
end
Rake::TestTask.new('test:unit') do |t|
t.libs << "test"
t.test_files = FileList['test/**/*.rb']
t.verbose = true
end
desc "Generate basic Documentation"
Rake::RDocTask.new do |t|
t.rdoc_dir = 'doc'
t.title = 'Distem'
t.options << '--line-numbers'
t.options << '--charset' << 'utf-8'
t.options << '--diagram'
t.rdoc_files.include('README.md')
t.rdoc_files.include('lib/**/*.rb')
end
desc "Run basic tests"
Rake::TestTask.new("test_units") { |t|
t.pattern = 'test/test_*.rb'
t.ruby_opts = ['-rubygems'] if defined? Gem
t.verbose = true
t.warning = true
}
desc "Generate source tgz package"
Rake::PackageTask::new("distem",DISTEM_VERSION) do |p|
p.need_tar_gz = true
p.package_files.include('lib/**/*')
p.package_files.include('ext/**/*')
p.package_files.include('bin/**/*')
p.package_files.include('test/**/*')
p.package_files.include('Rakefile', 'COPYING','README.md')
end
begin
require 'yard/sinatra'
require 'nokogiri'
desc "Generate the YARD documentation"
task :yard do
system("yard --plugin 'sinatra' doc --title \"YARD documentation for distem #{DISTEM_VERSION}\" --files files/resources_desc.md --list-undoc")
if File::directory?('../distem-private/www/doc/')
# edit *.html and remove footer to avoid the date that will change on each
# generation of the docs.
Dir['doc/**/*.html'].each do |f|
doc = Nokogiri::HTML::Document::parse(IO::read(f))
footer = doc.at_css("div#footer")
footer.remove unless footer.nil?
File::open(f, 'w') do |fd|
fd.puts doc
end
end
puts "\n\nCopying to ../distem-private/www/doc/..."
system("rsync -a doc/ ../distem-private/www/doc/")
puts "Remember to use git add -f (.html ignored by default)"
end
# cleanup
system("rm -rf .yardoc")
end
rescue LoadError
puts "yard-sinatra or nokogiri not found. Cannot generate documentation."
end
desc "Generate the REST API Documentation"
task :doc_netapi do
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'lib')
require 'docapi'
require 'rdoc/generator/docapi'
Docapi::CLI.new.generate(["lib/distem/netapi/server.rb"], "doc/netapi")
system('scripts/gendoc-netapi.sh')
end
desc "Builds a Debian package"
task :debian do
sh 'dpkg-buildpackage -us -uc'
end
desc "Builds a git snapshot package"
task :snapshot do
sh 'cp debian/changelog debian/changelog.git'
date = `date --iso=seconds |sed 's/+.*//' |sed 's/[-T:]//g'`.chomp
sh "sed -i '1 s/)/+git#{date})/' debian/changelog"
sh 'dpkg-buildpackage -us -uc'
sh 'mv debian/changelog.git debian/changelog'
end
desc "Build the last distem package built inside sbuild"
task :sbuild do
pkg = `cd .. ; ls distem*dsc | tail -1`.chomp
Dir::chdir('..') do
sh "sbuild -d distem32 --arch i386 #{pkg}"
sh "sbuild -d distem64 #{pkg}"
end
end
desc "Generate the manpages using help2man"
task :man do
(Dir['bin/*'] + ['scripts/distem-bootstrap', 'scripts/distem-devbootstrap']).each do |f|
FileUtils.mkdir_p('man')
# This hack is required so that the executables can find the extension and load them
ENV['RUBYLIB'] = File.join(File.dirname(__FILE__), 'debian', 'distem', RbConfig::CONFIG['vendorarchdir'])
system("help2man --no-info --version-string='#{DISTEM_VERSION}' #{f} > man/#{File.basename(f)}.1")
system("man -Hcat man/#{File.basename(f)}.1 | sed 's/−/-/g' > man/#{File.basename(f)}.html")
end
if File::directory?('../distem-private/www/man/')
# edit *.html and remove footer to avoid the date that will change on each
# generation of the docs.
puts "\n\nCopying to ../distem-private/www/man/..."
system("rsync -a man/*.html ../distem-private/www/man/")
puts "Remember to use git add -f (.html ignored by default)"
end
end
desc "Reindent everything"
task :reindent do
system('find bin lib -type f -exec vim -s .vim-reindent {} \;')
end
desc "Find patterns that confuse vim"
task :makevimfriendly do
Dir['**/*.rb'].each do |f|
if IO::read(f) =~ /\\\n\s*(unless|if)/
puts f
end
end
end