Skip to content

Commit

Permalink
Task comments are now additive (with /).
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@211 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information
jimweirich committed Jun 22, 2004
1 parent 19b4661 commit a569398
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions rake/CHANGES
@@ -1,5 +1,8 @@
= Rake Changelog

== Version next
* Task comments are now additive, combined with "/".

== Version 0.4.0
* FileList now uses deferred loading. The file system is not searched
until the first call that needs the file names.
Expand Down
22 changes: 17 additions & 5 deletions rake/lib/rake.rb
Expand Up @@ -60,7 +60,7 @@ class Task
attr_reader :prerequisites

# Comment for this task.
attr_reader :comment
attr_accessor :comment

# Source dependency for rule synthesized tasks. Nil if task was not
# sythesized from a rule.
Expand All @@ -70,8 +70,6 @@ class Task
# use +enhance+ to add actions and prerequisites.
def initialize(task_name)
@name = task_name
@comment = $last_comment
$last_comment = nil
@prerequisites = []
@actions = []
@already_invoked = false
Expand Down Expand Up @@ -127,6 +125,18 @@ def timestamp
@prerequisites.collect { |p| Task[p].timestamp }.max || Time.now
end

# Add a comment to the task. If a comment alread exists, separate
# the new comment with " / ".
def add_comment(comment)
return if ! $last_comment
if @comment
@comment << " / "
else
@comment = ''
end
@comment << $last_comment
end

# Class Methods ----------------------------------------------------

class << self
Expand Down Expand Up @@ -170,12 +180,14 @@ 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.
# added to the existing task. Returns the defined task.
def define_task(args, &block)
task_name, deps = resolve_args(args)
deps = [deps] if (Symbol === deps) || (String === deps)
deps = deps.collect {|d| d.to_s }
lookup(task_name).enhance(deps, &block)
t = lookup(task_name)
t.add_comment($last_comment)
t.enhance(deps, &block)
end

# Define a rule for synthesizing tasks.
Expand Down
10 changes: 10 additions & 0 deletions rake/test/data/multidesc/Rakefile
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

desc "A"
task :a

desc "B"
task :b

desc "A2"
task :a
6 changes: 6 additions & 0 deletions rake/test/functional.rb
Expand Up @@ -43,6 +43,12 @@ def test_env_availabe_at_task_scope
assert_status
end

def test_multi_desc
Dir.chdir("test/data/multidesc") do rake "-T" end
assert_match %r{^rake a *# A / A2 *$}, @out
assert_match %r{^rake b *# B *$}, @out
end

private

def rake(options="")
Expand Down

0 comments on commit a569398

Please sign in to comment.