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

Fix package dir location #751

Merged
merged 2 commits into from
Sep 16, 2015
Merged
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
15 changes: 9 additions & 6 deletions cmake/interrogate_setup_dot_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def _get_locations(pkgs, package_dir):
if key in package_dir:
locations[key] = package_dir[key]
elif parent_location is not None:
locations[key] = parent_location
locations[key] = os.path.join(parent_location, splits[key_len])
else:
locations[key] = allprefix
locations[key] = os.path.join(allprefix, key)
parent_location = locations[key]
return locations

Expand Down Expand Up @@ -116,17 +116,20 @@ def generate_cmake_file(package_name, version, scripts, package_dir, pkgs, modul
if splits[1] in ['msg', 'srv']:
continue
# check every child has the same root folder as its parent
parent_name = '.'.join(splits[:1])
if location != locations[parent_name]:
root_name = splits[0]
root_location = location
for _ in range(len(splits) - 1):
root_location = os.path.dirname(root_location)
if root_location != locations[root_name]:
raise RuntimeError(
"catkin_export_python does not support setup.py files that combine across multiple directories: %s in %s, %s in %s" % (pkgname, location, parent_name, locations[parent_name]))
"catkin_export_python does not support setup.py files that combine across multiple directories: %s in %s, %s in %s" % (pkgname, location, root_name, locations[root_name]))

# If checks pass, remove all submodules
pkgs = [p for p in pkgs if '.' not in p]

resolved_pkgs = []
for pkg in pkgs:
resolved_pkgs += [os.path.join(locations[pkg], pkg)]
resolved_pkgs += [locations[pkg]]

result.append(r'set(%s_PACKAGES "%s")' % (prefix, ';'.join(pkgs)))
result.append(r'set(%s_PACKAGE_DIRS "%s")' % (prefix, ';'.join(resolved_pkgs).replace("\\", "/")))
Expand Down
18 changes: 9 additions & 9 deletions test/unit_tests/test_interrogate_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def test_generate_cmake_file(self):
cmake_lines)

def test_get_locations(self):
self.assertEqual({'foo': ''}, _get_locations(['foo'], {}))
self.assertEqual({'foo': 'src'}, _get_locations(['foo'],
{'': 'src'}))
self.assertEqual({'foo': 'src', 'foo.bar': 'src'}, _get_locations(['foo.bar'],
{'': 'src'}))
self.assertEqual({'foo': 'foo'}, _get_locations(['foo'], {}))
self.assertEqual({'foo': 'src/foo'},
_get_locations(['foo'], {'': 'src'}))
self.assertEqual({'foo': 'src/foo', 'foo.bar': 'src/foo/bar'},
_get_locations(['foo.bar'], {'': 'src'}))
self.assertEqual({'foo': 'src'}, _get_locations(['foo'],
{'foo': 'src'}))
self.assertEqual({'foo': 'src', 'foo.bar': 'src'}, _get_locations(['foo.bar'],
{'foo': 'src'}))
self.assertEqual({'foo': 'src', 'foo.bar': 'src/bar'},
_get_locations(['foo.bar'], {'foo': 'src'}))

def test_generate_cmake_file_noallprefix(self):
cmake_lines = (generate_cmake_file(package_name='pack1',
Expand All @@ -76,7 +76,7 @@ def test_generate_cmake_file_noallprefix(self):
self.assertEqual(['set(pack1_SETUP_PY_VERSION "0.0.1")',
'set(pack1_SETUP_PY_SCRIPTS "")',
'set(pack1_SETUP_PY_PACKAGES "foo;bar")',
'set(pack1_SETUP_PY_PACKAGE_DIRS "src/foo;lib/bar")',
'set(pack1_SETUP_PY_PACKAGE_DIRS "src;lib")',
'set(pack1_SETUP_PY_MODULES "")',
'set(pack1_SETUP_PY_MODULE_DIRS "")'],
cmake_lines)
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_interrogate_setup_py(self):
self.assertEqual("""set(foo_SETUP_PY_VERSION "0.1.1")
set(foo_SETUP_PY_SCRIPTS "")
set(foo_SETUP_PY_PACKAGES "foo;bar")
set(foo_SETUP_PY_PACKAGE_DIRS "src/foo;lib/bar")
set(foo_SETUP_PY_PACKAGE_DIRS "src;lib")
set(foo_SETUP_PY_MODULES "")
set(foo_SETUP_PY_MODULE_DIRS "")""", contents)
os.remove(outfile)
Expand Down