Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate <depend> conditions in CMake variables #1134

Open
wants to merge 2 commits into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmake/parse_package_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from __future__ import print_function

import argparse
import os
import sys
from collections import OrderedDict

Expand Down Expand Up @@ -82,13 +83,14 @@ def _get_output(package):

def _get_dependency_values(key, depends):
values = OrderedDict()
values[key] = ' '.join(['"%s"' % str(d) for d in depends])
for d in depends:
filtered_deps = [d for d in depends if d.evaluated_condition is not False]
values[key] = ' '.join(['"%s"' % d.name for d in filtered_deps])
for d in filtered_deps:
comparisons = ['version_lt', 'version_lte', 'version_eq', 'version_gte', 'version_gt']
for comp in comparisons:
value = getattr(d, comp, None)
if value is not None:
values['%s_%s_%s' % (key, str(d), comp.upper())] = '"%s"' % value
values['%s_%s_%s' % (key, d.name, comp.upper())] = '"%s"' % value
return values


Expand All @@ -99,6 +101,7 @@ def main(argv=sys.argv[1:]):
parser.add_argument('outfile')
args = parser.parse_args(argv)
package = parse_package(args.package_xml)
package.evaluate_conditions(os.environ)

# Force utf8 encoding for python3.
# This way unicode files can still be processed on non-unicode locales.
Expand Down
25 changes: 17 additions & 8 deletions test/unit_tests/test_parse_package_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
class ParsePackageXmlTest(unittest.TestCase):

def test_get_output(self):
class MockDependency(object):
__slots__ = [
'name',
'evaluated_condition',
]
def __init__(self, name):
self.name = name
self.evaluated_condition = None

pack = Mock()
pack.package_format = 2
pack.name = 'foopack'
pack.version = '0.1.2'
pack.maintainers = ['m1', 'm2']
pack.build_depends = ['bd1', 'bd2']
pack.buildtool_depends = ['catkin']
pack.build_export_depends = ['bed1', 'bed2']
pack.buildtool_export_depends = ['bted1', 'bted2']
pack.exec_depends = ['ed1', 'ed2']
pack.run_depends = ['rd1', 'rd2']
pack.test_depends = ['td1', 'td2']
pack.doc_depends = ['dd1', 'dd2']
pack.build_depends = [MockDependency(name) for name in ['bd1', 'bd2']]
pack.buildtool_depends = [MockDependency(name) for name in ['catkin']]
pack.build_export_depends = [MockDependency(name) for name in ['bed1', 'bed2']]
pack.buildtool_export_depends = [MockDependency(name) for name in ['bted1', 'bted2']]
pack.exec_depends = [MockDependency(name) for name in ['ed1', 'ed2']]
pack.run_depends = [MockDependency(name) for name in ['rd1', 'rd2']]
pack.test_depends = [MockDependency(name) for name in ['td1', 'td2']]
pack.doc_depends = [MockDependency(name) for name in ['dd1', 'dd2']]
pack.urls = []
pack.exports = []
result = _get_output(pack)
Expand Down