class PaperHouse::AutoDepends

Automatically detects compilation dependencies.

Attributes

data[R]

Public Class Methods

new(c_file, o_file, cc, cc_options) click to toggle source

@private

# File lib/paper_house/auto_depends.rb, line 12
def initialize(c_file, o_file, cc, cc_options)
  @cc = cc
  @command = "#{@cc} -H #{cc_options} -c #{c_file} -o #{o_file}"
  @data = []
  @out = STDERR
end

Public Instance Methods

run() click to toggle source

Runs dependency detection.

# File lib/paper_house/auto_depends.rb, line 20
def run
  @out.puts @command
  exit_status = popen_command
  fail BuildFailed.new(@command, exit_status) if exit_status != 0
end

Private Instance Methods

extract_header_path_from(line) click to toggle source
# File lib/paper_house/auto_depends.rb, line 52
def extract_header_path_from(line)
  @data << line.sub(/^\.+\s+/, '').strip
end
filter_out_include_guards_warnings(stderr) click to toggle source
# File lib/paper_house/auto_depends.rb, line 58
def filter_out_include_guards_warnings(stderr)
  stderr.each_line do |each|
    next unless each =~ /:$/
    @out.puts each
    return
  end
end
parse_cc_h_stderr(stderr) click to toggle source
# File lib/paper_house/auto_depends.rb, line 35
def parse_cc_h_stderr(stderr)
  stderr.each do |each|
    parse_cc_h_stderr_line(each, stderr)
  end
end
parse_cc_h_stderr_line(line, stderr) click to toggle source
# File lib/paper_house/auto_depends.rb, line 41
def parse_cc_h_stderr_line(line, stderr)
  case line
  when /^\./
    extract_header_path_from line
  when /Multiple include guards/
    filter_out_include_guards_warnings stderr
  else
    @out.puts line
  end
end
popen_command() click to toggle source
# File lib/paper_house/auto_depends.rb, line 28
def popen_command
  POpen4.popen4(@command) do |_stdout, stderr, stdin, |
    stdin.close
    parse_cc_h_stderr stderr
  end
end