diff --git a/lib/pkg-config.rb b/lib/pkg-config.rb index 542d67c..af5a696 100644 --- a/lib/pkg-config.rb +++ b/lib/pkg-config.rb @@ -264,6 +264,14 @@ def compute_native_pkg_config_prefix end def compute_default_path + libdir = ENV["PKG_CONFIG_LIBDIR"] + if libdir + return [ + with_config("pkg-config-path") || ENV["PKG_CONFIG_PATH"], + libdir, + ].compact.join(SEPARATOR) + end + default_paths = nil if native_pkg_config pc_path = run_command(native_pkg_config.to_s, @@ -315,9 +323,6 @@ def compute_default_path mingw_pkgconfig_path = Pathname.new(mingw_bin_path) + "../lib/pkgconfig" default_paths.unshift(mingw_pkgconfig_path.cleanpath.to_s) end - libdir = ENV["PKG_CONFIG_LIBDIR"] - default_paths.unshift(libdir) if libdir - paths = [] if /-darwin\d[\d\.]*\z/ =~ RUBY_PLATFORM and /\A(\d+\.\d+)/ =~ run_command("sw_vers", "-productVersion") diff --git a/test/test-pkg-config.rb b/test/test-pkg-config.rb index 67893b3..222e736 100644 --- a/test/test-pkg-config.rb +++ b/test/test-pkg-config.rb @@ -21,6 +21,21 @@ def setup @glib = PackageConfig.new("glib-2.0", options) end + def test_explicit_libdir_replaces_default_paths + original_libdir = ENV["PKG_CONFIG_LIBDIR"] + original_path = ENV["PKG_CONFIG_PATH"] + ENV["PKG_CONFIG_LIBDIR"] = "/isolated/pkgconfig" + ENV["PKG_CONFIG_PATH"] = "/extra/pkgconfig" + assert_equal([ + "/extra/pkgconfig", + "/isolated/pkgconfig", + ].join(File::PATH_SEPARATOR), + PackageConfig.__send__(:compute_default_path)) + ensure + ENV["PKG_CONFIG_LIBDIR"] = original_libdir + ENV["PKG_CONFIG_PATH"] = original_path + end + def only_pkg_config_version(major, minor) pkg_config_version = `#{@pkgconf} --version`.chomp current_major, current_minor = pkg_config_version.split(".").collect(&:to_i)