-
Notifications
You must be signed in to change notification settings - Fork 335
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
Print device by family function #205
Conversation
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.
I just tried the code out and
stm32_print_devices_by_family(FAMILY STM32F4)
returns nothing. I figured out that call must be stm32_print_devices_by_family(FAMILY F4)
. There should be a warning about unknown family in stm32_get_devices_by_family
and maybe just some little more documentation.
Also I do not see why the function needs FAMILY
as first keyword as it's in the name of the function. So maybe we could simplify the call.
If I omit FAMILY
just all device get printed instead of an error that I didn't call function properly.
I think this needs a bit of rework before being merged. Maybe even stm32_get_devices_by_family
must be reworked.
Maybe I'm a bit too extreme but we could completely remove file devices.cmake
. This is typically something not scalable and not maintainable. And I do not see the practical use for it as we (are supposed to) support almost all STM32 devices and this list may even not fully know what we support. @Hish15 @rmspacefish what do you think of removing the file ?
edit: @rmspacefish I see you use the function in #206 but I'm still worried because of how device list is maintained.
I will try to add the warning if the specified family is unknown. I actually found this function useful to find the right target name for my specific board quickly, because the documentation does not have a similar list. I added some more documentation in the README, so I guess you mean documentation in the code? I can add that as well. I actually like the feature that it simply prints all families with no families specified. |
|
README.md
Outdated
* `stm32_get_devices_by_family(DEVICES [FAMILY <family>])` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty) | ||
* `stm32_print_devices_by_family([FAMILY <family>])` - Print all supported devices by family (or all devices if `<family>` is empty) |
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.
For me this makes more sense.
* `stm32_get_devices_by_family(DEVICES [FAMILY <family>])` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty) | |
* `stm32_print_devices_by_family([FAMILY <family>])` - Print all supported devices by family (or all devices if `<family>` is empty) | |
* `stm32_get_devices_by_family(DEVICES <family>)` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty) | |
* `stm32_print_devices_by_family(<family>)` - Print all supported devices by family (or all devices if `<family>` is empty) |
FAMILY
is only needed when you have multiple possible keywords.
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.
Hmm I thought FAMILY
has to be specified as a keyword. Does it work without it?
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.
No I mean you could change the implementation so that FAMILY is not used.
It brings nothing here.
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.
I think it is okay that way. I think this was done because https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html is used. Using it also allows easier extensibility (e.g. you still want to parse multiple families, but you also want to pass an option or something like a filter)
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.
Using it also allows easier extensibility (e.g. you still want to parse multiple families, but you also want to pass an option or something like a filter)
OK I understand the point for evolution even if I don't think this function will evolve any soon.
cmake_parse_arguments is fine. I didn't know it before but it permits to do clean things.
I think if you want to have a clean function then all misuse errors should be managed
stm32_print_devices_by_family(H7) # this shall throw error because of no FAMILY given
stm32_print_devices_by_family(FAMILY H7 L4) #this should throw error OR change FAMILY to a "multi_value_keywords"
stm32_print_devices_by_family(FAMILYH7) # this should throw error unknown keyword or something
stm32_print_devices_by_family(FAMILY) # this should throw error missing argument
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.
It does make sense to define those functions.
I find the name misleading. In fact the functions are actually stm32_print_devices_from_family
or stm32_print_family_devices
.
This is minor and will not block the merging of the PR, but it is my 2 cents.
cmake/stm32/devices.cmake
Outdated
@@ -1125,9 +1128,15 @@ function(stm32_get_devices_by_family DEVICES) | |||
if(ARG_FAMILY) | |||
list(FILTER LIST INCLUDE REGEX "^${ARG_FAMILY}") | |||
endif() | |||
if(NOT LIST) |
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 bit is weird, where does STM32_ALL_DEVICES come from? this test checks this var, not the LIST
var.
I also strongly advice against using LIST
as a var name. It's not self explanatory, and it is also a cmake key word!
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 bit is weird, where does STM32_ALL_DEVICES come from ?
This is one of the main problems for me. It comes from here : https://github.com/ObKo/stm32-cmake/blob/master/cmake/stm32/devices.cmake
and is used only for these functions. See my very first comment in the PR where I already mentioned it and @rmspacefish seems to have an use the function.
Co-authored-by: Hish15 <pharamhector@gmail.com>
I will introduce the safety checks mentioned by @atsju when I find some time. I'll also change the name to something better than |
1. More checks 2. Multiple families can now be specified
I found out that the function to get the device list is used in
|
Just to mention I have seen this during #235 and I removed the CORE keyword as it is not used. You could remove it now I suppose. I will have a look at the rest later. Thank you for the update |
Okay,
|
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.
I need to dig further and I'm not 100% sure of how this needs to be done. If you let me some time I will try things out and propose some changes. I don't want to abuse of your time by pointing in wrong direction and needing reverse.
cmake/stm32/devices.cmake
Outdated
if(NOT ${ARGV0} STREQUAL "STM_DEVICES") | ||
message(WARNING "Passed list ${ARGV0} invalid. Still setting STM_DEVICES variable") | ||
endif() |
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 is not what the function is doing. See https://markdewing.github.io/blog/posts/notes-on-cmake/
stm32_get_devices_by_family(retVal FAMILY L4)
message(STATUS "retVal is ${retVal}")
message(STATUS "STM_DEVICES is ${STM_DEVICES}")
outputs
[build] CMake Warning at C:/GIT/stm32-cmake/cmake/stm32/devices.cmake:1131 (message):
[build] Passed list retVal invalid. Still setting STM_DEVICES variable
[build] Call Stack (most recent call first):
[build] CMakeLists.txt:8 (stm32_get_devices_by_family)
[build]
[build]
[build] -- retVal is L412C8;L412CB;L412K8;L412KB;L412R8;L412RB;L412T8;L412TB;L422CB;L422KB;L422RB;L422TB;L431CB;L431CC;L431KB;L431KC;L431RB;L431RC;L431VC;L432KB;L432KC;L433CB;L433CC;L433RB;L433RC;L433VC;L442KC;L443CC;L443RC;L443VC;L451CC;L451CE;L451RC;L451RE;L451VC;L451VE;L452CC;L452CE;L452RC;L452RE;L452VC;L452VE;L462CE;L462RE;L462VE;L471QE;L471QG;L471RE;L471RG;L471VE;L471VG;L471ZE;L471ZG;L475RC;L475RE;L475RG;L475VC;L475VE;L475VG;L476JE;L476JG;L476ME;L476MG;L476QE;L476QG;L476RC;L476RE;L476RG;L476VC;L476VE;L476VG;L476ZE;L476ZG;L486JG;L486QG;L486RG;L486VG;L486ZG;L496AE;L496AG;L496QE;L496QG;L496RE;L496RG;L496VE;L496VG;L496ZE;L496ZG;L4A6AG;L4A6QG;L4A6RG;L4A6VG;L4A6ZG;L4P5AE;L4P5AG;L4P5CE;L4P5CG;L4P5QE;L4P5QG;L4P5RE;L4P5RG;L4P5VE;L4P5VG;L4P5ZE;L4P5ZG;L4Q5AG;L4Q5CG;L4Q5QG;L4Q5RG;L4Q5VG;L4Q5ZG;L4R5AG;L4R5AI;L4R5QG;L4R5QI;L4R5VG;L4R5VI;L4R5ZG;L4R5ZI;L4R7AI;L4R7VI;L4R7ZI;L4R9AG;L4R9AI;L4R9VG;L4R9VI;L4R9ZG;L4R9ZI;L4S5AI;L4S5QI;L4S5VI;L4S5ZI;L4S7AI;L4S7VI;L4S7ZI;L4S9AI;L4S9VI;L4S9ZI
[build] -- STM_DEVICES is
cmake/stm32/devices.cmake
Outdated
message(WARNING "Passed list ${ARGV0} invalid. Still setting STM_DEVICES variable") | ||
endif() | ||
endif() | ||
if(ARGC MATCHES 2) |
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.
MATCHES
is for regex. Here EQUAL
may be more appropriate
https://cmake.org/cmake/help/latest/command/if.html#matches
cmake/stm32/devices.cmake
Outdated
if(NOT ARGV1 STREQUAL "FAMILY") | ||
message(WARNING "Unknown keyword: ${ARGV1}. Matching all devices..") | ||
endif() |
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.
I think this can be handled by cmake_parse_arguments
see https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html
<prefix>_KEYWORDS_MISSING_VALUES
and <prefix>_UNPARSED_ARGUMENTS
I think it will be safer and avoid unexpected corner cases
cmake/stm32/devices.cmake
Outdated
set(ARG_OPTIONS "") | ||
set(ARG_SINGLE "") | ||
set(ARG_MULTIPLE FAMILY) | ||
cmake_parse_arguments(PARSE_ARGV 0 ARG "${ARG_OPTIONS}" "${ARG_SINGLE}" "${ARG_MULTIPLE}") | ||
# Some basic argument checks | ||
if(ARGC MATCHES 1) | ||
# FAMILY is the only keyword here | ||
if(NOT ARGV STREQUAL "FAMILY") | ||
message(WARNING "Unknown keyword: ${ARGV}. Matching all devices..") | ||
endif() | ||
if(NOT ARG_FAMILY) | ||
message(STATUS "FAMILY keyword specified without any families. Matching all devices..") | ||
endif() | ||
endif() |
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.
maybe all checks are done in stm32_get_devices_by_family.
In devices.cmake
I added a pretty printer as well. The tests appear to be problematic now though.. |
I did not realize the That took longer than expected. It would be great if you could run all your checks again. I hope we will be able to merge it soon |
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
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.
I'm willing to do the PR, but lets stop adding commits to it first :D
Waiting the Go
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.
@Hish15 Go
Maybe squash merge ?
Improved stm32_get_devices_by_family to print out the devices
I added a function which simply uses the existing stm32_get_devices_by_family to print out
the devices without returning them. I also updated the documentation accordingly.