Skip to content

Commit

Permalink
Conditionally exclude tests and dependencies (#649)
Browse files Browse the repository at this point in the history
In the debian generator, we can decorate the Build-Depends to omit them
if the `nocheck` flag is set.

For RPMs, there isn't a standard mechanism for skipping tests but we
actually created a build flag for skipping tests, so the only work here
was to wire that custom flag into the dependency enumeration.
  • Loading branch information
cottsay authored Oct 28, 2021
1 parent f9769f2 commit 53beb52
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 8 deletions.
12 changes: 9 additions & 3 deletions bloom/generators/debian/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,18 @@ def generate_substitutions_from_package(
dep for dep in (package.run_depends + package.buildtool_export_depends)
if dep.evaluated_condition is not False]
build_depends = [
dep for dep in (package.build_depends + package.buildtool_depends + package.test_depends)
dep for dep in (package.build_depends + package.buildtool_depends)
if dep.evaluated_condition is not False]
test_depends = [
dep for dep in (package.test_depends)
if dep.evaluated_condition is not False]
replaces = [
dep for dep in package.replaces
if dep.evaluated_condition is not False]
conflicts = [
dep for dep in package.conflicts
if dep.evaluated_condition is not False]
unresolved_keys = depends + build_depends + replaces + conflicts
unresolved_keys = depends + build_depends + test_depends + replaces + conflicts
# The installer key is not considered here, but it is checked when the keys are checked before this
resolved_deps = resolve_dependencies(unresolved_keys, os_name,
os_version, ros_distro,
Expand All @@ -367,8 +370,11 @@ def generate_substitutions_from_package(
data['Depends'] = sorted(
set(format_depends(depends, resolved_deps))
)
# For more information on <!nocheck>, see
# https://wiki.debian.org/BuildProfileSpec
data['BuildDepends'] = sorted(
set(format_depends(build_depends, resolved_deps))
set(format_depends(build_depends, resolved_deps)) |
set(p + ' <!nocheck>' for p in format_depends(test_depends, resolved_deps))
)
data['Replaces'] = sorted(
set(format_depends(replaces, resolved_deps))
Expand Down
6 changes: 5 additions & 1 deletion bloom/generators/debian/templates/ament_cmake/rules.em
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export PKG_CONFIG_PATH=@(InstallationPrefix)/lib/pkgconfig
# Explicitly enable -DNDEBUG, see:
# https://github.com/ros-infrastructure/bloom/issues/327
export DEB_CXXFLAGS_MAINT_APPEND=-DNDEBUG
ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
BUILD_TESTING_ARG=-DBUILD_TESTING=OFF
endif

DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

Expand All @@ -31,7 +34,8 @@ override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_INSTALL_PREFIX="@(InstallationPrefix)" \
-DAMENT_PREFIX_PATH="@(InstallationPrefix)" \
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)"
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
$(BUILD_TESTING_ARG)

override_dh_auto_build:
# In case we're installing to a non-standard location, look for a setup.sh
Expand Down
6 changes: 5 additions & 1 deletion bloom/generators/debian/templates/catkin/rules.em
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export PKG_CONFIG_PATH=@(InstallationPrefix)/lib/pkgconfig
# Explicitly enable -DNDEBUG, see:
# https://github.com/ros-infrastructure/bloom/issues/327
export DEB_CXXFLAGS_MAINT_APPEND=-DNDEBUG
ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
BUILD_TESTING_ARG=-DBUILD_TESTING=OFF -DCATKIN_ENABLE_TESTING=OFF
endif

DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

Expand All @@ -31,7 +34,8 @@ override_dh_auto_configure:
dh_auto_configure -- \
-DCATKIN_BUILD_BINARY_PACKAGE="1" \
-DCMAKE_INSTALL_PREFIX="@(InstallationPrefix)" \
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)"
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
$(BUILD_TESTING_ARG)

override_dh_auto_build:
# In case we're installing to a non-standard location, look for a setup.sh
Expand Down
6 changes: 5 additions & 1 deletion bloom/generators/debian/templates/cmake/rules.em
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export PKG_CONFIG_PATH=@(InstallationPrefix)/lib/pkgconfig
# Explicitly enable -DNDEBUG, see:
# https://github.com/ros-infrastructure/bloom/issues/327
export DEB_CXXFLAGS_MAINT_APPEND=-DNDEBUG
ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
BUILD_TESTING_ARG=-DBUILD_TESTING=OFF
endif

# Solve shlibdeps errors in REP136 packages that use GNUInstallDirs:
export DEB_HOST_MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
Expand All @@ -33,7 +36,8 @@ override_dh_auto_configure:
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi && \
dh_auto_configure -- \
-DCMAKE_INSTALL_PREFIX="@(InstallationPrefix)" \
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)"
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
$(BUILD_TESTING_ARG)

override_dh_auto_build:
# In case we're installing to a non-standard location, look for a setup.sh
Expand Down
10 changes: 8 additions & 2 deletions bloom/generators/rpm/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,18 @@ def generate_substitutions_from_package(
dep for dep in (package.run_depends + package.buildtool_export_depends)
if dep.evaluated_condition is not False and dep.name not in skip_keys]
build_depends = [
dep for dep in (package.build_depends + package.buildtool_depends + package.test_depends)
dep for dep in (package.build_depends + package.buildtool_depends)
if dep.evaluated_condition is not False and dep.name not in skip_keys]
test_depends = [
dep for dep in (package.test_depends)
if dep.evaluated_condition is not False and dep.name not in skip_keys]
replaces = [
dep for dep in package.replaces
if dep.evaluated_condition is not False]
conflicts = [
dep for dep in package.conflicts
if dep.evaluated_condition is not False]
unresolved_keys = depends + build_depends + replaces + conflicts
unresolved_keys = depends + build_depends + test_depends + replaces + conflicts
# The installer key is not considered here, but it is checked when the keys are checked before this
resolved_deps = resolve_dependencies(unresolved_keys, os_name,
os_version, ros_distro,
Expand All @@ -260,6 +263,9 @@ def generate_substitutions_from_package(
data['BuildDepends'] = sorted(
set(format_depends(build_depends, resolved_deps))
)
data['TestDepends'] = sorted(
set(format_depends(test_depends, resolved_deps)).difference(data['BuildDepends'])
)
data['Replaces'] = sorted(
set(format_depends(replaces, resolved_deps))
)
Expand Down
6 changes: 6 additions & 0 deletions bloom/generators/rpm/templates/ament_cmake/template.spec.em
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Source0: %{name}-%{version}.tar.gz
@[for p in Conflicts]Conflicts: @p@\n@[end for]@
@[for p in Replaces]Obsoletes: @p@\n@[end for]@
@[for p in Provides]Provides: @p@\n@[end for]@
@[if TestDepends]@\n%if 0%{?with_tests}
@[for p in TestDepends]BuildRequires: @p@\n@[end for]@
%endif@\n@[end if]@
@[if Supplements]@\n%if 0%{?with_weak_deps}
@[for p in Supplements]Supplements: @p@\n@[end for]@
%endif@\n@[end if]@
Expand All @@ -46,6 +49,9 @@ mkdir -p .obj-%{_target_platform} && cd .obj-%{_target_platform}
-DAMENT_PREFIX_PATH="@(InstallationPrefix)" \
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
-DSETUPTOOLS_DEB_LAYOUT=OFF \
%if !0%{?with_tests}
-DBUILD_TESTING=OFF \
%endif
..

%make_build
Expand Down
3 changes: 3 additions & 0 deletions bloom/generators/rpm/templates/ament_python/template.spec.em
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Source0: %{name}-%{version}.tar.gz
@[for p in Conflicts]Conflicts: @p@\n@[end for]@
@[for p in Replaces]Obsoletes: @p@\n@[end for]@
@[for p in Provides]Provides: @p@\n@[end for]@
@[if TestDepends]@\n%if 0%{?with_tests}
@[for p in TestDepends]BuildRequires: @p@\n@[end for]@
%endif@\n@[end if]@
@[if Supplements]@\n%if 0%{?with_weak_deps}
@[for p in Supplements]Supplements: @p@\n@[end for]@
%endif@\n@[end if]@
Expand Down
8 changes: 8 additions & 0 deletions bloom/generators/rpm/templates/catkin/template.spec.em
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%bcond_without tests
%bcond_without weak_deps

%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
Expand All @@ -19,6 +20,9 @@ Source0: %{name}-%{version}.tar.gz
@[for p in Conflicts]Conflicts: @p@\n@[end for]@
@[for p in Replaces]Obsoletes: @p@\n@[end for]@
@[for p in Provides]Provides: @p@\n@[end for]@
@[if TestDepends]@\n%if 0%{?with_tests}
@[for p in TestDepends]BuildRequires: @p@\n@[end for]@
%endif@\n@[end if]@
@[if Supplements]@\n%if 0%{?with_weak_deps}
@[for p in Supplements]Supplements: @p@\n@[end for]@
%endif@\n@[end if]@
Expand All @@ -45,6 +49,10 @@ mkdir -p .obj-%{_target_platform} && cd .obj-%{_target_platform}
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
-DSETUPTOOLS_DEB_LAYOUT=OFF \
-DCATKIN_BUILD_BINARY_PACKAGE="1" \
%if !0%{?with_tests}
-DBUILD_TESTING=OFF \
-DCATKIN_ENABLE_TESTING=OFF \
%endif
..

%make_build
Expand Down
6 changes: 6 additions & 0 deletions bloom/generators/rpm/templates/cmake/template.spec.em
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Source0: %{name}-%{version}.tar.gz
@[for p in Conflicts]Conflicts: @p@\n@[end for]@
@[for p in Replaces]Obsoletes: @p@\n@[end for]@
@[for p in Provides]Provides: @p@\n@[end for]@
@[if TestDepends]@\n%if 0%{?with_tests}
@[for p in TestDepends]BuildRequires: @p@\n@[end for]@
%endif@\n@[end if]@
@[if Supplements]@\n%if 0%{?with_weak_deps}
@[for p in Supplements]Supplements: @p@\n@[end for]@
%endif@\n@[end if]@
Expand All @@ -45,6 +48,9 @@ mkdir -p .obj-%{_target_platform} && cd .obj-%{_target_platform}
-DCMAKE_INSTALL_PREFIX="@(InstallationPrefix)" \
-DCMAKE_PREFIX_PATH="@(InstallationPrefix)" \
-DSETUPTOOLS_DEB_LAYOUT=OFF \
%if !0%{?with_tests}
-DBUILD_TESTING=OFF \
%endif
..

%make_build
Expand Down

0 comments on commit 53beb52

Please sign in to comment.