Skip to content

Commit

Permalink
Release micro-ROS Foxy (#9)
Browse files Browse the repository at this point in the history
* Avoid logging on build time based on RCutils flags (#6)

* Add RCL_YAML_PARSER and RCL_LOGGING CMake options.

* Replace RCL_YAML_PARSER by RCL_COMMAND_LINE_ENABLED and RCL_LOGGING by RCL_LOGGING_ENABLED.

* Disabled logging fix

* Fix remapping (#7)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Co-authored-by: julibert <julianbermudez@eprosima.com>
  • Loading branch information
3 people committed Sep 17, 2020
1 parent 055d7eb commit a519483
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 14 deletions.
53 changes: 42 additions & 11 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ cmake_minimum_required(VERSION 3.5)

project(rcl)

option(RCL_COMMAND_LINE_ENABLED "Enable/disable the rcl_yaml_param_parser tool" OFF)
option(RCL_LOGGING_ENABLED "Enable/disable logging" OFF)

find_package(ament_cmake_ros REQUIRED)

find_package(rcl_interfaces REQUIRED)
find_package(rcl_yaml_param_parser REQUIRED)
find_package(rcutils REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_implementation REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(tracetools REQUIRED)

if(RCL_COMMAND_LINE_ENABLED)
find_package(rcl_yaml_param_parser REQUIRED)
endif()

include(cmake/rcl_set_symbol_visibility_hidden.cmake)
include(cmake/get_default_rcl_logging_implementation.cmake)
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)

if(RCL_LOGGING_ENABLED)
include(cmake/get_default_rcl_logging_implementation.cmake)
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)
endif()

# Default to C11
if(NOT CMAKE_C_STANDARD)
Expand All @@ -31,7 +40,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

set(${PROJECT_NAME}_sources
src/rcl/arguments.c
$<$<BOOL:${RCL_COMMAND_LINE_ENABLED}>:src/rcl/arguments.c>
src/rcl/client.c
src/rcl/common.c
src/rcl/context.c
Expand All @@ -45,12 +54,12 @@ set(${PROJECT_NAME}_sources
src/rcl/lexer.c
src/rcl/lexer_lookahead.c
src/rcl/localhost.c
src/rcl/logging_rosout.c
src/rcl/logging.c
$<$<BOOL:${RCL_LOGGING_ENABLED}>:src/rcl/logging_rosout.c>
$<$<BOOL:${RCL_LOGGING_ENABLED}>:src/rcl/logging.c>
src/rcl/node.c
src/rcl/node_options.c
src/rcl/publisher.c
src/rcl/remap.c
$<$<BOOL:${RCL_COMMAND_LINE_ENABLED}>:src/rcl/remap.c>
src/rcl/rmw_implementation_identifier_check.c
src/rcl/security.c
src/rcl/service.c
Expand All @@ -69,15 +78,31 @@ target_include_directories(${PROJECT_NAME} PUBLIC
# specific order: dependents before dependencies
ament_target_dependencies(${PROJECT_NAME}
"rcl_interfaces"
"rcl_yaml_param_parser"
"rcutils"
"rmw"
"rmw_implementation"
${RCL_LOGGING_IMPL}
"rosidl_runtime_c"
"tracetools"
)

if(RCL_COMMAND_LINE_ENABLED)
ament_target_dependencies(${PROJECT_NAME}
"rcl_yaml_param_parser"
)
endif()

if(RCL_LOGGING_ENABLED)
ament_target_dependencies(${PROJECT_NAME}
${RCL_LOGGING_IMPL}
)
endif()

target_compile_definitions(${PROJECT_NAME}
PRIVATE
$<$<BOOL:${RCL_COMMAND_LINE_ENABLED}>:RCL_COMMAND_LINE_ENABLED>
$<$<BOOL:${RCL_LOGGING_ENABLED}>:RCL_LOGGING_ENABLED>
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_BUILDING_DLL")
Expand All @@ -102,14 +127,20 @@ ament_export_targets(${PROJECT_NAME})

ament_export_dependencies(ament_cmake)
ament_export_dependencies(rcl_interfaces)
ament_export_dependencies(rcl_yaml_param_parser)
ament_export_dependencies(rmw_implementation)
ament_export_dependencies(rmw)
ament_export_dependencies(rcutils)
ament_export_dependencies(${RCL_LOGGING_IMPL})
ament_export_dependencies(rosidl_runtime_c)
ament_export_dependencies(tracetools)

if(RCL_COMMAND_LINE_ENABLED)
ament_export_dependencies(rcl_yaml_param_parser)
endif()

if(RCL_LOGGING_ENABLED)
ament_export_dependencies(${RCL_LOGGING_IMPL})
endif()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
Expand Down
4 changes: 4 additions & 0 deletions rcl/include/rcl/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extern "C"
#include "rmw/init.h"

#include "rcl/allocator.h"
#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/arguments.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcl/init_options.h"
#include "rcl/macros.h"
#include "rcl/types.h"
Expand Down Expand Up @@ -107,9 +109,11 @@ struct rcl_context_impl_t;
*/
typedef struct rcl_context_t
{
#ifdef RCL_COMMAND_LINE_ENABLED
/// Global arguments for all nodes which share this context.
/** Typically generated by the parsing of argc/argv in `rcl_init()`. */
rcl_arguments_t global_arguments;
#endif // RCL_COMMAND_LINE_ENABLED

/// Implementation specific pointer.
struct rcl_context_impl_t * impl;
Expand Down
2 changes: 2 additions & 0 deletions rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extern "C"
#include <stdint.h>

#include "rcl/allocator.h"
#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/arguments.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcl/context.h"
#include "rcl/macros.h"
#include "rcl/node_options.h"
Expand Down
5 changes: 5 additions & 0 deletions rcl/include/rcl/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ extern "C"
#endif

#include "rcl/allocator.h"
#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/arguments.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcl/macros.h"

#include "rcl/domain_id.h"

Expand Down Expand Up @@ -57,8 +60,10 @@ typedef struct rcl_node_options_t
/// If false then only use arguments in this struct, otherwise use global arguments also.
bool use_global_arguments;

#ifdef RCL_COMMAND_LINE_ENABLED
/// Command line arguments that apply only to this node.
rcl_arguments_t arguments;
#endif // RCL_COMMAND_LINE_ENABLED

/// Flag to enable rosout for this node
bool enable_rosout;
Expand Down
7 changes: 7 additions & 0 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ extern "C"

#include "rcl/error_handling.h"
#include "rcl/expand_topic_name.h"
#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/remap.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcutils/logging_macros.h"
#include "rcutils/stdatomic_helper.h"
#include "rmw/error_handling.h"
Expand Down Expand Up @@ -130,6 +132,7 @@ rcl_client_init(
ret = RCL_RET_ERROR;
goto cleanup;
}
#ifdef RCL_COMMAND_LINE_ENABLED
rcl_arguments_t * global_args = NULL;
if (node_options->use_global_arguments) {
global_args = &(node->context->global_arguments);
Expand All @@ -143,6 +146,10 @@ rcl_client_init(
remapped_service_name = expanded_service_name;
expanded_service_name = NULL;
}
#else
remapped_service_name = (char *)allocator->allocate(strlen(expanded_service_name) + 1, allocator->state);
memcpy(remapped_service_name, expanded_service_name, strlen(expanded_service_name) + 1);
#endif // RCL_COMMAND_LINE_ENABLED

// Validate the expanded service name.
int validation_result;
Expand Down
4 changes: 4 additions & 0 deletions rcl/src/rcl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ rcl_get_zero_initialized_context(void)
.instance_id_storage = {0},
};
// this is not constexpr so it cannot be in the struct initialization
#ifdef RCL_COMMAND_LINE_ENABLED
context.global_arguments = rcl_get_zero_initialized_arguments();
#endif // RCL_COMMAND_LINE_ENABLED
// ensure assumption about static storage
static_assert(
sizeof(context.instance_id_storage) >= sizeof(atomic_uint_least64_t),
Expand Down Expand Up @@ -103,6 +105,7 @@ __cleanup_context(rcl_context_t * context)
// reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive)
rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);

#ifdef RCL_COMMAND_LINE_ENABLED
// clean up global_arguments if initialized
if (NULL != context->global_arguments.impl) {
rcl_ret_t ret = rcl_arguments_fini(&(context->global_arguments));
Expand All @@ -115,6 +118,7 @@ __cleanup_context(rcl_context_t * context)
rcl_reset_error();
}
}
#endif // RCL_COMMAND_LINE_ENABLED

// if impl is null, nothing else can be cleaned up
if (NULL != context->impl) {
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extern "C"

#include "rcl/error_handling.h"
#include "rcl/expand_topic_name.h"
#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/remap.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcutils/logging_macros.h"
#include "rmw/error_handling.h"
#include "rmw/validate_full_topic_name.h"
Expand Down
12 changes: 12 additions & 0 deletions rcl/src/rcl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ extern "C"

#include "tracetools/tracetools.h"

#ifdef RCL_COMMAND_LINE_ENABLED
#include "rcl/arguments.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "rcl/domain_id.h"
#include "rcl/error_handling.h"
#include "rcl/localhost.h"
#ifdef RCL_LOGGING_ENABLED
#include "rcl/logging.h"
#endif // RCL_LOGGING_ENABLED
#include "rcl/security.h"
#include "rcl/validate_enclave_name.h"

#ifdef RCL_COMMAND_LINE_ENABLED
#include "./arguments_impl.h"
#endif // RCL_COMMAND_LINE_ENABLED
#include "./common.h"
#include "./context_impl.h"
#include "./init_options_impl.h"
Expand Down Expand Up @@ -80,8 +86,10 @@ rcl_init(
return RCL_RET_ALREADY_INIT;
}

#ifdef RCL_COMMAND_LINE_ENABLED
// Zero initialize global arguments.
context->global_arguments = rcl_get_zero_initialized_arguments();
#endif // RCL_COMMAND_LINE_ENABLED

// Setup impl for context.
// use zero_allocate so the cleanup function will not try to clean up uninitialized parts later
Expand Down Expand Up @@ -123,13 +131,15 @@ rcl_init(
}
}

#ifdef RCL_COMMAND_LINE_ENABLED
// Parse the ROS specific arguments.
ret = rcl_parse_arguments(argc, argv, allocator, &context->global_arguments);
if (RCL_RET_OK != ret) {
fail_ret = ret;
RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "Failed to parse global arguments");
goto fail;
}
#endif // RCL_COMMAND_LINE_ENABLED

// Set the instance id.
uint64_t next_instance_id = rcutils_atomic_fetch_add_uint64_t(&__rcl_next_unique_id, 1);
Expand Down Expand Up @@ -167,6 +177,7 @@ rcl_init(
}
}

#ifdef RCL_COMMAND_LINE_ENABLED
if (context->global_arguments.impl->enclave) {
context->impl->init_options.impl->rmw_init_options.enclave = rcutils_strdup(
context->global_arguments.impl->enclave,
Expand All @@ -175,6 +186,7 @@ rcl_init(
context->impl->init_options.impl->rmw_init_options.enclave = rcutils_strdup(
"/", context->impl->allocator);
}
#endif RCL_COMMAND_LINE_ENABLED
int validation_result;
size_t invalid_index;
ret = rcl_validate_enclave_name(
Expand Down
10 changes: 7 additions & 3 deletions rcl/src/rcl/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ rcl_logging_configure_with_output_handler(
g_logging_allocator = *allocator;
int default_level = global_args->impl->log_level;
const char * config_file = global_args->impl->external_log_config_file;
g_rcl_logging_stdout_enabled = !global_args->impl->log_stdout_disabled;
g_rcl_logging_rosout_enabled = !global_args->impl->log_rosout_disabled;
g_rcl_logging_ext_lib_enabled = !global_args->impl->log_ext_lib_disabled;
bool global_disable = false;
#ifdef RCUTILS_NO_LOGGING
global_disable = true;
#endif
g_rcl_logging_stdout_enabled = !global_args->impl->log_stdout_disabled && !global_disable;
g_rcl_logging_rosout_enabled = !global_args->impl->log_rosout_disabled && !global_disable;
g_rcl_logging_ext_lib_enabled = !global_args->impl->log_ext_lib_disabled && !global_disable;
rcl_ret_t status = RCL_RET_OK;
g_rcl_logging_num_out_handlers = 0;

Expand Down
Loading

0 comments on commit a519483

Please sign in to comment.