From a1bb9d81fd0d5af5f9cd48d6458fb5cf9e07774d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 27 Aug 2019 19:47:21 -0400 Subject: [PATCH] check_program: do not fail on Windows for non-existent PATH entries --- lib/rscons/util.rb | 22 ++++++++++++---------- spec/build_tests_spec.rb | 20 +++++++++++++++++--- spec/rscons/util_spec.rb | 5 ++++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index cca75e9..256547b 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -204,16 +204,18 @@ module Rscons File.file?(path) and File.executable?(path) end if RbConfig::CONFIG["host_os"] =~ /mswin|windows|mingw/i - executable = executable.downcase - dir_entries = Dir.entries(path_entry) - dir_entries.find do |entry| - path = "#{path_entry}/#{entry}" - entry = entry.downcase - if ((entry == executable) or - (entry == "#{executable}.exe") or - (entry == "#{executable}.com") or - (entry == "#{executable}.bat")) and is_executable[path] - return path + if File.directory?(path_entry) + executable = executable.downcase + dir_entries = Dir.entries(path_entry) + dir_entries.find do |entry| + path = "#{path_entry}/#{entry}" + entry = entry.downcase + if ((entry == executable) or + (entry == "#{executable}.exe") or + (entry == "#{executable}.com") or + (entry == "#{executable}.bat")) and is_executable[path] + return path + end end end else diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 2995fce..11d5a38 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -145,7 +145,11 @@ EOF stdout, stderr, status = nil, nil, nil Bundler.with_clean_env do env = ENV.to_h - env["PATH"] = "#{@build_test_run_dir}/_bin#{File::PATH_SEPARATOR}#{env["PATH"]}" + path = ["#{@build_test_run_dir}/_bin", "#{env["PATH"]}"] + if options[:path] + path = Array(options[:path]) + path + end + env["PATH"] = path.join(File::PATH_SEPARATOR) stdout, stderr, status = Open3.capture3(env, *command) File.open("#{@build_test_run_dir}/.stdout", "wb") do |fh| fh.write(stdout) @@ -2046,6 +2050,16 @@ EOF expect(result.stdout).to match /Checking for program 'find'... .*find/ end + context "with non-existent PATH entries" do + it "succeeds when the requested program is found" do + test_dir "configure" + result = run_rscons(rsconscript: "check_program_success.rb", op: "configure", path: "/foo/bar") + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /Checking for program 'find'... .*find/ + end + end + it "fails when the requested program is not found" do test_dir "configure" result = run_rscons(rsconscript: "check_program_failure.rb", op: "configure") @@ -2188,8 +2202,8 @@ EOF expect(result.stdout).to match /Setting build directory\.\.\. bb/ expect(result.stdout).to match %r{Setting prefix\.\.\. /my/prefix} expect(result.stdout).to match /Checking for C compiler\.\.\. gcc/ - expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. g++/ - expect(result.stdout).to match /Checking for D compiler\.\.\. gdc/ + expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. g\+\+/ + expect(result.stdout).to match /Checking for D compiler\.\.\. (gdc|ldc2)/ expect(result.stdout).to match /Checking for package 'mypackage'\.\.\. found/ expect(result.stdout).to match /Checking for C header 'stdio.h'\.\.\. found/ expect(result.stdout).to match /Checking for C\+\+ header 'iostream'\.\.\. found/ diff --git a/spec/rscons/util_spec.rb b/spec/rscons/util_spec.rb index 6771e79..26babfe 100644 --- a/spec/rscons/util_spec.rb +++ b/spec/rscons/util_spec.rb @@ -121,7 +121,10 @@ EOF before(:each) do stub_const("File::PATH_SEPARATOR", ";") stub_const("RbConfig::CONFIG", "host_os" => "mingw") - expect(ENV).to receive(:[]).with("PATH").and_return("C:\\bin;C:\\Windows") + expect(ENV).to receive(:[]).with("PATH").and_return("C:\\none;C:\\bin;C:\\Windows") + allow(File).to receive(:directory?).with("C:\\none").and_return(false) + allow(File).to receive(:directory?).with("C:\\bin").and_return(true) + allow(File).to receive(:directory?).with("C:\\Windows").and_return(true) allow(Dir).to receive(:entries).with("C:\\bin").and_return(%w[one.com]) allow(Dir).to receive(:entries).with("C:\\Windows").and_return(%w[two.exe Three.bat]) end