Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 2 ⬅️ 5 - Add standalone executables (#121) #256

Draft
wants to merge 1 commit into
base: ign-launch2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ ign_find_package(TINYXML2 REQUIRED PRIVATE PRETTY tinyxml2)
ign_find_package(ignition-common3 REQUIRED PRIVATE)
set(IGN_COMMON_MAJOR_VER ${ignition-common3_VERSION_MAJOR})

#--------------------------------------
# Find ignition-utils
ign_find_package(ignition-utils1 REQUIRED COMPONENTS cli)
set(IGN_UTILS_VER ${ignition-utils1_VERSION_MAJOR})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't want to add a new dependency to a stable branch. If this is needed to fix the tests, let's just disable them. I'm doing so in #255, so maybe that could be backported instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it's not for the tests, it's using the cli component for the standalone executables:

I'll see if we can backport some of the cmake changes without switching to a standalone executable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scpeters were you able to take a look to that? let us know if we can help you on that one


#--------------------------------------
# Find ignition-plugin
ign_find_package(ignition-plugin1 REQUIRED_BY launch COMPONENTS loader register)
Expand Down
6 changes: 6 additions & 0 deletions examples/ls.ign
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0'?>
<ignition version='1.0'>
<executable name='ls'>
<command>ls</command>
</executable>
</ignition>
92 changes: 16 additions & 76 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# add_subdirectory(plugins)

set (sources
ign.cc
Manager.cc
)

set (gtest_sources
Manager_TEST.cc
ign_TEST.cc
)

# Create the library target.
Expand Down Expand Up @@ -35,80 +33,22 @@ ign_build_tests(TYPE UNIT SOURCES ${gtest_sources}
ignition-common${IGN_COMMON_MAJOR_VER}::ignition-common${IGN_COMMON_MAJOR_VER}
)

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

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

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

# Generate a the ruby script.
# Note that the major version of the library is included in the name.
# Ex: cmdlaunch0.rb
if (APPLE)
set(IGN_LIBRARY_NAME lib${PROJECT_LIBRARY_TARGET_NAME}.dylib)
else()
set(IGN_LIBRARY_NAME lib${PROJECT_LIBRARY_TARGET_NAME}.so)
endif()

configure_file(
"cmdlaunch.rb.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmdlaunch${PROJECT_VERSION_MAJOR}.rb" @ONLY)


# Install the ruby command line library in an unversioned location.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmdlaunch${PROJECT_VERSION_MAJOR}.rb DESTINATION lib/ruby/ignition)

set(ign_library_path
"${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdlaunch${PROJECT_VERSION_MAJOR}")

# Generate a configuration file.
# Note that the major version of the library is included in the name.
# Ex: fuel0.yaml
configure_file(
"launch.yaml.in"
"${CMAKE_CURRENT_BINARY_DIR}/launch${PROJECT_VERSION_MAJOR}.yaml" @ONLY)

# Install the yaml configuration files in an unversioned location.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/launch${PROJECT_VERSION_MAJOR}.yaml DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/)

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
# Ex: cmdlaunch0.rb
set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmdlaunch${PROJECT_VERSION_MAJOR}.rb")
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(IGN_LIBRARY_NAME "$<TARGET_FILE:${PROJECT_LIBRARY_TARGET_NAME}>")

configure_file(
"cmdlaunch.rb.in"
"${cmd_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")

# Used only for internal testing.
set(ign_library_path "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmdlaunch${PROJECT_VERSION_MAJOR}")

# Generate a configuration file for internal testing.
# Note that the major version of the library is included in the name.
# Ex: launch0.yaml
configure_file(
"launch.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/launch${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
# if(TARGET UNIT_ign_TEST)
# # Running `ign launch` on macOS has problems when run with /usr/bin/ruby
# # due to System Integrity Protection (SIP). Try to find ruby from
# # homebrew as a workaround.
# if (APPLE)
# find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin)
# endif()
#
# target_compile_definitions(UNIT_ign_TEST PRIVATE
# "BREW_RUBY=\"${BREW_RUBY} \"")
#
# target_compile_definitions(UNIT_ign_TEST PRIVATE
# "IGN_PATH=\"${HAVE_IGN_TOOLS}\"")
# endif()

add_subdirectory(cmd)

#===============================================================================
# Bash completion
Expand Down
126 changes: 126 additions & 0 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Collect source files into the "sources" variable and unit test files into the
# "gtest_sources" variable.
ign_get_libsources_and_unittests(sources gtest_sources)

add_library(ign STATIC ign.cc)
target_include_directories(ign PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ign PUBLIC
${PROJECT_LIBRARY_TARGET_NAME}
ignition-common${IGN_COMMON_MAJOR_VER}::ignition-common${IGN_COMMON_MAJOR_VER}
)

set(launch_executable ign-launch)
add_executable(${launch_executable} launch_main.cc)
target_link_libraries(${launch_executable}
ign
ignition-utils${IGN_UTILS_VER}::cli
ignition-common${IGN_COMMON_MAJOR_VER}::ignition-common${IGN_COMMON_MAJOR_VER}
)

install(
TARGETS
${launch_executable}
DESTINATION
${IGN_LIB_INSTALL_DIR}/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})
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
# multi-configuration generators, like Visual Studio.
target_compile_definitions(${test} PRIVATE
"DETAIL_IGN_TRANSPORT_TEST_DIR=\"$<TARGET_FILE_DIR:${test}>\""
"IGN_TEST_LIBRARY_PATH=\"$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>\"")

endforeach()

if (TARGET UNIT_ign_TEST)
set_tests_properties(
UNIT_ign_TEST
PROPERTIES
ENVIRONMENT
"IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
)
endif()

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
# Ex: cmdlaunch5.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 "${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.
set(launch_exe_location "$<TARGET_FILE:${launch_executable}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured_test}"
@ONLY
)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}"
)

#===============================================================================
# Used for the installed version.
# Generate the ruby script that gets installed.
# Note that the major version of the library is included in the name.
# Ex: cmdlaunch5.rb
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
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(launch_exe_location "../../../${CMAKE_INSTALL_LIBDIR}/ignition/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}/$<TARGET_FILE_NAME:${launch_executable}>")

message("launch_exe_location " ${launch_exe_location})

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated}"
INPUT "${cmd_script_configured}")

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: launch5.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${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}")

# Generate the configuration file that is installed.
# Note that the major version of the library is included in the name.
# Ex: launch5.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_CURRENT_BINARY_DIR}/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)

# Install the yaml configuration files in an unversioned location.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/)

# Install the ruby command line library in an unversioned location.
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition)
65 changes: 65 additions & 0 deletions src/cmd/cmdlaunch.rb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env ruby

# Copyright (C) 2014 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'

# Constants.
LIBRARY_VERSION = '@PROJECT_VERSION_FULL@'
COMMANDS = {
"launch" => "@launch_exe_location@",
}

#
# Class for the Ignition launch command line tools.
#
class Cmd
def execute(args)
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 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))
end
conf_version = LIBRARY_VERSION
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 exe_version.eql? conf_version
puts "Error: Version mismatch. Your configuration file version is
[#{conf_version}] but #{exe_name} version is [#{exe_version}]."
exit(-1)
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
13 changes: 6 additions & 7 deletions src/ign.cc → src/cmd/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,28 @@

#include "ignition/launch/config.hh"
#include "ign.hh"
#include "Manager.hh"
#include "../Manager.hh"

//////////////////////////////////////////////////
extern "C" IGNITION_LAUNCH_VISIBLE char *ignitionVersion()
extern "C" char *ignitionVersion()
{
return strdup(IGNITION_LAUNCH_VERSION_FULL);
}

//////////////////////////////////////////////////
extern "C" IGNITION_LAUNCH_VISIBLE const char *configPath()
extern "C" const char *configPath()
{
return IGNITION_LAUNCH_INITIAL_CONFIG_PATH;
}

//////////////////////////////////////////////////
extern "C" IGNITION_LAUNCH_VISIBLE void cmdVerbosity(
const char *_verbosity)
extern "C" void cmdVerbosity(const int _verbosity)
{
ignition::common::Console::SetVerbosity(std::atoi(_verbosity));
ignition::common::Console::SetVerbosity(_verbosity);
}

//////////////////////////////////////////////////
extern "C" IGNITION_LAUNCH_VISIBLE int run(const char *_config)
extern "C" int run(const char *_config)
{
ignition::launch::Manager mgr;
return mgr.RunConfig(_config);
Expand Down
8 changes: 4 additions & 4 deletions src/ign.hh → src/cmd/ign.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

/// \brief External hook to read the library version.
/// \return C-string representing the version. Ex.: 0.1.2
extern "C" IGNITION_LAUNCH_VISIBLE char *ignitionVersion();
extern "C" char *ignitionVersion();

/// \brief Set verbosity level
/// \param[in] _verbosity 0 to 4
extern "C" IGNITION_LAUNCH_VISIBLE void cmdVerbosity(
const char *_verbosity);
extern "C" void cmdVerbosity(
const int _verbosity);

/// \brief External hook to execute 'ign fuel list -t model' from the command
/// line.
/// \param[in] _config Config file to run.
/// \return 1 if successful, 0 if not.
extern "C" IGNITION_LAUNCH_VISIBLE int run(const char *_config);
extern "C" int run(const char *_config);

#endif
Loading
Loading