-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapfile
154 lines (127 loc) · 3.35 KB
/
tapfile
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
#
# Helpers
#
def gemspecs
@gemspecs ||= begin
require 'rubygems'
require 'rubygems/specification'
{}
end
end
def gemspec(name)
gemspecs[name] ||= begin
path = File.expand_path("#{name}.gemspec")
eval(File.read(path), binding, path, 0)
end
end
#
# Dependency tasks
#
singleton do
desc 'Checkout submodules'
task :submodules do
output = `git submodule status 2>&1`
if output =~ /^-/m
puts "Missing submodules:\n#{output}"
sh "git submodule init"
sh "git submodule update"
puts
end
end
end
#
# Tasks
#
class ModuleTask < Tap::Task
def call(names)
pwd = Dir.pwd
names = %w{
tap
tap-test
tap-tasks
tap-gen
} if names.empty?
names.each do |name|
begin
Dir.chdir(name)
process(name)
ensure
Dir.chdir(pwd)
end
end
end
end
baseclass ModuleTask
desc 'Prints the gemspec manifest.'
task :manifest do |config, name|
# collect files from the gemspec, labeling with true or false corresponding
# to the file existing or not
files = {}
gemspec(name).files.each do |file|
files[File.expand_path(file)] = [File.exists?(file), file]
end
# gather non-rdoc/pkg files for the project and add to the files list if
# they are not included already (marking by the absence of a label)
Dir.glob('**/*').each do |file|
next if file =~ /\A(rdoc|pkg|test|specs|images|.*\.rbc)/ || File.directory?(file)
files[File.expand_path(file)] ||= [true, file]
end
# sort and output the results
files.values.sort_by {|exists, file| file }.each do |entry|
puts '%-5s %s' % entry
end
end
desc 'Generate documentation.'
task :rdoc, :force => false do |config, name|
require 'cdoc'
spec = gemspec(name)
files = spec.files.select {|file|
file =~ /lib.*\.rb$/
} + spec.extra_rdoc_files
args = %w{
--fmt cdoc
--template cdoc/cdoc_html_template
--op rdoc
} + spec.rdoc_options + files.uniq
args << '--force-update' if config.force
RDoc::RDoc.new.document(args)
end
desc 'Publish RDoc to RubyForge'
task :publish_rdoc => :rdoc do |config, name|
require 'yaml'
config = YAML.load_file File.expand_path('~/.rubyforge/user-config.yml')
username = config['username']
sh "rsync -v -c -r rdoc/ #{username}@rubyforge.org:/var/www/gforge-projects/tap/#{name == 'tap' ? 'rdoc' : name}"
end
desc 'Generate a gem.'
task(:gem,
:install => false,
:uninstall => false,
:sudo => true
) do |config, name|
destination_dir = File.expand_path('pkg')
unless File.directory?(destination_dir)
FileUtils.mkdir_p(destination_dir)
end
path = ::Gem::Builder.new(gemspec(name)).build
dest = File.join(destination_dir, File.basename(path))
FileUtils.mv(path, dest)
cmd = config.sudo ? 'sudo gem' : 'gem'
sh "#{cmd} uninstall #{name}" if config.uninstall
sh "#{cmd} install #{dest} --no-rdoc --no-ri" if config.install
end
desc 'Run tests.'
task({:test => :submodules}, {:all => false}) do |config, name|
libs = %W{
../configurable/lib
../lazydoc/lib
../#{name}/lib
}
gemspec(name).dependencies.each do |dep|
libs << File.join('..', dep.name, 'lib')
end
cmd = ['ruby', '-w', '-e', 'ARGV.each {|test| load test}']
libs.uniq.each {|lib| cmd.concat ['-I', lib] }
cmd.concat Dir.glob("test/**/*_test.rb")
with_env('ALL' => config.all.to_s) { sh(*cmd) }
end