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

Deprecate public ign functions in favor of gz #250

Merged
merged 23 commits into from
Jun 16, 2022
Merged

Conversation

chapulina
Copy link
Contributor

@chapulina chapulina commented May 5, 2022

Summary

Deprecate the ign_ functions that are used by downstream packages and replace them with gz_ counterparts. Warnings are commented out and will be enabled once all our libraries have migrated to gz_.

As far as I can tell, CMake doesn't provide a convenient way for a function to forward arguments to another. So I had to play a bit with the scopes to make sure all the values passed in and returned from a function worked correctly.

Here are the rules I came up with:

  • If a function doesn't take any arguments and doesn't set or get any variables from the parent scope, it can be wrapped directly like this:
function(ign_XXX)
    gz_XXX()
endfunction()
function(gz_XXX)
  # Exactly the same as old ign_XXX
endfunction()
  • If a function takes named arguments, those can be forwarded directly:
function(ign_XXX named_arg)
    gz_XXX(${named_arg})
endfunction()
function(gz_XXX)
  # Exactly the same as old ign_XXX
endfunction()
  • If a function takes optional arguments parsed with cmake_parse_arguments, parse those at the old ign_ function and skip parsing them in the new function with the help of a skip_parsing variable.
function(ign_XXX named_arg)

    # Exactly same as in gz_ below
    set(options SOME_OPTION)
    set(oneValueArgs SOME_VALUE)
    set(multiValueArgs SOME_MULTIVALUE)
    cmake_parse_arguments(gz_install_all_headers "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    set(gz_XXX_skip_parsing true)
    gz_XXX(${named_arg})
endfunction()
function(gz_XXX)

   # Skip parsing when called from ign_, otherwise parse as usual
    if (NOT gz_XXX_skip_parsing)
      set(options SOME_OPTION)
      set(oneValueArgs SOME_VALUE)
      set(multiValueArgs SOME_MULTIVALUE)
      cmake_parse_arguments(gz_install_all_headers "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
    endif()

  # The rest is exactly the same as old ign_XXX
endfunction()
  • If a function sets values to the parent scope, those need to be bubbled up by the ign_ wrapper function:
function(ign_XXX)
    gz_XXX()

    set(${gz_XXX_RETURN_VALUE} ${${gz_XXX_RETURN_VALUE}} PARENT_SCOPE)
endfunction()
function(gz_XXX)
  # Exactly the same as old ign_XXX
  # Includes somewhere
  # set(${gz_XXX_RETURN_VALUE} ${calculated_value} PARENT_SCOPE)
endfunction()

Test it

  1. Compile the stack using this branch, and verify that everything still works the same way
  2. Uncomment some of the commented warnings, then compile the stack and verify that warnings show up
  3. Update downstream packages to use gz_ instead of ign_ and verify that they work the same, without warnings

TODO

Keeping as draft until

  • All ign_ functions have been deprecated
  • Set up CI compiling the entire stack to verify point 1 above

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸

@chapulina chapulina added 🌱 garden Ignition Garden ign to gz Renaming Ignition to Gazebo. labels May 5, 2022
@methylDragon
Copy link
Contributor

methylDragon commented May 7, 2022

Problem

There's a small issue with the approach you're using for bubbling parsed variables down to a gz_ prefixed function.

If you have something like ign_A -> gz_A -> gz_B, the common skip_parsing variable causes gz_B to skip its parsing, which is not good (and breaks in the case of gz-gui!)

Solution

I'd recommend using a prefix to mangle the names. Like gz_b_skip_parsing.

Working Example

See working example here: https://github.com/gazebosim/gz-gui/pull/395/files#diff-befa40e675cae663c40a34346dbbffd61207a9fac4c557ecc9015786b8bc95c1

@methylDragon methylDragon marked this pull request as ready for review May 7, 2022 00:47
@methylDragon methylDragon marked this pull request as draft May 7, 2022 00:47
@chapulina
Copy link
Contributor Author

I'd recommend using a prefix to mangle the names. Like gz_b_skip_parsing.

Thanks for catching that, updated this PR with this pattern

Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
@chapulina chapulina changed the base branch from main to chapulina/3/ign_deprecations_3 May 17, 2022 03:38
@chapulina chapulina force-pushed the chapulina/3/gz_functions branch 2 times, most recently from d2c1b2a to d019a7c Compare May 17, 2022 03:47
@chapulina chapulina changed the base branch from chapulina/3/ign_deprecations_3 to chapulina/3/ign_deprecations_4 May 17, 2022 04:12
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
@chapulina chapulina changed the base branch from chapulina/3/ign_deprecations_4 to chapulina/3/ign_deprecations_5 May 17, 2022 04:30
Base automatically changed from chapulina/3/ign_deprecations_5 to main May 24, 2022 16:42
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
@chapulina chapulina changed the base branch from main to chapulina/3/internal_ign May 24, 2022 17:56
@chapulina
Copy link
Contributor Author

This PR now builds on top of

These are the functions and macros currently migrated by this PR:

ign_pkg_check_modules_quiet
ign_pkg_config_library_entry
ign_pkg_config_entry
ign_pkg_check_modules
ign_add_component
ign_target_interface_include_directories
ign_build_executables

There are still some to go.

Base automatically changed from chapulina/3/internal_ign to main May 27, 2022 17:31
@chapulina chapulina marked this pull request as ready for review June 16, 2022 17:41
@methylDragon
Copy link
Contributor

Will approve once my local build works with this

@chapulina chapulina merged commit 8572411 into main Jun 16, 2022
@chapulina chapulina deleted the chapulina/3/gz_functions branch June 16, 2022 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden ign to gz Renaming Ignition to Gazebo.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants