Skip to content

Commit

Permalink
Add to the existing PKG_CONFIG_PATH if any when looking for packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed May 25, 2023
1 parent 17b3d4b commit 5c3b514
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changes

## v0.8.0 (in progress)
## v0.7.1 (in progress)

### Bug fixes
- When using the `PKG_CONFIG_PATH` specified by mopack, add it to any existing
`PKG_CONFIG_PATH` from the environment

---

Expand Down
2 changes: 1 addition & 1 deletion bfg9000/app_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.8.0.dev0'
version = '0.7.1.dev0'
8 changes: 7 additions & 1 deletion bfg9000/tools/pkg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def run(self, names, type, *args, extra_env=None, installed=None,
return self._options[type][1](result)
return result

def search_path(self, extra=[]):
path = self.env.variables.get('PKG_CONFIG_PATH')
if path:
return shell.join_paths(extra + [path])
return shell.join_paths(extra)


class PkgConfigPackage(Package):
def __init__(self, pkg_config, name, submodules=None,
Expand All @@ -113,7 +119,7 @@ def __init__(self, pkg_config, name, submodules=None,
super().__init__(name, submodules, format=format, deps=deps)

self._pkg_config = pkg_config
self._env = ({'PKG_CONFIG_PATH': shell.join_paths(search_path)}
self._env = ({'PKG_CONFIG_PATH': pkg_config.search_path(search_path)}
if search_path else {})
self.pcnames = pcnames if pcnames is not None else [name]

Expand Down
6 changes: 5 additions & 1 deletion doc/about/changes.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changes

## v0.8.0
## v0.7.1
in progress
{: .subtitle}

### Bug fixes
- When using the `PKG_CONFIG_PATH` specified by mopack, add it to any existing
`PKG_CONFIG_PATH` from the environment

---

## v0.7.0
Expand Down
17 changes: 17 additions & 0 deletions test/unit/tools/test_pkg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ def mock_check_which(*args, **kwargs):
mock.patch('warnings.warn'):
self.assertEqual(PkgConfig(env).command, ['pkgconf'])

def test_search_path(self):
env = make_env(platform='linux', clear_variables=True)
with mock.patch('bfg9000.tools.pkg_config.check_which',
return_value=('pkg-confing', True)):
self.assertEqual(PkgConfig(env).search_path(), '')
self.assertEqual(PkgConfig(env).search_path(['foo', 'bar']),
'foo' + os.pathsep + 'bar')

def test_search_path_extend(self):
env = make_env(platform='linux', clear_variables=True,
variables={'PKG_CONFIG_PATH': 'env'})
with mock.patch('bfg9000.tools.pkg_config.check_which',
return_value=('pkg-confing', True)):
self.assertEqual(PkgConfig(env).search_path(), 'env')
self.assertEqual(PkgConfig(env).search_path(['foo', 'bar']),
'foo' + os.pathsep + 'bar' + os.pathsep + 'env')


class TestPkgConfigPackage(ToolTestCase):
tool_type = PkgConfig
Expand Down

0 comments on commit 5c3b514

Please sign in to comment.