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

zephyr_library_compile_options(): de-duplicate #15094

Merged

Conversation

marc-hb
Copy link
Collaborator

@marc-hb marc-hb commented Apr 1, 2019

PR #14776 / commit 915a353 changed function
zephyr_library_compile_options() to use MD5 instead of RANDOM for build
reproduction reasons. As later predicted by Sebastian Bøe in the PR
(thx), the names generated for these pseudo-libraries won't be unique
anymore if the exact same flag gets added more than once.

To reproduce the issue, simply add the following two lines in some
CMakeLists.txt file like samples/hello_world/CMakeLists.txt:

zephyr_library_compile_options("-Dfubar=barfu")
zephyr_library_compile_options("-Dfubar=barfu")

cmake will then fail like this:

CMake Error at zephyr/cmake/extensions.cmake:403 (add_library):
add_library cannot create target
"options_interface_lib_e689fdb7eb15d801c2f95dd61301fc5e" because
another target with the same name already exists. The existing
target is an interface library created in source directory
"zephyr/samples/hello_world". See documentation for
policy CMP0002 for more details.
Call Stack (most recent call first):
CMakeLists.txt:9 (zephyr_library_compile_options)

As suggested by Sebastian, discard duplicate options. After this fix
cmake succeeds with this warning:

CMake Warning at zephyr/cmake/extensions.cmake:404 (message):
-Dfubar=barfu already added, ignoring duplicate
Call Stack (most recent call first):
CMakeLists.txt:9 (zephyr_library_compile_options)

Fixes #15093

Signed-off-by: Marc Herbert [email protected]

@codecov-io
Copy link

Codecov Report

Merging #15094 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #15094   +/-   ##
=======================================
  Coverage   52.87%   52.87%           
=======================================
  Files         309      309           
  Lines       45267    45267           
  Branches    10451    10451           
=======================================
  Hits        23934    23934           
  Misses      16558    16558           
  Partials     4775     4775

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eead93...3417d54. Read the comment docs.

@marc-hb marc-hb requested review from carlescufi and galak April 1, 2019 21:09
@@ -400,6 +400,11 @@ function(zephyr_library_compile_options item)
string(MD5 uniqueness ${item})
set(lib_name options_interface_lib_${uniqueness})

if (TARGET ${lib_name})
message(WARNING "${item} already added, ignoring duplicate")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should drop the warning to align with CMake's silent de-duplication.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are you sure? I thought the silent de-duplication was a bug you just discovered. Is it really a feature?

Copy link
Collaborator

@SebastianBoe SebastianBoe Apr 3, 2019

Choose a reason for hiding this comment

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

I am sure.

It is CMake behaviour that we want to align with to be consistent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally we want to keep the logs quiet. It's best to prefer errors and avoid warnings. In this case we can't use an error as that would be inconsistent with CMake.

Copy link
Member

Choose a reason for hiding this comment

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

@marc-hb can you please address the above?

Copy link
Collaborator Author

@marc-hb marc-hb Apr 3, 2019

Choose a reason for hiding this comment

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

I will remove the warning.

The entire and unique purpose of this PR is to restore the same behaviour than CMake, so no question about that. I would still appreciate more clarity on that behaviour though; I mean I would still like to know whether that behaviour is a CMake feature or a CMake bug. * If * adding the same option twice is considered a usage error, then users would rather be warned about their error than enjoy the consistency of wasting as much time as they would have with CMake. Now I don't work in any Zephyr support role right now so this is admittedly just for my personal education.

Copy link
Member

Choose a reason for hiding this comment

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

please submit the change ASAP, this PR is resolved a P1 bug, we need to clear the P1 bug list ASAP, otherwise we might resort to reverting the change introducing this issue.

Copy link
Collaborator Author

@marc-hb marc-hb Apr 4, 2019

Choose a reason for hiding this comment

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

I will submit the change today.

Sorry I had no idea issue #15093 was now high priority, this is complete news to me. Github doesn't notify label changes and #15093 is not even assigned to me, it's still assigned to @SebastianBoe . I asked in #15093 about its priority but no one gave any assessment.
Please make some github noise next time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a CMake feature.

They have explicitly written code to de-duplicate the flags.

PR zephyrproject-rtos#14776 / commit 915a353 changed function
zephyr_library_compile_options() to use MD5 instead of RANDOM for build
reproduction reasons. As later predicted by Sebastian Bøe in the PR
(thx), the names generated for these pseudo-libraries won't be unique
anymore if the exact same flag gets added more than once.

To reproduce the issue, simply add the following two lines in some
CMakeLists.txt file like samples/hello_world/CMakeLists.txt:

zephyr_library_compile_options("-Dfubar=barfu")
zephyr_library_compile_options("-Dfubar=barfu")

cmake will then fail like this:

 CMake Error at zephyr/cmake/extensions.cmake:403 (add_library):
  add_library cannot create target
  "options_interface_lib_e689fdb7eb15d801c2f95dd61301fc5e" because
  another target with the same name already exists.  The existing
  target is an interface library created in source directory
  "zephyr/samples/hello_world".  See documentation for
  policy CMP0002 for more details.
 Call Stack (most recent call first):
  CMakeLists.txt:9 (zephyr_library_compile_options)

As requested by Sebastian, silently discard duplicate options just like
CMake does.

Fixes zephyrproject-rtos#15093

Signed-off-by: Marc Herbert <[email protected]>
@marc-hb marc-hb force-pushed the deduplicate-library-options branch from 3417d54 to c9ba025 Compare April 4, 2019 00:41
@nashif nashif added this to the v1.14.0 milestone Apr 4, 2019
@nashif nashif merged commit 4635343 into zephyrproject-rtos:master Apr 4, 2019
@marc-hb marc-hb deleted the deduplicate-library-options branch April 4, 2019 17:13
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.

zephyr_library_compile_options() lost support for duplicates
5 participants