Skip to content

Commit

Permalink
Refs #21886: Make hellow world docker compose file generic and refact…
Browse files Browse the repository at this point in the history
…or CMakeLists.txt

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL committed Nov 12, 2024
1 parent 16018d9 commit a31502a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
61 changes: 44 additions & 17 deletions test/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ set(SHELL_EXECUTABLE "")
set(TINYXML2_LIB_DIR_COMPOSE_VOLUME "")
set(TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH "")

# Configure TinyXML2 library path if installed in user library path
if(NOT (TINYXML2_FROM_SOURCE OR TINYXML2_FROM_THIRDPARTY))
message(STATUS "TINYXML2_LIBRARY " ${TINYXML2_LIBRARY})
file(GLOB TINYXML2_LIBRARY_DIRS LIST_DIRECTORIES false ${TINYXML2_LIBRARY})
if (TINYXML2_LIBRARY_DIRS)
list (GET TINYXML2_LIBRARY_DIRS 0 TINYXML2_LIBRARY_HEAD_DIR)
get_filename_component(TINYXML2_LIB_DIR ${TINYXML2_LIBRARY_HEAD_DIR} DIRECTORY)
message(STATUS "TINYXML2_LIB_DIR " ${TINYXML2_LIB_DIR})
set(TINYXML2_LIB_DIR_COMPOSE_VOLUME "- ${TINYXML2_LIB_DIR}:${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/fastdds:ro")
set(TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/fastdds")
else()
message(FATAL_ERROR "Could not find a valid TinyXML 2 lirbary path.")
endif()
endif()

# Linux configurations
if(UNIX AND NOT(APPLE) AND NOT(QNXNTO) AND NOT(ANDROID))
# Find bash
Expand All @@ -39,6 +54,21 @@ if(UNIX AND NOT(APPLE) AND NOT(QNXNTO) AND NOT(ANDROID))
set(SHELL_EXECUTABLE ${BASH_EXECUTABLE})
set(DOCKER_IMAGE_NAME "ubuntu:22.04")

set(PROJECT_BINATY_DIR_COMPOSE_VOLUME "${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}")
set(fastcdr_LIB_DIR_COMPOSE_VOLUME "${fastcdr_LIB_DIR}:${fastcdr_LIB_DIR}")
set(CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME "${CMAKE_INSTALL_PREFIX}:${CMAKE_INSTALL_PREFIX}")

set(PATH_ENVIRONMENT_VARIABLE_COMPOSE "LD_LIBRARY_PATH: ${PROJECT_BINARY_DIR}/src/cpp:${fastcdr_LIB_DIR}")
if (TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH)
set(PATH_ENVIRONMENT_VARIABLE_COMPOSE "${PATH_ENVIRONMENT_VARIABLE_COMPOSE}:${TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH}")
endif()
set(EXAMPLE_PREFIX_DIR_COMPOSE "${PROJECT_BINARY_DIR}/examples/cpp")
set(EXAMPLE_SUFFIX_DIR_COMPOSE "")
set(FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE "${PROJECT_BINARY_DIR}/examples/cpp/")
set(COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE "$\${EXAMPLE_DIR}")
set(COMMAND_CONCATENATE_COMPOSE "&")
set(COMMAND_BACKGROUND_JOB_COMPOSE "")

# Windows configurations
elseif(WIN32)
# Find pwsh
Expand All @@ -47,8 +77,8 @@ elseif(WIN32)
message(FATAL_ERROR "pwsh not found")
endif()

# Temporary, in the is installed here
set(SHELL_EXECUTABLE "C:/Program Files/PowerShell/latest/pwsh.exe")
set(PWSH_VERSION_DOCKER "latest")
set(SHELL_EXECUTABLE "C:/Program Files/PowerShell/${PWSH_VERSION_DOCKER}/pwsh.exe")

set(FILE_EXTENSION ".exe")
set(DOCKER_IMAGE_NAME "windows-testing")
Expand All @@ -60,6 +90,18 @@ elseif(WIN32)
string(REGEX REPLACE ".:" "C:" PROJECT_BINARY_DIR_C ${PROJECT_BINARY_DIR})
string(REGEX REPLACE ".:" "C:" fastcdr_INSTALL_DIR_C ${fastcdr_INSTALL_DIR})

set(PROJECT_BINATY_DIR_COMPOSE_VOLUME "${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR_C}")
set(fastcdr_LIB_DIR_COMPOSE_VOLUME "${fastcdr_INSTALL_DIR}/bin:${fastcdr_INSTALL_DIR_C}/bin")
set(CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME "${CMAKE_INSTALL_PREFIX}/bin:${CMAKE_INSTALL_PREFIX_C}/bin")

set(PATH_ENVIRONMENT_VARIABLE_COMPOSE "PATH: C:/Program Files/OpenSSL-Win64;${CMAKE_INSTALL_PREFIX_C}/bin;${fastcdr_INSTALL_DIR_C}/bin;C:/Windows/System32;C:/Windows/System32/downlevel;")
set(EXAMPLE_PREFIX_DIR_COMPOSE "${PROJECT_BINARY_DIR_C}/examples/cpp")
set(EXAMPLE_SUFFIX_DIR_COMPOSE "RelWithDebInfo")
set(FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE "${PROJECT_BINARY_DIR_C}/examples/cpp")
set(COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE "& $\$Env:EXAMPLE_DIR")
set(COMMAND_CONCATENATE_COMPOSE "&\" \"&")
set(COMMAND_BACKGROUND_JOB_COMPOSE "; Receive-Job 1 -Wait")

set(WIN_DOCKERFILE ${CMAKE_CURRENT_LIST_DIR}/windows/Dockerfile)
# Generate image for testing
add_custom_target(
Expand All @@ -77,21 +119,6 @@ else()
message(FATAL_ERROR "Unsupported platform")
endif()

# Configure TinyXML2 library path if installed in user library path
if(NOT (TINYXML2_FROM_SOURCE OR TINYXML2_FROM_THIRDPARTY))
message(STATUS "TINYXML2_LIBRARY " ${TINYXML2_LIBRARY})
file(GLOB TINYXML2_LIBRARY_DIRS LIST_DIRECTORIES false ${TINYXML2_LIBRARY})
if (TINYXML2_LIBRARY_DIRS)
list (GET TINYXML2_LIBRARY_DIRS 0 TINYXML2_LIBRARY_HEAD_DIR)
get_filename_component(TINYXML2_LIB_DIR ${TINYXML2_LIBRARY_HEAD_DIR} DIRECTORY)
message(STATUS "TINYXML2_LIB_DIR " ${TINYXML2_LIB_DIR})
set(TINYXML2_LIB_DIR_COMPOSE_VOLUME "- ${TINYXML2_LIB_DIR}:${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/fastdds:ro")
set(TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH ":${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/fastdds")
else()
message(FATAL_ERROR "Could not find a valid TinyXML 2 lirbary path.")
endif()
endif()

# Find all pytest files for testing
file(GLOB examples_python_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*world.py)

Expand Down
28 changes: 14 additions & 14 deletions test/examples/hello_world.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ services:
waitset-subscriber:
image: @DOCKER_IMAGE_NAME@
volumes:
- @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR_C@
- @fastcdr_INSTALL_DIR@/bin:@fastcdr_INSTALL_DIR_C@/bin
- @CMAKE_INSTALL_PREFIX@/bin:@CMAKE_INSTALL_PREFIX_C@/bin
- @PROJECT_BINATY_DIR_COMPOSE_VOLUME@
- @fastcdr_LIB_DIR_COMPOSE_VOLUME@
- @CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME@
@TINYXML2_LIB_DIR_COMPOSE_VOLUME@
environment:
PATH: C:/Program Files/OpenSSL-Win64;@CMAKE_INSTALL_PREFIX_C@/bin;@fastcdr_INSTALL_DIR_C@/bin;C:/Windows/System32;C:/Windows/System32/downlevel;
EXAMPLE_DIR: @PROJECT_BINARY_DIR_C@/examples/cpp/hello_world/RelWithDebInfo
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR_C@/examples/cpp/hello_world/hello_world_profile.xml
command: @SHELL_EXECUTABLE@ -c "& $$Env:EXAMPLE_DIR/hello_world@FILE_EXTENSION@ subscriber --waitset --samples 30"
@PATH_ENVIRONMENT_VARIABLE_COMPOSE@
EXAMPLE_DIR: @EXAMPLE_PREFIX_DIR_COMPOSE@/hello_world/@EXAMPLE_SUFFIX_DIR_COMPOSE@
FASTDDS_DEFAULT_PROFILES_FILE: @FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE@/hello_world/hello_world_profile.xml
command: @SHELL_EXECUTABLE@ -c "@COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE@/hello_world@FILE_EXTENSION@ subscriber --waitset --samples 10"

subscriber-publisher:
image: @DOCKER_IMAGE_NAME@
volumes:
- @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR_C@
- @fastcdr_INSTALL_DIR@/bin:@fastcdr_INSTALL_DIR_C@/bin
- @CMAKE_INSTALL_PREFIX@/bin:@CMAKE_INSTALL_PREFIX_C@/bin
- @PROJECT_BINATY_DIR_COMPOSE_VOLUME@
- @fastcdr_LIB_DIR_COMPOSE_VOLUME@
- @CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME@
@TINYXML2_LIB_DIR_COMPOSE_VOLUME@
environment:
PATH: C:/Program Files/OpenSSL-Win64;@CMAKE_INSTALL_PREFIX_C@/bin;@fastcdr_INSTALL_DIR_C@/bin;C:/Windows/System32;C:/Windows/System32/downlevel;
EXAMPLE_DIR: @PROJECT_BINARY_DIR_C@/examples/cpp/hello_world/RelWithDebInfo
FASTDDS_DEFAULT_PROFILES_FILE: @PROJECT_BINARY_DIR_C@/examples/cpp/hello_world/hello_world_profile.xml
command: @SHELL_EXECUTABLE@ -c "& $$Env:EXAMPLE_DIR/hello_world@FILE_EXTENSION@ publisher --samples 30 &" "& $$Env:EXAMPLE_DIR/hello_world@FILE_EXTENSION@ subscriber --samples 30; Receive-Job 1 -Wait"
@PATH_ENVIRONMENT_VARIABLE_COMPOSE@
EXAMPLE_DIR: @EXAMPLE_PREFIX_DIR_COMPOSE@/hello_world/@EXAMPLE_SUFFIX_DIR_COMPOSE@
FASTDDS_DEFAULT_PROFILES_FILE: @FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE@/hello_world/hello_world_profile.xml
command: @SHELL_EXECUTABLE@ -c "@COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE@/hello_world@FILE_EXTENSION@ publisher --samples 10 --matched 2 @COMMAND_CONCATENATE_COMPOSE@ @COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE@/hello_world@FILE_EXTENSION@ subscriber --samples 10@COMMAND_BACKGROUND_JOB_COMPOSE@"
depends_on:
- waitset-subscriber

0 comments on commit a31502a

Please sign in to comment.