Skip to content

Commit 5887348

Browse files
committed
Fixing Rakefile's bootstrap
1 parent 1f41acd commit 5887348

File tree

1 file changed

+96
-78
lines changed

1 file changed

+96
-78
lines changed

Rakefile

Lines changed: 96 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,125 @@
1-
task :build do
2-
title "Building the gem"
3-
end
4-
5-
require "bundler/gem_tasks"
6-
71
# Bootstrap task
82
#-----------------------------------------------------------------------------#
93

104
desc 'Install dependencies'
115
task :bootstrap do
12-
sh "bundle install"
6+
if system('which bundle')
7+
sh "bundle install"
8+
else
9+
$stderr.puts red("[!] Please install the bundler gem manually:\n" \
10+
' $ [sudo] gem install bundler')
11+
exit 1
12+
end
1313
end
1414

15+
begin
1516

16-
# Release tasks
17-
#-----------------------------------------------------------------------------#
18-
19-
desc "Build the gem for distribution"
20-
task :release_build => ['ext:clean', 'ext:precompile', :build]
17+
task :build do
18+
title "Building the gem"
19+
end
2120

22-
desc "Runs the tasks necessary for the release of the gem"
23-
task :pre_release do
24-
title "Running pre-release tasks"
25-
tmp = File.expand_path('../tmp', __FILE__)
26-
sh "rm -rf '#{tmp}'"
27-
Rake::Task[:release_build].invoke
28-
end
21+
require "bundler/gem_tasks"
2922

30-
# Always prebuilt for gems!
31-
Rake::Task[:build].enhance [:pre_release]
23+
# Release tasks
24+
#-----------------------------------------------------------------------------#
3225

33-
# Ext Namespace
34-
#-----------------------------------------------------------------------------#
26+
desc "Build the gem for distribution"
27+
task :release_build => ['ext:clean', 'ext:precompile', :build]
3528

36-
namespace :ext do
37-
desc "Clean the ext files"
38-
task :clean do
39-
title "Cleaning extension"
40-
sh "cd ext/xcodeproj && rm -f Makefile *.o *.bundle prebuilt/**/*.o prebuilt/**/*.bundle"
29+
desc "Runs the tasks necessary for the release of the gem"
30+
task :pre_release do
31+
title "Running pre-release tasks"
32+
tmp = File.expand_path('../tmp', __FILE__)
33+
sh "rm -rf '#{tmp}'"
34+
Rake::Task[:release_build].invoke
4135
end
4236

43-
desc "Build the ext"
44-
task :build do
45-
title "Building the extension"
46-
Dir.chdir 'ext/xcodeproj' do
47-
if on_rvm?
48-
sh "CFLAGS='-I#{rvm_ruby_dir}/include' ruby extconf.rb"
49-
else
50-
sh "ruby extconf.rb"
51-
end
52-
sh "make"
37+
# Always prebuilt for gems!
38+
Rake::Task[:build].enhance [:pre_release]
39+
40+
# Ext Namespace
41+
#-----------------------------------------------------------------------------#
42+
43+
namespace :ext do
44+
desc "Clean the ext files"
45+
task :clean do
46+
title "Cleaning extension"
47+
sh "cd ext/xcodeproj && rm -f Makefile *.o *.bundle prebuilt/**/*.o prebuilt/**/*.bundle"
5348
end
54-
end
5549

56-
desc "Pre-compile the ext for default Ruby on 10.8 and 10.9"
57-
task :precompile do
58-
title "Pre-compiling the extension"
59-
versions = Dir.glob(File.expand_path('../ext/xcodeproj/prebuilt/*darwin*', __FILE__)).sort
60-
versions.each do |version|
61-
Dir.chdir version do
62-
subtitle "#{File.basename(version)}"
50+
desc "Build the ext"
51+
task :build do
52+
title "Building the extension"
53+
Dir.chdir 'ext/xcodeproj' do
54+
if on_rvm?
55+
sh "CFLAGS='-I#{rvm_ruby_dir}/include' ruby extconf.rb"
56+
else
57+
sh "ruby extconf.rb"
58+
end
6359
sh "make"
6460
end
6561
end
62+
63+
desc "Pre-compile the ext for default Ruby on 10.8 and 10.9"
64+
task :precompile do
65+
title "Pre-compiling the extension"
66+
versions = Dir.glob(File.expand_path('../ext/xcodeproj/prebuilt/*darwin*', __FILE__)).sort
67+
versions.each do |version|
68+
Dir.chdir version do
69+
subtitle "#{File.basename(version)}"
70+
sh "make"
71+
end
72+
end
73+
end
74+
75+
desc "Clean and build the ext"
76+
task :cleanbuild => [:clean, :build]
6677
end
6778

68-
desc "Clean and build the ext"
69-
task :cleanbuild => [:clean, :build]
70-
end
79+
# Travis support
80+
def on_rvm?
81+
`which ruby`.strip.include?('.rvm')
82+
end
7183

72-
# Travis support
73-
def on_rvm?
74-
`which ruby`.strip.include?('.rvm')
75-
end
84+
def rvm_ruby_dir
85+
@rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
86+
end
7687

77-
def rvm_ruby_dir
78-
@rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
79-
end
88+
#-----------------------------------------------------------------------------#
8089

81-
#-----------------------------------------------------------------------------#
90+
namespace :spec do
91+
desc "Run all specs"
92+
task :all do
93+
puts "\n\033[0;32mUsing #{`ruby --version`.chomp}\033[0m"
94+
Rake::Task["ext:cleanbuild"].invoke
8295

83-
namespace :spec do
84-
desc "Run all specs"
85-
task :all do
86-
puts "\n\033[0;32mUsing #{`ruby --version`.chomp}\033[0m"
87-
Rake::Task["ext:cleanbuild"].invoke
96+
title "Running the specs"
97+
ENV['GENERATE_COVERAGE'] = 'true'
98+
sh "bundle exec bacon #{FileList['spec/**/*_spec.rb'].join(' ')}"
99+
end
88100

89-
title "Running the specs"
90-
ENV['GENERATE_COVERAGE'] = 'true'
91-
sh "bundle exec bacon #{FileList['spec/**/*_spec.rb'].join(' ')}"
92-
end
101+
desc "Automatically run specs"
102+
task :kick do
103+
exec "bundle exec kicker -c"
104+
end
93105

94-
desc "Automatically run specs"
95-
task :kick do
96-
exec "bundle exec kicker -c"
106+
desc "Run single spec"
107+
task :single, :spec_file do |t, args|
108+
sh "bundle exec bacon #{args.spec_file}"
109+
end
97110
end
98111

99-
desc "Run single spec"
100-
task :single, :spec_file do |t, args|
101-
sh "bundle exec bacon #{args.spec_file}"
102-
end
103-
end
112+
desc "Run all specs"
113+
task :spec => 'spec:all'
104114

105-
desc "Run all specs"
106-
task :spec => 'spec:all'
115+
task :default => :spec
107116

108-
task :default => :spec
117+
rescue LoadError
118+
$stderr.puts red('[!] Some Rake tasks haven been disabled because the ' \
119+
'environment couldn’t be loaded. Be sure to run `rake bootstrap` first.')
120+
end
109121

110-
# UI
122+
# UI Helpers
111123
#-----------------------------------------------------------------------------#
112124

113125
# Prints a title.
@@ -135,3 +147,9 @@ end
135147
def cyan(string)
136148
"\n\033[0;36m#{string}\033[0m"
137149
end
150+
151+
# Colorizes a string to red.
152+
#
153+
def red(string)
154+
"\033[0;31m#{string}\e[0m"
155+
end

0 commit comments

Comments
 (0)