You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by dj...@apache.org on 2010/02/28 05:36:24 UTC
svn commit: r917116 - /buildr/trunk/addon/buildr/cc.rb
Author: djspiewak
Date: Sun Feb 28 04:36:23 2010
New Revision: 917116
URL: http://svn.apache.org/viewvc?rev=917116&view=rev
Log:
Added prototype continuous compilation task
Added:
buildr/trunk/addon/buildr/cc.rb
Added: buildr/trunk/addon/buildr/cc.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/addon/buildr/cc.rb?rev=917116&view=auto
==============================================================================
--- buildr/trunk/addon/buildr/cc.rb (added)
+++ buildr/trunk/addon/buildr/cc.rb Sun Feb 28 04:36:23 2010
@@ -0,0 +1,67 @@
+module Buildr
+ module CC
+ include Extension
+
+ class << self
+ def check_mtime(dirs, ext, old_times)
+ times = old_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
+ end
+ end
+
+ [times, changed]
+ end
+
+ def strip_filename(project, name)
+ name.gsub project.base_dir + File::SEPARATOR, ''
+ end
+ end
+
+ first_time do
+ Project.local_task :cc
+ 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
+
+ dir_names = dirs.map { |file| Buildr::CC.strip_filename project, file }
+ if dirs.length == 1
+ info "Monitoring directory: #{dir_names.first}"
+ else
+ info "Monitoring directories: [#{dir_names.join ', '}]"
+ end
+ trace "Monitoring extensions: [#{ext.join ', '}]"
+
+ while true
+ sleep 0.2
+
+ times, changed = Buildr::CC.check_mtime dirs, ext, times
+ unless changed.empty?
+ info '' # better spacing
+
+ changed.each do |file|
+ info "Detected changes in #{Buildr::CC.strip_filename project, file}"
+ end
+
+ project.task(:compile).reenable
+ project.task(:compile).invoke
+ end
+ end
+ end
+ end
+ end
+
+ class Project
+ include CC
+ end
+end