change Environment#parse_makefile_deps() to a class method
This commit is contained in:
parent
0cd9dbd1bd
commit
1280cfb465
@ -69,7 +69,7 @@ module Rscons
|
||||
return false unless env.execute("#{com_prefix} #{target}", command)
|
||||
deps = sources
|
||||
if File.exists?(vars['_DEPFILE'])
|
||||
deps += env.parse_makefile_deps(vars['_DEPFILE'], target)
|
||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
||||
FileUtils.rm_f(vars['_DEPFILE'])
|
||||
end
|
||||
cache.register_build(target, command, deps.uniq)
|
||||
|
@ -204,30 +204,6 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Parse dependencies for a given target from a Makefile.
|
||||
# This method is used internally by RScons builders.
|
||||
# @param mf_fname [String] File name of the Makefile to read.
|
||||
# @param target [String] Name of the target to gather dependencies for.
|
||||
def parse_makefile_deps(mf_fname, target)
|
||||
deps = []
|
||||
buildup = ''
|
||||
File.read(mf_fname).each_line do |line|
|
||||
if line =~ /^(.*)\\\s*$/
|
||||
buildup += ' ' + $1
|
||||
else
|
||||
buildup += ' ' + line
|
||||
if buildup =~ /^(.*): (.*)$/
|
||||
mf_target, mf_deps = $1.strip, $2
|
||||
if mf_target == target
|
||||
deps += mf_deps.split(' ').map(&:strip)
|
||||
end
|
||||
end
|
||||
buildup = ''
|
||||
end
|
||||
end
|
||||
deps
|
||||
end
|
||||
|
||||
# Build a list of source files into files containing one of the suffixes
|
||||
# given by suffixes.
|
||||
# This method is used internally by RScons builders.
|
||||
@ -276,5 +252,29 @@ module Rscons
|
||||
end
|
||||
builder.run(target, sources, cache, self, vars)
|
||||
end
|
||||
|
||||
# Parse dependencies for a given target from a Makefile.
|
||||
# This method is used internally by RScons builders.
|
||||
# @param mf_fname [String] File name of the Makefile to read.
|
||||
# @param target [String] Name of the target to gather dependencies for.
|
||||
def self.parse_makefile_deps(mf_fname, target)
|
||||
deps = []
|
||||
buildup = ''
|
||||
File.read(mf_fname).each_line do |line|
|
||||
if line =~ /^(.*)\\\s*$/
|
||||
buildup += ' ' + $1
|
||||
else
|
||||
buildup += ' ' + line
|
||||
if buildup =~ /^(.*): (.*)$/
|
||||
mf_target, mf_deps = $1.strip, $2
|
||||
if mf_target == target
|
||||
deps += mf_deps.split(' ').map(&:strip)
|
||||
end
|
||||
end
|
||||
buildup = ''
|
||||
end
|
||||
end
|
||||
deps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Rscons
|
||||
describe Environment do
|
||||
describe '.clone' do
|
||||
describe "#clone" do
|
||||
it 'should create unique copies of each construction variable' do
|
||||
env = Environment.new
|
||||
env["CPPPATH"] << "path1"
|
||||
@ -11,13 +11,12 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
describe '.parse_makefile_deps' do
|
||||
describe ".parse_makefile_deps" do
|
||||
it 'handles dependencies on one line' do
|
||||
File.should_receive(:read).with('makefile').and_return(<<EOS)
|
||||
module.o: source.cc
|
||||
EOS
|
||||
env = Environment.new
|
||||
env.parse_makefile_deps('makefile', 'module.o').should == ['source.cc']
|
||||
Environment.parse_makefile_deps('makefile', 'module.o').should == ['source.cc']
|
||||
end
|
||||
|
||||
it 'handles dependencies split across many lines' do
|
||||
@ -26,8 +25,7 @@ module.o: module.c \\
|
||||
module.h \\
|
||||
other.h
|
||||
EOS
|
||||
env = Environment.new
|
||||
env.parse_makefile_deps('makefile', 'module.o').should == [
|
||||
Environment.parse_makefile_deps('makefile', 'module.o').should == [
|
||||
'module.c', 'module.h', 'other.h']
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user