move Environment.parse_makefile_deps to Util
This commit is contained in:
parent
db788cdd35
commit
1b63dc7503
@ -111,7 +111,7 @@ module Rscons
|
|||||||
if options[:command_status]
|
if options[:command_status]
|
||||||
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||||
if File.exists?(vars['_DEPFILE'])
|
if File.exists?(vars['_DEPFILE'])
|
||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'])
|
deps += Util.parse_makefile_deps(vars['_DEPFILE'])
|
||||||
end
|
end
|
||||||
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
||||||
target
|
target
|
||||||
|
@ -49,7 +49,7 @@ module Rscons
|
|||||||
if options[:command_status]
|
if options[:command_status]
|
||||||
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||||
if File.exists?(vars['_DEPFILE'])
|
if File.exists?(vars['_DEPFILE'])
|
||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'])
|
deps += Util.parse_makefile_deps(vars['_DEPFILE'])
|
||||||
end
|
end
|
||||||
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
||||||
target
|
target
|
||||||
|
@ -96,7 +96,7 @@ module Rscons
|
|||||||
if options[:command_status]
|
if options[:command_status]
|
||||||
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||||
if File.exists?(vars['_DEPFILE'])
|
if File.exists?(vars['_DEPFILE'])
|
||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'])
|
deps += Util.parse_makefile_deps(vars['_DEPFILE'])
|
||||||
end
|
end
|
||||||
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
||||||
target
|
target
|
||||||
|
@ -806,31 +806,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse dependencies from a Makefile.
|
|
||||||
#
|
|
||||||
# This method is used internally by Rscons builders.
|
|
||||||
#
|
|
||||||
# @param mf_fname [String] File name of the Makefile to read.
|
|
||||||
#
|
|
||||||
# @return [Array<String>] Paths of dependency files.
|
|
||||||
def self.parse_makefile_deps(mf_fname)
|
|
||||||
deps = []
|
|
||||||
buildup = ''
|
|
||||||
File.read(mf_fname).each_line do |line|
|
|
||||||
if line =~ /^(.*)\\\s*$/
|
|
||||||
buildup += ' ' + $1
|
|
||||||
else
|
|
||||||
buildup += ' ' + line
|
|
||||||
if buildup =~ /^.*: (.*)$/
|
|
||||||
mf_deps = $1
|
|
||||||
deps += mf_deps.split(' ').map(&:strip)
|
|
||||||
end
|
|
||||||
buildup = ''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
deps
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Environment.class_init
|
Environment.class_init
|
||||||
|
@ -64,6 +64,33 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Parse dependencies from a Makefile.
|
||||||
|
#
|
||||||
|
# This method is used internally by Rscons builders.
|
||||||
|
#
|
||||||
|
# @param mf_fname [String]
|
||||||
|
# File name of the Makefile to read.
|
||||||
|
#
|
||||||
|
# @return [Array<String>]
|
||||||
|
# Paths of dependency files.
|
||||||
|
def parse_makefile_deps(mf_fname)
|
||||||
|
deps = []
|
||||||
|
buildup = ''
|
||||||
|
File.read(mf_fname).each_line do |line|
|
||||||
|
if line =~ /^(.*)\\\s*$/
|
||||||
|
buildup += ' ' + $1
|
||||||
|
else
|
||||||
|
buildup += ' ' + line
|
||||||
|
if buildup =~ /^.*: (.*)$/
|
||||||
|
mf_deps = $1
|
||||||
|
deps += mf_deps.split(' ').map(&:strip)
|
||||||
|
end
|
||||||
|
buildup = ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
deps
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Check if a directory contains a certain executable.
|
# Check if a directory contains a certain executable.
|
||||||
|
@ -255,24 +255,5 @@ module Rscons
|
|||||||
expect(subject.__send__(:features_met?, builder, %w[-shared])).to be_falsey
|
expect(subject.__send__(:features_met?, builder, %w[-shared])).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".parse_makefile_deps" do
|
|
||||||
it 'handles dependencies on one line' do
|
|
||||||
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
|
||||||
module.o: source.cc
|
|
||||||
EOS
|
|
||||||
expect(Environment.parse_makefile_deps('makefile')).to eq ['source.cc']
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'handles dependencies split across many lines' do
|
|
||||||
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
|
||||||
module.o: module.c \\
|
|
||||||
module.h \\
|
|
||||||
other.h
|
|
||||||
EOS
|
|
||||||
expect(Environment.parse_makefile_deps('makefile')).to eq [
|
|
||||||
'module.c', 'module.h', 'other.h']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -111,5 +111,24 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".parse_makefile_deps" do
|
||||||
|
it 'handles dependencies on one line' do
|
||||||
|
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||||
|
module.o: source.cc
|
||||||
|
EOS
|
||||||
|
expect(Util.parse_makefile_deps('makefile')).to eq ['source.cc']
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'handles dependencies split across many lines' do
|
||||||
|
expect(File).to receive(:read).with('makefile').and_return(<<EOS)
|
||||||
|
module.o: module.c \\
|
||||||
|
module.h \\
|
||||||
|
other.h
|
||||||
|
EOS
|
||||||
|
expect(Util.parse_makefile_deps('makefile')).to eq [
|
||||||
|
'module.c', 'module.h', 'other.h']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user