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

catkin plugin: check stage-snaps for ROS dependencies #2525

Merged
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -442,6 +442,7 @@ def pull(self):
# dependency has been staged.
catkin = None
underlay_build_path = None
dependency_workspaces = [self.rosdir]
if self.options.underlay:
underlay_build_path = self.options.underlay["build-path"]
if underlay_build_path:
@@ -457,19 +458,20 @@ def pull(self):
"setup.sh".format(underlay_build_path)
)

# Use catkin_find to discover dependencies already in the underlay
catkin = _Catkin(
self._rosdistro,
underlay_build_path,
self._catkin_path,
self.PLUGIN_STAGE_SOURCES,
self.PLUGIN_STAGE_KEYRINGS,
self.project,
)
catkin.setup()

dependency_workspaces.append(underlay_build_path)
self._generate_snapcraft_setup_sh(self.installdir, underlay_build_path)

# Use catkin_find to discover dependencies already in the underlay
catkin = _Catkin(
self._rosdistro,
dependency_workspaces,
self._catkin_path,
self.PLUGIN_STAGE_SOURCES,
self.PLUGIN_STAGE_KEYRINGS,
self.project,
)
catkin.setup()

# Pull our own compilers so we use ones that match up with the version
# of ROS we're using.
compilers = Compilers(
@@ -677,6 +679,15 @@ def _new_path(path):

self._rewrite_cmake_paths(_new_path)

# Also rewrite any occurrence of $SNAPCRAFT_STAGE to be our install
# directory (this may be the case if stage-snaps were used).
file_utils.replace_in_file(
self.rosdir,
re.compile(r".*Config.cmake$"),
re.compile(r"\$ENV{SNAPCRAFT_STAGE}"),
self.installdir,
)

def _rewrite_cmake_paths(self, new_path_callable):
def _rewrite_paths(match):
paths = match.group(1).strip().split(";")
@@ -1062,14 +1073,14 @@ class _Catkin:
def __init__(
This conversation was marked as resolved by kyrofa

This comment has been minimized.

Copy link
@sergiusens

sergiusens Apr 9, 2019

Collaborator

minor, but can we add some type annotations to init?

This comment has been minimized.

Copy link
@kyrofa

kyrofa Apr 9, 2019

Author Member

Sure, done.

self,
ros_distro,
workspace,
workspaces,
catkin_path,
ubuntu_sources,
ubuntu_keyrings,
project,
):
self._ros_distro = ros_distro
self._workspace = workspace
self._workspaces = workspaces
self._catkin_path = catkin_path
self._ubuntu_sources = ubuntu_sources
self._ubuntu_keyrings = ubuntu_keyrings
@@ -1095,10 +1106,15 @@ def setup(self):
ubuntu.unpack(self._catkin_install_path)

def find(self, package_name):
try:
return self._run(["--first-only", package_name]).strip()
except subprocess.CalledProcessError:
raise CatkinPackageNotFoundError(package_name)
with contextlib.suppress(subprocess.CalledProcessError):
path = self._run(["--first-only", package_name]).strip()

# Not a valid find if the package resolves into our own catkin
# workspace. That won't be transitioned into the snap.
if not path.startswith(self._catkin_install_path):
return path

raise CatkinPackageNotFoundError(package_name)

def _run(self, arguments):
with tempfile.NamedTemporaryFile(mode="w+") as f:
@@ -1136,11 +1152,13 @@ def _run(self, arguments):
ros_path, os.path.join(ros_path, "setup.sh")
)
)
lines.append(
"_CATKIN_SETUP_DIR={} source {} --extend".format(
self._workspace, os.path.join(self._workspace, "setup.sh")

for workspace in self._workspaces:
lines.append(
"_CATKIN_SETUP_DIR={} source {} --extend".format(
workspace, os.path.join(workspace, "setup.sh")
)
)
)

lines.append('exec "$@"')
f.write("\n".join(lines))
@@ -0,0 +1,13 @@
name: catkin-stage-snaps
version: "1.0"
summary: ROS stage-snaps test
description: Verify that ROS stage-snaps are checked for dependencies.
confinement: strict
base: core18

parts:
catkin-part:
plugin: catkin
source: .
include-roscore: false
stage-snaps: [fake-ros-package-kyrofa/latest/edge]
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 2.8.3)
project(test_package)

find_package(catkin REQUIRED)

catkin_package()
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<package>
<name>test_package</name>
<version>0.0.0</version>
<description>A description</description>
<maintainer email="me@example.com">me</maintainer>
<license>GPLv3</license>
<buildtool_depend>catkin</buildtool_depend>

<build_depend>fake-ros-package</build_depend>
<run_depend>fake-ros-package</run_depend>
</package>
@@ -0,0 +1,6 @@
# What is this, and why isn't it used?

Spread tests do not build this snap, but spread tests (specifically
catkin-stage-snaps) use it as a stage-snap. It's here to provide an
understanding of what that stage-snap contains, as well as to facilitate
updating it in the future.
@@ -0,0 +1,24 @@
name: fake-ros-package-kyrofa
This conversation was marked as resolved by kyrofa

This comment has been minimized.

Copy link
@sergiusens

sergiusens Apr 9, 2019

Collaborator

can you rename this to test-snapcraft-fake-ros-package-core18? Or will this work with other bases?

This comment has been minimized.

Copy link
@kyrofa

kyrofa Apr 9, 2019

Author Member

It will not work with other bases given that "melodic" is hard-coded (which snapcraft will only use on core18). I've renamed it.

base: core18
version: '0.1'
summary: Bare-bones ROS dependency for snapcraft CLI test
description: |
This snap contains a single unusable ROS package. This snap is not meant to
be used for anything other than snapcraft CLI tests.
grade: devel
confinement: strict
architectures: [all]

parts:
catkin-part:
plugin: catkin
source: .
catkin-packages: []
include-roscore: false
override-build: |
mkdir -p "$SNAPCRAFT_PART_INSTALL/opt/ros/melodic/share/fake-ros-package"
stage:
- opt/ros/melodic/_setup_util.py
- opt/ros/melodic/setup.sh
- opt/ros/melodic/share/fake-ros-package
@@ -0,0 +1,30 @@
summary: Build catkin snap using stage-snaps
warn-timeout: 9m # Keep less than 10 minutes so Travis can't timeout
priority: 100 # Run this test early so we're not waiting for it

environment:
SNAP_DIR: ../snaps/catkin-stage-snaps

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
set_base "$SNAP_DIR/snap/snapcraft.yaml"
restore: |
cd "$SNAP_DIR"
snapcraft clean
rm -f ./*.snap
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
restore_yaml "snap/snapcraft.yaml"
# This test is written specifically for core18
systems: [ubuntu-18*]

execute: |
cd "$SNAP_DIR"
# This will fail if the stage-snap isn't properly searched for ROS
# dependencies.
snapcraft pull
@@ -964,6 +964,11 @@ def test_prepare_build(self, use_python_mock):
"contents": '"/usr/lib/foo"',
"expected": '"{}/usr/lib/foo"'.format(plugin.installdir),
},
{
"path": "anotherConfig.cmake",
"contents": '"$ENV{SNAPCRAFT_STAGE}/usr/lib/another"',
"expected": '"{}/usr/lib/another"'.format(plugin.installdir),
},
{
"path": "bar.cmake",
"contents": '"/usr/lib/bar"',
@@ -1981,6 +1986,16 @@ def test_find(self):
" ".join(positional_args), Contains("catkin_find --first-only foo")
)

def test_find_only_in_catkin_workspace(self):
self.check_output_mock.return_value = os.path.join(
self.catkin._catkin_install_path, "bar"
).encode(sys.getfilesystemencoding())

with testtools.ExpectedException(
catkin.CatkinPackageNotFoundError, "Unable to find Catkin package 'foo'"
):
self.catkin.find("foo")

def test_find_non_existing_package(self):
self.check_output_mock.side_effect = subprocess.CalledProcessError(1, "foo")

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.