1 # frozen_string_literal: true
3 require "bundler/gem_tasks"
4 require "rake/testtask"
6 desc "Run all the tests"
9 desc "Install gem dependencies"
12 spec = Gem::Specification.load('rack.gemspec')
13 spec.dependencies.each do |dep|
14 reqs = dep.requirements_list
15 reqs = (["-v"] * reqs.size).zip(reqs).flatten
16 # Use system over sh, because we want to ignore errors!
17 system Gem.ruby, "-S", "gem", "install", '--conservative', dep.name, *reqs
21 desc "Make an archive as .tar.gz"
22 task dist: %w[chmod changelog spec rdoc] do
23 sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
24 sh "pax -waf #{release}.tar -s ':^:#{release}/:' SPEC.rdoc ChangeLog doc rack.gemspec"
25 sh "gzip -f -9 #{release}.tar"
28 desc "Make an official release"
29 task :officialrelease do
30 puts "Official build for #{release}..."
32 sh "git clone --shared . stage"
33 sh "cd stage && rake officialrelease_really"
34 sh "mv stage/#{release}.tar.gz stage/#{release}.gem ."
37 task officialrelease_really: %w[spec dist gem] do
38 sh "shasum #{release}.tar.gz #{release}.gem"
42 "rack-" + File.read('lib/rack/version.rb')[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2]
45 desc "Make binaries executable"
47 Dir["bin/*"].each { |binary| File.chmod(0755, binary) }
48 Dir["test/cgi/test*"].each { |binary| File.chmod(0755, binary) }
51 desc "Generate a ChangeLog"
52 task changelog: "ChangeLog"
55 file "ChangeLog" => '.git/index' do
56 File.open("ChangeLog", "w") { |out|
58 log.force_encoding(Encoding::BINARY)
59 log.split("\0").map { |chunk|
60 author = chunk[/Author: (.*)/, 1].strip
61 date = chunk[/Date: (.*)/, 1].strip
62 desc, detail = $'.strip.split("\n", 2)
64 detail = detail.gsub(/.*darcs-hash:.*/, '')
66 out.puts "#{date} #{author}"
67 out.puts " * #{desc.strip}"
68 out.puts detail unless detail.empty?
74 desc "Generate Rack Specification"
75 task spec: "SPEC.rdoc"
77 file 'lib/rack/lint.rb'
78 file "SPEC.rdoc" => 'lib/rack/lint.rb' do
79 File.open("SPEC.rdoc", "wb") { |file|
80 IO.foreach("lib/rack/lint.rb") { |line|
81 if line =~ /^\s*## ?(.*)/
88 Rake::TestTask.new("test:regular") do |t|
90 t.test_files = FileList["test/**/*_test.rb", "test/**/spec_*.rb", "test/gemloader.rb"]
95 desc "Run tests with coverage"
98 Rake::Task['test:regular'].invoke
101 desc "Run separate tests for each test file, to test directly requiring components"
102 task "test:separate" do
104 FileList["test/**/spec_*.rb"].each do |file|
105 puts "#{FileUtils::RUBY} -w #{file}"
106 fails << file unless system({'SEPARATE'=>'1'}, FileUtils::RUBY, '-w', file)
109 puts 'All test files passed'
111 puts "Failures in the following test files:"
113 raise "At least one separate test failed"
117 desc "Run all the fast + platform agnostic tests"
118 task test: %w[spec test:regular test:separate]
120 desc "Run all the tests we run on CI"
124 sh "gem build rack.gemspec"
129 desc "Generate RDoc documentation"
130 task rdoc: %w[changelog spec] do
131 sh(*%w{rdoc --line-numbers --main README.rdoc
132 --title 'Rack\ Documentation' --charset utf-8 -U -o doc} +
133 %w{README.rdoc KNOWN-ISSUES SPEC.rdoc ChangeLog} +
134 `git ls-files lib/\*\*/\*.rb`.strip.split)
135 cp "contrib/rdoc.css", "doc/rdoc.css"