File: Rantfile

package info (click to toggle)
rant 0.5.8-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,880 kB
  • ctags: 2,171
  • sloc: ruby: 23,192; ansic: 115; makefile: 33; cs: 22; cpp: 15
file content (334 lines) | stat: -rw-r--r-- 8,394 bytes parent folder | download | duplicates (3)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

# Rantfile for Rant :)

import "md5"
import %w(rubytest rubydoc rubypackage autoclean win32/rubycmdwrapper sys/more)

ENV["RANT_DEV_LIB_DIR"] = sys.expand_path("lib")

task :default => :test

dist_files = sys.filelist [
    "NEWS", "README", "INSTALL", "COPYING",
    "Rantfile", "install.rb", "setup.rb",
    "run_rant", "run_import"
    ]
dist_files.glob_unix "{bin,lib,test,doc,misc}/**/*"
dist_files.exclude_name "html", "coverage"

hp_files = sys["doc/homepage/*"]
rdoc_files = sys["README", "NEWS", "INSTALL", "doc/*.rdoc"]

# remove when compiler stuff is getting useful...
dist_files.exclude "lib/rant/compiler*", "lib/rant/import/c/program.rb"

rdoc_opts = %w(-S -c UTF-8 --title Rant --main README)

gen RubyPackage, "rant#{var :pkg_ext}" do |t|
    t.version = `#{sys.sp Env::RUBY_EXE} run_rant --version`.split[1]
    t.summary = "Rant is a Ruby based build tool."
    t.files = dist_files
    t.bindir = "bin"
    t.executable %w(rant rant-import)
    t.author = "Stefan Lang (maintained by Xavier Shay)"
    t.email = "contact@rhnh.net"
    t.rubyforge_project = "rant"
    t.homepage = "http://rant.rubyforge.org"
    t.has_rdoc = false
    t.gem_extra_rdoc_files = rdoc_files
    t.gem_rdoc_options = rdoc_opts
    desc "Create packages for distribution."
    t.package_task
end

task "dev-pkg" do
    make Package::Tgz, "pkg/rant-dev", :files => dist_files
end

task "dist-files" do
    puts dist_files
end

desc "Generate documentation."
gen RubyDoc do |g|
    g.verbose = true
    g.dir = "doc/html"
    g.files = rdoc_files
    g.opts = rdoc_opts + %w(-T doc/jamis.rb)
end

html_index = "doc/html/index.html"
api_index = html_index.sub("index", "api")

enhance "doc/html/index.html" do
    sys.rm_f api_index # remove old RDoc index page
    make "hp2doc"
end

task "hp2doc" do
    if test(?f, html_index) && !test(?f, api_index)
        sys.mv html_index, api_index
    end
    sys.cp hp_files, "doc/html"
end

desc "Publish html docs on make.rubyfore.org.",
     "Note: scp will prompt for rubyforge password."
task "publish-docs" => :doc do
    sys "scp -r doc/html/* meink@rubyforge.org:/var/www/gforge-projects/rant/"
end

task "publish-hp" do
    sys "scp -r doc/homepage/* meink@rubyforge.org:/var/www/gforge-projects/rant/"
end

desc "Run basic tests."
gen RubyTest do |g|
    g.libs << "test"
    g.test_files = sys["test/test_*.rb", "test/units/**/test_*.rb"]
end

desc "Run just unit tests."
gen RubyTest, "test:units".to_sym do |g|
    g.libs << "test"
    g.test_files = sys["test/units/**/test_*.rb"]
end

desc "Run first test-project."
gen RubyTest, :testp1 do |g|
    g.libs << "test"
    g.test_files = ["test/project1/test_project.rb"]
end

desc "Run second test project."
gen RubyTest, :testp2 do |g|
    g.libs << "test"
    g.test_files = ["test/project2/test_project.rb"]
end

desc "Test small Ruby project."
gen RubyTest, :testrb1 do |g|
    g.libs << "test"
    g.test_files = %w(test/project_rb1/test_project_rb1.rb)
end

desc "Test plugins."
gen RubyTest, :testplugins do |g|
    g.libs << "test"
    g.test_files = sys["test/plugin/**/test_*"]
end

desc "Run all tests and generate coverage with rcov."
task :cov do
    lp = File.expand_path "lib"
    sys.cd "test" do
	sys %W(rcov -xtutil.rb,ts_*,tc_*,test_* -I#{lp} ts_all.rb)
    end
end

desc "Test project with subdirs."
gen RubyTest, :tsubdirs do |t|
    t.libs << "test"
    t.test_files = sys["test/subdirs/test_*.rb"]
end

desc "Test rant-import command."
gen RubyTest, :trimport do |t|
    t.libs << "test"
    t.test_files = sys["test/rant-import/test_*.rb"]
end

desc "Test import/ libraries."
gen RubyTest, :timport do |t|
    t.libs << "test"
    t.test_files = sys["test/import/**/test_*.rb"]
end

desc "Test C support."
gen RubyTest, :tc do |t|
    t.libs << "test"
    t.test_files = sys["test/c/test_*.rb", "test/import/c/**/test_*.rb"]
end

desc "Run all tests."
task :tall do
    puts "Running build tool tests..."
    make "trantfile"
    puts "Build tool tests successful."
    puts "Running library tests..."
    make "tlib"
    puts "All tests (build tool and library) successful."
end

gen RubyTest, :trantfile do |t|
    t.libs << "test"
    t.test_files = sys["test/**/test_*.rb"].exclude("test/lib/*")
end

gen RubyTest, :tlib do |t|
    t.libs << "test"
    t.test_files = sys["test/lib/**/test_*.rb"]
end

task :t180 do |t|
    # my installed testrb version doesn't work with ruby-1.8.0
    sys.cd "test"
    if var[:TEST]
        sys "ruby180", "-w", "-rtest/unit", "-I", sys.expand_path("@lib"),
            "-I", sys.expand_path("."), var[:TEST].sub(/^test\//, '')
    else
        sys "ruby180 ts_all.rb"
    end
end

desc "Remove autogenerated files."
gen AutoClean, :clean
var[:clean].include %w(
    InstalledFiles .config bench-rant bench-depsearch test/coverage
)

# Just for quick visual testing of rant...
task :please_fail do |t|
    sys "mix_nix_gibts"
end

task "to-win" => :package do
    win_dir = "/mnt/data_fat/stefan/Ruby"
    Dir["pkg/*"].each { |f|
	target = File.join(win_dir, File.basename(f))
	make target => f do |t|
            sys.rm_rf target if test(?e, target)
            sys.cp_r f, t.name
	end
    }
end

desc "Install Rant."
task :install do
    sys.ruby "setup.rb"
    # try to install man page
    man_path = ENV["MANPATH"]
    if man_path
        puts "trying to install rant(1) manpage..."
        require 'rbconfig'
        prefix = Config::CONFIG["prefix"]
        dirs = sys.split_path man_path
        man_dir = dirs.find{|d| d == "#{prefix}/man" } || dirs.first
        sys.install "doc/rant.1", "#{man_dir}/man1", :mode => 0644 if man_dir
    end
end

if Env.on_windows?
    enhance :install => (gen Win32::RubyCmdWrapper, sys["bin/*"])
end

task "svn-clean" do
    `svn stat`.split(/\n/).each { |line|
        sys.clean line[7..-1] if line[0] == ??
    }
end

task "check-168" do
    rbfiles = sys["bin/rant*", "lib/**/*.rb"]
    ok = []
    bad = []
    rbfiles.each { |fn|
        sys "ruby168 -c #{fn}" do |ps|
            (ps.exitstatus == 0 ? ok : bad) << fn
        end
    }
    puts "Bad files:"
    bad.each { |b| puts "  #{b}" }
    puts "#{ok.size} of #{rbfiles.size} are OK"
end

desc "Create local backup of svn repos on berlios."
task "fetch-svn-dump" do
    require 'net/http'
    require 'uri'
    url = URI.parse("http://svn.berlios.de/svndumps/rant-repos.gz")
    req = Net::HTTP::Get.new(url.path)
    ds = Time.now.strftime("%Y-%m-%d")
    puts "Starting download from: #{url}"
    res = Net::HTTP.start(url.host, url.port) { |http|
        http.request(req)
    }
    sys.write_to_file "../rant-repos_#{ds}.gz", res.body
end

task "stats" do
    require 'scriptlines'
    files = sys["lib/**/*.rb"]
    puts ScriptLines.headline
    sum = ScriptLines.new("TOTAL (#{files.size} scripts)")
    files.each { |fn|
        File.open(fn) do |file|
            script_lines = ScriptLines.new(fn)
            script_lines.read(file)
            sum += script_lines
            puts script_lines
        end
    }
    puts sum
end

task "rb-stats" do
    files = sys["lib/**/*.rb"]
    lines = 0
    code_lines = 0
    files.each { |fn|
        l, c =  count_rb_lines(fn)
        lines += l
        code_lines += c
    }
    puts "Number of Ruby files under lib/: #{files.size}"
    puts "  #{lines} total lines"
    puts "  #{code_lines} LOC"

    files.exclude("lib/rant/archive*")

    lines = 0
    code_lines = 0
    files.each { |fn|
        l, c =  count_rb_lines(fn)
        lines += l
        code_lines += c
    }
    puts "  without lib/rant/archive/: #{files.size}"
    puts "    #{lines} total lines"
    puts "    #{code_lines} LOC"
end

def count_rb_lines(fn)
    lines = 0
    code_lines = 0
    in_multiline_comment = false
    File.readlines(fn).each { |line|
        lines += 1
        case line
        when /=end(\s|$)/:
            in_multiline_comment = false
            next
        when /^\s*$/, /^\s*#/: next
        when /^=begin(\s|$)/
            in_multiline_comment = true
        end
        code_lines += 1 unless in_multiline_comment
    }
    [lines, code_lines]
end

@prefix = var[:prefix] || "/usr/local"

task "uninstall" do
    print <<-EOF
    Run task _uninstall_ to uninstall Rant from prefix[#@prefix].
    EOF
end

task "_uninstall_" do
    sys.rm_rf FileList["#@prefix/lib/ruby/site_ruby/1.8/rant*"]
    sys.rm_f FileList["#@prefix/bin/rant*"]
end

# vim:ft=ruby