Buildr cc doesn't support explicitly listed source files (patch included)
-------------------------------------------------------------------------

                 Key: BUILDR-627
                 URL: https://issues.apache.org/jira/browse/BUILDR-627
             Project: Buildr
          Issue Type: Bug
          Components: Core features
    Affects Versions: 1.4.7
         Environment: Mac OSX 10.7

$ buildr --version
Buildr 1.4.7

$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]

$ java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)
            Reporter: Christopher Tiwald
            Priority: Minor
             Fix For: 1.4.7


Buildr cc's timestamp logic only handles source directories, not source files. 
This means that `buildr cc` neglects to recompile when explicitly declared 
source files are touched. The relevant logic in cc.rb:

      timestamps = lambda do
        times = {}
        dirs.each { |d| Dir.glob("#{d}/**/*").map { |f| times[f] = File.mtime f 
} }
        times
      end

When d is a file, Dir.glob("#{d}/**/*") returns [], meaning the timestamp is 
never recorded. The patch seems simple: Add a check to see what 'd' is. I've 
coded a patch to do just that. I've tested that it works for both dirs and 
files, but can't get rake spec to work on an up-to-date trunk. That problem, 
however, doesn't appear to be my patch. I've pushed the patch to my github 
buildr clone at 
https://github.com/ctiwald/buildr/commit/e9530fa554e9d64c720567aa00bfb6dbbea1fea0
 and the raw git diff output is below. I'd be happy to submit this via another 
method. I wasn't quite clear on how to submit a patch in JIRA.

Raw git patch:

CompileTask's 'from' method accepts both directories and files, but
the cc task polls files incorrectly. Test whether or not the source
is a file or a directory and apply File.mtime accordingly. Directories
use the original logic, running File.mtime on a map of <directory>/**/*.
Skip the mapping if the source is a file.
---
 lib/buildr/core/cc.rb |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/buildr/core/cc.rb b/lib/buildr/core/cc.rb
index 8638072..74e3677 100644
--- a/lib/buildr/core/cc.rb
+++ b/lib/buildr/core/cc.rb
@@ -53,21 +53,27 @@ module Buildr
         build_failed(project, ex)
       end
 
-      dirs = []
+      srcs = []
       each_project do |p|
-        dirs += p.compile.sources.map(&:to_s)
-        dirs += p.test.compile.sources.map(&:to_s)
-        dirs += p.resources.sources.map(&:to_s)
+        srcs += p.compile.sources.map(&:to_s)
+        srcs += p.test.compile.sources.map(&:to_s)
+        srcs += p.resources.sources.map(&:to_s)
       end
-      if dirs.length == 1
-        info "Monitoring directory: #{dirs.first}"
+      if srcs.length == 1
+        info "Monitoring directory: #{srcs.first}"
       else
-        info "Monitoring directories: [#{dirs.join ', '}]"
+        info "Monitoring directories: [#{srcs.join ', '}]"
       end
 
       timestamps = lambda do
         times = {}
-        dirs.each { |d| Dir.glob("#{d}/**/*").map { |f| times[f] = File.mtime 
f } }
+        srcs.each { |a|
+          if File.directory? a
+            Dir.glob("#{a}/**/*").map { |f| times[f] = File.mtime f }
+          else
+            times[a] = File.mtime a
+          end
+        }
         times
       end

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to