Skip to content

Commit

Permalink
Add flag to also add build-dep for runtime-depends
Browse files Browse the repository at this point in the history
Superflore  is correct to generate runtime dependencies when an
dependency is needed to provide headers and libraries needed to consume
an element but not to build it. Some tooling struggles to interpret the
c/c++ dependency graph when the dependencies are represented as
runtime-dependencies.

This commit adds a flag to additionally generate a build-dependency
for elements that depend on a ROS package that defines a package as
a runtime dependency.
  • Loading branch information
harrysarson committed Feb 7, 2025
1 parent e5818da commit 415c0e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions superflore/generators/buildstream/bst_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
srcrev_cache, skip_keys, repo_dir, external_repos,
*,
exclude_source,
runtime_as_build_dependencies,
):
self.repo_dir = repo_dir
self.external_repos = external_repos
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(
self.srcrev = srcrev_cache[self.src_uri]
self.skip_keys = skip_keys
self.exclude_source = exclude_source
self.runtime_as_build_dependencies = runtime_as_build_dependencies

def get_license_line(self):
self.license_line = ''
Expand Down Expand Up @@ -313,9 +315,15 @@ def get_element_text(self, distributor):
exec_deps, sys_deps = self.get_dependencies(
self.rdepends, self.rdepends_external)

element["build-depends"] = buildstack + sorted(deps | buildtool_native_deps)
build_deps = deps | buildtool_native_deps
runtime_deps = deps | export_deps | buildtool_export_native_deps | exec_deps

element["runtime-depends"] = [base] + sorted(deps | export_deps | buildtool_export_native_deps | exec_deps)
if self.runtime_as_build_dependencies:
build_deps |= runtime_deps

element["build-depends"] = buildstack + sorted(build_deps)

element["runtime-depends"] = [base] + sorted(runtime_deps)

variables = {}
if self.build_type == "ament_cmake":
Expand Down
6 changes: 6 additions & 0 deletions superflore/generators/buildstream/gen_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def regenerate_pkg(
overlay, pkg, rosdistro, preserve_existing, srcrev_cache,
skip_keys, external_repos, generated_elements_dir = "elements/generated",
exclude_source=False,
runtime_as_build_dependencies=False,
):
pkg_names = get_package_names(rosdistro)[0]
if pkg not in pkg_names:
Expand Down Expand Up @@ -99,6 +100,7 @@ def regenerate_pkg(
current = bst_element(
rosdistro, pkg, srcrev_cache, skip_keys, repo_dir, external_repos,
exclude_source=exclude_source,
runtime_as_build_dependencies=runtime_as_build_dependencies,
)
except InvalidPackage as e:
err('Invalid package: ' + str(e))
Expand Down Expand Up @@ -146,6 +148,7 @@ def _gen_element_for_package(
pkg_rosinstall, srcrev_cache, skip_keys, repo_dir, external_repos,
*,
exclude_source,
runtime_as_build_dependencies,
):
pkg_names = get_package_names(rosdistro)
pkg_dep_walker = DependencyWalker(rosdistro)
Expand Down Expand Up @@ -175,6 +178,7 @@ def _gen_element_for_package(
repo_dir,
external_repos,
exclude_source=exclude_source,
runtime_as_build_dependencies=runtime_as_build_dependencies,
)
# add build dependencies
for bdep in pkg_build_deps:
Expand Down Expand Up @@ -204,6 +208,7 @@ def __init__(
self, rosdistro, pkg_name, srcrev_cache, skip_keys, repo_dir, external_repos,
*,
exclude_source,
runtime_as_build_dependencies,
):
pkg = rosdistro.release_packages[pkg_name]
repo = rosdistro.repositories[pkg.repository_name].release_repository
Expand All @@ -217,6 +222,7 @@ def __init__(
rosdistro, pkg_name, pkg, repo, ros_pkg, pkg_rosinstall,
srcrev_cache, skip_keys, repo_dir, external_repos,
exclude_source=exclude_source,
runtime_as_build_dependencies=runtime_as_build_dependencies,
)

def element_text(self):
Expand Down
9 changes: 8 additions & 1 deletion superflore/generators/buildstream/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def main():
default="elements/generated",
help='directory for generated bst elements',
type=str)
parser.add_argument(
'--runtime-as-build-dependencies',
default=False,
action='store_true',
help='Generate a build-dependency for exported dependencies as well as a runtime-dependency')
parser.add_argument(
'--exclude-sources-for',
default=[],
Expand Down Expand Up @@ -153,6 +158,7 @@ def main():
distro = get_distro(args.ros_distro)
packages = args.only
exclude_sources_for = args.exclude_sources_for
runtime_as_build_dependencies = args.runtime_as_build_dependencies
include_dependencies = True
if include_dependencies:
packages = set(packages) | \
Expand All @@ -172,7 +178,8 @@ def main():
srcrev_cache,
skip_keys=skip_keys,
external_repos=external_repos,
exclude_source=pkg in exclude_sources_for
exclude_source=pkg in exclude_sources_for,
runtime_as_build_dependencies=runtime_as_build_dependencies,
)
except KeyError:
err("No package to satisfy key '%s' available "
Expand Down

0 comments on commit 415c0e5

Please sign in to comment.