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

Use functions instead of macros where possible to avoid leaking variables #835

Merged
merged 1 commit into from
Jan 27, 2017
Merged

Use functions instead of macros where possible to avoid leaking variables #835

merged 1 commit into from
Jan 27, 2017

Conversation

ksperling
Copy link
Contributor

My primary reason for this PR is the first commit that makes list_insert_in_workspace_order a function, as it leaks a variable called cmd which triggers a bug in ExternalProject_Add (the value of the cmd variable becomes the default BUILD and INSTALL command for the external project, so order_paths.py just gets run a couple more times instead of actually building anything).

I filed a PR for CMake to fix this (https://gitlab.kitware.com/cmake/cmake/merge_requests/264), but I think it would be good to also fix this on the catkin side regardless. In general it seems to me using functions instead of macros wherever possible is desirable to avoid polluting the caller's variable namespace, but I'm by no means a CMake expert.

All tests still seem to pass (and my projects still build, and ExternalProject_Add works as expected)

@ksperling
Copy link
Contributor Author

Bump?

@dirk-thomas
Copy link
Member

Sorry for not responding on this before. I currently have to focus on ROS 2 related tasks. Hopefully I will have time to look at this in the next weeks.

@ksperling
Copy link
Contributor Author

Thanks for the update :)

endif()
math(EXPR _index "${_index} + 1")
endwhile()
set(${VAR} "${result}" PARENT_SCOPE)
debug_message(10 "catkin_filter_libraries_for_build_configuration(${VAR} ${ARG_UNPARSED_ARGUMENTS} BUILD_TYPE ${ARG_BUILD_TYPE}) ${${VAR}}")
Copy link
Member

Choose a reason for hiding this comment

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

Does ${${VAR}} work in this context? Does it get the updated value set in the parent scope in the line above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it doesn't see the updated value, good catch. Seems like the child scope starts out with a copy of the parent scope at the start of the function, rather than dynamically inheriting any variables not present locally.

macro(catkin_unpack_libraries_with_build_configuration VAR)
set(${VAR} "")
function(catkin_unpack_libraries_with_build_configuration VAR)
set(result "")
foreach(lib ${ARGN})
string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}")
list(APPEND ${VAR} "${lib}")
Copy link
Member

Choose a reason for hiding this comment

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

This should append to result.

@ksperling
Copy link
Contributor Author

Thanks for the review, I've addressed those two issues in the last commit. Let me know if you want me to squash everything into 1 commit.

endif()
math(EXPR _index "${_index} + 1")
endwhile()
set(${VAR} "${result}" PARENT_SCOPE)
#debug_message(10 "catkin_pack_libraries_with_build_configuration(${VAR} ${_argn}) ${${VAR}}")
Copy link
Member

Choose a reason for hiding this comment

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

Just to be safe if someone enables this line in the future can you also update it to use ${result} instead of ${${VAR}}.

endif()
endforeach()
set(${VAR} "${result}" PARENT_SCOPE)
#set(_argn ${ARGN})
#debug_message(10 "catkin_replace_imported_library_targets(${VAR} ${_argn}) ${${VAR}}")
Copy link
Member

Choose a reason for hiding this comment

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

Just to be safe if someone enables this line in the future can you also update it to use ${result} instead of ${${VAR}}.

@dirk-thomas
Copy link
Member

Thanks for iterating on this. I added two more comments inline.

If you can squash the commits afterwards that would be great. Otherwise I can take care of it during the merge.

…al variables.

The leaked 'cmd' variable in particular triggers a bug in cmake's ExternalProject_Add,
see https://gitlab.kitware.com/cmake/cmake/merge_requests/264

Also replace other macros with functions where possible.
@ksperling
Copy link
Contributor Author

Should all be tidied up now.

@dirk-thomas
Copy link
Member

dirk-thomas commented Jan 26, 2017

Thanks for the update. It looks good to me. I ran a prerelease test locally with 100+ packages to convince myself that the chance for regressions is minimal. Lets hope the next release builds "agree" with that 😉

@ros/ros_team Please review.

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm

@dirk-thomas dirk-thomas merged commit 5cd8c81 into ros:kinetic-devel Jan 27, 2017
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.

3 participants