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

Support specifying any number of specific CMake targets #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 31 additions & 8 deletions colcon_cmake/task/cmake/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0

from argparse import SUPPRESS
import ast
from contextlib import suppress
import os
from pathlib import Path
import re
import warnings

from colcon_cmake.task.cmake import CMAKE_EXECUTABLE
from colcon_cmake.task.cmake import get_buildfile
Expand Down Expand Up @@ -43,12 +45,20 @@ def add_arguments(self, *, parser): # noqa: D102
'default, e.g. add `--event-handlers console_cohesion+`)')
parser.add_argument(
'--cmake-target',
help='Build a specific target instead of the default target')
help=SUPPRESS)
parser.add_argument(
'--cmake-targets',
help='Build specific targets instead of the default target',
nargs='*')
parser.add_argument(
'--cmake-target-skip-unavailable',
action='store_true',
help="Skip building packages which don't have the target passed "
'to --cmake-target')
help=SUPPRESS)
parser.add_argument(
'--cmake-targets-skip-unavailable',
action='store_true',
help='Skip building any targets passed to --cmake-targets for '
"which packages don't have that target")
parser.add_argument(
'--cmake-clean-cache',
action='store_true',
Expand All @@ -71,6 +81,19 @@ async def build( # noqa: D102
pkg = self.context.pkg
args = self.context.args

if args.cmake_target is not None:
warnings.warn(
'--cmake-target is deprecated, please use --cmake-targets')
if args.cmake_targets is None:
args.cmake_targets = []
args.cmake_targets.append(args.cmake_target)
if args.cmake_target_skip_unavailable:
warnings.warn(
'--cmake-target-skip-unavailable is deprecated, please use '
'--cmake-targets-skip-unavailable')
args.cmake_targets_skip_unavailable = \
args.cmake_target_skip_unavailable

logger.info(
"Building CMake package in '{args.path}'".format_map(locals()))

Expand Down Expand Up @@ -106,7 +129,7 @@ async def build( # noqa: D102
return rc

# skip install step if a specific target was requested
if not args.cmake_target:
if args.cmake_targets is None:
if await has_target(args.build_base, 'install'):
completed = await self._install(args, env)
if completed.returncode:
Expand Down Expand Up @@ -215,9 +238,9 @@ async def _build(self, args, env, *, additional_targets=None):
raise RuntimeError("Could not find 'cmake' executable")

targets = []
if args.cmake_target:
targets.append(args.cmake_target)
else:
if args.cmake_targets:
targets += args.cmake_targets
elif args.cmake_targets is None:
targets.append('')
if additional_targets:
targets += additional_targets
Expand All @@ -232,7 +255,7 @@ async def _build(self, args, env, *, additional_targets=None):
for i, target in enumerate(targets):
cmd = [CMAKE_EXECUTABLE, '--build', args.build_base]
if target:
if args.cmake_target_skip_unavailable:
if args.cmake_targets_skip_unavailable:
if not await has_target(args.build_base, target):
continue
self.progress("build target '{target}'".format_map(locals()))
Expand Down
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apache
argcomplete
argparse
basepath
buildfile
cmake
Expand Down