Return-Path: Delivered-To: apmail-buildr-commits-archive@www.apache.org Received: (qmail 36321 invoked from network); 1 Mar 2010 09:03:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Mar 2010 09:03:47 -0000 Received: (qmail 51692 invoked by uid 500); 28 Feb 2010 04:37:07 -0000 Delivered-To: apmail-buildr-commits-archive@buildr.apache.org Received: (qmail 51664 invoked by uid 500); 28 Feb 2010 04:37:07 -0000 Mailing-List: contact commits-help@buildr.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@buildr.apache.org Delivered-To: mailing list commits@buildr.apache.org Received: (qmail 51657 invoked by uid 99); 28 Feb 2010 04:37:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 04:37:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 04:37:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7695C2388900; Sun, 28 Feb 2010 04:36:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r917119 - /buildr/trunk/lib/buildr/core/cc.rb Date: Sun, 28 Feb 2010 04:36:46 -0000 To: commits@buildr.apache.org From: djspiewak@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100228043646.7695C2388900@eris.apache.org> Author: djspiewak Date: Sun Feb 28 04:36:46 2010 New Revision: 917119 URL: http://svn.apache.org/viewvc?rev=917119&view=rev Log: Added resource monitoring to cc task Modified: buildr/trunk/lib/buildr/core/cc.rb Modified: buildr/trunk/lib/buildr/core/cc.rb URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/cc.rb?rev=917119&r1=917118&r2=917119&view=diff ============================================================================== --- buildr/trunk/lib/buildr/core/cc.rb (original) +++ buildr/trunk/lib/buildr/core/cc.rb Sun Feb 28 04:36:46 2010 @@ -1,21 +1,29 @@ +require 'buildr/core/common' +require 'buildr/core/project' +require 'buildr/core/build' +require 'buildr/core/compile' + module Buildr module CC include Extension class << self - def check_mtime(dirs, ext, old_times) - times = old_times + def check_mtime(pattern, old_times) + times = {} changed = [] - dirs.each do |dir| - Dir.glob "#{dir}/**/*.{#{ext.join ','}}" do |fname| - if old_times[fname].nil? || old_times[fname] < File.mtime(fname) - times[fname] = File.mtime fname - changed << fname - end + Dir.glob pattern do |fname| + times[fname] = File.mtime fname + if old_times[fname].nil? || old_times[fname] < File.mtime(fname) + changed << fname end end + # detect deletion (slower than it could be) + old_times.each_key do |fname| + changed << fname unless times.has_key? fname + end + [times, changed] end @@ -29,23 +37,33 @@ end before_define do |project| - project.task :cc => :compile do - dirs = project.compile.sources.map(&:to_s) - ext = Buildr::Compiler.select(project.compile.compiler).source_ext.map(&:to_s) - times, _ = Buildr::CC.check_mtime dirs, ext, {} # establish baseline + project.task :cc => [:compile, 'test:compile'] do + main_dirs = project.compile.sources.map(&:to_s) + test_dirs = project.task('test:compile').sources.map(&:to_s) + res_dirs = project.resources.sources.map(&:to_s) + + main_ext = Buildr::Compiler.select(project.compile.compiler).source_ext.map(&:to_s) + test_ext = Buildr::Compiler.select(project.task('test:compile').compiler).source_ext.map(&:to_s) + + test_tail = if test_dirs.empty? then '' else ",{#{test_dirs.join ','}}/**/*.{#{test_ext.join ','}}" end + res_tail = if res_dirs.empty? then '' else ",{#{res_dirs.join ','}}/**/*" end + + pattern = "{{#{main_dirs.join ','}}/**/*.{#{main_ext.join ','}}#{test_tail}#{res_tail}}" + + times, _ = Buildr::CC.check_mtime pattern, {} # establish baseline - dir_names = dirs.map { |file| Buildr::CC.strip_filename project, file } - if dirs.length == 1 + dir_names = (main_dirs + test_dirs + res_dirs).map { |file| Buildr::CC.strip_filename project, file } + if dir_names.length == 1 info "Monitoring directory: #{dir_names.first}" else info "Monitoring directories: [#{dir_names.join ', '}]" end - trace "Monitoring extensions: [#{ext.join ', '}]" + trace "Monitoring extensions: [#{main_ext.join ', '}]" while true sleep project.cc.frequency - times, changed = Buildr::CC.check_mtime dirs, ext, times + times, changed = Buildr::CC.check_mtime pattern, times unless changed.empty? info '' # better spacing @@ -53,8 +71,26 @@ info "Detected changes in #{Buildr::CC.strip_filename project, file}" end - project.task(:compile).reenable + in_main = main_dirs.any? do |dir| + changed.any? { |file| file.index(dir) == 0 } + end + + in_test = test_dirs.any? do |dir| + changed.any? { |file| file.index(dir) == 0 } + end + + in_res = res_dirs.any? do |dir| + changed.any? { |file| file.index(dir) == 0 } + end + + # TODO for some reason, resources task doesn't run like this + project.task(:resources).reenable if in_res + project.task(:compile).reenable if in_main + project.task('test:compile').reenable if in_test + + project.task(:resources).invoke project.task(:compile).invoke + project.task('test:compile').invoke end end end @@ -65,7 +101,7 @@ end class CCOptions - attr_writer :frequency + attr_writer :frequency # TODO this is a bad name, maybe "delay"? def frequency @frequency ||= 0.2