From 1b63dc75030175b88cb7a9ed000594ee2912e393 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 10 Feb 2019 21:23:52 -0500 Subject: [PATCH] move Environment.parse_makefile_deps to Util --- lib/rscons/builders/object.rb | 2 +- lib/rscons/builders/preprocess.rb | 2 +- lib/rscons/builders/shared_object.rb | 2 +- lib/rscons/environment.rb | 25 ------------------------- lib/rscons/util.rb | 27 +++++++++++++++++++++++++++ spec/rscons/environment_spec.rb | 19 ------------------- spec/rscons/util_spec.rb | 19 +++++++++++++++++++ 7 files changed, 49 insertions(+), 47 deletions(-) diff --git a/lib/rscons/builders/object.rb b/lib/rscons/builders/object.rb index 6bf807f..ee75012 100644 --- a/lib/rscons/builders/object.rb +++ b/lib/rscons/builders/object.rb @@ -111,7 +111,7 @@ module Rscons if options[:command_status] target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars) if File.exists?(vars['_DEPFILE']) - deps += Environment.parse_makefile_deps(vars['_DEPFILE']) + deps += Util.parse_makefile_deps(vars['_DEPFILE']) end cache.register_build(target, options[:tc].command, deps.uniq, env) target diff --git a/lib/rscons/builders/preprocess.rb b/lib/rscons/builders/preprocess.rb index 2238cc5..c0b1a86 100644 --- a/lib/rscons/builders/preprocess.rb +++ b/lib/rscons/builders/preprocess.rb @@ -49,7 +49,7 @@ module Rscons if options[:command_status] target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars) if File.exists?(vars['_DEPFILE']) - deps += Environment.parse_makefile_deps(vars['_DEPFILE']) + deps += Util.parse_makefile_deps(vars['_DEPFILE']) end cache.register_build(target, options[:tc].command, deps.uniq, env) target diff --git a/lib/rscons/builders/shared_object.rb b/lib/rscons/builders/shared_object.rb index 34bb522..19d4afe 100644 --- a/lib/rscons/builders/shared_object.rb +++ b/lib/rscons/builders/shared_object.rb @@ -96,7 +96,7 @@ module Rscons if options[:command_status] target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars) if File.exists?(vars['_DEPFILE']) - deps += Environment.parse_makefile_deps(vars['_DEPFILE']) + deps += Util.parse_makefile_deps(vars['_DEPFILE']) end cache.register_build(target, options[:tc].command, deps.uniq, env) target diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 47af51d..05998d7 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -806,31 +806,6 @@ module Rscons 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] 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 Environment.class_init diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index 340c970..fbacbef 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -64,6 +64,33 @@ module Rscons 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] + # 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 # Check if a directory contains a certain executable. diff --git a/spec/rscons/environment_spec.rb b/spec/rscons/environment_spec.rb index 351dc9b..60098ec 100644 --- a/spec/rscons/environment_spec.rb +++ b/spec/rscons/environment_spec.rb @@ -255,24 +255,5 @@ module Rscons expect(subject.__send__(:features_met?, builder, %w[-shared])).to be_falsey end end - - describe ".parse_makefile_deps" do - it 'handles dependencies on one line' do - expect(File).to receive(:read).with('makefile').and_return(<