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

Fix use of Backward on macOS #67

Merged
merged 8 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,6 @@ else (build_errors)
${PROJECT_NAME_LOWER}")
endif(build_errors)

include(CTest)

add_subdirectory(src)
76 changes: 73 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,78 @@ if(WIN32)
endif()
install (TARGETS backward DESTINATION ${LIB_INSTALL_DIR})

#===============================================================================
# Used for the installed version.
if(APPLE)
# On macOS, the full path to the library since DYLD_LIBRARY_PATH may not work.
set(backward_library_name ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/$<TARGET_FILE_NAME:backward>)
Copy link
Member

Choose a reason for hiding this comment

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

someone recently submitted gazebosim/gazebo-classic#3076 to change ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} to ${CMAKE_INSTALL_FULL_LIBDIR}, so I think we could do the same here

else()
set(backward_library_name $<TARGET_FILE_NAME:backward>)
endif()

# Two steps to create `ign`, First using `configure_file`, to interpolate cmake variables. Then
# use `file(GENERATE ...)` to use generator expressions
configure_file(ign.in ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name} INPUT ${PROJECT_BINARY_DIR}/${executable_name}_before_gen )
install (PROGRAMS ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name} DESTINATION ${BIN_INSTALL_DIR})
set(ign_script_configured ${PROJECT_BINARY_DIR}/${executable_name}_before_gen)
set(ign_script_generated ${PROJECT_BINARY_DIR}/$<CONFIG>/${executable_name})

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

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

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

set(IGN_DESIGNIATION tools)
set(cmd_script_configured_test "${CMAKE_CURRENT_BINARY_DIR}/cmd${IGN_DESIGNIATION}_TEST.rb.configured")
set(cmd_script_generated_test "${PROJECT_BINARY_DIR}/test/lib/$<CONFIG>/ruby/ignition/cmd${IGN_DESIGNIATION}_TEST.rb")

configure_file(
"cmd${IGN_DESIGNIATION}_TEST.rb.in"
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any @ symbols in this file that need configuring. I think we can just add it as cmdtools_TEST.rb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 311d588.

"${cmd_script_configured_test}"
@ONLY)

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

set(ign_library_path ${cmd_script_generated_test})

set(yaml_output_dir "${PROJECT_BINARY_DIR}/test/conf/" )
set(yaml_output_configured_test "${yaml_output_dir}/${IGN_DESIGNIATION}_TEST.yaml.configured" )
set(yaml_output_generated_test "${yaml_output_dir}/$<CONFIG>/${IGN_DESIGNIATION}_TEST.yaml" )
configure_file(
"${IGN_DESIGNIATION}_TEST.yaml.in"
${yaml_output_configured_test} @ONLY)

file(GENERATE
OUTPUT "${yaml_output_generated_test}"
INPUT "${yaml_output_configured_test}")

add_test(NAME UNIT_ign_TEST COMMAND ruby ${ign_script_generated_test} tools_TEST)
Copy link
Member

Choose a reason for hiding this comment

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

calling ruby like this will work if it's in the PATH. In some cases, we may need to find_program and refer to the cmake variable here, but we can address that once we see CI failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.


set_tests_properties(
UNIT_ign_TEST
PROPERTIES
ENVIRONMENT
"IGN_CONFIG_PATH=${yaml_output_dir}/$<CONFIG>"
)
set_tests_properties(UNIT_ign_TEST PROPERTIES
PASS_REGULAR_EXPRESSION "Test passed"
)

set_tests_properties(UNIT_ign_TEST PROPERTIES
FAIL_REGULAR_EXPRESSION "Library error"
)
endif()
# END TEST
#==============================
30 changes: 30 additions & 0 deletions src/cmdtools_TEST.rb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/ruby

# 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.

require 'optparse'

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

class Cmd
#
# Execute the command
#
def execute(args)
puts "Test passed"
end
end

11 changes: 2 additions & 9 deletions src/ign.in
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,10 @@ if ARGV.include?('--versions')
end

# Start Backward before loading plugins
backward_library_name = if (/darwin/ =~ RUBY_PLATFORM).nil?
'$<TARGET_FILE_NAME:backward>'
else
# On macOS, the full path to the library since
# DYLD_LIBRARY_PATH may not work.
'$<TARGET_FILE:backward>'
end
begin
SharedLibInterface::Importer.dlload backward_library_name
SharedLibInterface::Importer.dlload '@backward_library_name@'
rescue SharedLibInterface::DLError
puts "Library error: #{backward_library_name} not found. Improved backtrace"\
puts 'Library error: @backward_library_name@ not found. Improved backtrace'\
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use STDERR.puts here, which might also help with the test failures that have expectations on the stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 311d588. I used warn instead because codecheck didn't like STDERR.puts.

' generation will be disabled'
end

Expand Down
9 changes: 9 additions & 0 deletions src/tools_TEST.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- # test commands
format: 1.0.0
library_name: @PROJECT_NAME@
library_version: ''
library_path: @ign_library_path@
commands:
- tools_TEST : Test command
---