Introduce config_checks_generator.py #196
No reviewers
Labels
No labels
approved
bug
dependencies
DO-NOT-MERGE
enhancement
good-first-issue
help-wanted
historical-reviewed
historical-reviewing
needs-adoption
needs-ci
needs-design-approval
needs-info
needs-preceding-pr
needs-review
needs-reviewer
needs-work
priority-high
priority-low
priority-medium
priority-scheduled
priority-very-high
single-reviewer
size-l
size-m
size-s
size-xs
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Mbed-TLS/mbedtls-framework!196
Loading…
Reference in a new issue
No description provided.
Delete branch "config-checks-generator-framework"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Infrastructure to generate config check headers, to be included in
${PROJECT}_config.c. This is just some basic logic, there will be a follow-up with more sophisticated check.Contributes to https://github.com/Mbed-TLS/mbedtls/issues/10147. See https://github.com/Mbed-TLS/mbedtls-framework/pull/164 for a the next step.
PR checklist
Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed.
Looks pretty good to me, just a few minor points/thoughts.
@ -0,0 +1,228 @@"""Generate C preprocessor code to check for bad configurations.Typo: s/to/for/ ?
@ -0,0 +29,4 @@class Checker:"""Description of checks for one option.By default, this class triggers an error if the option is set afterMinor: I think I'd slightly prefer if the base class did nothing, but OK.
Ok, may this is me not being object-oriented enough, but I don't find this approach of "get the text from the parent method and then patch it" very readable. I'd find it much more readable to just have
here directly, and I don't think that's an unacceptable amount of duplication. (I mean, it's 2 lines of pretty trivial code.)
Point taken about readability, but I do think the design makes sense. Conceptually, we want the same C code for a removed option as for an internal option. The only difference is the need to add an annotation for check-names.
I've added a comment to explain (I really should have done that from the start). Is that acceptable?
I have some minor comments at the design. I won't specifically request changes, but I would like to discuss them.
Otherwise the code is sensibe and does functioanlly what is expected to do
@ -0,0 +92,4 @@Use the given prefix for auxiliary macro names."""methods = {I am not sure if declaring a dictionary just to use it as an enum map is neccessary. Since we are matching the names we could get away with something like
method = getattr(self, position.name.lower())@ -0,0 +111,4 @@def __init__(self, name: str, version: str, suggestion: str = '') -> None:super().__init__(name, suggestion)self.version = versionI would include the version in the Checker class, as an optional parameter and forgo the inheritance completely and put the subclass as an attribute which defines how the affected method change.
e.g
Of-course this seems to be the first of many so you have better scope of what this should do in its final form. I just suggest that if we could reduce complexity it would be worth it.
For clarity what I propose when invoked would look like:
@ -0,0 +131,4 @@code, flags=re.M)class BranchData(typing.NamedTuple):This is an immutable object, that is used as the source of thruth for the whole logic. I would consider using a dataclass
p.s in that case we can also use the post_init to do input sanitatisation
@ -0,0 +131,4 @@code, flags=re.M)class BranchData(typing.NamedTuple):What would be the benefits of a dataclass over a NamedTuple?
I only foresee a single place in each repository where we'll create an instance of that class, so I don't think we need to do any input sanitization.
@ -0,0 +92,4 @@Use the given prefix for auxiliary macro names."""methods = {That's shorter but I don't think it's clearer. And it's not type-safe. So I don't see it as better.
@ -0,0 +111,4 @@def __init__(self, name: str, version: str, suggestion: str = '') -> None:super().__init__(name, suggestion)self.version = versionI'm not sure but I suspect that it only looks like it could be simpler because the classes here aren't the full story. Can you please take a look at https://github.com/Mbed-TLS/mbedtls-framework/pull/164 with the added classes (not ready for review yet, but I'm not planning any more changes to that part before 1.0), and see if your comment is still applicable there?
@ -0,0 +1,228 @@"""Generate C preprocessor code to check for bad configurations.Looking at the companion pr
It could make sense to do this formatting in Pyhton rather than cmake?
maybe rename list_only to list_human, and add a new list_cmake for the properly formatted output?
@ -0,0 +1,228 @@"""Generate C preprocessor code to check for bad configurations.Yeah, good point. Especially since the old CMake version on the CI lacks a lot of string manipulation features. We already have scripts with a
--list-for-cmakeoption.This branch was too old to pass the CI, so I rebased in on top of the head of
main. The previous version is available at https://github.com/gilles-peskine-arm/mbedtls-framework/tree/config-checks-generator-framework-2. I've also pushed a new commit "Add option --list-for-cmake".@ -0,0 +92,4 @@Use the given prefix for auxiliary macro names."""methods = {In general I would rather we refrain from using enums in python until we upgrade to 3.10 and have match, unless:
Otherwise we are just adding complexity without much benefit. My proposal was geared towards implemeting 2.
Either way I won't block this Pr for the choice of tooling.
@ -0,0 +111,4 @@def __init__(self, name: str, version: str, suggestion: str = '') -> None:super().__init__(name, suggestion)self.version = versionI see your point. Using inheritance may be the simplest and easier to maintain approach.
@ -0,0 +131,4 @@code, flags=re.M)class BranchData(typing.NamedTuple):Not much in that case, and depends on how we wish to use that.
If that a small immutable, input object, named.tuple is the best choice. If in the future there are plans to do things like conditional immutability, or input checking, then dataclass allows you to attach those extra functionalities.
@ -0,0 +1,228 @@"""Generate C preprocessor code to check for bad configurations.Thanks for adding this. I was thinking about it. and it would be nice ( not now, when we have bandwith ) to standardize it across the libraries and our scripting.
The need:
Proposal:
--cmakeIf you agree it would be usefull I could make an issue.
But that is way beyond the scope the 1.0
LGTM
LGTM, thanks!
@ -0,0 +131,4 @@code, flags=re.M)class BranchData(typing.NamedTuple):Right, here this is exactly what it is.
@ -0,0 +1,228 @@"""Generate C preprocessor code to check for bad configurations.Sounds good, but also, sounds like the kind of grand refactoring that we'll never find the time to do 😢