Skip to content

Commit

Permalink
invoke colcon instead of ament_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Apr 11, 2018
1 parent f4e517f commit 1ae7661
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion create_jenkins_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main(argv=None):
'use_osrf_connext_debs_default': 'false',
'use_fastrtps_default': 'true',
'use_opensplice_default': 'false',
'ament_build_args_default': '--parallel --cmake-args -DSECURITY=ON --',
'ament_build_args_default': '--cmake-args " -DSECURITY=ON" --event-handler console_cohesion+',
'ament_test_args_default': '--retest-until-pass 10',
'enable_c_coverage_default': 'false',
'dont_notify_every_unstable_build': 'false',
Expand Down
97 changes: 57 additions & 40 deletions ros2_batch_job/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
import os
import platform
from shutil import which
import subprocess
import sys

Expand Down Expand Up @@ -48,6 +49,7 @@
pip_dependencies = [
'EmPy',
'coverage',
'catkin_pkg',
'flake8',
'flake8-blind-except',
'flake8-builtins==1.1.1',
Expand All @@ -65,9 +67,25 @@
'pyparsing',
'pytest',
'pytest-cov',
'pytest-repeat',
'pytest-rerunfailures',
'pytest-runner',
'pyyaml',
'vcstool',
] + [
'git+https://github.com/colcon/colcon-core.git',
'git+https://github.com/colcon/colcon-defaults.git',
'git+https://github.com/colcon/colcon-library-path.git',
'git+https://github.com/colcon/colcon-metadata.git',
'git+https://github.com/colcon/colcon-output.git',
'git+https://github.com/colcon/colcon-package-information.git',
'git+https://github.com/colcon/colcon-package-selection.git',
'git+https://github.com/colcon/colcon-parallel-executor.git',
'git+https://github.com/colcon/colcon-python-setup-py.git',
'git+https://github.com/colcon/colcon-recursive-crawl.git',
'git+https://github.com/colcon/colcon-test-result.git',
'git+https://github.com/colcon/colcon-cmake.git',
'git+https://github.com/colcon/colcon-ros.git',
]

gcov_flags = " -fprofile-arcs -ftest-coverage "
Expand Down Expand Up @@ -178,11 +196,10 @@ def get_args(sysargv=None):
def process_coverage(args, job):
print('# BEGIN SUBSECTION: coverage analysis')
# Collect all .gcda files in args.workspace
ament_py = get_ament_script(args.sourcespace)
output = subprocess.check_output(
[job.python, '-u', ament_py, 'list_packages', args.sourcespace])
[args.colcon_script, 'list', '--base-paths', args.sourcespace])
for line in output.decode().splitlines():
package_name, package_path = line.split(' ', 1)
package_name, package_path, _ = line.split('\t', 2)
print(package_name)
package_build_path = os.path.join(args.buildspace, package_name)
gcda_files = []
Expand Down Expand Up @@ -237,58 +254,53 @@ def process_coverage(args, job):


def build_and_test(args, job):
ament_py = get_ament_script(args.sourcespace)
coverage = args.coverage and args.os == 'linux'

print('# BEGIN SUBSECTION: ament build')
# Now run ament build
os.environ['COLCON_LOG_PATH'] = os.path.join(os.getcwd(), 'log')

print('# BEGIN SUBSECTION: colcon build')
ret_build = job.run([
'"%s"' % job.python, '-u', '"%s"' % ament_py, 'build',
'"%s"' % args.sourcespace,
'--build-tests',
'--build-space', '"%s"' % args.buildspace,
'--install-space', '"%s"' % args.installspace,
] + (['--isolated'] if args.isolated else []) +
(
['--cmake-args', '-DCMAKE_BUILD_TYPE=' +
args.cmake_build_type + ' --']
args.colcon_script, 'build',
'--base-paths', '"%s"' % args.sourcespace,
# '--build-tests',
'--build-base', '"%s"' % args.buildspace,
'--install-base', '"%s"' % args.installspace,
] + (['--merge-install'] if not args.isolated else []) + [
'--cmake-args', '" -DBUILD_TESTING=1"',
] + (
['--cmake-args', '" -DCMAKE_BUILD_TYPE=' +
args.cmake_build_type + '"']
if args.cmake_build_type else []
) + args.ament_build_args +
(['--ament-cmake-args -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} ' +
gcov_flags + ' " -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} ' +
gcov_flags + '" --']
(['--ament-cmake-args " -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} ' +
gcov_flags + '" " -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} ' +
gcov_flags + '"']
if coverage else []), shell=True)
info("ament.py build returned: '{0}'".format(ret_build))
info("colcon build returned: '{0}'".format(ret_build))
print('# END SUBSECTION')
if ret_build:
return ret_build

print('# BEGIN SUBSECTION: ament test')
# Run tests
print('# BEGIN SUBSECTION: colcon test')
ret_test = job.run([
'"%s"' % job.python, '-u', '"%s"' % ament_py, 'test',
'"%s"' % args.sourcespace,
'--build-space', '"%s"' % args.buildspace,
'--install-space', '"%s"' % args.installspace,
# Skip building and installing, since we just did that successfully.
'--skip-build', '--skip-install',
# Ignore return codes that indicate test failures;
# they'll be picked up later in test reporting.
'--ignore-return-codes',
] + (['--isolated'] if args.isolated else []) + args.ament_test_args,
args.colcon_script, 'test',
'--base-paths', '"%s"' % args.sourcespace,
'--build-base', '"%s"' % args.buildspace,
'--install-base', '"%s"' % args.installspace,
] + (['--merge-install'] if not args.isolated else []) + args.ament_test_args,
exit_on_error=False, shell=True)
info("ament.py test returned: '{0}'".format(ret_test))
info("colcon test returned: '{0}'".format(ret_test))
print('# END SUBSECTION')
if ret_test:
return ret_test

print('# BEGIN SUBSECTION: ament test_results')
print('# BEGIN SUBSECTION: colcon test-result')
# Collect the test results
ret_test_results = job.run(
['"%s"' % job.python, '-u', '"%s"' % ament_py, 'test_results', '"%s"' % args.buildspace],
[args.colcon_script, 'test-result', '--build-base', '"%s"' % args.buildspace, '--all'],
exit_on_error=False, shell=True
)
info("ament.py test_results returned: '{0}'".format(ret_test_results))
info("colcon test-result returned: '{0}'".format(ret_test_results))
print('# END SUBSECTION')
if coverage:
process_coverage(args, job)
Expand Down Expand Up @@ -367,6 +379,7 @@ def run(args, build_function, blacklisted_package_names=None):
# Check the env
job.show_env()

colcon_script = None
# Enter a venv if asked to, the venv must be in a path without spaces
if args.do_venv:
print('# BEGIN SUBSECTION: enter virtualenv')
Expand Down Expand Up @@ -402,6 +415,11 @@ def run(args, build_function, blacklisted_package_names=None):
job.run(['"%s"' % job.python, '-m', 'pip', '--version'], shell=True)
# Install pip dependencies
job.run(['"%s"' % job.python, '-m', 'pip', 'install', '-U'] + pip_dependencies, shell=True)
if sys.platform != 'win32':
colcon_script = os.path.join(venv_path, 'bin', 'colcon')
else:
colcon_script = 'c:\\python36\\Scripts\\colcon.exe'
args.colcon_script = colcon_script
# Show what pip has
job.run(['"%s"' % job.python, '-m', 'pip', 'freeze'], shell=True)
print('# END SUBSECTION')
Expand Down Expand Up @@ -500,18 +518,17 @@ def run(args, build_function, blacklisted_package_names=None):
# Allow the batch job to push custom sourcing onto the run command
job.setup_env()

# create AMENT_IGNORE files in package folders which should not be used
# create COLCON_IGNORE files in package folders which should not be used
if blacklisted_package_names:
print('# BEGIN SUBSECTION: ignored packages')
print('Trying to ignore the following packages:')
[print('- ' + name) for name in blacklisted_package_names]
ament_py = get_ament_script(args.sourcespace)
output = subprocess.check_output(
[job.python, '-u', ament_py, 'list_packages', args.sourcespace])
[colcon_script, 'list', '--base-paths', args.sourcespace])
for line in output.decode().splitlines():
package_name, package_path = line.split(' ', 1)
package_name, package_path, _ = line.split('\t', 2)
if package_name in blacklisted_package_names:
marker_file = os.path.join(args.sourcespace, package_path, 'AMENT_IGNORE')
marker_file = os.path.join(args.sourcespace, package_path, 'COLCON_IGNORE')
print('Create marker file: ' + marker_file)
with open(marker_file, 'w'):
pass
Expand Down

0 comments on commit 1ae7661

Please sign in to comment.