Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions to model CLI (#893) #928

Merged
merged 5 commits into from
Jul 23, 2021
Merged
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
32 changes: 18 additions & 14 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ set(gui_sources
PARENT_SCOPE
)

ign_add_component(model SOURCES cmd/ModelCommandAPI.cc GET_TARGET_NAME model_lib_target)
ign_add_component(ign SOURCES ign.cc GET_TARGET_NAME ign_lib_target)
ign_add_component(ign
SOURCES
ign.cc
cmd/ModelCommandAPI.cc
GET_TARGET_NAME ign_lib_target)
target_link_libraries(${ign_lib_target}
PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
Expand Down Expand Up @@ -137,7 +140,14 @@ ign_build_tests(TYPE UNIT
ignition-gazebo${PROJECT_VERSION_MAJOR}
)

if(TARGET UNIT_ign_TEST)
# Command line tests need extra settings
foreach(CMD_TEST
UNIT_ign_TEST
UNIT_ModelCommandAPI_TEST)

if(NOT TARGET ${CMD_TEST})
continue()
endif()

# Running `ign gazebo` on macOS has problems when run with /usr/bin/ruby
# due to System Integrity Protection (SIP). Try to find ruby from
Expand All @@ -146,33 +156,27 @@ if(TARGET UNIT_ign_TEST)
find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin)
endif()

add_dependencies(UNIT_ign_TEST
add_dependencies(${CMD_TEST}
${ign_lib_target}
TestModelSystem
TestSensorSystem
TestWorldSystem
)

target_compile_definitions(UNIT_ign_TEST PRIVATE
target_compile_definitions(${CMD_TEST} PRIVATE
"BREW_RUBY=\"${BREW_RUBY} \"")

target_compile_definitions(UNIT_ign_TEST PRIVATE
target_compile_definitions(${CMD_TEST} PRIVATE
"IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"")

set(_env_vars)
list(APPEND _env_vars "IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf")
list(APPEND _env_vars "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:TestModelSystem>")

set_tests_properties(UNIT_ign_TEST PROPERTIES
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT "${_env_vars}")
endif()

if(TARGET UNIT_ModelCommandAPI_TEST)

target_compile_definitions(UNIT_ModelCommandAPI_TEST PRIVATE
"IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"")

endif()
endforeach()

if(NOT WIN32)
add_subdirectory(cmd)
Expand Down
9 changes: 9 additions & 0 deletions src/EntityComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ ComponentKey EntityComponentManager::CreateComponentImplementation(
const Entity _entity, const ComponentTypeId _componentTypeId,
const components::BaseComponent *_data)
{
// make sure the entity exists
if (!this->HasEntity(_entity))
{
ignerr << "Trying to create a component of type [" << _componentTypeId
<< "] attached to entity [" << _entity << "], but this entity does not "
<< "exist. This create component request will be ignored." << std::endl;
return ComponentKey();
}

// If type hasn't been instantiated yet, create a storage for it
if (!this->HasComponentType(_componentTypeId))
{
Expand Down
10 changes: 10 additions & 0 deletions src/EntityComponentManager_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ TEST_P(EntityComponentManagerFixture, EntitiesAndComponents)
EXPECT_FALSE(manager.EntityHasComponentType(entity, DoubleComponent::typeId));
EXPECT_FALSE(manager.EntityHasComponentType(entity2, IntComponent::typeId));

// Try to add a component to an entity that does not exist
EXPECT_FALSE(manager.HasEntity(kNullEntity));
EXPECT_FALSE(manager.EntityHasComponentType(kNullEntity,
IntComponent::typeId));
EXPECT_EQ(ComponentKey(), manager.CreateComponent<IntComponent>(kNullEntity,
IntComponent(123)));
EXPECT_FALSE(manager.HasEntity(kNullEntity));
EXPECT_FALSE(manager.EntityHasComponentType(kNullEntity,
IntComponent::typeId));

// Remove all entities
manager.RequestRemoveEntities();
EXPECT_EQ(3u, manager.EntityCount());
Expand Down
Loading