Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Allow to skip pipeline steps by name
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <[email protected]>
  • Loading branch information
emersonknapp committed Aug 15, 2020
1 parent 5b49619 commit 2f6fe2e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
33 changes: 8 additions & 25 deletions ros_cross_compile/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ros_cross_compile.pipeline_stages import PipelineStage
from ros_cross_compile.pipeline_stages import PipelineStageConfigOptions
from ros_cross_compile.platform import Platform
from ros_cross_compile.sysroot_creator import build_internals_dir
from ros_cross_compile.sysroot_creator import build_internals_dir, rosdep_install_script

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('Rosdep Gatherer')
Expand All @@ -34,9 +34,6 @@
_IMG_NAME = 'ros_cross_compile:rosdep'


def rosdep_install_script(platform: Platform) -> Path:
"""Construct relative path of the script that installs rosdeps into the sysroot image."""
return build_internals_dir(platform) / 'install_rosdeps.sh'


def gather_rosdeps(
Expand Down Expand Up @@ -88,18 +85,6 @@ def gather_rosdeps(
)


def assert_install_rosdep_script_exists(
ros_workspace_dir: Path,
platform: Platform
) -> bool:
install_rosdep_script_path = ros_workspace_dir / rosdep_install_script(platform)
if not install_rosdep_script_path.is_file():
raise RuntimeError(
'Rosdep installation script has never been created, you need to run this without '
'skipping rosdep collection at least once.')
return True


class CollectDependencies(PipelineStage):
"""
This stage determines what external dependencies are needed for building.
Expand All @@ -124,15 +109,13 @@ def __call__(self, platform: Platform, docker_client: DockerClient, ros_workspac
"""
# NOTE: Stage skipping will be handled more generically in the future;
# for now we handle this specific case internally to maintain the original API.
if not pipeline_stage_config_options.skip_rosdep_collection:
gather_rosdeps(
docker_client=docker_client,
platform=platform,
workspace=ros_workspace_dir,
skip_rosdep_keys=pipeline_stage_config_options.skip_rosdep_keys,
custom_script=pipeline_stage_config_options.custom_script,
custom_data_dir=pipeline_stage_config_options.custom_data_dir)
assert_install_rosdep_script_exists(ros_workspace_dir, platform)
gather_rosdeps(
docker_client=docker_client,
platform=platform,
workspace=ros_workspace_dir,
skip_rosdep_keys=pipeline_stage_config_options.skip_rosdep_keys,
custom_script=pipeline_stage_config_options.custom_script,
custom_data_dir=pipeline_stage_config_options.custom_data_dir)

img_size = docker_client.get_image_size(_IMG_NAME)
data_collector.add_size(self.name, img_size)
3 changes: 1 addition & 2 deletions ros_cross_compile/pipeline_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
argparse options in ros_cross_compile.py.
"""
PipelineStageConfigOptions = NamedTuple('PipelineStageConfigOptions',
[('skip_rosdep_collection', bool),
('skip_rosdep_keys', List[str]),
[('skip_rosdep_keys', List[str]),
('custom_script', Optional[Path]),
('custom_data_dir', Optional[Path]),
('custom_setup_script', Optional[Path])])
Expand Down
18 changes: 8 additions & 10 deletions ros_cross_compile/ros_cross_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ def parse_args(args: List[str]) -> argparse.Namespace:
type=str,
help='Relative path within the workspace to a file that provides colcon arguments. '
'See "Package Selection and Build Customization" in README.md for more details.')
parser.add_argument(
'--skip-rosdep-collection',
action='store_true',
required=False,
help='Skip querying rosdep for dependencies. This is intended to save time when running '
'repeatedly during development, but has undefined behavior if the dependencies of '
'the workspace have changed since the last time they were collected.')
parser.add_argument(
'--skip-rosdep-keys',
default=[],
Expand All @@ -162,6 +155,11 @@ def parse_args(args: List[str]) -> argparse.Namespace:
action='store_true',
required=False,
help='All collected metrics will be printed to stdout via the logging framework.')
parser.add_argument(
'--skip-steps',
nargs='+',
choices=[stage.name for stage in stages],
help='Skip these steps')
parser.add_argument(
'--create-runtime-image',
help='Create a Docker image with the specified name that contains all '
Expand Down Expand Up @@ -192,15 +190,15 @@ def cross_compile_pipeline(
colcon_defaults_file=args.colcon_defaults)

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('{}'.format(stage.name)):
stage(platform, docker_client, ros_workspace_dir, customizations, data_collector)
if stage.name not in args.skip_steps:
with data_collector.timer('{}'.format(stage.name)):
stage(platform, docker_client, ros_workspace_dir, customizations, data_collector)


def main():
Expand Down
20 changes: 19 additions & 1 deletion ros_cross_compile/sysroot_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def build_internals_dir(platform: Platform) -> Path:
return Path(INTERNALS_DIR) / str(platform)


def rosdep_install_script(platform: Platform) -> Path:
"""Construct relative path of the script that installs rosdeps into the sysroot image."""
return build_internals_dir(platform) / 'install_rosdeps.sh'


def _copytree(src: Path, dest: Path) -> None:
"""Copy contents of directory 'src' into 'dest'."""
copy_tree(str(src), str(dest))
Expand All @@ -45,6 +50,18 @@ def _copyfile(src: Path, dest: Path) -> None:
shutil.copy(str(src), str(dest))


def assert_install_rosdep_script_exists(
ros_workspace_dir: Path,
platform: Platform
) -> bool:
install_rosdep_script_path = ros_workspace_dir / rosdep_install_script(platform)
if not install_rosdep_script_path.is_file():
raise RuntimeError(
'Rosdep installation script has never been created, you need to run this without '
'skipping rosdep collection at least once.')
return True


def setup_emulator(arch: str, output_dir: Path) -> None:
"""Copy the appropriate emulator binary to the output location."""
emulator_name = 'qemu-{}-static'.format(arch)
Expand Down Expand Up @@ -116,6 +133,7 @@ def create_workspace_sysroot(
image_tag = platform.sysroot_image_tag
sysroot_destination = (ros_workspace / build_internals_dir(platform)).parent / 'sysroot'

assert_install_rosdep_script_exists(ros_workspace, platform)
logger.info('Building sysroot image: %s', image_tag)
docker_client.build_image(
dockerfile_name='sysroot.Dockerfile',
Expand Down Expand Up @@ -146,7 +164,7 @@ class CreateSysroot(PipelineStage):
"""

def __init__(self):
super().__init__('create_workspace_sysroot_image')
super().__init__('create_sysroot')

def __call__(self, platform: Platform, docker_client: DockerClient, ros_workspace_dir: Path,
pipeline_stage_config_options: PipelineStageConfigOptions,
Expand Down

0 comments on commit 2f6fe2e

Please sign in to comment.