From 6a8243547a705aceffc414857b42f8ea94417327 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Sat, 18 Apr 2020 01:49:31 -0400 Subject: [PATCH] rule learns to accept Symbols as a prereq name rules presently expect string names as their prereqs (among others: Procs/Methods, RegExp patterns, or pathmap specs) This adds the conventional ability for a prereq task to be specified using a Symbol as is common with non-file-based tasks. --- lib/rake/task_manager.rb | 4 ++-- test/test_rake_rules.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/rake/task_manager.rb b/lib/rake/task_manager.rb index 97e3b9459..0db5c241e 100644 --- a/lib/rake/task_manager.rb +++ b/lib/rake/task_manager.rb @@ -300,8 +300,8 @@ def make_sources(task_name, task_pattern, extensions) when /^\./ source = task_name.sub(task_pattern, ext) source == ext ? task_name.ext(ext) : source - when String - ext + when String, Symbol + ext.to_s when Proc, Method if ext.arity == 1 ext.call(task_name) diff --git a/test/test_rake_rules.rb b/test/test_rake_rules.rb index bfb8e775f..e20df9350 100644 --- a/test/test_rake_rules.rb +++ b/test/test_rake_rules.rb @@ -80,6 +80,17 @@ def test_rule_prereqs_can_be_created_by_string assert_equal [OBJFILE], @runs end + def test_rule_prereqs_can_be_created_by_symbol + task :nonfile do |t| + @runs << t.name + end + rule ".o" => :nonfile do |t| + @runs << t.name + end + Task[OBJFILE].invoke + assert_equal ["nonfile", OBJFILE], @runs + end + def test_plain_strings_as_dependents_refer_to_files create_file(SRCFILE) rule ".o" => SRCFILE do |t|