From b09d9cbd621e9faba85590cc07286091db7d32b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Ram=C3=ADrez?= Date: Tue, 29 Oct 2024 12:49:29 +0100 Subject: [PATCH 1/2] Fixed import (#165) --- examples/extensions/commands/clean/cmd_clean.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/extensions/commands/clean/cmd_clean.py b/examples/extensions/commands/clean/cmd_clean.py index bcdd24c8..fb22e14a 100644 --- a/examples/extensions/commands/clean/cmd_clean.py +++ b/examples/extensions/commands/clean/cmd_clean.py @@ -1,8 +1,7 @@ from conan.api.conan_api import ConanAPI +from conan.api.input import UserInput from conan.api.output import ConanOutput, Color from conan.cli.command import OnceArgument, conan_command -from conans.client.userio import UserInput - recipe_color = Color.BRIGHT_BLUE removed_color = Color.BRIGHT_YELLOW From be895a14a68f05ff29d2c3b70a893cbd6edb82ba Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 Nov 2024 07:27:55 +0100 Subject: [PATCH 2/2] Add ROSEnv example (#164) * rosenv example * missing files * changes * add to readme * add docker ci for the example * fix * fix * Update examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt Co-authored-by: Carlos Zoido * update example * Update examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt * test in github actions * use bash * fix cd * wip * Update examples/tools/README.md Co-authored-by: Carlos Zoido * Update .github/workflows/ros-tests.yml * add develop2 testing * wip * wip * minor changes * wip --------- Co-authored-by: Carlos Zoido --- .github/workflows/ros-tests.yml | 52 +++++++++++++++++++ .gitignore | 3 ++ examples/tools/README.md | 4 ++ .../rosenv/workspace/consumer/CMakeLists.txt | 24 +++++++++ .../ros/rosenv/workspace/consumer/package.xml | 20 +++++++ .../rosenv/workspace/consumer/src/main.cpp | 10 ++++ .../workspace/str_printer/CMakeLists.txt | 38 ++++++++++++++ .../workspace/str_printer/conanfile.txt | 7 +++ .../include/str_printer/str_printer.h | 11 ++++ .../rosenv/workspace/str_printer/package.xml | 18 +++++++ .../workspace/str_printer/src/str_printer.cpp | 11 ++++ .../tools/ros/rosenv/workspace/test_ros.sh | 8 +++ test/examples_tools.py | 2 +- 13 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ros-tests.yml create mode 100644 examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt create mode 100644 examples/tools/ros/rosenv/workspace/consumer/package.xml create mode 100644 examples/tools/ros/rosenv/workspace/consumer/src/main.cpp create mode 100644 examples/tools/ros/rosenv/workspace/str_printer/CMakeLists.txt create mode 100644 examples/tools/ros/rosenv/workspace/str_printer/conanfile.txt create mode 100644 examples/tools/ros/rosenv/workspace/str_printer/include/str_printer/str_printer.h create mode 100644 examples/tools/ros/rosenv/workspace/str_printer/package.xml create mode 100644 examples/tools/ros/rosenv/workspace/str_printer/src/str_printer.cpp create mode 100755 examples/tools/ros/rosenv/workspace/test_ros.sh diff --git a/.github/workflows/ros-tests.yml b/.github/workflows/ros-tests.yml new file mode 100644 index 00000000..4b083bd5 --- /dev/null +++ b/.github/workflows/ros-tests.yml @@ -0,0 +1,52 @@ +name: ROS and Conan Integration Test + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test_conan_release: + runs-on: ubuntu-latest + container: + image: osrf/ros:humble-desktop + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure environment and install Conan release + run: | + apt-get update && apt-get install -y python3 python3-pip + python3 -m pip install conan + chmod +x ./examples/tools/ros/rosenv/workspace/test_ros.sh + + - name: Run example with latest Conan release + shell: bash + run: | + cd examples/tools/ros/rosenv/workspace + ./test_ros.sh + + test_conan_develop2: + runs-on: ubuntu-latest + container: + image: osrf/ros:humble-desktop + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure environment and install Conan from develop2 branch + run: | + apt-get update && apt-get install -y python3 python3-pip + python3 -m pip install git+https://github.com/conan-io/conan.git + chmod +x ./examples/tools/ros/rosenv/workspace/test_ros.sh + + - name: Run example with Conan from repo + shell: bash + run: | + cd examples/tools/ros/rosenv/workspace + ./test_ros.sh diff --git a/.gitignore b/.gitignore index cd4a0b0c..f0e0b113 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,6 @@ examples/tools/google/bazeltoolchain/7_x/string_formatter/MODULE.bazel.lock examples/libraries/libcurl/ascii_art_color/conan/* examples/libraries/libcurl/ascii_art_color/asciiartgen/x64/* examples/libraries/libcurl/ascii_art_color/x64/Release/* + +examples/tools/ros/rosenv/workspace/install/ +examples/tools/ros/rosenv/workspace/log/ diff --git a/examples/tools/README.md b/examples/tools/README.md index 6c03d656..034f6b66 100644 --- a/examples/tools/README.md +++ b/examples/tools/README.md @@ -24,3 +24,7 @@ - Build a [Bazel 6.x compatible project](bazel/bazeltoolchain/6_x/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_project.rst) - Build a [Bazel >= 7.1 compatible project](bazel/bazeltoolchain/7_x/string_formatter/) using Conan and [fmt](https://fmt.dev/). [Docs](https://docs.conan.io/2/examples/tools/google/bazeltoolchain/build_simple_bazel_7x_project.rst) + +### [tools.ros](ros) + +- Build [ROS packages inside their workspace](ros/rosenv/workspace/) using dependencies from Conan Center and consuming them also as transitive dependencies. diff --git a/examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt b/examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt new file mode 100644 index 00000000..d71998b3 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/consumer/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.8) +project(consumer) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(str_printer REQUIRED) + +add_executable(main src/main.cpp) + +target_include_directories(main PUBLIC + $ + $) + +target_compile_features(main PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +ament_target_dependencies(main str_printer) + +install(TARGETS main + DESTINATION lib/${PROJECT_NAME}) + +ament_package() diff --git a/examples/tools/ros/rosenv/workspace/consumer/package.xml b/examples/tools/ros/rosenv/workspace/consumer/package.xml new file mode 100644 index 00000000..087ca778 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/consumer/package.xml @@ -0,0 +1,20 @@ + + + + consumer + 0.0.0 + Consumer application that prints a fancy string + danimtb + MIT + + ament_cmake + + ament_lint_auto + ament_lint_common + + str_printer + + + ament_cmake + + diff --git a/examples/tools/ros/rosenv/workspace/consumer/src/main.cpp b/examples/tools/ros/rosenv/workspace/consumer/src/main.cpp new file mode 100644 index 00000000..3deba4ed --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/consumer/src/main.cpp @@ -0,0 +1,10 @@ +#include "str_printer/str_printer.h" + +int main(int argc, char ** argv) +{ + (void) argc; + (void) argv; + + str_printer("Hi there! I am using fmt library fetched with Conan C/C++ Package Manager"); + return 0; +} diff --git a/examples/tools/ros/rosenv/workspace/str_printer/CMakeLists.txt b/examples/tools/ros/rosenv/workspace/str_printer/CMakeLists.txt new file mode 100644 index 00000000..0d462662 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/str_printer/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.8) +project(str_printer) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(fmt REQUIRED) # Retrieved with Conan C/C++ Package Manager + +add_library(str_printer src/str_printer.cpp) + +target_include_directories(str_printer PUBLIC + $ + $) + +target_compile_features(str_printer PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +ament_target_dependencies(str_printer fmt) + +ament_export_targets(str_printerTargets HAS_LIBRARY_TARGET) +ament_export_dependencies(fmt) + +install( + DIRECTORY include/ + DESTINATION include +) + +install( + TARGETS str_printer + EXPORT str_printerTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +ament_package() diff --git a/examples/tools/ros/rosenv/workspace/str_printer/conanfile.txt b/examples/tools/ros/rosenv/workspace/str_printer/conanfile.txt new file mode 100644 index 00000000..ecfa8931 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/str_printer/conanfile.txt @@ -0,0 +1,7 @@ +[requires] +fmt/11.0.2 + +[generators] +CMakeDeps +CMakeToolchain +ROSEnv \ No newline at end of file diff --git a/examples/tools/ros/rosenv/workspace/str_printer/include/str_printer/str_printer.h b/examples/tools/ros/rosenv/workspace/str_printer/include/str_printer/str_printer.h new file mode 100644 index 00000000..6a7d59a7 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/str_printer/include/str_printer/str_printer.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#ifdef WIN32 + #define FN_EXPORT __declspec(dllexport) +#else + #define FN_EXPORT +#endif + +FN_EXPORT void str_printer(std::string); diff --git a/examples/tools/ros/rosenv/workspace/str_printer/package.xml b/examples/tools/ros/rosenv/workspace/str_printer/package.xml new file mode 100644 index 00000000..84c1387f --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/str_printer/package.xml @@ -0,0 +1,18 @@ + + + + str_printer + 0.0.0 + Library that provides a function to print a fancy string using the fmt library fetched by Conan C/C++ Package Manager + danimtb + MIT + + ament_cmake + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/examples/tools/ros/rosenv/workspace/str_printer/src/str_printer.cpp b/examples/tools/ros/rosenv/workspace/str_printer/src/str_printer.cpp new file mode 100644 index 00000000..d53fa028 --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/str_printer/src/str_printer.cpp @@ -0,0 +1,11 @@ +#include +#include + +#include "fmt/core.h" +#include "fmt/color.h" + +#include "str_printer.h" + +void str_printer(std::string str) { + fmt::print(fmt::fg(fmt::color::gold) | fmt::emphasis::bold, "{}\n", str); +} diff --git a/examples/tools/ros/rosenv/workspace/test_ros.sh b/examples/tools/ros/rosenv/workspace/test_ros.sh new file mode 100755 index 00000000..76ea1bcc --- /dev/null +++ b/examples/tools/ros/rosenv/workspace/test_ros.sh @@ -0,0 +1,8 @@ +source /opt/ros/humble/setup.bash +conan profile detect --force +conan install str_printer/conanfile.txt --build=missing --output-folder install/conan +source install/conan/conanrosenv.sh +colcon build --packages-select str_printer +colcon build --packages-select consumer +source install/setup.bash +ros2 run consumer main diff --git a/test/examples_tools.py b/test/examples_tools.py index af2d777a..16028d27 100644 --- a/test/examples_tools.py +++ b/test/examples_tools.py @@ -44,7 +44,7 @@ def run(cmd, error=False): print("Running: {}".format(cmd)) start_time = time.time() - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, text=True) + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, text=True, encoding='utf-8') output = ''