From 44f60f656704f077d84ec2126da0840129e290de Mon Sep 17 00:00:00 2001 From: methylDragon Date: Sun, 12 Jun 2022 22:06:40 -0700 Subject: [PATCH] Migrate ign executable to gz Signed-off-by: methylDragon --- README.md | 18 +++++++------- cmake/run_test.cmake | 6 ++--- etc/gz.bash_completion.sh | 35 ++++++++++++++++++++++++++ src/CMakeLists.txt | 52 +++++++++++++++++++-------------------- src/UNIT_gz_TEST.yaml.in | 4 +-- src/cmdUNIT_gz_TEST.rb | 2 +- src/gz.in | 18 +++++++------- tools/junit_fail.xml.in | 2 +- tools/junit_pass.xml.in | 2 +- 9 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 etc/gz.bash_completion.sh diff --git a/README.md b/README.md index 06f28b5..8607cb7 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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`: @@ -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 @@ -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: diff --git a/cmake/run_test.cmake b/cmake/run_test.cmake index a39fccb..f02a71b 100644 --- a/cmake/run_test.cmake +++ b/cmake/run_test.cmake @@ -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) @@ -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 diff --git a/etc/gz.bash_completion.sh b/etc/gz.bash_completion.sh new file mode 100644 index 0000000..6bf167a --- /dev/null +++ b/etc/gz.bash_completion.sh @@ -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" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc59ca1..927fdee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) @@ -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}) #=============================================================================== @@ -48,42 +48,42 @@ else() set(backward_library_name $) 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}/$/${executable_name}) +set(gz_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen) +set(gz_script_generated ${PROJECT_BINARY_DIR}/$/${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 $) - set(ign_script_configured_test ${PROJECT_BINARY_DIR}/test/bin/${executable_name}_before_gen) - set(ign_script_generated_test ${PROJECT_BINARY_DIR}/$/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}/$/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") @@ -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 ) diff --git a/src/UNIT_gz_TEST.yaml.in b/src/UNIT_gz_TEST.yaml.in index 8faeab7..10a3ba2 100644 --- a/src/UNIT_gz_TEST.yaml.in +++ b/src/UNIT_gz_TEST.yaml.in @@ -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 --- diff --git a/src/cmdUNIT_gz_TEST.rb b/src/cmdUNIT_gz_TEST.rb index 09ceaba..641d2b3 100755 --- a/src/cmdUNIT_gz_TEST.rb +++ b/src/cmdUNIT_gz_TEST.rb @@ -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 diff --git a/src/gz.in b/src/gz.in index 46c3a13..0b07429 100755 --- a/src/gz.in +++ b/src/gz.in @@ -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 @@ -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 [options]\n\n"\ +usage = 'The \'gz\' command provides a command line interface to the Gazebo'\ + " Tools.\n\n"\ + " gz [options]\n\n"\ "List of available commands:\n\n"\ " help: Print this help text.\n" @@ -200,7 +200,7 @@ usage += "\nOptions:\n\n"\ " --versions Show the available versions.\n"\ ' --commands Show the available commands.' -usage += "\nUse 'ign help ' to print help for a command.\n" +usage += "\nUse 'gz help ' to print help for a command.\n" OptionParser.new do |opts| opts.banner = usage @@ -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) diff --git a/tools/junit_fail.xml.in b/tools/junit_fail.xml.in index 18196ab..de88d69 100644 --- a/tools/junit_fail.xml.in +++ b/tools/junit_fail.xml.in @@ -1,7 +1,7 @@ - + diff --git a/tools/junit_pass.xml.in b/tools/junit_pass.xml.in index ee86976..9e92270 100644 --- a/tools/junit_pass.xml.in +++ b/tools/junit_pass.xml.in @@ -1,6 +1,6 @@ - +