Permalink
Browse files

Changed argument specification to use task command rather than desc c…

…ommand"

git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@621 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information...
1 parent 8e05fcd commit 32fef525079dbbad3e1df1aeb23692f53401394e jimweirich committed Dec 21, 2007
Showing with 228 additions and 211 deletions.
  1. +17 −16 Rakefile
  2. +51 −66 lib/rake.rb
  3. +3 −1 test/test_application.rb
  4. +7 −0 test/test_filelist.rb
  5. +5 −0 test/test_pathmap.rb
  6. +14 −21 test/test_task_arguments.rb
  7. +131 −107 test/test_tasks.rb
View
@@ -293,15 +293,16 @@ end
task :noop
#plugin "release_manager"
-desc "[rel, reuse, reltest] Make a new release"
-task :release => [
- :prerelease,
- :clobber,
- :test_all,
- :update_version,
- :package,
- :tag] do
-
+desc "Make a new release"
+task :release, :rel, :reuse, :reltest,
+ :needs => [
+ :prerelease,
+ :clobber,
+ :test_all,
+ :update_version,
+ :package,
+ :tag
+ ] do
announce
announce "**************************************************************"
announce "* Release #{$package_version} Complete."
@@ -311,8 +312,7 @@ task :release => [
end
# Validate that everything is ready to go for a release.
-desc "[rel, reuse, reltest]"
-task :prerelease do |t, rel, reuse, reltest|
+task :prerelease, :rel, :reuse, :reltest do |t, rel, reuse, reltest|
$package_version = rel
announce
announce "**************************************************************"
@@ -345,8 +345,8 @@ task :prerelease do |t, rel, reuse, reltest|
end
end
-desc "[rel, reuse, reltest]"
-task :update_version => [:prerelease] do |t, rel, reuse, reltest|
+task :update_version, :rel, :reuse, :reltest,
+ :needs => [:prerelease] do |t, rel, reuse, reltest|
if rel == CURRENT_VERSION
announce "No version change ... skipping version update"
else
@@ -371,15 +371,16 @@ task :update_version => [:prerelease] do |t, rel, reuse, reltest|
end
end
-desc "[rel, reuse, reltest] Tag all the CVS files with the latest release number (REL=x.y.z)"
-task :tag => [:prerelease] do |t, rel, reuse, reltest|
+desc "Tag all the CVS files with the latest release number (REL=x.y.z)"
+task :tag, :rel, :reuse, :reltest,
+ :needs => [:prerelease] do |t, rel, reuse, reltest|
reltag = "REL_#{rel.gsub(/\./, '_')}"
reltag << reuse.gsub(/\./, '_') if reuse
announce "Tagging Repository with [#{reltag}]"
if reltest
announce "Release Task Testing, skipping CVS tagging"
else
- sh %{svn copy svn+ssh://rubyforge.org/var/svn/rake/trunk svn+ssh://rubyforge.org/var/svn/rake/tags/#{reltag} -m 'Commiting release #{reltag}'}
+ sh %{svn copy svn+ssh://rubyforge.org/var/svn/rake/trunk svn+ssh://rubyforge.org/var/svn/rake/tags/#{reltag} -m 'Commiting release #{reltag}'} ###'
end
end
View
@@ -29,7 +29,7 @@
# as a library via a require statement, but it can be distributed
# independently as an application.
-RAKEVERSION = '0.7.99.3'
+RAKEVERSION = '0.7.99.4'
require 'rbconfig'
require 'ftools'
@@ -208,7 +208,7 @@ def pathmap(spec=nil, &block)
when '%x'
result << $1 if self =~ /[^\/](\.[^.]+)$/
when '%X'
- if self =~ /^(.+[^\/])(\.[^.]+)$/
+ if self =~ /^(.*[^\/])(\.[^.]+)$/
result << $1
else
result << self
@@ -289,11 +289,10 @@ class TaskArguments
def initialize(names, values, parent=nil)
@names = names
- @values = values
@parent = parent
@hash = {}
names.each_with_index { |name, i|
- @hash[name.to_s] = @values[i]
+ @hash[name.to_sym] = values[i]
}
end
@@ -306,33 +305,23 @@ def new_scope(names)
# Find an argument value by name or index.
def [](index)
- case index
- when Integer
- @values[index]
- else
- lookup(index.to_s)
- end
- end
-
- # Compare to an array
- def ==(other)
- to_ary == other
- end
-
- def to_ary
- @values
+ lookup(index.to_sym)
end
def each(&block)
- @values.each(&block)
+ @hash.each(&block)
end
def method_missing(sym, *args, &block)
- lookup(sym.to_s)
+ lookup(sym.to_sym)
+ end
+
+ def to_hash
+ @hash
end
def to_s
- "[" + @values.collect { |v| v.inspect }.join(', ') + "]"
+ @hash.inspect
end
def inspect
@@ -344,10 +333,10 @@ def inspect
def lookup(name)
if @hash.has_key?(name)
@hash[name]
- elsif ENV.has_key?(name)
- ENV[name]
- elsif ENV.has_key?(name.upcase)
- ENV[name.upcase]
+ elsif ENV.has_key?(name.to_s)
+ ENV[name.to_s]
+ elsif ENV.has_key?(name.to_s.upcase)
+ ENV[name.to_s.upcase]
elsif @parent
@parent.lookup(name)
end
@@ -575,13 +564,7 @@ def timestamp
# argument list (enclosed brackets) and an optional comment.
def add_description(description)
return if ! description
- if description =~ %r{\A\s*(\[([^\]]*)\])\s*(.*)\Z}m
- arg_string = $2
- comment = $3.strip
- else
- comment = description.strip
- end
- set_arg_names(arg_string) if arg_string
+ comment = description.strip
add_comment(comment) if comment && ! comment.empty?
end
@@ -604,17 +587,14 @@ def add_comment(comment)
else
@comment = @full_comment
end
-# if @comment.length > 50
-# @comment = @comment[0, 47] + "..."
-# end
end
private :add_comment
- # Set the names of the arguments for this task.
- def set_arg_names(arg_string)
- @arg_names = arg_string.split(',').collect { |n| n.strip }
+ # Set the names of the arguments for this task. +args+ should be
+ # an array of symbols, one for each argument name.
+ def set_arg_names(args)
+ @arg_names = args.map { |a| a.to_sym }
end
- private :set_arg_names
# Return a string describing the internal state of a task. Useful for
# debugging.
@@ -668,13 +648,13 @@ def task_defined?(task_name)
# Define a task given +args+ and an option block. If a rule with the
# given name already exists, the prerequisites and actions are added to
# the existing task. Returns the defined task.
- def define_task(args, &block)
- Rake.application.define_task(self, args, &block)
+ def define_task(*args, &block)
+ Rake.application.define_task(self, *args, &block)
end
# Define a rule for synthesizing tasks.
- def create_rule(args, &block)
- Rake.application.create_rule(args, &block)
+ def create_rule(*args, &block)
+ Rake.application.create_rule(*args, &block)
end
# Apply the scope to the task name according to the rules for
@@ -775,8 +755,8 @@ def invoke_prerequisites(args, invocation_chain)
# rm_rf "html"
# end
#
-def task(args, &block)
- Rake::Task.define_task(args, &block)
+def task(*args, &block)
+ Rake::Task.define_task(*args, &block)
end
@@ -849,8 +829,8 @@ def namespace(name=nil, &block)
# sh %{cc -o #{t.name} #{t.source}}
# end
#
-def rule(args, &block)
- Rake::Task.create_rule(args, &block)
+def rule(*args, &block)
+ Rake::Task.create_rule(*args, &block)
end
# Describe the next rake task.
@@ -1166,7 +1146,7 @@ class FileList
# List of array methods (that are not in +Object+) that need to be
# delegated.
- ARRAY_METHODS = Array.instance_methods - Object.instance_methods
+ ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
# List of additional methods that must be delegated.
MUST_DEFINE = %w[to_a inspect]
@@ -1621,18 +1601,19 @@ def initialize
@last_description = nil
end
- def create_rule(args, &block)
- pattern, deps = resolve_args(args)
+ def create_rule(*args, &block)
+ pattern, arg_names, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
@rules << [pattern, deps, block]
end
- def define_task(task_class, args, &block)
- task_name, deps = resolve_args(args)
+ def define_task(task_class, *args, &block)
+ task_name, arg_names, deps = resolve_args(args)
task_name = task_class.scope_name(@scope, task_name)
deps = [deps] unless deps.respond_to?(:to_ary)
deps = deps.collect {|d| d.to_s }
task = intern(task_class, task_name)
+ task.set_arg_names(arg_names) unless arg_names.empty?
task.add_description(@last_description)
@last_description = nil
task.enhance(deps, &block)
@@ -1659,20 +1640,25 @@ def synthesize_file_task(task_name)
define_task(Rake::FileTask, task_name)
end
- # Resolve the arguments for a task/rule.
+ # Resolve the arguments for a task/rule. Returns a triplet of
+ # [task_name, arg_list, dependencies_list].
+ # TODO: Rework this to handle arguments
def resolve_args(args)
- case args
- when Hash
- fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
- fail "No Task Name Given" if args.size < 1
- task_name = args.keys[0]
- deps = args[task_name]
- deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
- else
- task_name = args
- deps = []
+ task_name = args.shift
+ arg_names = args #.map { |a| a.to_sym }
+ needs = []
+ if task_name.is_a?(Hash)
+ hash = task_name
+ task_name = hash.keys[0]
+ needs = hash[task_name]
+ end
+ if arg_names.last.is_a?(Hash)
+ hash = arg_names.pop
+ needs = hash[:needs]
+ fail "Unrecognized keys in task hash: #{hash.keys.inspect}" if hash.size > 1
end
- [task_name, deps]
+ needs = [needs] unless needs.respond_to?(:to_ary)
+ [task_name, arg_names, needs]
end
# If a rule can be found that matches the task name, enhance the
@@ -2132,7 +2118,6 @@ def handle_options
$silent = options.silent
end
rescue NoMethodError => ex
- puts "DBG: RESCUING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
raise GetoptLong::InvalidOption, "While parsing options, error = #{ex.class}:#{ex.message}"
end
View
@@ -258,7 +258,9 @@ def test_default_options
def test_bad_options
assert_raise GetoptLong::InvalidOption do
- flags('--bad', '-t') do |opts|
+ capture_stderr do
+ flags('--bad', '-t') do |opts|
+ end
end
end
end
View
@@ -18,6 +18,13 @@ def teardown
FileUtils.rm_rf("testdata")
end
+ def test_delgating_methods_do_not_include_to_a_or_to_ary
+ assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
+ assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
+ assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
+ assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
+ end
+
def test_create
fl = FileList.new
assert_equal 0, fl.size
View
@@ -60,6 +60,11 @@ def test_X_returns_everything_but_extension
assert_equal "abc", "abc".pathmap("%X")
assert_equal "abc", "abc.rb".pathmap("%X")
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
+ assert_equal "ab.xyz", "ab.xyz.rb".pathmap("%X")
+ assert_equal "a.xyz", "a.xyz.rb".pathmap("%X")
+ assert_equal "abc", "abc.rb".pathmap("%X")
+ assert_equal "ab", "ab.rb".pathmap("%X")
+ assert_equal "a", "a.rb".pathmap("%X")
assert_equal ".depends", ".depends".pathmap("%X")
assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
assert_equal "/.depends", "/.depends".pathmap("%X")
Oops, something went wrong.

0 comments on commit 32fef52

Please sign in to comment.