From 0921c748151c5989643d204f61f77a1e476a1d77 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 25 Jan 2021 09:10:22 -0600 Subject: [PATCH 01/22] Add standalone executables Signed-off-by: Michael Carroll --- src/CMakeLists.txt | 11 +-- src/ign/CMakeLists.txt | 12 +++ src/{ => ign}/ign.cc | 0 src/{ => ign}/ign.hh | 0 src/{ => ign}/ign_TEST.cc | 0 src/{ => ign}/ign_src_TEST.cc | 0 src/ign/transport_main.cc | 174 ++++++++++++++++++++++++++++++++++ 7 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 src/ign/CMakeLists.txt rename src/{ => ign}/ign.cc (100%) rename src/{ => ign}/ign.hh (100%) rename src/{ => ign}/ign_TEST.cc (100%) rename src/{ => ign}/ign_src_TEST.cc (100%) create mode 100644 src/ign/transport_main.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97772404f..b93c566e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,12 +2,6 @@ # "gtest_sources" variable. ign_get_libsources_and_unittests(sources gtest_sources) -# Skip command line tests for Windows, see -# https://github.com/ignitionrobotics/ign-transport/issues/104 -if (MSVC) - list(REMOVE_ITEM gtest_sources ign_TEST.cc) -endif() - if (MSVC) # Warning #4251 is the "dll-interface" warning that tells you when types used # by a class are not being exported. These generated source files have private @@ -66,6 +60,5 @@ if(MSVC) endif() # Command line support. -if(NOT WIN32) - add_subdirectory(cmd) -endif() +add_subdirectory(cmd) +add_subdirectory(ign) diff --git a/src/ign/CMakeLists.txt b/src/ign/CMakeLists.txt new file mode 100644 index 000000000..4afe031c8 --- /dev/null +++ b/src/ign/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable( + transport + transport_main.cc + ign.cc +) + +target_link_libraries(transport + ignition-utils${IGN_UTILS_VER}::cli + ${PROJECT_LIBRARY_TARGET_NAME} +) + +install(TARGETS transport DESTINATION lib/ignition/transport9) diff --git a/src/ign.cc b/src/ign/ign.cc similarity index 100% rename from src/ign.cc rename to src/ign/ign.cc diff --git a/src/ign.hh b/src/ign/ign.hh similarity index 100% rename from src/ign.hh rename to src/ign/ign.hh diff --git a/src/ign_TEST.cc b/src/ign/ign_TEST.cc similarity index 100% rename from src/ign_TEST.cc rename to src/ign/ign_TEST.cc diff --git a/src/ign_src_TEST.cc b/src/ign/ign_src_TEST.cc similarity index 100% rename from src/ign_src_TEST.cc rename to src/ign/ign_src_TEST.cc diff --git a/src/ign/transport_main.cc b/src/ign/transport_main.cc new file mode 100644 index 000000000..cb3e983ca --- /dev/null +++ b/src/ign/transport_main.cc @@ -0,0 +1,174 @@ +#include + +#include "ign.hh" + +#include + +////////////////////////////////////////////////// +/// \brief Enumeration of available commands +enum class TopicCommand +{ + kTopicList, + kTopicInfo, + kTopicPub, + kTopicEcho +}; + +////////////////////////////////////////////////// +struct TopicOptions +{ + TopicCommand command; + std::string topic{""}; + std::string msgType{""}; + std::string msgData{""}; + double duration{-1}; + int count{-1}; +}; + +////////////////////////////////////////////////// +void run_subcommand_topic(const TopicOptions &_opt) +{ + switch(_opt.command) + { + case TopicCommand::kTopicList: + cmdTopicList(); + break; + case TopicCommand::kTopicInfo: + cmdTopicInfo(_opt.topic.c_str()); + break; + case TopicCommand::kTopicPub: + cmdTopicPub(_opt.topic.c_str(), + _opt.msgType.c_str(), + _opt.msgData.c_str()); + break; + case TopicCommand::kTopicEcho: + cmdTopicEcho(_opt.topic.c_str(), _opt.duration, _opt.count); + break; + default: + break; + } +} + +////////////////////////////////////////////////// +void add_subcommand_topic(CLI::App &_app) +{ + CLI::App* sub = _app.add_subcommand("topic", "Introspect ignition topics"); + auto opt = std::make_shared(); + + auto topicOpt = sub->add_option("-t,--topic", opt->topic, "Name of a topic"); + auto msgTypeOpt = sub->add_option("-m,--msgtype", opt->msgType, "Type of message to publish"); + auto durationOpt = sub->add_option("-d,--duration", opt->duration, "Duration (seconds) to run"); + auto countOpt = sub->add_option("-n,--num", opt->count, "Numer of messages to echo and then exit"); + + durationOpt->excludes(countOpt); + countOpt->excludes(durationOpt); + + // Use an option group to guarantee exactly one command choosen + auto command = sub->add_option_group("command", "Command to be executed"); + command->add_flag_callback("-l,--list", [&](){ opt->command = TopicCommand::kTopicList; }); + command->add_flag_callback("-i,--info", [&](){ opt->command = TopicCommand::kTopicInfo; }) + ->needs(topicOpt); + command->add_flag_callback("-e,--echo", [&](){ opt->command = TopicCommand::kTopicEcho; }); + command->add_option_function("-p,--pub", + [&](const std::string &_msgData){ + opt->command = TopicCommand::kTopicPub; + opt->msgData = _msgData; + }) + ->needs(topicOpt) + ->needs(msgTypeOpt); + command->require_option(1); + + sub->callback([opt](){run_subcommand_topic(*opt); }); +} + + +////////////////////////////////////////////////// +/// \brief Enumeration of available commands +enum class ServiceCommand +{ + kServiceList, + kServiceInfo, + kServiceReq, +}; + +////////////////////////////////////////////////// +struct ServiceOptions +{ + ServiceCommand command; + std::string service{""}; + std::string reqData{""}; + std::string reqType{""}; + std::string repType{""}; + int timeout{-1}; +}; + +////////////////////////////////////////////////// +void run_subcommand_service(const ServiceOptions &_opt) +{ + switch(_opt.command) + { + case ServiceCommand::kServiceList: + cmdServiceList(); + break; + case ServiceCommand::kServiceInfo: + cmdServiceInfo(_opt.service.c_str()); + break; + case ServiceCommand::kServiceReq: + cmdServiceReq(_opt.service.c_str(), + _opt.reqType.c_str(), _opt.repType.c_str(), + _opt.timeout, _opt.reqData.c_str()); + break; + default: + break; + } +} + +////////////////////////////////////////////////// +void add_subcommand_service(CLI::App &_app) +{ + CLI::App* sub = _app.add_subcommand("service", "Introspect ignition services"); + auto opt = std::make_shared(); + sub->callback([opt](){run_subcommand_service(*opt); }); + + auto serviceOpt = sub->add_option("-s,--service", opt->service, "Name of a service"); + auto reqTypeOpt = sub->add_option("--reqtype", opt->reqType, "Type of a request."); + auto repTypeOpt = sub->add_option("--reptype", opt->repType, "Type of a response."); + auto timeoutOpt = sub->add_option("--timeout", opt->timeout, "Timeout in milliseconds."); + + // Use an option group to guarantee exactly one command choosen + auto command = sub->add_option_group("command", "Command to be executed"); + command->add_flag_callback("-l,--list", [&](){ opt->command = ServiceCommand::kServiceList; }); + command->add_flag_callback("-i,--info", [&](){ opt->command = ServiceCommand::kServiceInfo; }) + ->needs(serviceOpt); + command->add_option_function("-r,--req", + [&](const std::string &_reqData){ + opt->command = ServiceCommand::kServiceReq; + opt->reqData = _reqData; + }) + ->needs(serviceOpt) + ->needs(reqTypeOpt) + ->needs(repTypeOpt) + ->needs(timeoutOpt); + command->require_option(1); + + sub->callback([opt](){run_subcommand_service(*opt); }); +} + +////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + CLI::App app{"transport"}; + + app.set_help_all_flag("--help-all", "Show all help"); + + app.add_flag_callback("-v,--version", [](){ + std::cout << IGNITION_TRANSPORT_VERSION_FULL << std::endl; + throw CLI::Success(); + }); + + add_subcommand_topic(app); + add_subcommand_service(app); + app.require_subcommand(); + + CLI11_PARSE(app, argc, argv); +} From 0dab3049fe1d2532feeb9b91320506a2e86dbee2 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 25 Jan 2021 11:14:44 -0600 Subject: [PATCH 02/22] Add CLI11 branch of utils Signed-off-by: Michael Carroll --- .github/ci/dependencies.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/ci/dependencies.yaml diff --git a/.github/ci/dependencies.yaml b/.github/ci/dependencies.yaml new file mode 100644 index 000000000..58735d2f5 --- /dev/null +++ b/.github/ci/dependencies.yaml @@ -0,0 +1,6 @@ +repositories: + ign-utils: + type: git + url: https://github.com/ignitionrobotics/ign-utils + version: CLI11 + From 172605bc10ae66921ca80e9d7a27cc80879c705f Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 25 Jan 2021 20:57:11 -0600 Subject: [PATCH 03/22] Attempt at minimally invaisive ruby edits Signed-off-by: Michael Carroll --- src/CMakeLists.txt | 1 - src/cmd/CMakeLists.txt | 17 +- src/cmd/cmdtransport.rb.in | 333 +---------------------------- src/{ign => cmd}/ign.cc | 0 src/{ign => cmd}/ign.hh | 0 src/{ign => cmd}/ign_TEST.cc | 0 src/{ign => cmd}/ign_src_TEST.cc | 0 src/{ign => cmd}/transport_main.cc | 0 8 files changed, 27 insertions(+), 324 deletions(-) rename src/{ign => cmd}/ign.cc (100%) rename src/{ign => cmd}/ign.hh (100%) rename src/{ign => cmd}/ign_TEST.cc (100%) rename src/{ign => cmd}/ign_src_TEST.cc (100%) rename src/{ign => cmd}/transport_main.cc (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b93c566e0..4f95769b2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,4 +61,3 @@ endif() # Command line support. add_subdirectory(cmd) -add_subdirectory(ign) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 643bb0d42..6ada5eb92 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -1,3 +1,16 @@ +add_executable( + transport + transport_main.cc + ign.cc +) + +target_link_libraries(transport + ignition-utils${IGN_UTILS_VER}::cli + ${PROJECT_LIBRARY_TARGET_NAME} +) + +install(TARGETS transport DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) + #=============================================================================== # Generate the ruby script for internal testing. # Note that the major version of the library is included in the name. @@ -29,7 +42,9 @@ set(cmd_script_configured "${cmd_script_generated}.configured") # Set the library_location variable to the relative path to the library file # within the install directory structure. -set(library_location "../../../${CMAKE_INSTALL_LIBDIR}/$") +set(exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") + +message(STATUS ${exe_location}) configure_file( "cmd${IGN_DESIGNATION}.rb.in" diff --git a/src/cmd/cmdtransport.rb.in b/src/cmd/cmdtransport.rb.in index a8b4d3a6c..a1ba4b622 100644 --- a/src/cmd/cmdtransport.rb.in +++ b/src/cmd/cmdtransport.rb.in @@ -1,4 +1,4 @@ -#!/usr/bin/ruby +#!/usr/bin/env ruby # Copyright (C) 2014 Open Source Robotics Foundation # @@ -14,353 +14,42 @@ # See the License for the specific language governing permissions and # limitations under the License. -# We use 'dl' for Ruby <= 1.9.x and 'fiddle' for Ruby >= 2.0.x -if RUBY_VERSION.split('.')[0] < '2' - require 'dl' - require 'dl/import' - include DL -else - require 'fiddle' - require 'fiddle/import' - include Fiddle -end - require 'optparse' # Constants. LIBRARY_NAME = '@library_location@' +EXE_NAME = '@exe_location@' LIBRARY_VERSION = '@PROJECT_VERSION_FULL@' -COMMON_OPTIONS = - " -h [ --help ] Print this help message.\n"\ - " \n" + - " --force-version Use a specific library version.\n"\ - " \n" + - ' --versions Show the available versions.' -COMMANDS = { 'topic' => - "Print information about topics.\n\n" + - " ign topic [options]\n\n" + - "Options:\n\n" + - " -i [ --info ] Get info about a topic.\n"+ - " Requires the -t option.\n"+ - " \n"+ - " -l [ --list ] List all topics.\n" + - " \n"+ - " -t [ --topic ] arg Name of a topic.\n" + - " Required with -i, -p.\n" + - " \n"+ - " -m [ --msgtype ] arg Type of message to " + - "publish.\n" + - " Arg is a message type.\n" + - " Required with -p.\n" + - " \n"+ - " -p [ --pub ] arg Publish a message.\n" + - " arg is the message data." + - " The format expected is\n " + - " the same used by Protobuf DebugString(). E.g.:\n\n" + - " ign topic -t /foo -m " + - " ignition.msgs.StringMsg\n " + - " -p \'data:\"Custom data\"\'\n\n" + - " Requires -t and -m.\n" + - " \n"+ - " -e [ --echo ] Output data to screen." + - " E.g.:\n\n" + - " ign topic -e -t /foo\n" + - " \n"+ - " Requires -t.\n" + - " \n"+ - " -d [--duration] arg Duration (seconds) to run"+ - ". Applicable with \n" + - " echo. This will override "+ - "-n.\n" + - " \n"+ - " -n [--num] arg Number of messages to " + - "echo and then exit. A value \n" + - " " + - "<=0 implies infinite messages. Applicable with \n" + - " " + - "echo. This is overriden by -d.\n" + - "\n" + - COMMON_OPTIONS, - 'service' => - "Print information about services.\n\n" + - " ign service [options]\n\n" + - "Options:\n\n" + - " -i [ --info ] Get info about a service."+ - "\n" + - " Requires the -s option.\n"+ - " \n"+ - " -l [ --list ] List all services.\n" + - " \n"+ - " -s [ --service ] arg Name of a service.\n" + - " Arg is a service name.\n" + - " Required with -i, -r.\n" + - " \n"+ - " -r [ --req ] arg Request a service.\n" + - " Arg is the input data." + - " The format expected is\n " + - " the same used by Protobuf DebugString(). E.g.:\n\n" + - " ign service -s /echo\n" + - " --reqtype ignition.msgs"+ - ".StringMsg\n" + - " --reptype ignition.msgs"+ - ".StringMsg\n" + - " --timeout 2000 --req \'"+ - "data: \"Hello\"\n\n" + - " Requires -s, --timeout,\n"+ - " --reqtype, --reptype.\n" + - " \n"+ - " --timeout arg Timeout in milliseconds." + - "\n Arg is a timeout in " + - "milliseconds.\n" + - " Required with -r.\n" + - " \n"+ - " --reqtype arg Type of a request.\n" + - " Arg is the request type." + - " \n\n"+ - " --reptype arg Type of a response.\n" + - " Arg is the response type."+ - " \n\n"+ - COMMON_OPTIONS - } # # Class for the Ignition transport command line tools. # class Cmd - # - # Return a structure describing the options. - # - def parse(args) - options = {} - - usage = COMMANDS[args[0]] - - # Read the command line arguments. - opt_parser = OptionParser.new do |opts| - opts.banner = usage - - opts.on('-h', '--help', 'Print this help message') do - puts usage - exit(0) - end - opts.on('-l', '--list', 'Print information about topics') do |l| - options['list'] = l - end - - opts.on('-t topic', '--topic', String, - 'Topic name') do |t| - options['topic'] = t - end - - opts.on('-s service', '--service', String, - 'Service name') do |t| - options['service'] = t - end - - opts.on('-m type', '--msgtype', String, - 'Message type') do |t| - options['msgtype'] = t - end - - opts.on('-p data', '--pub', String, - 'Publish a message') do |t| - options['pub'] = t - end - - opts.on('-i', '--info', String, - 'Print information about a topic') do |t| - options['info'] = t - end - - opts.on('-r data', '--req', String, - 'Request a data') do |t| - options['req'] = t - end - - opts.on('--timeout data', Integer, - 'Timeout') do |t| - options['timeout'] = t - end - - opts.on('--reqtype type', String, - 'Request type') do |t| - options['reqtype'] = t - end - - opts.on('--reptype type', String, - 'Response type') do |t| - options['reptype'] = t - end - - opts.on('-e', '--echo', String, - 'Output topic data to screen') do |e| - options['echo'] = e - end - - opts.on('-d secs', '--duration', Float, - 'Duration (seconds) to run') do |d| - options['duration'] = d - end - - opts.on('-n num', '--num', Integer, - 'Number of messages to echo') do |n| - options['num'] = n - end - - end - begin - opt_parser.parse!(args) - rescue - puts usage - exit(-1) - end - - # Check that there is at least one command and there is a plugin that knows - # how to handle it. - if ARGV.empty? || !COMMANDS.key?(ARGV[0]) || - options.empty? - puts usage - exit(-1) - end - - options['command'] = ARGV[0] - - options - end # parse() - def execute(args) - options = parse(args) - - # puts 'Parsed:' - # puts options - # Read the plugin that handles the command. - if LIBRARY_NAME[0] == '/' + if EXE_NAME[0] == '/' # If the first character is a slash, we'll assume that we've been given an # absolute path to the library. This is only used during test mode. - plugin = LIBRARY_NAME + exe_name = EXE_NAME else # We're assuming that the library path is relative to the current # location of this script. - plugin = File.expand_path(File.join(File.dirname(__FILE__), LIBRARY_NAME)) + exe_name = File.expand_path(File.join(File.dirname(__FILE__), EXE_NAME)) end conf_version = LIBRARY_VERSION - - begin - Importer.dlload plugin - rescue DLError - puts "Library error: [#{plugin}] not found." - exit(-1) - end - - # Read the library version. - Importer.extern 'char* ignitionVersion()' - begin - plugin_version = Importer.ignitionVersion.to_s - rescue DLError - puts "Library error: Problem running 'ignitionVersion()' from #{plugin}." - exit(-1) - end + exe_version = `#{exe_name} --version`.strip # Sanity check: Verify that the version of the yaml file matches the version # of the library that we are using. - unless plugin_version.eql? conf_version + unless exe_version.eql? conf_version puts "Error: Version mismatch. Your configuration file version is - [#{conf_version}] but #{plugin} version is [#{plugin_version}]." + [#{conf_version}] but #{exe_name} version is [#{exe_version}]." exit(-1) end - begin - case options['command'] - when 'topic' - if options.key?('list') - Importer.extern 'void cmdTopicList()' - Importer.cmdTopicList - elsif options.key?('info') - if not options.key?('topic') - puts 'ign topic --info: missing topic name (-t )' - puts 'Try ign topic --help' - else - Importer.extern 'void cmdTopicInfo(const char *)' - Importer.cmdTopicInfo(options['topic']) - end - elsif options.key?('pub') - if not options.key?('topic') - puts 'ign topic --pub: missing topic name (-t )' - puts 'Try ign topic --help' - elsif not options.key?('msgtype') - puts 'ign topic --pub: missing message type (--msgtype )' - puts 'Try ign topic --help' - else - Importer.extern 'void cmdTopicPub(const char *, const char *, const char *)' - Importer.cmdTopicPub(options['topic'], options['msgtype'], - options['pub']) - end - elsif options.key?('echo') - if not options.key?('topic') - puts 'ign topic --echo: missing topic name (-t )' - puts 'Try ign topic --help' - else - duration = -1.0 - count = -1 - if options.key?('duration') - duration = options['duration'] - end - if options.key?('num') - count = options['num'] - end + args = args.join(' ') + puts "#{args}" - Importer.extern 'void cmdTopicEcho(const char*, double, int)' - topic = options['topic'] - Importer.cmdTopicEcho(topic, duration.to_f, count.to_i) - end - else - puts 'Command error: I do not have an implementation '\ - 'for this command.' - end - when 'service' - if options.key?('list') - Importer.extern 'void cmdServiceList()' - Importer.cmdServiceList - elsif options.key?('info') - if not options.key?('service') - puts 'ign service --info: missing service name (-s )' - puts 'Try ign service --help' - else - Importer.extern 'void cmdServiceInfo(const char *)' - Importer.cmdServiceInfo(options['service']) - end - elsif options.key?('req') - if not options.key?('service') - puts 'ign service --req: missing service name (-s )' - puts 'Try ign service --help' - elsif not options.key?('reqtype') - puts 'ign service --req: missing input type (--reqtype )' - puts 'Try ign service --help' - elsif not options.key?('reptype') - puts 'ign service --req: missing response type (--reptype )' - puts 'Try ign service --help' - elsif not options.key?('timeout') - puts 'ign service --req: missing timeout in ms (--timeout '\ - ')' - puts 'Try ign service --help' - else - Importer.extern 'void cmdServiceReq(const char *, const char *,'\ - 'const char *, int, const char *)' - Importer.cmdServiceReq(options['service'], options['reqtype'], - options['reptype'], options['timeout'], options['req']) - end - else - puts 'Command error: I do not have an implementation '\ - 'for this command.' - end - else - puts 'Command error: I do not have an implementation for '\ - "command [ign #{options['command']}]." - end - rescue - puts "Library error: Problem running [#{options['command']}]() "\ - "from #{plugin}." - end + puts `#{exe_name} #{args}` end end diff --git a/src/ign/ign.cc b/src/cmd/ign.cc similarity index 100% rename from src/ign/ign.cc rename to src/cmd/ign.cc diff --git a/src/ign/ign.hh b/src/cmd/ign.hh similarity index 100% rename from src/ign/ign.hh rename to src/cmd/ign.hh diff --git a/src/ign/ign_TEST.cc b/src/cmd/ign_TEST.cc similarity index 100% rename from src/ign/ign_TEST.cc rename to src/cmd/ign_TEST.cc diff --git a/src/ign/ign_src_TEST.cc b/src/cmd/ign_src_TEST.cc similarity index 100% rename from src/ign/ign_src_TEST.cc rename to src/cmd/ign_src_TEST.cc diff --git a/src/ign/transport_main.cc b/src/cmd/transport_main.cc similarity index 100% rename from src/ign/transport_main.cc rename to src/cmd/transport_main.cc From fc18bac8f264681d5d9165cb251833b2f163c206 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Mon, 1 Feb 2021 01:55:08 -0800 Subject: [PATCH 04/22] Re-enable ign tests, fix test cmd file Signed-off-by: Steve Peters --- src/cmd/CMakeLists.txt | 34 ++++++++++++++++++++++++++-------- src/cmd/cmdtransport.rb.in | 2 -- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 6ada5eb92..74d4beb0b 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -1,15 +1,35 @@ -add_executable( - transport +# Collect source files into the "sources" variable and unit test files into the +# "gtest_sources" variable. +ign_get_libsources_and_unittests(sources gtest_sources) + +set(executable transport) +add_executable(${executable} transport_main.cc ign.cc ) -target_link_libraries(transport +target_link_libraries(${executable} ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) -install(TARGETS transport DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +install(TARGETS ${executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) + +# Build the unit tests. +ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} + TEST_LIST test_list + LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) + +foreach(test ${test_list}) + + # Inform each test of its output directory so it knows where to call the + # auxiliary files from. Using a generator expression here is useful for + # multi-configuration generators, like Visual Studio. + target_compile_definitions(${test} PRIVATE + "DETAIL_IGN_TRANSPORT_TEST_DIR=\"$\"" + "IGN_TEST_LIBRARY_PATH=\"$\"") + +endforeach() #=============================================================================== # Generate the ruby script for internal testing. @@ -20,7 +40,7 @@ set(cmd_script_configured_test "${cmd_script_generated_test}.configured") # Set the library_location variable to the full path of the library file within # the build directory. -set(library_location "$") +set(exe_location "$") configure_file( "cmd${IGN_DESIGNATION}.rb.in" @@ -42,9 +62,7 @@ set(cmd_script_configured "${cmd_script_generated}.configured") # Set the library_location variable to the relative path to the library file # within the install directory structure. -set(exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") - -message(STATUS ${exe_location}) +set(exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") configure_file( "cmd${IGN_DESIGNATION}.rb.in" diff --git a/src/cmd/cmdtransport.rb.in b/src/cmd/cmdtransport.rb.in index a1ba4b622..c0670d7d1 100644 --- a/src/cmd/cmdtransport.rb.in +++ b/src/cmd/cmdtransport.rb.in @@ -48,8 +48,6 @@ class Cmd end args = args.join(' ') - puts "#{args}" - puts `#{exe_name} #{args}` end end From 7bccb17474db6b64320ee1551e0ff5b5944b03e9 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 1 Feb 2021 10:48:56 -0600 Subject: [PATCH 05/22] Remove ign directory Signed-off-by: Michael Carroll --- src/ign/CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/ign/CMakeLists.txt diff --git a/src/ign/CMakeLists.txt b/src/ign/CMakeLists.txt deleted file mode 100644 index 4afe031c8..000000000 --- a/src/ign/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable( - transport - transport_main.cc - ign.cc -) - -target_link_libraries(transport - ignition-utils${IGN_UTILS_VER}::cli - ${PROJECT_LIBRARY_TARGET_NAME} -) - -install(TARGETS transport DESTINATION lib/ignition/transport9) From 381e740d755cb848636704287d91e7afebd0384a Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 1 Feb 2021 11:52:32 -0600 Subject: [PATCH 06/22] Split topic and service into their own executables Signed-off-by: Michael Carroll --- src/cmd/CMakeLists.txt | 22 ++++- src/cmd/service_main.cc | 118 ++++++++++++++++++++++++++ src/cmd/topic_main.cc | 128 ++++++++++++++++++++++++++++ src/cmd/transport_main.cc | 174 -------------------------------------- 4 files changed, 264 insertions(+), 178 deletions(-) create mode 100644 src/cmd/service_main.cc create mode 100644 src/cmd/topic_main.cc delete mode 100644 src/cmd/transport_main.cc diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 74d4beb0b..0622b61e2 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -2,17 +2,30 @@ # "gtest_sources" variable. ign_get_libsources_and_unittests(sources gtest_sources) -set(executable transport) -add_executable(${executable} - transport_main.cc - ign.cc +# Make a small static lib of command line functions +add_library(ign STATIC ign.cc) +target_link_libraries(ign + ${PROJECT_LIBRARY_TARGET_NAME} ) +# Build topic CLI executable +set(executable ign-transport-topic) +add_executable(${executable} topic_main.cc) target_link_libraries(${executable} + ign ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) +install(TARGETS ${executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +# Build service CLI executable +set(executable ign-transport-service) +add_executable(${executable} service_main.cc) +target_link_libraries(${executable} + ign + ignition-utils${IGN_UTILS_VER}::cli + ${PROJECT_LIBRARY_TARGET_NAME} +) install(TARGETS ${executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) # Build the unit tests. @@ -21,6 +34,7 @@ ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) foreach(test ${test_list}) + target_link_libraries(${test} ign) # Inform each test of its output directory so it knows where to call the # auxiliary files from. Using a generator expression here is useful for diff --git a/src/cmd/service_main.cc b/src/cmd/service_main.cc new file mode 100644 index 000000000..22b7931d3 --- /dev/null +++ b/src/cmd/service_main.cc @@ -0,0 +1,118 @@ +#include + +#include "ign.hh" + +#include + +////////////////////////////////////////////////// +/// \brief Enumeration of available commands +enum class ServiceCommand +{ + kNone, + kServiceList, + kServiceInfo, + kServiceReq, +}; + +////////////////////////////////////////////////// +/// \brief Structure to hold all available service options +struct ServiceOptions +{ + /// \brief Command to execute + ServiceCommand command{ServiceCommand::kNone}; + + /// \brief Name of the service + std::string service{""}; + + /// \brief Data used with a service request + std::string reqData{""}; + + /// \brief Request type to use when requesting + std::string reqType{""}; + + /// \brief Response type to use when requesting + std::string repType{""}; + + /// \brief Timeout to use when requesting (in milliseconds) + int timeout{-1}; +}; + +////////////////////////////////////////////////// +/// \brief Callback fired when options are successfully parsed +void runServiceCommand(const ServiceOptions &_opt) +{ + switch(_opt.command) + { + case ServiceCommand::kServiceList: + cmdServiceList(); + break; + case ServiceCommand::kServiceInfo: + cmdServiceInfo(_opt.service.c_str()); + break; + case ServiceCommand::kServiceReq: + cmdServiceReq(_opt.service.c_str(), + _opt.reqType.c_str(), _opt.repType.c_str(), + _opt.timeout, _opt.reqData.c_str()); + break; + case ServiceCommand::kNone: + default: + // In the event that there is no command, display help + throw CLI::CallForHelp(); + break; + } +} + +////////////////////////////////////////////////// +void addServiceFlags(CLI::App &_app) +{ + auto opt = std::make_shared(); + + auto serviceOpt = _app.add_option("-s,--service", + opt->service, "Name of a service"); + auto reqTypeOpt = _app.add_option("--reqtype", + opt->reqType, "Type of a request."); + auto repTypeOpt = _app.add_option("--reptype", + opt->repType, "Type of a response."); + auto timeoutOpt = _app.add_option("--timeout", + opt->timeout, "Timeout in milliseconds."); + + auto command = _app.add_option_group("command", "Command to be executed"); + command->add_flag_callback("-l,--list", + [opt](){ + opt->command = ServiceCommand::kServiceList; + }, "List available services"); + + command->add_flag_callback("-i,--info", + [opt](){ + opt->command = ServiceCommand::kServiceInfo; + }, "Get information about a service") + ->needs(serviceOpt); + + command->add_option_function("-r,--req", + [&](const std::string &_reqData){ + opt->command = ServiceCommand::kServiceReq; + opt->reqData = _reqData; + }, "Perform a service request") + ->needs(serviceOpt) + ->needs(reqTypeOpt) + ->needs(repTypeOpt) + ->needs(timeoutOpt); + + _app.callback([opt](){runServiceCommand(*opt); }); +} + +////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + CLI::App app{"Introspect Ignition services"}; + + app.set_help_all_flag("--help-all", "Show all help"); + + app.add_flag_callback("-v,--version", [](){ + std::cout << IGNITION_TRANSPORT_VERSION_FULL << std::endl; + throw CLI::Success(); + }); + + addServiceFlags(app); + CLI11_PARSE(app, argc, argv); +} diff --git a/src/cmd/topic_main.cc b/src/cmd/topic_main.cc new file mode 100644 index 000000000..d596ebf0a --- /dev/null +++ b/src/cmd/topic_main.cc @@ -0,0 +1,128 @@ +#include + +#include "ign.hh" + +#include + +////////////////////////////////////////////////// +/// \brief Enumeration of available commands +enum class TopicCommand +{ + kNone, + kTopicList, + kTopicInfo, + kTopicPub, + kTopicEcho +}; + +////////////////////////////////////////////////// +/// \brief Structure to hold all available topic options +struct TopicOptions +{ + /// \brief Command to execute + TopicCommand command{TopicCommand::kNone}; + + /// \brief Name of the topic + std::string topic{""}; + + /// \brief Message type to use when publishing + std::string msgType{""}; + + /// \brief Message data to use when publishing + std::string msgData{""}; + + /// \brief Amount of time to echo (in seconds) + double duration{-1}; + + /// \brief Number of messages to echo + int count{-1}; +}; + +////////////////////////////////////////////////// +/// \brief Callback fired when options are successfully parsed +void runTopicCommand(const TopicOptions &_opt) +{ + switch(_opt.command) + { + case TopicCommand::kTopicList: + cmdTopicList(); + break; + case TopicCommand::kTopicInfo: + cmdTopicInfo(_opt.topic.c_str()); + break; + case TopicCommand::kTopicPub: + cmdTopicPub(_opt.topic.c_str(), + _opt.msgType.c_str(), + _opt.msgData.c_str()); + break; + case TopicCommand::kTopicEcho: + cmdTopicEcho(_opt.topic.c_str(), _opt.duration, _opt.count); + break; + case TopicCommand::kNone: + default: + // In the event that there is no command, display help + throw CLI::CallForHelp(); + } +} + +////////////////////////////////////////////////// +void addTopicFlags(CLI::App &_app) +{ + auto opt = std::make_shared(); + + auto topicOpt = _app.add_option("-t,--topic", + opt->topic, "Name of a topic"); + auto msgTypeOpt = _app.add_option("-m,--msgtype", + opt->msgType, "Type of message to publish"); + auto durationOpt = _app.add_option("-d,--duration", + opt->duration, + "Duration (seconds) to run"); + auto countOpt = _app.add_option("-n,--num", + opt->count, + "Numer of messages to echo and then exit"); + + durationOpt->excludes(countOpt); + countOpt->excludes(durationOpt); + + auto command = _app.add_option_group("command", "Command to be executed"); + + command->add_flag_callback("-l,--list", + [opt](){ + opt->command = TopicCommand::kTopicList; + }); + + command->add_flag_callback("-i,--info", + [opt](){ + opt->command = TopicCommand::kTopicInfo; + }) + ->needs(topicOpt); + + command->add_flag_callback("-e,--echo", + [opt](){ + opt->command = TopicCommand::kTopicEcho; + }); + + command->add_option_function("-p,--pub", + [&](const std::string &_msgData){ + opt->command = TopicCommand::kTopicPub; + opt->msgData = _msgData; + }) + ->needs(topicOpt) + ->needs(msgTypeOpt); + + _app.callback([opt](){runTopicCommand(*opt); }); +} + +////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + CLI::App app{"Introspect Ignition topics"}; + + app.add_flag_callback("-v,--version", [](){ + std::cout << IGNITION_TRANSPORT_VERSION_FULL << std::endl; + throw CLI::Success(); + }); + + addTopicFlags(app); + CLI11_PARSE(app, argc, argv); +} diff --git a/src/cmd/transport_main.cc b/src/cmd/transport_main.cc deleted file mode 100644 index cb3e983ca..000000000 --- a/src/cmd/transport_main.cc +++ /dev/null @@ -1,174 +0,0 @@ -#include - -#include "ign.hh" - -#include - -////////////////////////////////////////////////// -/// \brief Enumeration of available commands -enum class TopicCommand -{ - kTopicList, - kTopicInfo, - kTopicPub, - kTopicEcho -}; - -////////////////////////////////////////////////// -struct TopicOptions -{ - TopicCommand command; - std::string topic{""}; - std::string msgType{""}; - std::string msgData{""}; - double duration{-1}; - int count{-1}; -}; - -////////////////////////////////////////////////// -void run_subcommand_topic(const TopicOptions &_opt) -{ - switch(_opt.command) - { - case TopicCommand::kTopicList: - cmdTopicList(); - break; - case TopicCommand::kTopicInfo: - cmdTopicInfo(_opt.topic.c_str()); - break; - case TopicCommand::kTopicPub: - cmdTopicPub(_opt.topic.c_str(), - _opt.msgType.c_str(), - _opt.msgData.c_str()); - break; - case TopicCommand::kTopicEcho: - cmdTopicEcho(_opt.topic.c_str(), _opt.duration, _opt.count); - break; - default: - break; - } -} - -////////////////////////////////////////////////// -void add_subcommand_topic(CLI::App &_app) -{ - CLI::App* sub = _app.add_subcommand("topic", "Introspect ignition topics"); - auto opt = std::make_shared(); - - auto topicOpt = sub->add_option("-t,--topic", opt->topic, "Name of a topic"); - auto msgTypeOpt = sub->add_option("-m,--msgtype", opt->msgType, "Type of message to publish"); - auto durationOpt = sub->add_option("-d,--duration", opt->duration, "Duration (seconds) to run"); - auto countOpt = sub->add_option("-n,--num", opt->count, "Numer of messages to echo and then exit"); - - durationOpt->excludes(countOpt); - countOpt->excludes(durationOpt); - - // Use an option group to guarantee exactly one command choosen - auto command = sub->add_option_group("command", "Command to be executed"); - command->add_flag_callback("-l,--list", [&](){ opt->command = TopicCommand::kTopicList; }); - command->add_flag_callback("-i,--info", [&](){ opt->command = TopicCommand::kTopicInfo; }) - ->needs(topicOpt); - command->add_flag_callback("-e,--echo", [&](){ opt->command = TopicCommand::kTopicEcho; }); - command->add_option_function("-p,--pub", - [&](const std::string &_msgData){ - opt->command = TopicCommand::kTopicPub; - opt->msgData = _msgData; - }) - ->needs(topicOpt) - ->needs(msgTypeOpt); - command->require_option(1); - - sub->callback([opt](){run_subcommand_topic(*opt); }); -} - - -////////////////////////////////////////////////// -/// \brief Enumeration of available commands -enum class ServiceCommand -{ - kServiceList, - kServiceInfo, - kServiceReq, -}; - -////////////////////////////////////////////////// -struct ServiceOptions -{ - ServiceCommand command; - std::string service{""}; - std::string reqData{""}; - std::string reqType{""}; - std::string repType{""}; - int timeout{-1}; -}; - -////////////////////////////////////////////////// -void run_subcommand_service(const ServiceOptions &_opt) -{ - switch(_opt.command) - { - case ServiceCommand::kServiceList: - cmdServiceList(); - break; - case ServiceCommand::kServiceInfo: - cmdServiceInfo(_opt.service.c_str()); - break; - case ServiceCommand::kServiceReq: - cmdServiceReq(_opt.service.c_str(), - _opt.reqType.c_str(), _opt.repType.c_str(), - _opt.timeout, _opt.reqData.c_str()); - break; - default: - break; - } -} - -////////////////////////////////////////////////// -void add_subcommand_service(CLI::App &_app) -{ - CLI::App* sub = _app.add_subcommand("service", "Introspect ignition services"); - auto opt = std::make_shared(); - sub->callback([opt](){run_subcommand_service(*opt); }); - - auto serviceOpt = sub->add_option("-s,--service", opt->service, "Name of a service"); - auto reqTypeOpt = sub->add_option("--reqtype", opt->reqType, "Type of a request."); - auto repTypeOpt = sub->add_option("--reptype", opt->repType, "Type of a response."); - auto timeoutOpt = sub->add_option("--timeout", opt->timeout, "Timeout in milliseconds."); - - // Use an option group to guarantee exactly one command choosen - auto command = sub->add_option_group("command", "Command to be executed"); - command->add_flag_callback("-l,--list", [&](){ opt->command = ServiceCommand::kServiceList; }); - command->add_flag_callback("-i,--info", [&](){ opt->command = ServiceCommand::kServiceInfo; }) - ->needs(serviceOpt); - command->add_option_function("-r,--req", - [&](const std::string &_reqData){ - opt->command = ServiceCommand::kServiceReq; - opt->reqData = _reqData; - }) - ->needs(serviceOpt) - ->needs(reqTypeOpt) - ->needs(repTypeOpt) - ->needs(timeoutOpt); - command->require_option(1); - - sub->callback([opt](){run_subcommand_service(*opt); }); -} - -////////////////////////////////////////////////// -int main(int argc, char** argv) -{ - CLI::App app{"transport"}; - - app.set_help_all_flag("--help-all", "Show all help"); - - app.add_flag_callback("-v,--version", [](){ - std::cout << IGNITION_TRANSPORT_VERSION_FULL << std::endl; - throw CLI::Success(); - }); - - add_subcommand_topic(app); - add_subcommand_service(app); - app.require_subcommand(); - - CLI11_PARSE(app, argc, argv); -} From 210859d19897ffb3ec91a74fa397a8d7bacd23be Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 1 Feb 2021 19:14:57 -0600 Subject: [PATCH 07/22] Lint Signed-off-by: Michael Carroll --- src/cmd/service_main.cc | 49 +++++++++++++++++++++++++++-------------- src/cmd/topic_main.cc | 47 ++++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/cmd/service_main.cc b/src/cmd/service_main.cc index 22b7931d3..93457fcd5 100644 --- a/src/cmd/service_main.cc +++ b/src/cmd/service_main.cc @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 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. + * + */ + #include #include "ign.hh" @@ -27,10 +44,10 @@ struct ServiceOptions /// \brief Data used with a service request std::string reqData{""}; - /// \brief Request type to use when requesting + /// \brief Request type to use when requesting std::string reqType{""}; - /// \brief Response type to use when requesting + /// \brief Response type to use when requesting std::string repType{""}; /// \brief Timeout to use when requesting (in milliseconds) @@ -50,7 +67,7 @@ void runServiceCommand(const ServiceOptions &_opt) cmdServiceInfo(_opt.service.c_str()); break; case ServiceCommand::kServiceReq: - cmdServiceReq(_opt.service.c_str(), + cmdServiceReq(_opt.service.c_str(), _opt.reqType.c_str(), _opt.repType.c_str(), _opt.timeout, _opt.reqData.c_str()); break; @@ -67,30 +84,30 @@ void addServiceFlags(CLI::App &_app) { auto opt = std::make_shared(); - auto serviceOpt = _app.add_option("-s,--service", + auto serviceOpt = _app.add_option("-s,--service", opt->service, "Name of a service"); - auto reqTypeOpt = _app.add_option("--reqtype", + auto reqTypeOpt = _app.add_option("--reqtype", opt->reqType, "Type of a request."); - auto repTypeOpt = _app.add_option("--reptype", + auto repTypeOpt = _app.add_option("--reptype", opt->repType, "Type of a response."); - auto timeoutOpt = _app.add_option("--timeout", + auto timeoutOpt = _app.add_option("--timeout", opt->timeout, "Timeout in milliseconds."); auto command = _app.add_option_group("command", "Command to be executed"); - command->add_flag_callback("-l,--list", - [opt](){ - opt->command = ServiceCommand::kServiceList; + command->add_flag_callback("-l,--list", + [opt](){ + opt->command = ServiceCommand::kServiceList; }, "List available services"); - command->add_flag_callback("-i,--info", - [opt](){ - opt->command = ServiceCommand::kServiceInfo; + command->add_flag_callback("-i,--info", + [opt](){ + opt->command = ServiceCommand::kServiceInfo; }, "Get information about a service") ->needs(serviceOpt); - command->add_option_function("-r,--req", - [&](const std::string &_reqData){ - opt->command = ServiceCommand::kServiceReq; + command->add_option_function("-r,--req", + [&](const std::string &_reqData){ + opt->command = ServiceCommand::kServiceReq; opt->reqData = _reqData; }, "Perform a service request") ->needs(serviceOpt) diff --git a/src/cmd/topic_main.cc b/src/cmd/topic_main.cc index d596ebf0a..d17881f93 100644 --- a/src/cmd/topic_main.cc +++ b/src/cmd/topic_main.cc @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2021 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. + * + */ + #include #include "ign.hh" @@ -34,7 +51,7 @@ struct TopicOptions /// \brief Amount of time to echo (in seconds) double duration{-1}; - /// \brief Number of messages to echo + /// \brief Number of messages to echo int count{-1}; }; @@ -70,15 +87,15 @@ void addTopicFlags(CLI::App &_app) { auto opt = std::make_shared(); - auto topicOpt = _app.add_option("-t,--topic", + auto topicOpt = _app.add_option("-t,--topic", opt->topic, "Name of a topic"); - auto msgTypeOpt = _app.add_option("-m,--msgtype", + auto msgTypeOpt = _app.add_option("-m,--msgtype", opt->msgType, "Type of message to publish"); - auto durationOpt = _app.add_option("-d,--duration", - opt->duration, + auto durationOpt = _app.add_option("-d,--duration", + opt->duration, "Duration (seconds) to run"); - auto countOpt = _app.add_option("-n,--num", - opt->count, + auto countOpt = _app.add_option("-n,--num", + opt->count, "Numer of messages to echo and then exit"); durationOpt->excludes(countOpt); @@ -86,20 +103,20 @@ void addTopicFlags(CLI::App &_app) auto command = _app.add_option_group("command", "Command to be executed"); - command->add_flag_callback("-l,--list", - [opt](){ - opt->command = TopicCommand::kTopicList; + command->add_flag_callback("-l,--list", + [opt](){ + opt->command = TopicCommand::kTopicList; }); - command->add_flag_callback("-i,--info", - [opt](){ - opt->command = TopicCommand::kTopicInfo; + command->add_flag_callback("-i,--info", + [opt](){ + opt->command = TopicCommand::kTopicInfo; }) ->needs(topicOpt); - command->add_flag_callback("-e,--echo", + command->add_flag_callback("-e,--echo", [opt](){ - opt->command = TopicCommand::kTopicEcho; + opt->command = TopicCommand::kTopicEcho; }); command->add_option_function("-p,--pub", From 37f354642cc0b4fac453f870a7c07f973cd89221 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Mon, 1 Feb 2021 17:39:27 -0800 Subject: [PATCH 08/22] Export path to both executables in ruby script Signed-off-by: Steve Peters --- src/cmd/CMakeLists.txt | 22 ++++++++++++---------- src/cmd/cmdtransport.rb.in | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 0622b61e2..b78078dd3 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -9,24 +9,24 @@ target_link_libraries(ign ) # Build topic CLI executable -set(executable ign-transport-topic) -add_executable(${executable} topic_main.cc) -target_link_libraries(${executable} +set(topic_executable ign-transport-topic) +add_executable(${topic_executable} topic_main.cc) +target_link_libraries(${topic_executable} ign ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) -install(TARGETS ${executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +install(TARGETS ${topic_executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) # Build service CLI executable -set(executable ign-transport-service) -add_executable(${executable} service_main.cc) -target_link_libraries(${executable} +set(service_executable ign-transport-service) +add_executable(${service_executable} service_main.cc) +target_link_libraries(${service_executable} ign ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) -install(TARGETS ${executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +install(TARGETS ${service_executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) # Build the unit tests. ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} @@ -54,7 +54,8 @@ set(cmd_script_configured_test "${cmd_script_generated_test}.configured") # Set the library_location variable to the full path of the library file within # the build directory. -set(exe_location "$") +set(service_exe_location "$") +set(topic_exe_location "$") configure_file( "cmd${IGN_DESIGNATION}.rb.in" @@ -76,7 +77,8 @@ set(cmd_script_configured "${cmd_script_generated}.configured") # Set the library_location variable to the relative path to the library file # within the install directory structure. -set(exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") +set(service_exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") +set(topic_exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$") configure_file( "cmd${IGN_DESIGNATION}.rb.in" diff --git a/src/cmd/cmdtransport.rb.in b/src/cmd/cmdtransport.rb.in index c0670d7d1..3f508eb17 100644 --- a/src/cmd/cmdtransport.rb.in +++ b/src/cmd/cmdtransport.rb.in @@ -17,24 +17,27 @@ require 'optparse' # Constants. -LIBRARY_NAME = '@library_location@' -EXE_NAME = '@exe_location@' LIBRARY_VERSION = '@PROJECT_VERSION_FULL@' +COMMANDS = { + "service" => "@service_exe_location@", + "topic" => "@topic_exe_location@", +} # # Class for the Ignition transport command line tools. # class Cmd def execute(args) - # Read the plugin that handles the command. - if EXE_NAME[0] == '/' + command = args[0] + exe_name = COMMANDS[command] + + if exe_name[0] == '/' # If the first character is a slash, we'll assume that we've been given an - # absolute path to the library. This is only used during test mode. - exe_name = EXE_NAME + # absolute path to the executable. This is only used during test mode. else # We're assuming that the library path is relative to the current # location of this script. - exe_name = File.expand_path(File.join(File.dirname(__FILE__), EXE_NAME)) + exe_name = File.expand_path(File.join(File.dirname(__FILE__), exe_name)) end conf_version = LIBRARY_VERSION exe_version = `#{exe_name} --version`.strip @@ -47,7 +50,8 @@ class Cmd exit(-1) end - args = args.join(' ') + # Drop command from list of arguments + args = args[1..-1].join(' ') puts `#{exe_name} #{args}` end end From 14afd749094ec63344a769d52abb217997bae805 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 25 Feb 2021 16:36:44 -0800 Subject: [PATCH 09/22] Use libignition-utils1-dev for CI Don't need to build ign-utils from source anymore. Signed-off-by: Steve Peters --- .github/ci/dependencies.yaml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .github/ci/dependencies.yaml diff --git a/.github/ci/dependencies.yaml b/.github/ci/dependencies.yaml deleted file mode 100644 index 58735d2f5..000000000 --- a/.github/ci/dependencies.yaml +++ /dev/null @@ -1,6 +0,0 @@ -repositories: - ign-utils: - type: git - url: https://github.com/ignitionrobotics/ign-utils - version: CLI11 - From c94fc593f4817a99003d8ff450d7bb38cef822ba Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 2 Mar 2021 22:58:45 -0800 Subject: [PATCH 10/22] Fix seg-faults in ign executables Signed-off-by: Steve Peters --- src/cmd/service_main.cc | 2 +- src/cmd/topic_main.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/service_main.cc b/src/cmd/service_main.cc index 93457fcd5..8ebda3ab1 100644 --- a/src/cmd/service_main.cc +++ b/src/cmd/service_main.cc @@ -106,7 +106,7 @@ void addServiceFlags(CLI::App &_app) ->needs(serviceOpt); command->add_option_function("-r,--req", - [&](const std::string &_reqData){ + [opt](const std::string &_reqData){ opt->command = ServiceCommand::kServiceReq; opt->reqData = _reqData; }, "Perform a service request") diff --git a/src/cmd/topic_main.cc b/src/cmd/topic_main.cc index d17881f93..6e1c7ab8b 100644 --- a/src/cmd/topic_main.cc +++ b/src/cmd/topic_main.cc @@ -120,7 +120,7 @@ void addTopicFlags(CLI::App &_app) }); command->add_option_function("-p,--pub", - [&](const std::string &_msgData){ + [opt](const std::string &_msgData){ opt->command = TopicCommand::kTopicPub; opt->msgData = _msgData; }) From 8936e12ee02d1d28ac1ce5aa6153526c260ce75b Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 2 Mar 2021 22:59:49 -0800 Subject: [PATCH 11/22] Use Open3.capture2e instead of `` to fix args Strings were losing their quoting with ``, but capture2e preserves strings with spaces. Also, return the error code from by the executable. Signed-off-by: Steve Peters --- src/cmd/cmdtransport.rb.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/cmdtransport.rb.in b/src/cmd/cmdtransport.rb.in index 3f508eb17..1ee747b61 100644 --- a/src/cmd/cmdtransport.rb.in +++ b/src/cmd/cmdtransport.rb.in @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'optparse' +require 'open3' # Constants. LIBRARY_VERSION = '@PROJECT_VERSION_FULL@' @@ -51,7 +51,8 @@ class Cmd end # Drop command from list of arguments - args = args[1..-1].join(' ') - puts `#{exe_name} #{args}` + stdout_and_stderr, status = Open3.capture2e(exe_name, *args[1..-1]) + print stdout_and_stderr + exit(status.exitstatus) end end From 0ecc1613910abeabe76c736a0f6a0c91947b0870 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 2 Mar 2021 23:01:35 -0800 Subject: [PATCH 12/22] ign_TEST: update expected error message Signed-off-by: Steve Peters --- src/cmd/ign_TEST.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/ign_TEST.cc b/src/cmd/ign_TEST.cc index f4ba5bf27..d73094897 100644 --- a/src/cmd/ign_TEST.cc +++ b/src/cmd/ign_TEST.cc @@ -345,6 +345,13 @@ TEST(ignTest, TopicPublish) // Try to publish using an incorrect topic name. error = "Topic [/] is not valid"; + output = custom_exec_str(ign + + " topic -t / -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+ + g_ignVersion); + EXPECT_EQ(output.compare(0, error.size(), error), 0); + + // Try to publish using an incorrect number of arguments. + error = "The following argument was not expected: wrong_topic"; output = custom_exec_str(ign + " topic -t / wrong_topic -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+ g_ignVersion); From befe59fafe68c173321930b01670761927bcae94 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Wed, 3 Mar 2021 11:12:18 -0800 Subject: [PATCH 13/22] configure.bat: install ign-utils Signed-off-by: Steve Peters --- configure.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.bat b/configure.bat index 87df2654e..7876eb805 100644 --- a/configure.bat +++ b/configure.bat @@ -7,6 +7,7 @@ call %win_lib% :download_unzip_install libzmq-4.2.3_cppzmq-4.2.2_vc15-x64-dll-MD.zip call %win_lib% :download_unzip_install sqlite-3.22.0-vc15-Win64-dll-MD.zip call %win_lib% :install_ign_project ign-msgs main +call %win_lib% :install_ign_project ign-utils main :: Set configuration variables @set build_type=Release From c6f85c8b851a5a2fd5d9312a56a635f9df8582d1 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 11 Mar 2021 21:46:27 -0800 Subject: [PATCH 14/22] Fix generation of cmd*.rb file on Windows Generate separate cmd*.rb files for each $ Signed-off-by: Steve Peters --- conf/CMakeLists.txt | 8 ++++++-- src/cmd/CMakeLists.txt | 13 +++++++++++-- src/cmd/ign_TEST.cc | 4 ---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt index 6c02f6887..9403b6dcf 100644 --- a/conf/CMakeLists.txt +++ b/conf/CMakeLists.txt @@ -1,12 +1,16 @@ # Used only for internal testing. -set(ign_library_path "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}") +set(ign_library_path "${CMAKE_BINARY_DIR}/test/lib/$/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}") # Generate a configuration file for internal testing. # Note that the major version of the library is included in the name. # Ex: transport0.yaml configure_file( "${IGN_DESIGNATION}.yaml.in" - "${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY) + "${CMAKE_CURRENT_BINARY_DIR}/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml.configured" @ONLY) + +file(GENERATE + OUTPUT "${CMAKE_BINARY_DIR}/test/conf/$/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" + INPUT "${CMAKE_CURRENT_BINARY_DIR}/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml.configured") # Used for the installed version. set(ign_library_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}") diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index b78078dd3..8d2f9c584 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -45,12 +45,21 @@ foreach(test ${test_list}) endforeach() +if (TARGET UNIT_ign_TEST) + set_tests_properties( + UNIT_ign_TEST + PROPERTIES + ENVIRONMENT + "IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$" + ) +endif() + #=============================================================================== # Generate the ruby script for internal testing. # Note that the major version of the library is included in the name. # Ex: cmdtransport0.rb -set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb") -set(cmd_script_configured_test "${cmd_script_generated_test}.configured") +set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/$/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb") +set(cmd_script_configured_test "${CMAKE_CURRENT_BINARY_DIR}/test_cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb.configured") # Set the library_location variable to the full path of the library file within # the build directory. diff --git a/src/cmd/ign_TEST.cc b/src/cmd/ign_TEST.cc index d73094897..4362035e4 100644 --- a/src/cmd/ign_TEST.cc +++ b/src/cmd/ign_TEST.cc @@ -460,10 +460,6 @@ int main(int argc, char **argv) // Set the partition name for this process. setenv("IGN_PARTITION", g_partition.c_str(), 1); - // Set IGN_CONFIG_PATH to the directory where the .yaml configuration files - // is located. - setenv("IGN_CONFIG_PATH", IGN_CONFIG_PATH, 1); - // Make sure that we load the library recently built and not the one installed // in your system. // Save the current value of LD_LIBRARY_PATH. From 0d8b134ab68fee39e83a15f0efa35761eb79a59f Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 11 Mar 2021 21:47:49 -0800 Subject: [PATCH 15/22] rm configure.bat Signed-off-by: Steve Peters --- configure.bat | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 configure.bat diff --git a/configure.bat b/configure.bat deleted file mode 100644 index 7876eb805..000000000 --- a/configure.bat +++ /dev/null @@ -1,33 +0,0 @@ - -:: NOTE: This script is only meant to be used as part of the ignition developers' CI system -:: Users and developers should build and install this library using cmake and Visual Studio - - -:: Install dependencies -call %win_lib% :download_unzip_install libzmq-4.2.3_cppzmq-4.2.2_vc15-x64-dll-MD.zip -call %win_lib% :download_unzip_install sqlite-3.22.0-vc15-Win64-dll-MD.zip -call %win_lib% :install_ign_project ign-msgs main -call %win_lib% :install_ign_project ign-utils main - -:: Set configuration variables -@set build_type=Release -@if not "%1"=="" set build_type=%1 -@echo Configuring for build type %build_type% - -:: Go to the directory that this configure.bat file exists in -cd /d %~dp0 - -:: Create a build directory and configure -md build -cd build -cmake .. ^ - -G "NMake Makefiles" ^ - -DCMAKE_INSTALL_PREFIX="%WORKSPACE_INSTALL_DIR%" ^ - -DCMAKE_PREFIX_PATH="%WORKSPACE_INSTALL_DIR%" ^ - -DCMAKE_BUILD_TYPE="%build_type%" ^ - --trace ^ - -DBUILD_TESTING:BOOL=False -:: Note: We disable testing by default. If the intention is for the CI to build and test -:: this project, then the CI script will turn it back on. - -:: If the caller wants to build and/or install, they should do so after calling this script From 35ce8fefd8f79d24ecc97d42fccd410ed457fafb Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Mon, 15 Mar 2021 02:12:53 -0700 Subject: [PATCH 16/22] Remove visibility macros from ign.cc These only need to be with the declaration, not the implementation. Signed-off-by: Steve Peters --- src/cmd/ign.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/ign.cc b/src/cmd/ign.cc index 2fed3319a..61acc900e 100644 --- a/src/cmd/ign.cc +++ b/src/cmd/ign.cc @@ -42,7 +42,7 @@ using namespace ignition; using namespace transport; ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicList() +extern "C" void cmdTopicList() { Node node; @@ -54,7 +54,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicList() } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicInfo(const char *_topic) +extern "C" void cmdTopicInfo(const char *_topic) { if (!_topic || std::string(_topic).empty()) { @@ -89,7 +89,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicInfo(const char *_topic) } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceList() +extern "C" void cmdServiceList() { Node node; @@ -101,7 +101,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceList() } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceInfo(const char *_service) +extern "C" void cmdServiceInfo(const char *_service) { if (!_service || std::string(_service).empty()) { @@ -136,7 +136,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceInfo(const char *_service) } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicPub(const char *_topic, +extern "C" void cmdTopicPub(const char *_topic, const char *_msgType, const char *_msgData) { if (!_topic) @@ -187,7 +187,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicPub(const char *_topic, } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceReq(const char *_service, +extern "C" void cmdServiceReq(const char *_service, const char *_reqType, const char *_repType, const int _timeout, const char *_reqData) { @@ -250,7 +250,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceReq(const char *_service, } ////////////////////////////////////////////////// -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicEcho(const char *_topic, +extern "C" void cmdTopicEcho(const char *_topic, const double _duration, int _count) { if (!_topic || std::string(_topic).empty()) @@ -299,7 +299,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicEcho(const char *_topic, } ////////////////////////////////////////////////// -extern "C" const char IGNITION_TRANSPORT_VISIBLE *ignitionVersion() +extern "C" const char *ignitionVersion() { return IGNITION_TRANSPORT_VERSION_FULL; } From 0058eddf5f9a71f6bab4df7801d3134a258e19e8 Mon Sep 17 00:00:00 2001 From: Jose Luis Rivero Date: Mon, 15 Mar 2021 18:43:27 +0100 Subject: [PATCH 17/22] Do not set VISIBILITY for extern C functions Signed-off-by: Jose Luis Rivero --- src/cmd/ign.hh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/ign.hh b/src/cmd/ign.hh index 242a44e32..00817c43d 100644 --- a/src/cmd/ign.hh +++ b/src/cmd/ign.hh @@ -24,17 +24,17 @@ /// \brief External hook to execute 'ign topic -i' from the command line. /// \param[in] _topic Topic name. -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicInfo(const char *_topic); +extern "C" void cmdTopicInfo(const char *_topic); /// \brief External hook to execute 'ign service -i' from the command line. /// \param[in] _service Service name. -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceInfo(const char *_service); +extern "C" void cmdServiceInfo(const char *_service); /// \brief External hook to execute 'ign topic -l' from the command line. -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicList(); +extern "C" void cmdTopicList(); /// \brief External hook to execute 'ign service -l' from the command line. -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceList(); +extern "C" void cmdServiceList(); /// \brief External hook to execute 'ign topic -p' from the command line. /// \param[in] _topic Topic name. @@ -43,7 +43,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceList(); /// DebugString(). /// E.g.: cmdTopicPub("/foo", "ignition.msgs.StringMsg", /// "'data:\"Custom data\"'); -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicPub(const char *_topic, +extern "C" void cmdTopicPub(const char *_topic, const char *_msgType, const char *_msgData); @@ -57,7 +57,7 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicPub(const char *_topic, /// E.g.: cmdServiceReq("/bar", "ignition.msgs.StringMsg", /// "ignition.msgs.StringMsg", 1000, /// "'data:\"Custom data\"'); -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceReq(const char *_service, +extern "C" void cmdServiceReq(const char *_service, const char *_reqType, const char *_repType, const int _timeout, @@ -71,12 +71,12 @@ extern "C" void IGNITION_TRANSPORT_VISIBLE cmdServiceReq(const char *_service, /// \param[in] _count Number of messages to echo and then stop. A value <= 0 /// indicates no limit. The _duration parameter overrides the _count /// parameter. -extern "C" void IGNITION_TRANSPORT_VISIBLE cmdTopicEcho(const char *_topic, +extern "C" void cmdTopicEcho(const char *_topic, const double _duration, int _count); /// \brief External hook to read the library version. /// \return C-string representing the version. Ex.: 0.1.2 -extern "C" const char IGNITION_TRANSPORT_VISIBLE *ignitionVersion(); +extern "C" const char *ignitionVersion(); #endif From 4dcbd4374130cf8fe993dacca061770c9f08ef04 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 18 Mar 2021 22:02:54 -0700 Subject: [PATCH 18/22] Disable UNIT_ign_TEST on windows It still has several issues Signed-off-by: Steve Peters --- src/cmd/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 8d2f9c584..edea0c257 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -2,6 +2,12 @@ # "gtest_sources" variable. ign_get_libsources_and_unittests(sources gtest_sources) +# Skip command line tests for Windows, see +# https://github.com/ignitionrobotics/ign-transport/issues/104 +if (MSVC) + list(REMOVE_ITEM gtest_sources ign_TEST.cc) +endif() + # Make a small static lib of command line functions add_library(ign STATIC ign.cc) target_link_libraries(ign From 66144141a6d4d961c28685e9a48bbd7d775f6dc0 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Wed, 31 Mar 2021 11:48:55 -0700 Subject: [PATCH 19/22] Use popen2e to print input as it arrives This fixes ign topic --echo Signed-off-by: Steve Peters --- src/cmd/cmdtransport.rb.in | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cmd/cmdtransport.rb.in b/src/cmd/cmdtransport.rb.in index 1ee747b61..e9f0b80e9 100644 --- a/src/cmd/cmdtransport.rb.in +++ b/src/cmd/cmdtransport.rb.in @@ -51,8 +51,16 @@ class Cmd end # Drop command from list of arguments - stdout_and_stderr, status = Open3.capture2e(exe_name, *args[1..-1]) - print stdout_and_stderr - exit(status.exitstatus) + Open3.popen2e(exe_name, *args[1..-1]) do |_in, out_err, wait_thr| + begin + out_err.each do |line| + print line + end + exit(wait_thr.value.exitstatus) + rescue Interrupt => e + print e.message + exit(-1) + end + end end end From 42472b2a4c2bf4217bc5f8af4064723c46ca43bb Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 27 Apr 2021 15:01:20 -0700 Subject: [PATCH 20/22] Install to IGN_LIB_INSTALL_DIR Fix behavior when installed to /usr on Linux Signed-off-by: Steve Peters --- src/cmd/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index edea0c257..e809cbc30 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -22,7 +22,7 @@ target_link_libraries(${topic_executable} ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) -install(TARGETS ${topic_executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +install(TARGETS ${topic_executable} DESTINATION ${IGN_LIB_INSTALL_DIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) # Build service CLI executable set(service_executable ign-transport-service) @@ -32,7 +32,7 @@ target_link_libraries(${service_executable} ignition-utils${IGN_UTILS_VER}::cli ${PROJECT_LIBRARY_TARGET_NAME} ) -install(TARGETS ${service_executable} DESTINATION lib/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) +install(TARGETS ${service_executable} DESTINATION ${IGN_LIB_INSTALL_DIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/) # Build the unit tests. ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} From 040faa7fa28d41be358c40d9ba93f01c3fe7288e Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 30 Apr 2021 19:16:47 -0700 Subject: [PATCH 21/22] Wait longer in TopicPublish test Signed-off-by: Steve Peters --- src/cmd/ign_TEST.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cmd/ign_TEST.cc b/src/cmd/ign_TEST.cc index 4362035e4..18580fb10 100644 --- a/src/cmd/ign_TEST.cc +++ b/src/cmd/ign_TEST.cc @@ -332,8 +332,11 @@ TEST(ignTest, TopicPublish) g_ignVersion); ASSERT_TRUE(output.empty()) << output; - std::this_thread::sleep_for(std::chrono::milliseconds(300)); - + unsigned int retries = 0; + while (g_topicCBStr != "good_value" && retries++ < 20u) + { + std::this_thread::sleep_for(std::chrono::milliseconds(300)); + } EXPECT_EQ(g_topicCBStr, "good_value"); // Try to publish a message not included in Ignition Messages. From f39b7d7667b904cff16f84d9965b5cb422e57008 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 11 May 2021 16:50:20 -0700 Subject: [PATCH 22/22] ign_TEST: improve reliability of TopicPublish test Keep calling `ign topic --pub` if messages aren't received. Signed-off-by: Steve Peters --- src/cmd/ign_TEST.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cmd/ign_TEST.cc b/src/cmd/ign_TEST.cc index 18580fb10..9d346345a 100644 --- a/src/cmd/ign_TEST.cc +++ b/src/cmd/ign_TEST.cc @@ -327,15 +327,20 @@ TEST(ignTest, TopicPublish) // Check the 'ign topic -p' command. std::string ign = std::string(IGN_PATH) + "/ign"; - std::string output = custom_exec_str(ign + - " topic -t /bar -m ign_msgs.StringMsg -p 'data:\"good_value\"' " + - g_ignVersion); + std::string output; - ASSERT_TRUE(output.empty()) << output; unsigned int retries = 0; - while (g_topicCBStr != "good_value" && retries++ < 20u) + while (g_topicCBStr != "good_value" && retries++ < 200u) { - std::this_thread::sleep_for(std::chrono::milliseconds(300)); + // Send on alternating retries + if (retries % 2) + { + output = custom_exec_str(ign + + " topic -t /bar -m ign_msgs.StringMsg -p 'data:\"good_value\"' " + + g_ignVersion); + EXPECT_TRUE(output.empty()) << output; + } + std::this_thread::sleep_for(std::chrono::milliseconds(30)); } EXPECT_EQ(g_topicCBStr, "good_value"); @@ -351,14 +356,14 @@ TEST(ignTest, TopicPublish) output = custom_exec_str(ign + " topic -t / -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+ g_ignVersion); - EXPECT_EQ(output.compare(0, error.size(), error), 0); + EXPECT_EQ(output.compare(0, error.size(), error), 0) << output; // Try to publish using an incorrect number of arguments. error = "The following argument was not expected: wrong_topic"; output = custom_exec_str(ign + " topic -t / wrong_topic -m ign_msgs.StringMsg -p 'data:\"good_value\"' "+ g_ignVersion); - EXPECT_EQ(output.compare(0, error.size(), error), 0); + EXPECT_EQ(output.compare(0, error.size(), error), 0) << output; } //////////////////////////////////////////////////