From a7b962c11aedec523cf6739cfb07958214fbc7fb Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 8 Sep 2023 21:04:28 -0400 Subject: [PATCH] Output a better error when pkg-config is not found - close #169 --- build_tests/configure/check_cfg_no_pkg_config.rb | 5 +++++ lib/rscons/configure_op.rb | 7 ++++++- spec/build_tests_spec.rb | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 build_tests/configure/check_cfg_no_pkg_config.rb diff --git a/build_tests/configure/check_cfg_no_pkg_config.rb b/build_tests/configure/check_cfg_no_pkg_config.rb new file mode 100644 index 0000000..e0de024 --- /dev/null +++ b/build_tests/configure/check_cfg_no_pkg_config.rb @@ -0,0 +1,5 @@ +ENV["PATH"] = "" + +configure do + check_cfg package: "mypackage" +end diff --git a/lib/rscons/configure_op.rb b/lib/rscons/configure_op.rb index 9d3e7b4..5bab789 100644 --- a/lib/rscons/configure_op.rb +++ b/lib/rscons/configure_op.rb @@ -125,7 +125,12 @@ module Rscons elsif program = options[:program] Ansi.write($stdout, "Checking '", :cyan, program, :reset, "'... ") end - program ||= "pkg-config" + unless program + program = "pkg-config" + unless Util.find_executable(program) + raise RsconsError.new("Error: executable '#{program}' not found") + end + end args = options[:args] || %w[--cflags --libs] command = [program, *args, package].compact stdout, _, status = log_and_test_command(command) diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index b321de3..2f5ec41 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -2369,6 +2369,13 @@ EOF expect(result.stdout).to_not match /gcc.*-o.*myconfigtest1.*-DMYPACKAGE/ expect(result.stdout).to match /gcc.*-o.*myconfigtest2.*-DMYPACKAGE/ end + + it "indicates that pkg-config command cannot be found" do + test_dir "configure" + result = run_rscons(args: %w[-f check_cfg_no_pkg_config.rb configure]) + expect(result.stderr).to match /Error: executable 'pkg-config' not found/ + expect(result.status).to_not eq 0 + end end context "when passed a program" do