Sha256: c1579e518627e2aa7a7ba95d615cd0374ac4b26be86cc68cd96d8888b5bd4ce1

Contents?: true

Size: 1.91 KB

Versions: 14

Compression:

Stored size: 1.91 KB

Contents

require 'autobuild/config'
require 'find'
require 'rake/tasklib'
require 'fileutils'

STAMPFILE = "autobuild-stamp"

module Autobuild
    def self.tree_timestamp(path, *exclude)
        # Exclude autobuild timestamps
	exclude.each { |rx| raise unless Regexp === rx }
        exclude << (/#{Regexp.quote(STAMPFILE)}$/)

        puts "getting tree timestamp for #{path}" if Autobuild.debug
        latest = Time.at(0)
        latest_file = ""

        Find.find(path) { |p|
            Find.prune if File.basename(p) =~ /^\./
            exclude.each { |pattern| 
                if p =~ pattern
                    puts "  excluding #{p}" if Autobuild.debug
                    Find.prune
                end
            }
            next if File.directory?(p)

            p_time = File.mtime(p)
            if latest < p_time
                latest = p_time
                latest_file = p
            end
        }

        puts "  newest file: #{latest_file} at #{latest}" if Autobuild.debug
        return latest
    end

    class SourceTreeTask < Rake::Task
        attr_accessor :exclude
	def initialize(*args, &block)
	    @exclude = []
	    super
	end
	    
        def timestamp
            Autobuild.tree_timestamp(name, %r#(?:^|/)(?:CVS|_darcs|\.svn)$#, *@exclude)
        end
    end
    def self.source_tree(path, &block)
        task = SourceTreeTask.define_task(path)
        block.call(task) unless !block
        task
    end
            
    def self.get_stamp(stampfile)
        return Time.at(0) if !File.exists?(stampfile)
        return File.mtime(stampfile)
    end

    def self.touch_stamp(stampfile)
        puts "Touching #{stampfile}" if Autobuild.debug
        FileUtils.touch(stampfile)

        # File modification times on most Unix filesystems have a granularity of
        # one second, so we (unfortunately) have to sleep 1s to make sure that
        # time comparisons will work as expected.
        sleep(1)
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
autobuild-1.4.9 lib/autobuild/timestamps.rb
autobuild-1.4.8 lib/autobuild/timestamps.rb
autobuild-1.4.7 lib/autobuild/timestamps.rb
autobuild-1.4.6 lib/autobuild/timestamps.rb
autobuild-1.4.5 lib/autobuild/timestamps.rb
autobuild-1.4.4 lib/autobuild/timestamps.rb
autobuild-1.4.3 lib/autobuild/timestamps.rb
autobuild-1.4.2 lib/autobuild/timestamps.rb
autobuild-1.4.1 lib/autobuild/timestamps.rb
autobuild-1.4.0 lib/autobuild/timestamps.rb
autobuild-1.3.3 lib/autobuild/timestamps.rb
autobuild-1.3.2 lib/autobuild/timestamps.rb
autobuild-1.3.1 lib/autobuild/timestamps.rb
autobuild-1.3.0 lib/autobuild/timestamps.rb