Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Directory DSL as task #67

Merged
merged 3 commits into from

3 participants

@zimbatm

For long, it has bothered me that the "directory" method didn't behave like the file and task task. This commit fixes that :)

@jimweirich
Owner

Can I get some tests for this?

@zimbatm

Here you go.

I am also considering changing the dependency chain to depend on the parent's directory creation.
That would be more semantically correct and also ensure right task execution order.

directory("a/b/c")
Task["a/b/c"].dependencies == ["a/b"]
Task["a/b"].dependencies == ["a"]
Task["a"].dependencies == []
@mattmassicotte

I've also found this surprising. I'd love to see this included!

@jimweirich jimweirich merged commit 27bfc63 into jimweirich:master
@jimweirich
Owner

merged to HEAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 5, 2011
  1. @zimbatm

    Fix file_create definition

    zimbatm authored
  2. @zimbatm

    directory DSL now behaves like other tasts

    zimbatm authored
    ... where you can set dependencies and such
Commits on Aug 8, 2011
  1. @zimbatm
This page is out of date. Refresh to see the latest.
View
9 lib/rake/dsl_definition.rb
@@ -52,8 +52,8 @@ def file(*args, &block)
# Declare a file creation task.
# (Mainly used for the directory command).
- def file_create(args, &block)
- Rake::FileCreationTask.define_task(args, &block)
+ def file_create(*args, &block)
+ Rake::FileCreationTask.define_task(*args, &block)
end
# Declare a set of files tasks to create the given directories on
@@ -62,12 +62,15 @@ def file_create(args, &block)
# Example:
# directory "testdata/doc"
#
- def directory(dir)
+ def directory(*args, &block)
+ ret = file_create(*args, &block)
+ dir, _ = *Rake.application.resolve_args(args)
Rake.each_dir_parent(dir) do |d|
file_create d do |t|
mkdir_p t.name if ! File.exist?(t.name)
end
end
+ ret
end
# Declare a task that performs its prerequisites in
View
1  test/helper.rb
@@ -1,4 +1,5 @@
require 'rubygems'
+$:.unshift File.expand_path('../../lib', __FILE__)
begin
gem 'minitest'
View
16 test/test_rake_directory_task.rb
@@ -43,4 +43,20 @@ def test_directory_win32
refute File.exist?('c:/a/b/c')
end
end
+
+ def test_can_use_blocks
+ runlist = []
+
+ t1 = directory("a/b/c" => :t2) { |t| runlist << t.name }
+ t2 = task(:t2) { |t| runlist << t.name }
+
+ verbose(false) {
+ t1.invoke
+ }
+
+ assert_equal Task["a/b/c"], t1
+ assert_equal FileCreationTask, Task["a/b/c"].class
+ assert_equal ["t2", "a/b/c"], runlist
+ assert File.directory?("a/b/c")
+ end
end
Something went wrong with that request. Please try again.