Skip to content

Add ament_cmake_core function to get install path of resource - #154

Closed
pbaughman wants to merge 1 commit into
ament:masterfrom
pbaughman:master
Closed

pbaughman wants to merge 1 commit into
ament:masterfrom
pbaughman:master

Conversation

@pbaughman

Copy link
Copy Markdown
Contributor
  • Parity with ament_index_python function get_package_prefix(package_name)

Need a way to do this but from a CMakeLists file. ament_cmake_index_has_resource is close, but doesn't tell you the path - it just tells you that the resource exists

 - Parity with ament_index_python function get_package_prefix(package_name)
@tfoote tfoote added the in review Waiting for review (Kanban column) label Feb 5, 2019
@wjwwood

wjwwood commented Feb 5, 2019

Copy link
Copy Markdown
Contributor

This function gets the contents of the file:

#
# Get the content of a specific resource from the index.
#
# :param var: the output variable name for the content of the requested
# resource
# :type var: string
# :param resource_type: the type of the resource
# :type resource_type: string
# :param resource_name: the name of the resource
# :type resource_name: string
# :param PREFIX_PATH: the prefix path to search for (default
# ``ament_index_get_prefix_path()``).
# :type PREFIX_PATH: list of strings
#
# @public
#

Maybe it should be refactored to use your new function (they're the same except the line that reads the file AFAICT).

@pbaughman

Copy link
Copy Markdown
Contributor Author

@wjwwood Good point - I'll make the change

@pbaughman

pbaughman commented Feb 5, 2019 •

Copy link
Copy Markdown
Contributor Author

@wjwwood Upon closer inspection, changing ament_index_get_resource to use the new function doesn't really make anything better. The new function is as long as the old function (because of the handling of ARG_PREFIX_PATH and checking if the file exists) , and contains a bunch of changes that I can't test very effectively.

I don't really want to risk messing it up

function(ament_index_get_resource var resource_type resource_name)
  if(resource_type STREQUAL "")
    message(FATAL_ERROR
      "ament_index_get_resource() called without a 'resource_type'")
  endif()
  if(resource_name STREQUAL "")
    message(FATAL_ERROR
      "ament_index_get_resource() called without a 'resource_name'")
  endif()

  cmake_parse_arguments(ARG "" "PREFIX_PATH" "" ${ARGN})
  if(ARG_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR "ament_index_get_resource() called with unused "
      "arguments: ${ARG_UNPARSED_ARGUMENTS}")
  endif()

  if(ARG_PREFIX_PATH)
    set(prefix_path "${ARG_PREFIX_PATH}")
  else()
    ament_index_get_prefix_path(prefix_path)
  endif()

  ament_index_get_resource_prefix_path(INSTALLDIR resource_type resource_name
    PREFIX_PATH prefix_path)

  set(filename
      "${INSTALLDIR}/share/ament_index/resource_index/${resource_type}/${resource_name}")
  if(EXISTS "${filename}")
    file(READ "${filename}" retval)
    set(${var} "${retval}" PARENT_SCOPE)
    return()
  message(FATAL_ERROR "ament_index_get_resource() called with not existing "
    "resource ('${resource_type}' '${resource_name}')")
endfunction()

@dirk-thomas

Copy link
Copy Markdown
Contributor

How about changing the semantic the existing CMake function ament_index_has_resource to match the Python API and instead of returning TRUE to return the prefix path in case the resource was found?

@wjwwood

wjwwood commented Feb 5, 2019 •

Copy link
Copy Markdown
Contributor

Well, I assumed that you could avoid much of the argument checking and just pass most arguments to the function that gets the directory. You'd only really need to extract the output var for the contents and inject the local var name for the path (to be used to read the file contents).

@dirk-thomas

Copy link
Copy Markdown
Contributor

Please see #155 which implements the mentioned alternative and comment if that works for your use case.

@pbaughman

Copy link
Copy Markdown
Contributor Author

When I test #155, building builtin_interfaces fails

@pbaughman

Copy link
Copy Markdown
Contributor Author

Closing in favor of #155

@pbaughman pbaughman closed this Feb 6, 2019
@tfoote tfoote removed the in review Waiting for review (Kanban column) label Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants