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

Merge ign-plugin1 ➡️ main #98

Merged
merged 5 commits into from
Aug 1, 2022
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
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ gz_configure_project(VERSION_SUFFIX pre1)
# Set project-specific options
#============================================================================

if (UNIX AND NOT APPLE)
set (EXTRA_TEST_LIB_DEPS stdc++fs)
else()
set (EXTRA_TEST_LIB_DEPS)
endif()

#============================================================================
# Search for project-specific dependencies
#============================================================================
Expand All @@ -39,7 +45,7 @@ gz_find_package(DL
#--------------------------------------
# Find gz-tools
find_program(GZ_TOOLS_PROGRAM gz)

set(GZ_TOOLS_VER 2)

#--------------------------------------
# Find gz-utils
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Build | Status
-- | --
Test coverage | [![codecov](https://codecov.io/gh/gazebosim/gz-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/gazebosim/gz-plugin/branch/master)
Ubuntu Focal | [![Build Status](https://build.osrfoundation.org/job/ignition_plugin-ci-master-focal-amd64/badge/icon)](https://build.osrfoundation.org/job/ignition_plugin-ci-master-focal-amd64/)
Test coverage | [![codecov](https://codecov.io/gh/gazebosim/gz-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/gazebosim/gz-plugin/branch/main)
Ubuntu Focal | [![Build Status](https://build.osrfoundation.org/job/ignition_plugin-ci-main-focal-amd64/badge/icon)](https://build.osrfoundation.org/job/ignition_plugin-ci-main-focal-amd64/)
Homebrew | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_plugin-ci-main-homebrew-amd64)](https://build.osrfoundation.org/job/ignition_plugin-ci-main-homebrew-amd64)
Windows 7 | [![Build Status](https://build.osrfoundation.org/job/ignition_plugin-ci-master-windows7-amd64/badge/icon)](https://build.osrfoundation.org/job/ignition_plugin-ci-master-windows7-amd64/)
Windows 7 | [![Build Status](https://build.osrfoundation.org/job/ignition_plugin-ci-main-windows7-amd64/badge/icon)](https://build.osrfoundation.org/job/ignition_plugin-ci-main-windows7-amd64/)

** Library for registering plugin libraries and dynamically loading them at runtime.**
**Library for registering plugin libraries and dynamically loading them at runtime.**

Gazebo Plugin is a component in the Gazebo framework, a set
Gazebo Plugin is a component in the [Gazebo](http://gazebosim.org) framework, a set
of libraries designed to rapidly develop robot applications.

[http://gazebosim.org](http://gazebosim.org)
Expand Down
4 changes: 3 additions & 1 deletion loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ target_link_libraries(${loader}
gz_build_tests(
TYPE UNIT
SOURCES ${tests}
LIB_DEPS ${loader}
LIB_DEPS
${loader}
${EXTRA_TEST_LIB_DEPS}
TEST_LIST test_targets)

foreach(test ${test_targets})
Expand Down
10 changes: 10 additions & 0 deletions loader/conf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ configure_file(
# Install the yaml configuration files in an unversioned location.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/)

# Tack version onto and install the bash completion script
configure_file(
"plugin.bash_completion.sh"
"${CMAKE_CURRENT_BINARY_DIR}/plugin${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/plugin${PROJECT_VERSION_MAJOR}.bash_completion.sh
DESTINATION
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${GZ_TOOLS_VER}.completion.d)
51 changes: 51 additions & 0 deletions loader/conf/plugin.bash_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# Copyright (C) 2022 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# bash tab-completion

# This is a per-library function definition, used in conjunction with the
# top-level entry point in gz-tools.
GZ_PLUGIN_COMPLETION_LIST="
-i --info
-p --plugin
-v --verbose
-h --help
--version
"

function _gz_plugin
{
if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then
# Specify options (-*) word list for this subcommand
COMPREPLY=($(compgen -W "$GZ_PLUGIN_COMPLETION_LIST" \
-- "${COMP_WORDS[COMP_CWORD]}" ))
return
else
# Just use bash default auto-complete, because we never have two
# subcommands in the same line. If that is ever needed, change here to
# detect subsequent subcommands
COMPREPLY=($(compgen -o default -- "${COMP_WORDS[COMP_CWORD]}"))
return
fi
}

function _gz_plugin_flags
{
for word in $GZ_PLUGIN_COMPLETION_LIST; do
echo "$word"
done
}
38 changes: 38 additions & 0 deletions loader/src/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
*/

#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>

Expand Down Expand Up @@ -206,3 +208,39 @@ TEST(gzTest, PluginInfoVerboseDummyPlugins)
output.find("There are 2 aliases with a name collision"))
<< output;
}

//////////////////////////////////////////////////
/// \brief Check --help message and bash completion script for consistent flags
TEST(gzTest, PluginHelpVsCompletionFlags)
{
// Path to gz executable
std::string gz = std::string(GZ_PATH);

// Flags in help message
std::string helpOutput = custom_exec_str(gz + " plugin --help " +
g_gzVersion);

// Call the output function in the bash completion script
std::filesystem::path scriptPath = GZ_PLUGIN_SOURCE_DIR;
scriptPath = scriptPath / "loader" / "conf" / "plugin.bash_completion.sh";

// Equivalent to:
// sh -c "bash -c \". /path/to/plugin.bash_completion.sh; _gz_plugin_flags\""
std::string cmd = "bash -c \". " + scriptPath.string() +
"; _gz_plugin_flags\"";
std::string scriptOutput = custom_exec_str(cmd);

// Tokenize script output
std::istringstream iss(scriptOutput);
std::vector<std::string> flags((std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());

EXPECT_GT(flags.size(), 0u);

// Match each flag in script output with help message
for (const auto &flag : flags)
{
EXPECT_NE(std::string::npos, helpOutput.find(flag)) << helpOutput
<< std::endl << "Flag: " << flag;
}
}