Skip to content

Commit

Permalink
ExtensionTask now generated clean and clobber tasks.
Browse files Browse the repository at this point in the history
These new tasks remove temporary (build files) and binaries
already built.
  • Loading branch information
luislavena committed Nov 7, 2008
1 parent 5e628e5 commit 187ebaf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
coverage
doc/html
tmp
18 changes: 18 additions & 0 deletions features/compile.feature
Expand Up @@ -51,3 +51,21 @@ Feature: Compile C code into Ruby extensions.
And output of rake task 'compile:extension_one' do not contain /extension_two/
And binary extension 'extension_one' do exist in 'lib'
And binary extension 'extension_two' do not exist in 'lib'

Scenario: removing temporary files
Given a safe project directory
And scaffold code for extension 'extension_one'
And I've already successfully executed rake task 'compile'
When rake task 'clean' is invoked
Then rake task 'clean' succeeded
And binary extension 'extension_one' do exist in 'lib'
And 'tmp' folder do not exist

Scenario: clobbering binary and temporary files
Given a safe project directory
And scaffold code for extension 'extension_one'
And I've already successfully executed rake task 'compile'
When rake task 'clobber' is invoked
Then rake task 'clobber' succeeded
And binary extension 'extension_one' do not exist in 'lib'
And 'tmp' folder do not exist
6 changes: 5 additions & 1 deletion features/step_definitions/folders.rb
Expand Up @@ -18,5 +18,9 @@
end

Then /^'(.*)' folder is created$/ do |folder|
File.exist?(folder).should be_true
File.directory?(folder).should be_true
end

Then /^'(.*)' folder do not exist$/ do |folder|
File.directory?(folder).should_not be_true
end
9 changes: 8 additions & 1 deletion lib/rake/extensiontask.rb
Expand Up @@ -4,6 +4,7 @@
# gem developer/creators.

require 'rake'
require 'rake/clean'
require 'rake/tasklib'
require 'rbconfig'

Expand Down Expand Up @@ -38,6 +39,9 @@ def define
directory "#{@tmp_dir}/#{@name}"
directory @lib_dir

# temporary dir should be on the cleaning
CLEAN.include(@tmp_dir)

# makefile depends of tmp_dir and config_script
# tmp/extension_name/Makefile
file makefile => [tmp_path, extconf] do
Expand All @@ -61,10 +65,13 @@ def define
cp tmp_binary, lib_binary
end

# clobbering should remove the binaries from lib_path
CLOBBER.include(lib_binary)

desc "Compile just the #{@name} extension"
task "compile:#{@name}" => [lib_binary]

desc "Compile the extension(s)"
desc "Compile the extension(s)" unless Rake::Task.task_defined?('compile')
task "compile" => ["compile:#{@name}"]
end

Expand Down
12 changes: 12 additions & 0 deletions spec/lib/rake/extensiontask_spec.rb
Expand Up @@ -137,6 +137,18 @@
Rake::Task["tmp/extension_one/Makefile"].prerequisites.should include("ext/extension_one/extconf.rb")
end
end

describe 'clean' do
it "should include 'tmp' in the pattern" do
CLEAN.should include('tmp')
end
end

describe 'clobber' do
it "should include 'lib/extension_one.{so,bundle}'" do
CLOBBER.should include("lib/#{ext_bin('extension_one')}")
end
end
end
end

Expand Down

0 comments on commit 187ebaf

Please sign in to comment.