diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index fbacbef..ff694c7 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -26,25 +26,6 @@ module Rscons command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ') end - # Make a relative path corresponding to a possibly absolute one. - # - # @param path [String] - # Input path that is possibly absolute. - # - # @return [String] - # Relative path. - def make_relative_path(path) - if absolute_path?(path) - if path =~ %r{^(\w):(.*)$} - "_#{$1}#{$2}" - else - "_#{path}" - end - else - path - end - end - # Look for an executable. # # @return [String, nil] @@ -64,6 +45,25 @@ module Rscons end end + # Make a relative path corresponding to a possibly absolute one. + # + # @param path [String] + # Input path that is possibly absolute. + # + # @return [String] + # Relative path. + def make_relative_path(path) + if absolute_path?(path) + if path =~ %r{^(\w):(.*)$} + "_#{$1}#{$2}" + else + "_#{path}" + end + else + path + end + end + # Parse dependencies from a Makefile. # # This method is used internally by Rscons builders. diff --git a/spec/rscons/util_spec.rb b/spec/rscons/util_spec.rb index cbc757e..ba08801 100644 --- a/spec/rscons/util_spec.rb +++ b/spec/rscons/util_spec.rb @@ -29,32 +29,6 @@ module Rscons end end - describe ".make_relative_path" do - context "when passed a relative path" do - it "returns the path itself" do - expect(Util.make_relative_path("foo/bar")).to eq "foo/bar" - end - end - - context "when passed an absolute path" do - before(:each) do - expect(Util).to receive(:absolute_path?).and_return(true) - end - - context "on Windows" do - it "returns a relative path corresponding to an absolute one" do - expect(Util.make_relative_path("D:/foo/bar")).to eq "_D/foo/bar" - end - end - - context "on non-Windows" do - it "returns a relative path corresponding to an absolute one" do - expect(Util.make_relative_path("/foo/bar")).to eq "_/foo/bar" - end - end - end - end - describe ".find_executable" do context "when given a path with directory components" do it "returns the path if it is executable" do @@ -111,6 +85,32 @@ module Rscons end end + describe ".make_relative_path" do + context "when passed a relative path" do + it "returns the path itself" do + expect(Util.make_relative_path("foo/bar")).to eq "foo/bar" + end + end + + context "when passed an absolute path" do + before(:each) do + expect(Util).to receive(:absolute_path?).and_return(true) + end + + context "on Windows" do + it "returns a relative path corresponding to an absolute one" do + expect(Util.make_relative_path("D:/foo/bar")).to eq "_D/foo/bar" + end + end + + context "on non-Windows" do + it "returns a relative path corresponding to an absolute one" do + expect(Util.make_relative_path("/foo/bar")).to eq "_/foo/bar" + 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(<