forked from quix/p4ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
109 lines (89 loc) · 1.93 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
begin
require 'rubygems'
gem 'rdoc'
rescue LoadError
end
require 'rubygems/package_task'
require 'rdoc/task'
require 'rake/contrib/rubyforgepublisher'
require 'fileutils'
include FileUtils
README = "README"
GEMSPEC = eval(File.read("p4ruby.gemspec"))
RAKEFILE = "Rakefile"
RAKEFILE_ORIG = "Rakefile.orig"
default_task_definition = %{
INSTALLER = './install.rb'
#
# default task compiles for the gem
#
task :default do
ARGV.clear
ARGV.push "--gem"
load INSTALLER
end
}
eval(default_task_definition)
task :clean => :clobber do
rm_rf ["work", "lib", "ext"]
end
task :update_docs do
ruby_path = File.join(
RbConfig::CONFIG["bindir"],
RbConfig::CONFIG["RUBY_INSTALL_NAME"])
help = "--help"
command = "ruby #{File.basename(INSTALLER)} #{help}"
output = `#{ruby_path} #{INSTALLER} #{help}`
# insert help output into README
replace_file(README) { |contents|
contents.sub(%r!#{command}.*?==!m) {
command + "\n\n " +
output + "\n=="
}
}
end
task :doc => :update_docs
task :doc => :rdoc
task :package => [:clean, :doc]
task :gem => :clean
RDoc::Task.new { |t|
t.main = README
t.rdoc_files.include([README])
t.rdoc_dir = "html"
t.title = "P4Ruby: #{GEMSPEC.summary}"
}
Gem::PackageTask.new(GEMSPEC) { |t|
t.need_tar = true
}
task :publish => :doc do
Rake::RubyForgePublisher.new('p4ruby', 'quix').upload
end
task :release do
mv(RAKEFILE, RAKEFILE_ORIG)
begin
File.open(RAKEFILE, "w") { |out|
out.puts default_task_definition.gsub(%r!^ !m, "")
}
Rake::Task[:package].invoke
ensure
mv(RAKEFILE_ORIG, RAKEFILE)
end
end
##################################################
# util
unless respond_to? :tap
module Kernel
def tap
yield self
self
end
end
end
def replace_file(file)
old_contents = File.read(file)
yield(old_contents).tap { |new_contents|
File.open(file, "w") { |output|
output.print(new_contents)
}
}
end