Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Pathname object as rule's prerequisite #528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/rake/task_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,29 @@ def attempt_rule(task_name, task_pattern, args, extensions, block, level)
end

# Make a list of sources from the list of file name extensions /
# translation procs.
def make_sources(task_name, task_pattern, extensions)
result = extensions.map { |ext|
case ext
# file paths / translation procs.
def make_sources(task_name, task_pattern, prereqs)
result = prereqs.map { |prereq|
case prereq
when /%/
task_name.pathmap(ext)
task_name.pathmap(prereq)
when %r{/}
ext
prereq
when /^\./
source = task_name.sub(task_pattern, ext)
source == ext ? task_name.ext(ext) : source
source = task_name.sub(task_pattern, prereq)
source == prereq ? task_name.ext(prereq) : source
when String, Symbol
ext.to_s
prereq.to_s
when Pathname
Rake.from_pathname(prereq)
when Proc, Method
if ext.arity == 1
ext.call(task_name)
if prereq.arity == 1
prereq.call(task_name)
else
ext.call
prereq.call
end
else
fail "Don't know how to handle rule dependent: #{ext.inspect}"
fail "Don't know how to handle rule dependent: #{prereq.inspect}"
end
}
result.flatten
Expand Down
10 changes: 10 additions & 0 deletions test/test_rake_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_rule_prereqs_can_be_created_by_string
assert_equal [OBJFILE], @runs
end

def test_rule_prereqs_can_be_created_by_pathname
create_file(SRCFILE)
create_file(FOOFILE)
rule ".o" => [".c", Pathname(FOOFILE)] do |t|
@runs << t.name
end
Task[OBJFILE].invoke
assert_equal [OBJFILE], @runs
end

def test_rule_prereqs_can_be_created_by_symbol
task :nonfile do |t|
@runs << t.name
Expand Down