-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support standalone executable in gz-msgs11 (#357)
Signed-off-by: Michael Carroll <[email protected]>
- Loading branch information
Showing
14 changed files
with
301 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
set(msgs_executable gz-msgs) | ||
add_executable(${msgs_executable} msgs_main.cc) | ||
target_link_libraries(${msgs_executable} | ||
${PROJECT_LIBRARY_TARGET_NAME} | ||
gz-utils${GZ_UTILS_VER}::cli | ||
) | ||
|
||
set(EXE_INSTALL_DIR ${CMAKE_INSTALL_LIBEXECDIR}/gz/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}/) | ||
install(TARGETS ${msgs_executable} DESTINATION ${EXE_INSTALL_DIR}) | ||
set(executable_location "../../../${EXE_INSTALL_DIR}/$<TARGET_FILE_NAME:${msgs_executable}>") | ||
|
||
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmd${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb") | ||
set(cmd_script_configured "${cmd_script_generated}.configured") | ||
|
||
configure_file( | ||
"cmd${GZ_DESIGNATION}.rb.in" | ||
"${cmd_script_configured}" | ||
@ONLY) | ||
|
||
file(GENERATE | ||
OUTPUT "${cmd_script_generated}" | ||
INPUT "${cmd_script_configured}") | ||
|
||
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/gz) | ||
|
||
#=============================================================================== | ||
# Bash completion | ||
|
||
# Tack version onto and install the bash completion script | ||
configure_file( | ||
"msgs.bash_completion.sh" | ||
"${CMAKE_CURRENT_BINARY_DIR}/msgs${PROJECT_VERSION_MAJOR}.bash_completion.sh" @ONLY) | ||
install( | ||
FILES | ||
${CMAKE_CURRENT_BINARY_DIR}/msgs${PROJECT_VERSION_MAJOR}.bash_completion.sh | ||
DESTINATION | ||
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/gz${GZ_TOOLS_VER}.completion.d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Copyright (C) 2016 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. | ||
|
||
require 'open3' | ||
require 'pathname' | ||
|
||
COMMANDS = { | ||
'msg' => '@executable_location@' | ||
}.freeze | ||
|
||
# Class for the Gazebo msgs command line tools. | ||
# | ||
class Cmd | ||
def execute(args) | ||
exe_name = COMMANDS[args[0]] | ||
|
||
unless Pathname.new(exe_name).absolute? | ||
# 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__), LIBRARY_NAME)) | ||
end | ||
|
||
# Drop command from list of arguments | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (C) 2023 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 <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <gz/utils/cli/CLI.hpp> | ||
#include <gz/utils/cli/GzFormatter.hpp> | ||
|
||
#include <gz/msgs/config.hh> | ||
#include <gz/msgs/Factory.hh> | ||
#include <gz/msgs/MessageTypes.hh> | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Enumeration of available commands | ||
enum class MsgCommand | ||
{ | ||
kNone, | ||
kMsgInfo, | ||
kMsgList, | ||
}; | ||
|
||
////////////////////////////////////////////////// | ||
/// \brief Structure to hold all available message options | ||
struct MsgOptions | ||
{ | ||
/// \brief Command to execute | ||
MsgCommand command {MsgCommand::kNone}; | ||
|
||
/// \brief List of messages for message info command | ||
std::vector<std::string> msgNames; | ||
}; | ||
|
||
////////////////////////////////////////////////// | ||
void runMsgInfo(const MsgOptions &_opt) | ||
{ | ||
for (const auto &msgName: _opt.msgNames) | ||
{ | ||
auto msg = gz::msgs::Factory::New(msgName); | ||
if (msg) | ||
{ | ||
auto descriptor = msg->GetDescriptor(); | ||
auto fileDescriptor = descriptor->file(); | ||
std::cout << "Name: " << descriptor->full_name() << std::endl; | ||
std::cout << "File: " << fileDescriptor->name() << std::endl << std::endl; | ||
std::cout << descriptor->DebugString() << std::endl; | ||
} | ||
else | ||
{ | ||
std::cerr << "Unable to create message of type[" << msgName << "]\n"; | ||
} | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void runMsgList(const MsgOptions &/*_opt*/) | ||
{ | ||
std::vector<std::string> types; | ||
gz::msgs::Factory::Types(types); | ||
|
||
for (auto const &type : types) | ||
std::cout << type << std::endl; | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void runMsgCommand(const MsgOptions &_opt) | ||
{ | ||
switch(_opt.command) | ||
{ | ||
case MsgCommand::kMsgInfo: | ||
runMsgInfo(_opt); | ||
break; | ||
case MsgCommand::kMsgList: | ||
runMsgList(_opt); | ||
break; | ||
case MsgCommand::kNone: | ||
default: | ||
// In the event that there is no command, display help | ||
throw CLI::CallForHelp(); | ||
break; | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void addMsgFlags(CLI::App &_app) | ||
{ | ||
auto opt = std::make_shared<MsgOptions>(); | ||
|
||
auto listOpt = _app.add_flag_callback("-l,--list", | ||
[opt](){ | ||
opt->command = MsgCommand::kMsgList; | ||
}, "List all message types."); | ||
|
||
auto infoOpt = _app.add_option("-i,--info", | ||
opt->msgNames, "Get info about the specified message type.") | ||
->excludes(listOpt); | ||
|
||
_app.callback([opt, infoOpt](){ | ||
if(infoOpt->count() > 0) { | ||
opt->command = MsgCommand::kMsgInfo; | ||
} | ||
runMsgCommand(*opt); | ||
}); | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
int main(int argc, char** argv) | ||
{ | ||
CLI::App app{"Print information about Gazebo messages"}; | ||
|
||
app.add_flag_callback("-v,--version", [](){ | ||
std::cout << GZ_MSGS_VERSION_FULL << std::endl; | ||
throw CLI::Success(); | ||
}); | ||
|
||
addMsgFlags(app); | ||
app.formatter(std::make_shared<GzFormatter>(&app)); | ||
CLI11_PARSE(app, argc, argv); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.