-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix incorrect #ifdefs on DEVICE_FOO macros #8957
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
Conversation
Are you sure those are ever defined as I agree that the majority of the code uses I would have thought the "approved" way to do what you're attempting these days would be to make a custom target derived from your base target, and put a We certainly should be consistent on the tests in the code. I just wonder if the consistency change should be to |
Thanks, testing currently blocked by #8983 |
No, I've tested this successfully, thanks for the reminder. |
Out of curiosity, how did you manage to test this? |
I'm using the -D option to build.py to (re)define the DEVICE_foo macros to 0. I'm no longer doing this btw, but instead have created custom platforms that never define them in the first place. |
All these config options are not macros, and not used as ‘-D’. Instead they are added to json files in device_has section, so if device does not have analog_in respective define will not be present, it won’t be zero. With ‘if (Device_foo)’ build will error if ‘foo’ is not present in specific target. |
@deepikabhavnani: The json results in these macros passed in via CFLAGS. Undefined macros evaluate to 0, and most checks in the code are #ifs, this PR just makes this usage consistent. |
@kegilbert - Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking on this a bit, I don't have any major objections at the moment. Pinging @c1728p9 for a follow up as this touches a lot of target level configuration options. This was something we sort of wanted to move towards in general for the OS as it encourages using the config system rather than defining a macro or using CFLAGS which we currently have a bit of a split on.
That being said the targets work in a very related but subtlety different manner so would like to hear from HAL.
Side note, ran this briefly by @theotherjimmy and @bridadan and they didn't have a strong preference it seemed like.
@ARMmbed/mbed-os-tools Can you review? There's similar issue reported #9133. Can we clean this up and have it also documented ? There are some good points in this discussion worth documenting if not yet there |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really affect the tools. This seems more like an Mbed OS convention/choice. But I would say definitely be consistent!
I'll just clarify what has already been mentioned. The behavior of device_has
is documented here. If an api is present in the device_has
config list, a macro with the name DEVICE_<API>
will be generated and set to 1
. If a certain api is not present in the list, it will not be included as a macro.
My 2 cents: regardless of how the tools produce/don't produce macros, seems like the source code should be able to switch its behavior on the value of the macro, not just its presence.
@kjbracey-arm @bulislaw Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve the concept.
This also tells us no toolchain is set to warn on #if FOO
if FOO
is undefined, and I'm okay with that. And that means that #if defined(FOO) && FOO
is an antipattern if in the main mbed code base, but I do see that a lot - presumably to try to avoid such a warning.
As this has been open a while, I suggest rebasing, and making sure to re-run the search-and-replace to check for any new ones arrived during discussion.
That is correct to avoid a warning from
@deece or @ARMmbed/mbed-os-core can we verify this is the case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, if it doesn't spam us with warning on any of supported toolchains.
@deece It sounds like everyone has warmed up to the idea.
Would you mind doing this before we start CI? |
DEVICE_SERIAL is always defined (either 0 or 1). Remove the faulty checks introduces in commit 26b9a1f and replace them with value checks as originally implemented. Fixes ARMmbed#8913 Signed-off-by: Alastair D'Silva <[email protected]>
@cmonr Done, picked up a few more things (maybe I missed them initially as I was manually reviewing).
(note: there are many false positives with this grep) It's worth getting more eyes on targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_MODULE_UBLOX_ODIN_W2/sdk/ublox-odin-w2-drivers/OdinWiFiInterface.*, I cleaned up some bits that looked sloppy, it probably warrants reviewing the whole module in detail. |
@deece As a word of caution, any changes to targets need to be OK'd by partners. We can proceeed in two ways:
Option 1 would hold up this PR until an OK was reached. Let us know what you'd like to do. I personally prefer Option 2. |
@cmonr I can split the partner-specific changes into separate PRs, just let me know which files should be split out (presumably the targets/*)? |
Yup, the |
The DEVICE_FOO macros are always defined (either 0 or 1). This patch replaces any instances of a define check on a DEVICE_FOO macro with value test instead. Signed-off-by: Alastair D'Silva <[email protected]>
Ok, I've split the partner code into #9163 |
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
The DEVICE_FOO macros are predefined to be 0 or 1. There are a number of instances which incorrectly check if they are defined, rather than checking the value.
This PR addresses most (if not all) of these incorrect checks.
Fixes #8913
Testing on master is blocked by #8912. A partial test on mbed-os-5.9.7 with Nucleo-F030R8 was successful.
Pull request type