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

2 ➡️ 5 #180

Merged
merged 4 commits into from
Jul 21, 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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ set(IGN_PLUGIN_MAJOR_VER ${ignition-plugin1_VERSION_MAJOR})
ign_find_package(ignition-tools
REQUIRED
PKGCONFIG "ignition-tools")
# Note that CLI files are installed regardless of whether the dependency is
# available during build time
find_program(HAVE_IGN_TOOLS ign)
set(IGN_TOOLS_VER 1)

#--------------------------------------
# Find ignition-transport
Expand Down
51 changes: 25 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Ignition Launch : Run and manage programs and plugins
# Gazebo Launch : Run and manage programs and plugins

**Maintainer:** nate AT openrobotics DOT org

[![GitHub open issues](https://img.shields.io/github/issues-raw/ignitionrobotics/ign-launch.svg)](https://github.com/ignitionrobotics/ign-launch/issues)
[![GitHub open pull requests](https://img.shields.io/github/issues-pr-raw/ignitionrobotics/ign-launch.svg)](https://github.com/ignitionrobotics/ign-launch/pulls)
[![GitHub open issues](https://img.shields.io/github/issues-raw/gazebosim/gz-launch.svg)](https://github.com/gazebosim/gz-launch/issues)
[![GitHub open pull requests](https://img.shields.io/github/issues-pr-raw/gazebosim/gz-launch.svg)](https://github.com/gazebosim/gz-launch/pulls)
[![Discourse topics](https://img.shields.io/discourse/https/community.gazebosim.org/topics.svg)](https://community.gazebosim.org)
[![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](https://www.apache.org/licenses/LICENSE-2.0)

Build | Status
-- | --
Test coverage | [![codecov](https://codecov.io/gh/ignitionrobotics/ign-launch/branch/ign-launch5/graph/badge.svg)](https://codecov.io/gh/ignitionrobotics/ign-launch)
Ubuntu Bionic | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_launch-ci-ign-launch5-bionic-amd64)](https://build.osrfoundation.org/job/ignition_launch-ci-ign-launch5-bionic-amd64)
Test coverage | [![codecov](https://codecov.io/gh/gazebosim/gz-launch/branch/ign-launch5/graph/badge.svg)](https://codecov.io/gh/gazebosim/gz-launch/branch/ign-launch5)
Ubuntu Focal | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_launch-ci-ign-launch5-focal-amd64)](https://build.osrfoundation.org/job/ignition_launch-ci-ign-launch5-focal-amd64)
Homebrew | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_launch-ci-ign-launch5-homebrew-amd64)](https://build.osrfoundation.org/job/ignition_launch-ci-ign-launch5-homebrew-amd64)
Windows | [![Build Status](https://build.osrfoundation.org/job/ign_launch-ign-5-win/badge/icon)](https://build.osrfoundation.org/job/ign_launch-ign-5-win/)

Ignition Launch, a component of [Ignition
Robotics](https://ignitionrobotics.org), provides a command line interface
Gazebo Launch, a component of [Gazebo](https://gazebosim.org), provides a command line interface
to run and manager application and plugins.

# Table of Contents
Expand Down Expand Up @@ -50,15 +49,15 @@ to run and manager application and plugins.

# Features

Ignition Launch is used to run and manage plugins and programs. A
Gazebo Launch is used to run and manage plugins and programs. A
configuration script can be used to specify which programs and plugins to
execute. Alternatively, individual programs and plugins can be run from the
command line. Example configuration scripts are located in the `examples`
directory.

1. Automatic ERB parsing of configuration files.
1. Pass arguments to launch files from the command line.
1. Plugins to launch Gazebo, joystick interface, and a websocket server for
1. Plugins to launch Gazebo Sim, joystick interface, and a websocket server for
simulation.

# Install
Expand Down Expand Up @@ -93,7 +92,7 @@ necessary prerequisites followed by building from source.
sudo apt-get -y install cmake build-essential curl cppcheck g++-8 doxygen ruby-ronn libtinyxml2-dev software-properties-common
```

1. Install required Ignition libraries
1. Install required Gazebo libraries

```
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
Expand All @@ -120,28 +119,28 @@ necessary prerequisites followed by building from source.
1. Clone the repository

```
git clone https://github.com/ignitionrobotics/ign-launch
git clone https://github.com/gazebosim/gz-launch
```

2. Configure and build

```
cd ign-launch; mkdir build; cd build; cmake ..; make
cd gz-launch; mkdir build; cd build; cmake ..; make
```

3. Optionally, install Ignition Launch
3. Optionally, install Gazebo Launch

```
sudo make install
```

# Usage

Sample launch configuration files are in the [examples directory](https://github.com/ignitionrobotics/ign-launch/blob/main/examples/).
Sample launch configuration files are in the [examples directory](https://github.com/gazebosim/gz-launch/blob/ign-launch5/examples/).

**Example**

1. Run a configuration that launches [Gazebo](https://ignitionrobotics.org/libs/gazebo).
1. Run a configuration that launches [Gazebo Sim](https://gazebosim.org/libs/gazebo).

```
ign launch gazebo.ign
Expand All @@ -153,7 +152,7 @@ In the event that the installation is a mix of Debian and from source, command
line tools from `ign-tools` may not work correctly.

A workaround for a single package is to define the environment variable
`IGN_CONFIG_PATH` to point to the location of the Ignition library installation,
`IGN_CONFIG_PATH` to point to the location of the Gazebo library installation,
where the YAML file for the package is found, such as
```
export IGN_CONFIG_PATH=/usr/local/share/ignition
Expand All @@ -162,7 +161,7 @@ export IGN_CONFIG_PATH=/usr/local/share/ignition
However, that environment variable only takes a single path, which means if the
installations from source are in different locations, only one can be specified.

Another workaround for working with multiple Ignition libraries on the command
Another workaround for working with multiple Gazebo libraries on the command
line is using symbolic links to each library's YAML file.
```
mkdir ~/.ignition/tools/configs -p
Expand All @@ -174,11 +173,11 @@ ln -s /usr/local/share/ignition/transportlog7.yaml .
export IGN_CONFIG_PATH=$HOME/.ignition/tools/configs
```

This issue is tracked [here](https://github.com/ignitionrobotics/ign-tools/issues/8).
This issue is tracked [here](https://github.com/gazebosim/gz-tools/issues/8).

# Documentation

API and tutorials can be found at [https://ignitionrobotics.org/libs/launch](https://ignitionrobotics.org/libs/launch).
API and tutorials can be found at [https://gazebosim.org/libs/launch](https://gazebosim.org/libs/launch).

You can also generate the documentation from a clone of this repository by following these steps.

Expand All @@ -191,13 +190,13 @@ You can also generate the documentation from a clone of this repository by follo
2. Clone the repository

```
git clone https://github.com/ignitionrobotics/ign-launch
git clone https://github.com/gazebosim/gz-launch
```

3. Configure and build the documentation.

```
cd ign-launch; mkdir build; cd build; cmake ../; make doc
cd gz-launch; mkdir build; cd build; cmake ../; make doc
```

4. View the documentation by running the following command from the build directory.
Expand Down Expand Up @@ -229,7 +228,7 @@ Follow these steps to run tests and static code analysis in your clone of this r
Refer to the following table for information about important directories and files in this repository.

```
ign-launch
gz-launch
├── examples Example launch configurations.
├── include/ignition/launch Header files.
├── src Source files and unit tests.
Expand All @@ -244,17 +243,17 @@ ign-launch

# Contributing

Please see the [contribution guide](https://ignitionrobotics.org/docs/all/contributing).
Please see the [contribution guide](https://gazebosim.org/docs/all/contributing).

# Code of Conduct

Please see
[CODE_OF_CONDUCT.md](https://github.com/ignitionrobotics/ign-gazebo/blob/main/CODE_OF_CONDUCT.md).
[CODE_OF_CONDUCT.md](https://github.com/gazebosim/gz-gazebo/blob/main/CODE_OF_CONDUCT.md).

# Versioning

This library uses [Semantic Versioning](https://semver.org/). Additionally, this library is part of the [Ignition Robotics project](https://ignitionrobotics.org) which periodically releases a versioned set of compatible and complimentary libraries. See the [Ignition Robotics website](https://ignitionrobotics.org) for version and release information.
This library uses [Semantic Versioning](https://semver.org/). Additionally, this library is part of the [Gazebo project](https://gazebosim.org) which periodically releases a versioned set of compatible and complimentary libraries. See the [Gazebo website](https://gazebosim.org) for version and release information.

# License

This library is licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0). See also the [LICENSE](https://github.com/ignitionrobotics/ign-launch/blob/main/LICENSE) file.
This library is licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0). See also the [LICENSE](https://github.com/gazebosim/gz-launch/blob/main/LICENSE) file.
26 changes: 26 additions & 0 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,34 @@ if (TARGET UNIT_ign_TEST)
ENVIRONMENT
"IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
)

# Running `ign launch` on macOS has problems when run with /usr/bin/ruby
# due to System Integrity Protection (SIP). Try to find ruby from
# homebrew as a workaround.
if (APPLE)
find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin)
endif()

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

target_compile_definitions(UNIT_ign_TEST PRIVATE
"IGN_PATH=\"${HAVE_IGN_TOOLS}\"")
endif()

#===============================================================================
# Bash completion

# Tack version onto and install the bash completion script
configure_file(
"launch.bash_completion.sh"
"${CMAKE_CURRENT_BINARY_DIR}/launch${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/launch${PROJECT_VERSION_MAJOR}.bash_completion.sh
DESTINATION
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${IGN_TOOLS_VER}.completion.d)

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#define pclose _pclose
#endif

static const std::string kIgnCommand(
std::string(BREW_RUBY) + std::string(IGN_PATH) + " launch ");

/////////////////////////////////////////////////
std::string customExecStr(std::string _cmd)
{
Expand All @@ -52,6 +55,7 @@ std::string customExecStr(std::string _cmd)
return result;
}

/////////////////////////////////////////////////
std::string get_config_path(const std::string filename)
{
return(ignition::common::joinPaths(
Expand Down Expand Up @@ -101,3 +105,34 @@ TEST(CmdLine, EchoBadErb)
std::string output = customExecStr(cmd);
EXPECT_NE(std::string::npos, output.find("is wrong for erb")) << output;
}

//////////////////////////////////////////////////
/// \brief Check --help message and bash completion script for consistent flags
TEST(CmdLine, HelpVsCompletionFlags)
{
// Flags in help message
std::string helpOutput = customExecStr(kIgnCommand + "--help");

// Call the output function in the bash completion script
std::string scriptPath = ignition::common::joinPaths(
std::string(PROJECT_SOURCE_PATH),
"src", "cmd", "launch.bash_completion.sh");

// Equivalent to:
// sh -c "bash -c \". /path/to/launch.bash_completion.sh; _gz_launch_flags\""
std::string cmd = "bash -c \". " + scriptPath + "; _gz_launch_flags\"";
std::string scriptOutput = customExecStr(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;
}
}
51 changes: 51 additions & 0 deletions src/cmd/launch.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 ign-tools.

GZ_LAUNCH_COMPLETION_LIST="
-h --help
--help-all
--version
-v --verbose
"

function _gz_launch
{
if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then
# Specify options (-*) word list for this subcommand
COMPREPLY=($(compgen -W "$GZ_LAUNCH_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_launch_flags
{
for word in $GZ_LAUNCH_COMPLETION_LIST; do
echo "$word"
done
}