Skip to content

Commit

Permalink
Merge pull request #32 from orocos-toolchain/fix_path_autodetection
Browse files Browse the repository at this point in the history
pkgconfig: minor fixes
  • Loading branch information
doudou authored Jun 9, 2016
2 parents f764866 + 8e0a88b commit bd775ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/utilrb/pkgconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ def self.get(name, version_spec = nil, preset_variables = Hash.new)
raise NotFound.new(name), "cannot find the pkg-config specification for #{name}"
end

candidates = loaded_packages[name] = Array.new
candidates = Array.new
paths.each do |p|
candidates << PkgConfig.load(p, preset_variables)
end
loaded_packages[name] = candidates
end

# Now try to find a matching spec
find_matching_version(candidates, version_spec)
if version_match = find_matching_version(candidates, version_spec)
version_match
else
raise NotFound, "found #{candidates.size} packages for #{name}, but none match the version specification #{version_spec}"
end
end

# Finds the provided package and optional version and returns its
Expand Down Expand Up @@ -461,8 +466,8 @@ def self.each_package(regex = nil)
end


FOUND_PATH_RX = /Scanning directory '(.*\/)((?:lib|lib64|share)\/.*)'$/
NONEXISTENT_PATH_RX = /Cannot open directory '.*\/((?:lib|lib64|share)\/.*)' in package search path:.*/
FOUND_PATH_RX = /Scanning directory (?:#\d+ )?'(.*\/)((?:lib|lib64|share)\/.*)'$/
NONEXISTENT_PATH_RX = /Cannot open directory (?:#\d+ )?'.*\/((?:lib|lib64|share)\/.*)' in package search path:.*/

# Returns the system-wide search path that is embedded in pkg-config
def self.default_search_path
Expand Down
14 changes: 14 additions & 0 deletions test/test_pkgconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ def test_find_package
PkgConfig.new('test_pkgconfig')
end

def test_path_autodetection_regexp
# PkgConfig 0.26
assert("Scanning directory '/usr/share/pkgconfig'" =~ Utilrb::PkgConfig::FOUND_PATH_RX)
assert_equal '/usr/share/pkgconfig', "#{$1}#{$2}"
assert("Cannot open directory '/usr/share/pkgconfig' in package search path:" =~ Utilrb::PkgConfig::NONEXISTENT_PATH_RX)
assert_equal 'share/pkgconfig', $1

# PkgConfig 0.29.1
assert("Scanning directory #10 '/usr/share/pkgconfig'" =~ Utilrb::PkgConfig::FOUND_PATH_RX)
assert_equal '/usr/share/pkgconfig', "#{$1}#{$2}"
assert("Cannot open directory #10 '/usr/share/pkgconfig' in package search path:" =~ Utilrb::PkgConfig::NONEXISTENT_PATH_RX)
assert_equal 'share/pkgconfig', $1
end

def test_load
pkg = PkgConfig.new('test_pkgconfig')
assert_equal('test_pkgconfig', pkg.name)
Expand Down

0 comments on commit bd775ff

Please sign in to comment.