Skip to content
This repository
Browse code

only define gem packaging tasks if rubygems is already loaded

  • Loading branch information...
commit 0781c28fc3c23fb46430f9596746859aee9573b6 1 parent fed9db5
Ryan Tomayko rtomayko authored

Showing 1 changed file with 70 additions and 70 deletions. Show diff stats Hide diff stats

  1. +70 70 Rakefile
140 Rakefile
@@ -5,6 +5,11 @@ require 'fileutils'
5 5 task :default => :test
6 6 task :spec => :test
7 7
  8 +def source_version
  9 + line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
  10 + line.match(/.*VERSION = '(.*)'/)[1]
  11 +end
  12 +
8 13 # SPECS ===============================================================
9 14
10 15 Rake::TestTask.new(:test) do |t|
@@ -12,50 +17,23 @@ Rake::TestTask.new(:test) do |t|
12 17 t.ruby_opts = ['-rubygems -I.'] if defined? Gem
13 18 end
14 19
15   -# PACKAGING ============================================================
16   -
17   -# Load the gemspec using the same limitations as github
18   -def spec
19   - require 'rubygems' unless defined? Gem::Specification
20   - @spec ||= eval(File.read('sinatra.gemspec'))
21   -end
22   -
23   -def package(ext='')
24   - "pkg/sinatra-#{spec.version}" + ext
25   -end
26   -
27   -desc 'Build packages'
28   -task :package => %w[.gem .tar.gz].map {|e| package(e)}
29   -
30   -desc 'Build and install as local gem'
31   -task :install => package('.gem') do
32   - sh "gem install #{package('.gem')}"
33   -end
34   -
35   -directory 'pkg/'
36   -CLOBBER.include('pkg')
37   -
38   -file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
39   - sh "gem build sinatra.gemspec"
40   - mv File.basename(f.name), f.name
41   -end
42   -
43   -file package('.tar.gz') => %w[pkg/] + spec.files do |f|
44   - sh <<-SH
45   - git archive \
46   - --prefix=sinatra-#{source_version}/ \
47   - --format=tar \
48   - HEAD | gzip > #{f.name}
49   - SH
  20 +# Rcov ================================================================
  21 +namespace :test do
  22 + desc 'Mesures test coverage'
  23 + task :coverage do
  24 + rm_f "coverage"
  25 + rcov = "rcov --text-summary --test-unit-only -Ilib"
  26 + system("#{rcov} --no-html --no-color test/*_test.rb")
  27 + end
50 28 end
51 29
52   -# Website ============================================================
  30 +# Website =============================================================
53 31 # Building docs requires HAML and the hanna gem:
54 32 # gem install mislav-hanna --source=http://gems.github.com
55 33
  34 +desc 'Generate RDoc under doc/api'
56 35 task 'doc' => ['doc:api']
57 36
58   -desc 'Generate Hanna RDoc under doc/api'
59 37 task 'doc:api' => ['doc/api/index.html']
60 38
61 39 file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
@@ -73,41 +51,63 @@ file 'doc/api/index.html' => FileList['lib/**/*.rb','README.rdoc'] do |f|
73 51 end
74 52 CLEAN.include 'doc/api'
75 53
76   -# Gemspec Helpers ====================================================
  54 +# PACKAGING ============================================================
77 55
78   -def source_version
79   - line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
80   - line.match(/.*VERSION = '(.*)'/)[1]
81   -end
  56 +if defined?(Gem)
  57 + # Load the gemspec using the same limitations as github
  58 + def spec
  59 + require 'rubygems' unless defined? Gem::Specification
  60 + @spec ||= eval(File.read('sinatra.gemspec'))
  61 + end
82 62
83   -task 'sinatra.gemspec' => FileList['{lib,test,compat}/**','Rakefile','CHANGES','*.rdoc'] do |f|
84   - # read spec file and split out manifest section
85   - spec = File.read(f.name)
86   - head, manifest, tail = spec.split(" # = MANIFEST =\n")
87   - # replace version and date
88   - head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
89   - head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
90   - # determine file list from git ls-files
91   - files = `git ls-files`.
92   - split("\n").
93   - sort.
94   - reject{ |file| file =~ /^\./ }.
95   - reject { |file| file =~ /^doc/ }.
96   - map{ |file| " #{file}" }.
97   - join("\n")
98   - # piece file back together and write...
99   - manifest = " s.files = %w[\n#{files}\n ]\n"
100   - spec = [head,manifest,tail].join(" # = MANIFEST =\n")
101   - File.open(f.name, 'w') { |io| io.write(spec) }
102   - puts "updated #{f.name}"
103   -end
  63 + def package(ext='')
  64 + "pkg/sinatra-#{spec.version}" + ext
  65 + end
104 66
105   -# Rcov ==============================================================
106   -namespace :test do
107   - desc 'Mesures test coverage'
108   - task :coverage do
109   - rm_f "coverage"
110   - rcov = "rcov --text-summary --test-unit-only -Ilib"
111   - system("#{rcov} --no-html --no-color test/*_test.rb")
  67 + desc 'Build packages'
  68 + task :package => %w[.gem .tar.gz].map {|e| package(e)}
  69 +
  70 + desc 'Build and install as local gem'
  71 + task :install => package('.gem') do
  72 + sh "gem install #{package('.gem')}"
  73 + end
  74 +
  75 + directory 'pkg/'
  76 + CLOBBER.include('pkg')
  77 +
  78 + file package('.gem') => %w[pkg/ sinatra.gemspec] + spec.files do |f|
  79 + sh "gem build sinatra.gemspec"
  80 + mv File.basename(f.name), f.name
  81 + end
  82 +
  83 + file package('.tar.gz') => %w[pkg/] + spec.files do |f|
  84 + sh <<-SH
  85 + git archive \
  86 + --prefix=sinatra-#{source_version}/ \
  87 + --format=tar \
  88 + HEAD | gzip > #{f.name}
  89 + SH
  90 + end
  91 +
  92 + task 'sinatra.gemspec' => FileList['{lib,test,compat}/**','Rakefile','CHANGES','*.rdoc'] do |f|
  93 + # read spec file and split out manifest section
  94 + spec = File.read(f.name)
  95 + head, manifest, tail = spec.split(" # = MANIFEST =\n")
  96 + # replace version and date
  97 + head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
  98 + head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
  99 + # determine file list from git ls-files
  100 + files = `git ls-files`.
  101 + split("\n").
  102 + sort.
  103 + reject{ |file| file =~ /^\./ }.
  104 + reject { |file| file =~ /^doc/ }.
  105 + map{ |file| " #{file}" }.
  106 + join("\n")
  107 + # piece file back together and write...
  108 + manifest = " s.files = %w[\n#{files}\n ]\n"
  109 + spec = [head,manifest,tail].join(" # = MANIFEST =\n")
  110 + File.open(f.name, 'w') { |io| io.write(spec) }
  111 + puts "updated #{f.name}"
112 112 end
113 113 end

0 comments on commit 0781c28

Please sign in to comment.
Something went wrong with that request. Please try again.