summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 430c4456df2f842746a865d4bbbd3507034d22c9 (plain)
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
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rake/testtask"

desc "Run all the tests"
task default: :test

desc "Install gem dependencies"
task :deps do
  require 'rubygems'
  spec = Gem::Specification.load('rack.gemspec')
  spec.dependencies.each do |dep|
    reqs = dep.requirements_list
    reqs = (["-v"] * reqs.size).zip(reqs).flatten
    # Use system over sh, because we want to ignore errors!
    system Gem.ruby, "-S", "gem", "install", '--conservative', dep.name, *reqs
  end
end

desc "Make an archive as .tar.gz"
task dist: %w[chmod changelog spec rdoc] do
  sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
  sh "pax -waf #{release}.tar -s ':^:#{release}/:' SPEC.rdoc ChangeLog doc rack.gemspec"
  sh "gzip -f -9 #{release}.tar"
end

desc "Make an official release"
task :officialrelease do
  puts "Official build for #{release}..."
  sh "rm -rf stage"
  sh "git clone --shared . stage"
  sh "cd stage && rake officialrelease_really"
  sh "mv stage/#{release}.tar.gz stage/#{release}.gem ."
end

task officialrelease_really: %w[spec dist gem] do
  sh "shasum #{release}.tar.gz #{release}.gem"
end

def release
  "rack-" + File.read('lib/rack/version.rb')[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2]
end

desc "Make binaries executable"
task :chmod do
  Dir["bin/*"].each { |binary| File.chmod(0755, binary) }
  Dir["test/cgi/test*"].each { |binary| File.chmod(0755, binary) }
end

desc "Generate a ChangeLog"
task changelog: "ChangeLog"

file '.git/index'
file "ChangeLog" => '.git/index' do
  File.open("ChangeLog", "w") { |out|
    log = `git log -z`
    log.force_encoding(Encoding::BINARY)
    log.split("\0").map { |chunk|
      author = chunk[/Author: (.*)/, 1].strip
      date = chunk[/Date: (.*)/, 1].strip
      desc, detail = $'.strip.split("\n", 2)
      detail ||= ""
      detail = detail.gsub(/.*darcs-hash:.*/, '')
      detail.rstrip!
      out.puts "#{date}  #{author}"
      out.puts "  * #{desc.strip}"
      out.puts detail  unless detail.empty?
      out.puts
    }
  }
end

desc "Generate Rack Specification"
task spec: "SPEC.rdoc"

file 'lib/rack/lint.rb'
file "SPEC.rdoc" => 'lib/rack/lint.rb' do
  File.open("SPEC.rdoc", "wb") { |file|
    IO.foreach("lib/rack/lint.rb") { |line|
      if line =~ /^\s*## ?(.*)/
        file.puts $1
      end
    }
  }
end

Rake::TestTask.new("test:regular") do |t|
  t.libs << "test"
  t.test_files = FileList["test/**/*_test.rb", "test/**/spec_*.rb", "test/gemloader.rb"]
  t.warning = false
  t.verbose = true
end

desc "Run tests with coverage"
task "test_cov" do
  ENV['COVERAGE'] = '1'
  Rake::Task['test:regular'].invoke
end

desc "Run all the fast + platform agnostic tests"
task test: %w[spec test:regular]

desc "Run all the tests we run on CI"
task ci: :test

task gem: :spec do
  sh "gem build rack.gemspec"
end

task doc: :rdoc

desc "Generate RDoc documentation"
task rdoc: %w[changelog spec] do
  sh(*%w{rdoc --line-numbers --main README.rdoc
              --title 'Rack\ Documentation' --charset utf-8 -U -o doc} +
              %w{README.rdoc KNOWN-ISSUES SPEC.rdoc ChangeLog} +
              `git ls-files lib/\*\*/\*.rb`.strip.split)
  cp "contrib/rdoc.css", "doc/rdoc.css"
end

task pushdoc: :rdoc do
  sh "rsync -avz doc/ rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
end

task pushsite: :pushdoc do
  sh "cd site && git gc"
  sh "rsync -avz site/ rack.rubyforge.org:/var/www/gforge-projects/rack/"
  sh "cd site && git push"
end

def clone_and_test(url, name, command)
  path = "external/#{name}"
  FileUtils.rm_rf path
  FileUtils.mkdir_p path

  sh("git clone #{url} #{path}")

  # I tried using `bundle config --local local.async ../` but it simply doesn't work.
  File.open("#{path}/Gemfile", "a") do |file|
    file.puts("gem 'rack', path: '../../'")
  end

  sh("cd #{path} && bundle install && #{command}")
end

task :external do
  Bundler.with_clean_env do
    clone_and_test("https://github.com/kickstarter/rack-attack", "rack-attack", "bundle exec rake")
    clone_and_test("https://github.com/socketry/falcon", "falcon", "bundle exec rspec")
  end
end