Skip to content

Commit

Permalink
Merge pull request #787 from ros/cmake_format_2_dependencies
Browse files Browse the repository at this point in the history
expose format 2 style dependencies, make order deterministic
  • Loading branch information
dirk-thomas committed Mar 18, 2016
2 parents fd22901 + 0cf9575 commit f55d223
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
13 changes: 11 additions & 2 deletions cmake/parse_package_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
from collections import OrderedDict
import sys
import argparse

Expand All @@ -49,14 +50,22 @@ def _get_output(package):
:param package: Package object
:returns: list of str, lines to output
"""
values = {}
values = OrderedDict()
values['VERSION'] = '"%s"' % package.version

values['MAINTAINER'] = '"%s"' % (', '.join([str(m) for m in package.maintainers]))

values['PACKAGE_FORMAT'] = '"%d"' % package.package_format
values.update(_get_dependency_values('BUILD_DEPENDS', package.build_depends))
values.update(_get_dependency_values('BUILD_EXPORT_DEPENDS', package.build_export_depends))
values.update(_get_dependency_values('BUILDTOOL_DEPENDS', package.buildtool_depends))
values.update(_get_dependency_values('BUILDTOOL_EXPORT_DEPENDS', package.buildtool_export_depends))
values.update(_get_dependency_values('EXEC_DEPENDS', package.exec_depends))
# the run dependencies are a convenience property to mimick format one like dependencies
# it contains the build export and exec_dependendcies
values.update(_get_dependency_values('RUN_DEPENDS', package.run_depends))
values.update(_get_dependency_values('TEST_DEPENDS', package.test_depends))
values.update(_get_dependency_values('DOC_DEPENDS', package.doc_depends))

deprecated = [e.content for e in package.exports if e.tagname == 'deprecated']
values['DEPRECATED'] = '"%s"' % ((deprecated[0] if deprecated[0] else 'TRUE') if deprecated else '')
Expand All @@ -68,7 +77,7 @@ def _get_output(package):
return output

def _get_dependency_values(key, depends):
values = {}
values = OrderedDict()
values[key] = ' '.join(['"%s"' % str(d) for d in depends])
for d in depends:
comparisons = ['version_lt', 'version_lte', 'version_eq', 'version_gte', 'version_gt']
Expand Down
54 changes: 40 additions & 14 deletions test/unit_tests/test_parse_package_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,37 @@ class ParsePackageXmlTest(unittest.TestCase):

def test_get_output(self):
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.exports = []
result = _get_output(pack)
self.assertEqual(set(['set(_CATKIN_CURRENT_PACKAGE "foopack")',
'set(foopack_MAINTAINER "m1, m2")',
'set(foopack_DEPRECATED "")',
'set(foopack_VERSION "0.1.2")',
'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
'set(foopack_RUN_DEPENDS "rd1" "rd2")',
'set(foopack_BUILDTOOL_DEPENDS "catkin")']), set(result))
self.assertEqual(
set([
'set(_CATKIN_CURRENT_PACKAGE "foopack")',
'set(foopack_MAINTAINER "m1, m2")',
'set(foopack_PACKAGE_FORMAT "2")',
'set(foopack_DEPRECATED "")',
'set(foopack_VERSION "0.1.2")',
'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
'set(foopack_BUILDTOOL_DEPENDS "catkin")',
'set(foopack_BUILD_EXPORT_DEPENDS "bed1" "bed2")',
'set(foopack_BUILDTOOL_EXPORT_DEPENDS "bted1" "bted2")',
'set(foopack_EXEC_DEPENDS "ed1" "ed2")',
'set(foopack_RUN_DEPENDS "rd1" "rd2")',
'set(foopack_TEST_DEPENDS "td1" "td2")',
'set(foopack_DOC_DEPENDS "dd1" "dd2")',
]),
set(result))

def test_main(self):
try:
Expand All @@ -53,12 +69,22 @@ def test_main(self):
self.assertTrue(os.path.isfile(check_file))
with open(check_file, 'r') as fhand:
contents = fhand.read()
self.assertEqual(set(['set(_CATKIN_CURRENT_PACKAGE "foopack")',
'set(foopack_MAINTAINER "foo <foo@bar.com>")',
'set(foopack_DEPRECATED "")',
'set(foopack_VERSION "0.1.2")',
'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
'set(foopack_RUN_DEPENDS "rd1" "rd2")',
'set(foopack_BUILDTOOL_DEPENDS )']), set(contents.splitlines()))
self.assertEqual(
set([
'set(_CATKIN_CURRENT_PACKAGE "foopack")',
'set(foopack_MAINTAINER "foo <foo@bar.com>")',
'set(foopack_PACKAGE_FORMAT "1")',
'set(foopack_DEPRECATED "")',
'set(foopack_VERSION "0.1.2")',
'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
'set(foopack_BUILDTOOL_DEPENDS )',
'set(foopack_BUILD_EXPORT_DEPENDS "rd1" "rd2")',
'set(foopack_BUILDTOOL_EXPORT_DEPENDS )',
'set(foopack_EXEC_DEPENDS "rd1" "rd2")',
'set(foopack_RUN_DEPENDS "rd1" "rd2")',
'set(foopack_TEST_DEPENDS )',
'set(foopack_DOC_DEPENDS )',
]),
set(contents.splitlines()))
finally:
shutil.rmtree(rootdir)

0 comments on commit f55d223

Please sign in to comment.