Example #1
0
def test_colcon_defaults(tmpdir):
    ws = Path(str(tmpdir))
    this_dir = Path(__file__).parent
    src = ws / 'src'
    src.mkdir()
    shutil.copytree(str(this_dir / 'dummy_pkg_ros2_cpp'),
                    str(src / 'dummy_pkg_ros2_cpp'))
    shutil.copytree(str(this_dir / 'dummy_pkg_ros2_py'),
                    str(src / 'dummy_pkg_ros2_py'))

    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')
    out_script = ws / rosdep_install_script(platform)

    # no defaults file should get everything
    gather_rosdeps(client, platform, workspace=ws)

    result = out_script.read_text()
    assert 'ros-dashing-ament-cmake' in result
    assert 'ros-dashing-rclcpp' in result
    assert 'ros-dashing-rclpy' in result

    # write defaults file and expect selective dependency output
    (ws / 'defaults.yaml').write_text("""
list:
  packages-select: [dummy_pkg_ros2_py]
""")
    gather_rosdeps(client, platform, workspace=ws)
    result = out_script.read_text()
    assert 'ros-dashing-ament-cmake' not in result
    assert 'ros-dashing-rclcpp' not in result
    assert 'ros-dashing-rclpy' in result
Example #2
0
def cross_compile_pipeline(args: argparse.Namespace, ):
    platform = Platform(args.arch, args.os, args.rosdistro,
                        args.sysroot_base_image)

    ros_workspace_dir = Path(args.ros_workspace)
    skip_rosdep_keys = args.skip_rosdep_keys
    custom_data_dir = _path_if(args.custom_data_dir)
    custom_rosdep_script = _path_if(args.custom_rosdep_script)
    custom_setup_script = _path_if(args.custom_setup_script)

    sysroot_build_context = prepare_docker_build_environment(
        platform=platform,
        ros_workspace=ros_workspace_dir,
        custom_setup_script=custom_setup_script,
        custom_data_dir=custom_data_dir)
    docker_client = DockerClient(args.sysroot_nocache,
                                 default_docker_dir=sysroot_build_context,
                                 colcon_defaults_file=args.colcon_defaults)

    if not args.skip_rosdep_collection:
        gather_rosdeps(docker_client=docker_client,
                       platform=platform,
                       workspace=ros_workspace_dir,
                       skip_rosdep_keys=skip_rosdep_keys,
                       custom_script=custom_rosdep_script,
                       custom_data_dir=custom_data_dir)
    assert_install_rosdep_script_exists(ros_workspace_dir, platform)
    create_workspace_sysroot_image(docker_client, platform)
    run_emulated_docker_build(docker_client, platform, ros_workspace_dir)
Example #3
0
def test_custom_rosdep_no_data_dir(tmpdir):
    script_contents = """
cat > /test_rules.yaml <<EOF
definitely_does_not_exist:
  ubuntu:
    bionic: [successful_test]
EOF
echo "yaml file:/test_rules.yaml" > /etc/ros/rosdep/sources.list.d/22-test-rules.list
"""
    ws = Path(str(tmpdir))
    pkg_xml = Path(ws) / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(CUSTOM_KEY_PKG_XML)
    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')

    rosdep_setup = ws / 'rosdep_setup.sh'
    rosdep_setup.write_text(script_contents)

    gather_rosdeps(client, platform, workspace=ws, custom_script=rosdep_setup)
    out_script = ws / rosdep_install_script(platform)
    result = out_script.read_text().splitlines()
    expected = [
        '#!/bin/bash',
        'set -euxo pipefail',
        '#[apt] Installation commands:',
        '  apt-get install -y successful_test',
    ]
    assert result == expected, 'Rosdep output did not meet expectations.'
Example #4
0
def test_rosdep_bad_key(tmpdir):
    ws = Path(str(tmpdir))
    pkg_xml = Path(ws) / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(CUSTOM_KEY_PKG_XML)
    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')
    with pytest.raises(docker.errors.ContainerError):
        gather_rosdeps(client, platform, workspace=ws)
Example #5
0
def test_dummy_skip_rosdep_multiple_keys_pkg(tmpdir):
    ws = Path(str(tmpdir))
    pkg_xml = ws / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(RCLCPP_PKG_XML)
    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')
    out_script = ws / rosdep_install_script(platform)

    skip_keys = ['ament_cmake', 'rclcpp']
    gather_rosdeps(client, platform, workspace=ws, skip_rosdep_keys=skip_keys)
    result = out_script.read_text()
    assert 'ros-dashing-ament-cmake' not in result
    assert 'ros-dashing-rclcpp' not in result
Example #6
0
def test_dummy_skip_rosdep_keys_doesnt_exist_pkg(tmpdir):
    ws = Path(str(tmpdir))
    pkg_xml = Path(ws) / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(CUSTOM_KEY_PKG_XML)
    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')
    skip_keys = ['definitely_does_not_exist']
    try:
        gather_rosdeps(client,
                       platform,
                       workspace=ws,
                       skip_rosdep_keys=skip_keys)
    except docker.errors.ContainerError:
        assert False
Example #7
0
def test_dummy_ros2_pkg(tmpdir):
    ws = Path(str(tmpdir))
    pkg_xml = ws / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(RCLCPP_PKG_XML)

    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')
    out_script = ws / rosdep_install_script(platform)

    gather_rosdeps(client, platform, workspace=ws)
    result = out_script.read_text().splitlines()
    expected = [
        '#!/bin/bash',
        'set -euxo pipefail',
        '#[apt] Installation commands:',
        '  apt-get install -y ros-dashing-ament-cmake',
        '  apt-get install -y ros-dashing-rclcpp',
    ]
    assert result == expected, 'Rosdep output did not meet expectations.'
Example #8
0
def test_custom_rosdep_no_data_dir(tmpdir):
    script_contents = """
cat > /test_rules.yaml <<EOF
definitely_does_not_exist:
  ubuntu:
    bionic: [successful_test]
EOF
echo "yaml file:/test_rules.yaml" > /etc/ros/rosdep/sources.list.d/22-test-rules.list
"""
    ws = Path(str(tmpdir))
    pkg_xml = Path(ws) / 'src' / 'dummy' / 'package.xml'
    pkg_xml.parent.mkdir(parents=True)
    pkg_xml.write_text(CUSTOM_KEY_PKG_XML)
    client = DockerClient()
    platform = Platform(arch='aarch64', os_name='ubuntu', ros_distro='dashing')

    rosdep_setup = ws / 'rosdep_setup.sh'
    rosdep_setup.write_text(script_contents)

    gather_rosdeps(client, platform, workspace=ws, custom_script=rosdep_setup)
    out_script = ws / rosdep_install_script(platform)
    result = out_script.read_text()
    assert 'successful_test' in result
def cross_compile_pipeline(
    args: argparse.Namespace,
):
    platform = Platform(args.arch, args.os, args.rosdistro, args.sysroot_base_image)

    ros_workspace_dir = Path(args.ros_workspace).resolve()
    if not (ros_workspace_dir / 'src').is_dir():
        raise ValueError(
            'Specified workspace "{}" does not look like a colcon workspace '
            '(there is no "src/" directory). Cannot continue'.format(ros_workspace_dir))

    skip_rosdep_keys = args.skip_rosdep_keys
    custom_data_dir = _path_if(args.custom_data_dir)
    custom_rosdep_script = _path_if(args.custom_rosdep_script)
    custom_setup_script = _path_if(args.custom_setup_script)

    sysroot_build_context = prepare_docker_build_environment(
        platform=platform,
        ros_workspace=ros_workspace_dir,
        custom_setup_script=custom_setup_script,
        custom_data_dir=custom_data_dir)
    docker_client = DockerClient(
        args.sysroot_nocache,
        default_docker_dir=sysroot_build_context,
        colcon_defaults_file=args.colcon_defaults)

    if not args.skip_rosdep_collection:
        gather_rosdeps(
            docker_client=docker_client,
            platform=platform,
            workspace=ros_workspace_dir,
            skip_rosdep_keys=skip_rosdep_keys,
            custom_script=custom_rosdep_script,
            custom_data_dir=custom_data_dir)
    assert_install_rosdep_script_exists(ros_workspace_dir, platform)
    create_workspace_sysroot_image(docker_client, platform)
    run_emulated_docker_build(docker_client, platform, ros_workspace_dir)