def cross_compile_pipeline( args: argparse.Namespace, data_collector: DataCollector, ): platform = Platform(args.arch, args.os, args.rosdistro, args.sysroot_base_image) ros_workspace_dir = _resolve_ros_workspace(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) stages = [DependenciesStage(), CreateSysrootStage(), DockerBuildStage()] customizations = PipelineStageConfigOptions(args.skip_rosdep_collection, skip_rosdep_keys, custom_rosdep_script, custom_data_dir, custom_setup_script) for stage in stages: with data_collector.timer('cross_compile_{}'.format(stage.name)): stage(platform, docker_client, ros_workspace_dir, customizations)
def test_basic_sysroot_creation(tmpdir): """Very simple smoke test to validate that syntax is correct.""" # Very simple smoke test to validate that all internal syntax is correct mock_docker_client = Mock() mock_data_collector = Mock() platform = Platform('aarch64', 'ubuntu', 'eloquent') stage = CreateSysrootStage() stage(platform, mock_docker_client, Path('dummy_path'), default_pipeline_options(), mock_data_collector) assert mock_docker_client.build_image.call_count == 1
def test_basic_sysroot_creation(tmpdir): """Very simple smoke test to validate that syntax is correct.""" # Very simple smoke test to validate that all internal syntax is correct mock_docker_client = Mock() platform = Platform('aarch64', 'ubuntu', 'eloquent') # a default set of customizations for the docker build stage customizations = PipelineStageConfigOptions(False, [], None, None, None) temp_stage = CreateSysrootStage() temp_stage(platform, mock_docker_client, Path('dummy_path'), customizations) assert mock_docker_client.build_image.call_count == 1
def buildable_env(request, tmpdir): """Set up a temporary directory with everything needed to run the EmulatedDockerBuildStage.""" platform = Platform('aarch64', 'ubuntu', 'foxy') ros_workspace = Path(str(tmpdir)) / 'ros_ws' _touch_anywhere(ros_workspace / rosdep_install_script(platform)) build_context = prepare_docker_build_environment(platform, ros_workspace) docker = DockerClient(disable_cache=False, default_docker_dir=build_context) options = default_pipeline_options() data_collector = DataCollector() CreateSysrootStage()(platform, docker, ros_workspace, options, data_collector) return BuildableEnv(platform, docker, ros_workspace, options, data_collector)
def test_custom_post_build_script(tmpdir): created_filename = 'file-created-by-post-build' platform = Platform('aarch64', 'ubuntu', 'foxy') ros_workspace = Path(str(tmpdir)) / 'ros_ws' _touch_anywhere(ros_workspace / rosdep_install_script(platform)) post_build_script = ros_workspace / 'post_build' post_build_script.write_text(""" #!/bin/bash echo "success" > {} """.format(created_filename)) build_context = prepare_docker_build_environment( platform, ros_workspace, custom_post_build_script=post_build_script) docker = DockerClient(disable_cache=False, default_docker_dir=build_context) options = default_pipeline_options() data_collector = DataCollector() CreateSysrootStage()(platform, docker, ros_workspace, options, data_collector) EmulatedDockerBuildStage()(platform, docker, ros_workspace, options, data_collector) assert (ros_workspace / created_filename).is_file()
from ros_cross_compile.docker_client import DEFAULT_COLCON_DEFAULTS_FILE from ros_cross_compile.docker_client import DockerClient from ros_cross_compile.pipeline_stages import PipelineStageOptions from ros_cross_compile.platform import Platform from ros_cross_compile.platform import SUPPORTED_ARCHITECTURES from ros_cross_compile.platform import SUPPORTED_ROS2_DISTROS from ros_cross_compile.platform import SUPPORTED_ROS_DISTROS from ros_cross_compile.sysroot_creator import CreateSysrootStage from ros_cross_compile.sysroot_creator import prepare_docker_build_environment logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) _PIPELINE = [ CollectDependencyListStage(), CreateSysrootStage(), EmulatedDockerBuildStage(), ] def _path_if(path: Optional[str] = None) -> Optional[Path]: return Path(path) if path else None def _resolve_ros_workspace(ros_workspace_input: str) -> Path: """Allow for relative paths to be passed in as a ros workspace dir.""" ros_workspace_dir = Path(ros_workspace_input).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(
def test_create_sysroot_stage_creation(): temp_stage = CreateSysrootStage() assert temp_stage
def test_create_sysroot_stage_name(): temp_stage = CreateSysrootStage() assert temp_stage._name == create_workspace_sysroot_image.__name__