class Canoe::DepAnalyzer
Public Class Methods
compiling_filter(deps, build_time, src_sfx = 'cpp', hdr_sfx = 'hpp')
click to toggle source
# File lib/dependence.rb, line 35 def compiling_filter(deps, build_time, src_sfx = 'cpp', hdr_sfx = 'hpp') files = [] @processed = {} @recompiles = {} deps.each_key do |k| @processed[k] = false @recompiles[k] = false end deps.each do |k, v| next if k.end_with? ".#{hdr_sfx}" if should_recompile?(k, build_time) files << k @processed[k] = true @recompiles[k] = true next end v.each do |f| next unless mark(f, build_time, deps) || mark(f.sub(".#{hdr_sfx}", ".#{src_sfx}"), build_time, deps) files << k @processed[k] = true @recompiles[k] = true break end end files end
new(dir, src_sfx = 'cpp', hdr_sfx = 'hpp')
click to toggle source
# File lib/dependence.rb, line 97 def initialize(dir, src_sfx = 'cpp', hdr_sfx = 'hpp') @dir = dir @deps = Hash.new [] @source_suffix = src_sfx @header_suffix = hdr_sfx end
read_from(filename)
click to toggle source
# File lib/dependence.rb, line 23 def read_from(filename) File.open(filename, 'r') do |f| ret = Hash.new [] f.each_with_index do |line, i| entry = line.split(': ') abort_on_err("Bad .canoe.deps format, line #{i + 1}") unless entry.length == 2 ret[entry[0]] = entry[1].split end ret end end
Private Class Methods
mark(file, build_time, deps)
click to toggle source
# File lib/dependence.rb, line 66 def mark(file, build_time, deps) ret = false return false unless File.exist? file return true if should_recompile?(file, build_time) deps[file].each do |f| if @processed[f] ret |= @recompiles[f] next end @processed[f] = true if mark(f, build_time, deps) @recompiles[f] = true return true end end ret end
should_recompile?(file, build_time)
click to toggle source
# File lib/dependence.rb, line 85 def should_recompile?(file, build_time) judge = build_time if build_time == Time.new(0) objfile = file_to_obj(file) return true unless File.exist? objfile judge = File.mtime(objfile) end File.mtime(file) > judge end
Public Instance Methods
build_dependence(include_path)
click to toggle source
# File lib/dependence.rb, line 104 def build_dependence(include_path) files = SourceFiles.get_all(@dir) do |f| f.end_with?(".#{@source_suffix}") || f.end_with?(".#{@header_suffix}") end @deps = Hash.new [] files.each do |fname| @deps[fname] = get_all_headers include_path, fname, @header_suffix end @deps end
build_to_file(include_path, filename)
click to toggle source
# File lib/dependence.rb, line 117 def build_to_file(include_path, filename) build_dependence include_path File.open(filename, 'w') do |f| @deps.each do |k, v| f.write "#{k}: #{v.join(' ')}\n" end end @deps end
Private Instance Methods
get_all_headers(include_path, file, suffix = 'hpp')
click to toggle source
# File lib/dependence.rb, line 131 def get_all_headers(include_path, file, suffix = 'hpp') File.open(file, 'r') do |f| ret = [] if file.end_with?(".#{@source_suffix}") header = file.sub(".#{@source_suffix}", ".#{@header_suffix}") ret += [header] if File.exist?(header) end f.each_line do |line| if (mat = line.match(/include "(.+\.#{suffix})"/)) include_path.each do |path| dep = "#{path}/#{mat[1]}" ret += [dep] if File.exist? dep end end end ret.uniq end end