Skip to content

Commit

Permalink
Migrate ign executable to gz
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Jun 13, 2022
1 parent 9ee6e70 commit 44f60f6
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 52 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Ubuntu Bionic | [![Build Status](https://build.osrfoundation.org/buildStatus/ico
Homebrew | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ignition_tools-ci-ign-tools2-homebrew-amd64)](https://build.osrfoundation.org/job/ignition_tools-ci-ign-tools2-homebrew-amd64)
Windows | [![Build Status](https://build.osrfoundation.org/buildStatus/icon?job=ign_tools-ign-1-win)](https://build.osrfoundation.org/job/ign_tools-ign-1-win)

Ignition tools provide the `ign` command line tool that accepts multiple
Ignition tools provide the `gz` command line tool that accepts multiple
subcommands. Each subcommand is implemented in a plugin that belongs to a
specific Ignition project. For example, all the commands that start with
`ign topic ...` will be implemented by the Gazebo Transport library.
`gz topic ...` will be implemented by the Gazebo Transport library.

[http://gazebosim.org](http://gazebosim.org)

Expand All @@ -32,7 +32,7 @@ We recommend following the Binary Installation instructions to get up and runnin

The Source Installation instructions should be used if you need the very latest software improvements, you need to modify the code, or you plan to make a contribution.

Windows support: Currently, the library builds on Windows, but the `ign` command-line tool is not readily functional. We are investigating this.
Windows support: Currently, the library builds on Windows, but the `gz` command-line tool is not readily functional. We are investigating this.

## Binary Installation

Expand All @@ -53,8 +53,8 @@ Miniconda suffices.

Create if necessary, and activate a Conda environment:
```
conda create -n ign-ws
conda activate ign-ws
conda create -n gz-ws
conda activate gz-ws
```

Install `ignition-tools`:
Expand Down Expand Up @@ -90,9 +90,9 @@ sudo make install

### Bash auto-completion

Source the [etc/ign.bash_completion.sh](etc/ign.bash_completion.sh) script in your bash terminal window to enable auto-complete:
Source the [etc/gz.bash_completion.sh](etc/gz.bash_completion.sh) script in your bash terminal window to enable auto-complete:
~~~
. etc/ign.bash_completion.sh
. etc/gz.bash_completion.sh
~~~

### Uninstallation
Expand All @@ -112,8 +112,8 @@ Miniconda suffices.

Create if necessary, and activate a Conda environment:
```
conda create -n ign-ws
conda activate ign-ws
conda create -n gz-ws
conda activate gz-ws
```

Install prerequisites:
Expand Down
6 changes: 3 additions & 3 deletions cmake/run_test.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This script is part of the unit test mechanism for ign-tools.
execute_process(COMMAND ruby ${IGN_SCRIPT}
execute_process(COMMAND ruby ${GZ_SCRIPT}
${TEST_NAME}
OUTPUT_VARIABLE TEST_OUTPUT
ERROR_VARIABLE TEST_ERROR)
Expand All @@ -12,8 +12,8 @@ execute_process(COMMAND
"../test_results/${TEST_NAME}.xml"
)

if (${TEST_OUTPUT} MATCHES "Test executed" AND NOT
((${TEST_OUTPUT} MATCHES "Library error") OR
if (${TEST_OUTPUT} MATCHES "Test executed" AND NOT
((${TEST_OUTPUT} MATCHES "Library error") OR
(${TEST_ERROR} MATCHES "Library error")))
execute_process(COMMAND
${CMAKE_COMMAND} -E copy
Expand Down
35 changes: 35 additions & 0 deletions etc/gz.bash_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# gz bash completion

function _gz
{
local prev cur cmd opts
local gz="$1"
COMPREPLY=()
cur="$2"
prev="$3"

# searching for the command
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then
cmd="${COMP_WORDS[i]}"
break
fi
done

if [[ "$cur" == -* ]] || [[ "$prev" != "gz" ]]; then

if [[ "$cmd" == "help" ]]; then
opts=$(gz --commands)
else
COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}" ))
complete -o filenames -o nospace -F "_gz" "gz"
return
fi

else
opts="$(gz --commands) help"
fi

COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F "_gz" "gz"
52 changes: 26 additions & 26 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ else()
set(ENV_PATH_DELIMITER ":")
endif()

set(executable_name "ign")
set(executable_name "gz")

if(WIN32)
set(executable_name "ign.rb")
set(executable_name "gz.rb")
endif()

if(MSVC)
Expand All @@ -34,9 +34,9 @@ if(MSVC)
target_compile_options(backward PUBLIC /wd4267)
target_compile_options(backward PUBLIC /wd4996)
endif()
install (TARGETS backward
install (TARGETS backward
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${BIN_INSTALL_DIR})

#===============================================================================
Expand All @@ -48,42 +48,42 @@ else()
set(backward_library_name $<TARGET_FILE_NAME:backward>)
endif()

# Two steps to create `ign`, First using `configure_file`, to interpolate cmake variables. Then
# Two steps to create `gz`, First using `configure_file`, to interpolate cmake variables. Then
# use `file(GENERATE ...)` to use generator expressions
set(ign_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
set(ign_script_generated ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name})
set(gz_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
set(gz_script_generated ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name})

configure_file(ign.in ${ign_script_configured})
file(GENERATE OUTPUT ${ign_script_generated} INPUT ${ign_script_configured})
install (PROGRAMS ${ign_script_generated} DESTINATION ${BIN_INSTALL_DIR})
configure_file(gz.in ${gz_script_configured})
file(GENERATE OUTPUT ${gz_script_generated} INPUT ${gz_script_configured})
install (PROGRAMS ${gz_script_generated} DESTINATION ${BIN_INSTALL_DIR})

if(WIN32)
# On Windows also install the executable as ign
# to permit to invoke ign via Git Bash
# On Windows also install the executable as gz
# to permit to invoke gz via Git Bash
# see https://github.com/gazebosim/gz-tools/issues/70
install (PROGRAMS ${ign_script_generated} DESTINATION ${BIN_INSTALL_DIR} RENAME ign)
# On Windows also install the ign.bat wrapper script to permit to
# invoke ign via Command Prompt or Powershell
install (PROGRAMS ign.bat DESTINATION ${BIN_INSTALL_DIR})
install (PROGRAMS ${gz_script_generated} DESTINATION ${BIN_INSTALL_DIR} RENAME gz)

# On Windows also install the gz.bat wrapper script to permit to
# invoke gz via Command Prompt or Powershell
install (PROGRAMS gz.bat DESTINATION ${BIN_INSTALL_DIR})
endif()

#===============================================================================
# BEGIN TEST ign command
# BEGIN TEST gz command
# Generate the ruby script for internal testing.
if(BUILD_TESTING)
set(backward_library_name $<TARGET_FILE:backward>)
set(ign_script_configured_test ${PROJECT_BINARY_DIR}/test/bin/${executable_name}_before_gen)
set(ign_script_generated_test ${PROJECT_BINARY_DIR}/$<CONFIG>/test/bin/${executable_name})
set(gz_script_configured_test ${PROJECT_BINARY_DIR}/test/bin/${executable_name}_before_gen)
set(gz_script_generated_test ${PROJECT_BINARY_DIR}/$<CONFIG>/test/bin/${executable_name})

# Two steps to create `ign`, First using `configure_file`, to interpolate cmake variables. Then
# Two steps to create `gz`, First using `configure_file`, to interpolate cmake variables. Then
# use `file(GENERATE ...)` to use generator expressions
configure_file(ign.in ${ign_script_configured_test})
file(GENERATE OUTPUT ${ign_script_generated_test} INPUT ${ign_script_configured_test})
configure_file(gz.in ${gz_script_configured_test})
file(GENERATE OUTPUT ${gz_script_generated_test} INPUT ${gz_script_configured_test})

set(TEST_NAME UNIT_ign_TEST)
set(TEST_NAME UNIT_gz_TEST)

set(ign_library_path "${PROJECT_SOURCE_DIR}/src/cmd${TEST_NAME}.rb")
set(gz_library_path "${PROJECT_SOURCE_DIR}/src/cmd${TEST_NAME}.rb")

set(yaml_output_dir "${PROJECT_BINARY_DIR}/test/conf" )
set(yaml_output_configured_test "${yaml_output_dir}/${TEST_NAME}.yaml.configured")
Expand Down Expand Up @@ -111,7 +111,7 @@ if(BUILD_TESTING)
NAME ${TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DTEST_NAME=${TEST_NAME}
-DIGN_SCRIPT=${ign_script_generated_test}
-DGZ_SCRIPT=${gz_script_generated_test}
-P ${PROJECT_SOURCE_DIR}/cmake/run_test.cmake
)

Expand Down
4 changes: 2 additions & 2 deletions src/UNIT_gz_TEST.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
format: 1.0.0
library_name: @PROJECT_NAME@
library_version: ''
library_path: @ign_library_path@
library_path: @gz_library_path@
commands:
- UNIT_ign_TEST : Test command
- UNIT_gz_TEST : Test command
---

2 changes: 1 addition & 1 deletion src/cmdUNIT_gz_TEST.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require 'optparse'

# Constants.
COMMANDS = { 'tools' => 'Test ign tools.\n\n' }.freeze
COMMANDS = { 'tools' => 'Test gz tools.\n\n' }.freeze

# Test Cmd class
class Cmd
Expand Down
18 changes: 9 additions & 9 deletions src/gz.in
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ conf_dirs.each do |conf_directory|
end
end

# Check that we have at least one configuration file with ign commands.
# Check that we have at least one configuration file with gz commands.
unless yaml_found
puts "I cannot find any available 'ign' command:\n"\
"\t* Did you install any ignition library?\n"\
puts "I cannot find any available 'gz' command:\n"\
"\t* Did you install any gazebo library?\n"\
"\t* Did you set the GZ_CONFIG_PATH environment variable?\n"\
"\t E.g.: export GZ_CONFIG_PATH=$HOME/local/share/ignition\n"
"\t E.g.: export GZ_CONFIG_PATH=$HOME/local/share/gz\n"
exit(-1)
end

Expand All @@ -176,9 +176,9 @@ commands = sorted_commands
# puts commands

# Read the command line arguments.
usage = 'The \'ign\' command provides a command line interface to the ignition'\
" tools.\n\n"\
" ign <command> [options]\n\n"\
usage = 'The \'gz\' command provides a command line interface to the Gazebo'\
" Tools.\n\n"\
" gz <command> [options]\n\n"\
"List of available commands:\n\n"\
" help: Print this help text.\n"

Expand All @@ -200,7 +200,7 @@ usage += "\nOptions:\n\n"\
" --versions Show the available versions.\n"\
' --commands Show the available commands.'

usage += "\nUse 'ign help <command>' to print help for a command.\n"
usage += "\nUse 'gz help <command>' to print help for a command.\n"

OptionParser.new do |opts|
opts.banner = usage
Expand Down Expand Up @@ -301,6 +301,6 @@ require cmd_rb_library
cmd = Cmd.new

# Set the process title to something nice.
Process.setproctitle("ign #{ARGV.join(' ')}")
Process.setproctitle("gz #{ARGV.join(' ')}")

cmd.execute(ARGV)
2 changes: 1 addition & 1 deletion tools/junit_fail.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="1" disabled="0" errors="0" timestamp="@TEST_TIME@" time="0" name="AllTests">
<testsuite name="@TEST_NAME@" tests="1" failures="1" disabled="0" errors="0" time="0">
<testcase name="ign_script" status="run" time="0" classname="@TEST_NAME@">
<testcase name="GZ_SCRIPT" status="run" time="0" classname="@TEST_NAME@">
<failure type="Standard" message="@TEST_NAME@ failed." />
</testcase>
</testsuite>
Expand Down
2 changes: 1 addition & 1 deletion tools/junit_pass.xml.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" timestamp="@TEST_TIME@" time="0" name="AllTests">
<testsuite name="@TEST_NAME@" tests="1" failures="0" disabled="0" errors="0" time="0">
<testcase name="ign_script" status="run" time="0" classname="@TEST_NAME@" />
<testcase name="GZ_SCRIPT" status="run" time="0" classname="@TEST_NAME@" />
</testsuite>
</testsuites>

0 comments on commit 44f60f6

Please sign in to comment.