Skip to content
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
8 changes: 8 additions & 0 deletions vinca/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ def get_release_package_xml(self, pkg_name):
def check_ros1(self):
return self._distribution_type == "ros1"

def get_ros_version(self):
"""Get ROS version number (1 or 2)"""
return "1" if self.check_ros1() else "2"

def get_package_prefix(self):
"""Get the package name prefix (ros for ROS1, ros2 for ROS2)"""
return "ros" if self.check_ros1() else "ros2"

def get_python_version(self):
return self._python_version

Expand Down
4 changes: 2 additions & 2 deletions vinca/generate_gha.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ def main():
]
if platform == "emscripten-wasm32":
# Hot fix to add the only ros package inside a if else statement
if "ros-humble-rmw-wasm-cpp" in str(reqs):
requirements[pkg_name].append("ros-humble-rmw-wasm-cpp")
if "ros2-rmw-wasm-cpp" in str(reqs):
requirements[pkg_name].append("ros2-rmw-wasm-cpp")

G = nx.DiGraph()
for pkg, reqs in requirements.items():
Expand Down
52 changes: 28 additions & 24 deletions vinca/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,14 @@ def generate_output(pkg_shortname, vinca_conf, distro, version, all_pkgs=None):
"ros_environment",
]:
output["requirements"]["host"].append(
f"ros-{config.ros_distro}-ros-environment"
f"{distro.get_package_prefix()}-ros-environment"
)
output["requirements"]["host"].append(
f"{distro.get_package_prefix()}-ros-workspace"
)
output["requirements"]["run"].append(
f"{distro.get_package_prefix()}-ros-workspace"
)
output["requirements"]["host"].append(f"ros-{config.ros_distro}-ros-workspace")
output["requirements"]["run"].append(f"ros-{config.ros_distro}-ros-workspace")

rm_deps, add_deps = get_depmods(vinca_conf, pkg.name)
gdeps = []
Expand Down Expand Up @@ -469,7 +473,7 @@ def generate_output(pkg_shortname, vinca_conf, distro, version, all_pkgs=None):
output["requirements"]["build"].append(
{
"if": "build_platform != target_platform",
"then": [f"ros-{config.ros_distro}-cyclonedds"],
"then": [f"{distro.get_package_prefix()}-cyclonedds"],
}
)

Expand Down Expand Up @@ -519,32 +523,31 @@ def sortkey(k):
if "cmake" not in output["requirements"]["build"]:
output["requirements"]["build"].append("cmake")

if f"ros-{config.ros_distro}-mimick-vendor" in output["requirements"]["build"]:
output["requirements"]["build"].remove(f"ros-{config.ros_distro}-mimick-vendor")
mimick_vendor_name = f"{distro.get_package_prefix()}-mimick-vendor"
if mimick_vendor_name in output["requirements"]["build"]:
output["requirements"]["build"].remove(mimick_vendor_name)
output["requirements"]["build"].append(
{
"if": "target_platform != 'emscripten-wasm32'",
"then": [f"ros-{config.ros_distro}-mimick-vendor"],
"then": [mimick_vendor_name],
}
)

if f"ros-{config.ros_distro}-mimick-vendor" in output["requirements"]["host"]:
output["requirements"]["host"].remove(f"ros-{config.ros_distro}-mimick-vendor")
if mimick_vendor_name in output["requirements"]["host"]:
output["requirements"]["host"].remove(mimick_vendor_name)
output["requirements"]["build"].append(
{
"if": "target_platform != 'emscripten-wasm32'",
"then": [f"ros-{config.ros_distro}-mimick-vendor"],
"then": [mimick_vendor_name],
}
)

if (
f"ros-{config.ros_distro}-rosidl-default-generators"
in output["requirements"]["host"]
):
rosidl_generators_name = f"{distro.get_package_prefix()}-rosidl-default-generators"
if rosidl_generators_name in output["requirements"]["host"]:
output["requirements"]["build"].append(
{
"if": "target_platform == 'emscripten-wasm32'",
"then": [f"ros-{config.ros_distro}-rosidl-default-generators"],
"then": [rosidl_generators_name],
}
)

Expand All @@ -558,7 +561,8 @@ def sortkey(k):
}
]

if f"ros-{config.ros_distro}-pybind11-vendor" in output["requirements"]["host"]:
pybind11_vendor_name = f"{distro.get_package_prefix()}-pybind11-vendor"
if pybind11_vendor_name in output["requirements"]["host"]:
output["requirements"]["host"] += ["pybind11"]
if "pybind11" in output["requirements"]["host"]:
output["requirements"]["build"] += [
Expand Down Expand Up @@ -983,7 +987,7 @@ def generate_mutex_package_recipe(vinca_conf, distro):

def parse_package(pkg, distro, vinca_conf, path):
name = pkg["name"].replace("_", "-")
final_name = f"ros-{distro.name}-{name}"
final_name = f"{distro.get_package_prefix()}-{name}"

recipe = {
"package": {"name": final_name, "version": pkg["version"]},
Expand Down Expand Up @@ -1148,7 +1152,7 @@ def main():
for o in outputs:
sources[o["package"]["name"]] = o["source"]
del o["source"]
write_recipe(sources, outputs, vinca_conf)
write_recipe(sources, outputs, vinca_conf, distro)

else:
if arguments.skip_already_built_repodata or vinca_conf.get("skip_existing"):
Expand All @@ -1168,10 +1172,10 @@ def main():
additional_recipe_names.add(add_rec_y["package"]["name"])
else:
if add_rec_y["package"]["name"] not in [
"ros-humble-rmw-wasm-cpp",
"ros-humble-wasm-cpp",
"ros-humble-dynmsg",
"ros-humble-test-wasm",
"ros2-rmw-wasm-cpp",
"ros2-wasm-cpp",
"ros2-dynmsg",
"ros2-test-wasm",
]:
additional_recipe_names.add(add_rec_y["package"]["name"])

Expand Down Expand Up @@ -1235,9 +1239,9 @@ def main():
outputs = generate_outputs(distro, vinca_conf)

if arguments.multiple_file:
write_recipe(source, outputs, vinca_conf, False)
write_recipe(source, outputs, vinca_conf, distro, False)
else:
write_recipe(source, outputs, vinca_conf)
write_recipe(source, outputs, vinca_conf, distro)

if unsatisfied_deps:
print("Unsatisfied dependencies:", unsatisfied_deps)
Expand Down
3 changes: 1 addition & 2 deletions vinca/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def resolve_pkgname(pkg_shortname, vinca_conf, distro, is_rundep=False):
return []
else:
return [
"ros-%s-%s"
% (vinca_conf["ros_distro"], pkg_shortname.replace("_", "-"))
"%s-%s" % (distro.get_package_prefix(), pkg_shortname.replace("_", "-"))
]
else:
if is_rundep: # for run dependencies, remove the version
Expand Down
10 changes: 8 additions & 2 deletions vinca/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def copyfile_with_exec_permissions(source_file, destination_file):
)


def write_recipe(source, outputs, vinca_conf, single_file=True):
def write_recipe(source, outputs, vinca_conf, distro, single_file=True):
# single_file = False
if single_file:
file = yaml.YAML()
Expand Down Expand Up @@ -200,6 +200,7 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
generate_build_script_for_recipe(
script_filename,
recipe_dir / script_filename,
distro.get_package_prefix(),
additional_cmake_args,
additional_folder,
)
Expand Down Expand Up @@ -238,7 +239,11 @@ def generate_template(template_in, template_out, extra_globals=None):


def generate_build_script_for_recipe(
script_name, output_path, additional_cmake_args="", additional_folder=""
script_name,
output_path,
ros_package_prefix,
additional_cmake_args="",
additional_folder="",
):
"""Generate a specific build script directly in the recipe directory."""
import pkg_resources
Expand All @@ -261,6 +266,7 @@ def generate_build_script_for_recipe(
)
with open(output_path, "w") as output_file:
extra_globals = {}
extra_globals["ros_package_prefix"] = ros_package_prefix
if additional_cmake_args:
extra_globals["additional_cmake_args"] = additional_cmake_args
else:
Expand Down
2 changes: 1 addition & 1 deletion vinca/templates/bld_ament_python.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setlocal
set "PYTHONPATH=%LIBRARY_PREFIX%\lib\site-packages;%SP_DIR%"

pushd %SRC_DIR%\%PKG_NAME%\src\work\@(additional_folder)
set "PKG_NAME_SHORT=%PKG_NAME:*ros-@(ros_distro)-=%"
set "PKG_NAME_SHORT=%PKG_NAME:*@(ros_package_prefix)-=%"
set "PKG_NAME_SHORT=%PKG_NAME_SHORT:-=_%"

:: If there is a setup.cfg that contains install-scripts then use pip to install
Expand Down
8 changes: 4 additions & 4 deletions vinca/templates/bld_catkin.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set CXX=cl.exe
set CL=/DROS_BUILD_SHARED_LIBS=1 /DNOGDI=1

set "CATKIN_BUILD_BINARY_PACKAGE_ARGS=-DCATKIN_BUILD_BINARY_PACKAGE=1"
if "%PKG_NAME%" == "ros-@(ros_distro)-catkin" (
if "%PKG_NAME%" == "@(ros_package_prefix)-catkin" (
:: create catkin cookie to make it is a catkin workspace
type NUL > %LIBRARY_PREFIX%\.catkin
:: keep the workspace activation scripts (e.g., local_setup.bat)
Expand Down Expand Up @@ -46,7 +46,7 @@ cmake ^
%SRC_DIR%\%PKG_NAME%\src\work\@(additional_folder)
if errorlevel 1 exit 1

if "%PKG_NAME%" == "ros-@(ros_distro)-eigenpy" (
if "%PKG_NAME%" == "@(ros_package_prefix)-eigenpy" (
cmake --build . --config Release --target all --parallel 1
if errorlevel 1 exit 1
) else (
Expand All @@ -62,7 +62,7 @@ if "%SKIP_TESTING%" == "OFF" (
cmake --build . --config Release --target install
if errorlevel 1 exit 1

if "%PKG_NAME%" == "ros-@(ros_distro)-catkin" (
if "%PKG_NAME%" == "@(ros_package_prefix)-catkin" (
:: Copy the [de]activate scripts to %PREFIX%\etc\conda\[de]activate.d.
:: This will allow them to be run on environment activation.
for %%F in (activate deactivate) DO (
Expand All @@ -71,7 +71,7 @@ if "%PKG_NAME%" == "ros-@(ros_distro)-catkin" (
)
)

if "%PKG_NAME%" == "ros-@(ros_distro)-ros-workspace" (
if "%PKG_NAME%" == "@(ros_package_prefix)-ros-workspace" (
:: Copy the [de]activate scripts to %PREFIX%\etc\conda\[de]activate.d.
:: This will allow them to be run on environment activation.
for %%F in (activate deactivate) DO (
Expand Down
2 changes: 1 addition & 1 deletion vinca/templates/bld_catkin_merge.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set CXX=cl.exe
:: https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170
set CL=/DROS_BUILD_SHARED_LIBS=1 /DNOGDI=1

set CATKIN_MAKE_ISOLATED=src\ros-@(ros_distro)-catkin\bin\catkin_make_isolated
set CATKIN_MAKE_ISOLATED=src\@(ros_package_prefix)-catkin\bin\catkin_make_isolated
set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH:\=/%

%PYTHON% %CATKIN_MAKE_ISOLATED% ^
Expand Down
4 changes: 2 additions & 2 deletions vinca/templates/build_ament_python.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pushd $SRC_DIR/$PKG_NAME/src/work/@(additional_folder)

# If there is a setup.cfg that contains install-scripts then we should not set it here
if [ -f setup.cfg ] && grep -q "install[-_]scripts" setup.cfg; then
# Remove e.g. ros-humble- from PKG_NAME
PKG_NAME_SHORT=${PKG_NAME#*ros-@(ros_distro)-}
# Remove e.g. ros2- or ros- from PKG_NAME
PKG_NAME_SHORT=${PKG_NAME#*@(ros_package_prefix)-}
# Substitute "-" with "_"
PKG_NAME_SHORT=${PKG_NAME_SHORT//-/_}
INSTALL_SCRIPTS_ARG="--install-scripts=$PREFIX/lib/$PKG_NAME_SHORT"
Expand Down
10 changes: 5 additions & 5 deletions vinca/templates/build_catkin.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eo pipefail

CATKIN_BUILD_BINARY_PACKAGE="ON"

if [ "${PKG_NAME}" == "ros-@(ros_distro)-catkin" ]; then
if [ "${PKG_NAME}" == "@(ros_package_prefix)-catkin" ]; then
# create catkin cookie to make it is a catkin workspace
touch $PREFIX/.catkin
# keep the workspace activation scripts (e.g., local_setup.bat)
Expand Down Expand Up @@ -85,7 +85,7 @@ fi

export SKIP_TESTING=@(skip_testing)

if [ "${PKG_NAME}" == "ros-noetic-euslisp" ] || [ "${PKG_NAME}" = "ros-noetic-jskeus" ] || [ "${PKG_NAME}" = "ros-noetic-roseus" ]; then
if [ "${PKG_NAME}" == "ros-euslisp" ] || [ "${PKG_NAME}" = "ros-jskeus" ] || [ "${PKG_NAME}" = "ros-roseus" ]; then
GENERATOR="Unix Makefiles"
else
GENERATOR="Ninja"
Expand Down Expand Up @@ -123,7 +123,7 @@ fi

cmake --build . --config Release --target install

if [ "${PKG_NAME}" == "ros-@(ros_distro)-catkin" ]; then
if [ "${PKG_NAME}" == "@(ros_package_prefix)-catkin" ]; then
# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d.
# This will allow them to be run on environment activation.
for CHANGE in "activate" "deactivate"
Expand All @@ -133,15 +133,15 @@ if [ "${PKG_NAME}" == "ros-@(ros_distro)-catkin" ]; then
done
fi

if [ "${PKG_NAME}" == "ros-@(ros_distro)-environment" ]; then
if [ "${PKG_NAME}" == "@(ros_package_prefix)-environment" ]; then
for SCRIPT in "1.ros_distro.sh" "1.ros_etc_dir.sh" "1.ros_package_path.sh" "1.ros_python_version.sh" "1.ros_version.sh"
do
mkdir -p "${PREFIX}/etc/conda/activate.d"
cp "${PREFIX}/etc/catkin/profile.d/${SCRIPT}" "${PREFIX}/etc/conda/activate.d/${SCRIPT}"
done
fi

if [ "${PKG_NAME}" == "ros-@(ros_distro)-ros-workspace" ]; then
if [ "${PKG_NAME}" == "@(ros_package_prefix)-ros-workspace" ]; then
# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d.
# This will allow them to be run on environment activation.
for CHANGE in "activate" "deactivate"
Expand Down
83 changes: 83 additions & 0 deletions vinca/test_naming_scheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Tests for the ROS package naming scheme."""

import pytest
from unittest.mock import Mock
from vinca.utils import ensure_name_is_without_distro_prefix_and_with_underscores
from vinca.distro import Distro


@pytest.mark.parametrize(
"input_name,expected_output",
[
# ROS2 packages
("ros2-my-package", "my_package"),
("ros2-complex-package-name", "complex_package_name"),
("ros2-ros-environment", "ros_environment"),
("ros2-ros-workspace", "ros_workspace"),
("ros2-catkin", "catkin"),
("ros2-navigation2", "navigation2"),
("ros2-my-very-long-package-name", "my_very_long_package_name"),
("ros2-navigation-stack-extra", "navigation_stack_extra"),
("ros2-my_package_name", "my_package_name"),
# ROS1 packages
("ros-my-package", "my_package"),
("ros-test-package", "test_package"),
("ros-ros-environment", "ros_environment"),
("ros-ros-workspace", "ros_workspace"),
("ros-catkin", "catkin"),
("ros-moveit", "moveit"),
("ros-simple", "simple"),
# Packages without prefix
("my-package", "my_package"),
# Edge cases
("ros2-a", "a"),
("ros-a", "a"),
("ros2-ros", "ros"),
],
)
def test_package_normalization(input_name, expected_output):
"""Test package name normalization for various inputs."""
vinca_conf = {}
result = ensure_name_is_without_distro_prefix_and_with_underscores(
input_name, vinca_conf
)
assert result == expected_output


@pytest.mark.parametrize(
"package_name",
[
"ros2-my-package",
"ros2-complex-package-name",
"ros-simple-package",
"ros-another-test",
],
)
def test_no_hyphens_in_output(package_name):
"""Test that normalized names contain no hyphens."""
vinca_conf = {}
result = ensure_name_is_without_distro_prefix_and_with_underscores(
package_name, vinca_conf
)
assert "-" not in result


@pytest.mark.parametrize(
"distribution_type,expected_prefix,expected_version",
[
("ros1", "ros", "1"),
("ros2", "ros2", "2"),
],
)
def test_distro_prefix_and_version(
distribution_type, expected_prefix, expected_version
):
"""Test that Distro returns correct package prefix and ROS version."""
distro = Mock(spec=Distro)
distro._distribution_type = distribution_type
distro.check_ros1 = lambda: distro._distribution_type == "ros1"
distro.get_package_prefix = lambda: "ros" if distro.check_ros1() else "ros2"
distro.get_ros_version = lambda: "1" if distro.check_ros1() else "2"

assert distro.get_package_prefix() == expected_prefix
assert distro.get_ros_version() == expected_version
Loading