-
Notifications
You must be signed in to change notification settings - Fork 3k
Add JSON schema based validation to mbed config script #5022
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
@scartmell-arm Wow thanks! |
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.
Looks great so far! In it's current form, it's a huge improvement over the old validation mechanism. Be aware that #4984 may create a conflict with the test changes.
tools/config/schema_app.json
Outdated
"pattern": "^([A-Za-z0-9_]+|[A-Za-z0-9_]+=[0-9]+|[A-Za-z0-9_]+=\\\".*\\\")$" | ||
} | ||
}, | ||
"__config_path": { |
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.
Is this key something that we should allow in the configuration file? or is it something that the tools could add after validation?
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 wasn't sure when I added it, it was in the allowable keys list, but isn't mentioned anywhere in the specification so it's probably fine to remove.
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's added 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.
You could do the validation before adding that key.
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.
That seems sensible, I'll do that.
tools/config/schema_lib.json
Outdated
"description": "Configuration file for an mbed library", | ||
"type": "object", | ||
"$id": "http://example.com/root.json", | ||
"definitions": { |
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.
These definitions look almost the same. Could they be moved to another file, and imported?
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.
Yeah, that should be possible. I'll have a look at separating out the common parts of them, I don't think there are any differences between app and lib config parameter handling that needs to be handled in the validation.
It looks like travis failed because it does not have the |
@scartmell-arm Looks like there's something missing from the schema: defining macros as evaluating to other macros. Do we need to add this to the documentation?
|
@theotherjimmy Yeah, that isn't currently included in the documentation. I have a feeling it's going to be a futile endeavour writing a regex pattern to cover the various valid macro forms so I'll also change that to something reasonable. Also, wrt the documentation, it states:
A number of the tests, and potentially some of the actual application configurations don't follow this so I haven't currently added it to the schema. Whilst it might be correct, I can't see any harm in defining target_overrides without config being set. |
I'll make a note to include that capability in the documentation.
Something reasonable like
Good. That line is just wrong. Adding to the list of documentation updates. |
@scartmell-arm It looks like #4984 changed the way those test worked out from underneath you. Could you rebase to resolve those conflicts? |
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.
Was this an omission?
tools/config/schema_lib.json
Outdated
"title": "Mbed Library Schema", | ||
"description": "Configuration file for an mbed library", | ||
"type": "object", | ||
"$id": "http://example.com/root.json", |
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 don't think this is quite right.
tools/config/schema_app.json
Outdated
"title": "Mbed Library Schema", | ||
"description": "Configuration file for an mbed library", | ||
"type": "object", | ||
"$id": "http://example.com/root.json", |
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 looks off too.
Build : FAILUREBuild number : 50 |
Build : FAILUREBuild number : 59 |
/morph build |
@theotherjimmy looks like this needs a re-review |
It's currently breaking in CI because some examples have mbed-app.json that apparently aren't handled by the schema. Specifically, mbed-cloud-client-example-sources-internal broke during the CI build because it's configuration contains |
Build : FAILUREBuild number : 184 |
@studavekar I can't find the failure in the above build. Could you take a look? |
There's a related one here: Build 729
|
I think you're right. Should we allow None? I'm thinking not, but it would be fine, as we would treat it the same as False. Up to @sg- really. |
@sg- Do you have an opinion on this ? |
None in the past has led to tracebacks. Is that still the case? If so, no to None, if handled properly then it seems ok. |
@sg- I don't think that |
@scartmell-arm Can you update the schema based on the feedback above? As this has been idle for some time, I would recommend rebase as well. |
Build : SUCCESSBuild number : 575 Triggering tests/morph test |
Build : SUCCESSBuild number : 1032 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 713 |
Test : SUCCESSBuild number : 841 |
This is now ready for integration |
@scartmell-arm Could you rebase this PR one last time? Looks like a conflict was recently introduced. |
- Added app and lib JSON schema definition files which specify the valid keys and values that can be used in mbed library and application configuration files. The primary different between the app and lib schema is that the lib config requires a name key. - Modified the expected error code in some of the test cases. The error message is now issued by the JSON validator. - Added some validation code to the config script which checks the validity of the mbed_app.json file when it is initially loaded. - Added some validation code to config script which checks each of the mbed_lib.json scripts when they are loaded. - Removed manual checks for allowable config keys from within the mbed_app and mbed_lib json files. - Removed the check_dict_types() function which was no longer being called.
- Removed the config_path setting from schema and moved the addition of the config_path value after the validation is done. - Altered the macro validation regex to be more lenient. Now verifies that if '=' is used in the macro definition that something comes after it.
- Moved all common definitions from schema_app and schema_lib into a separate definitions file. - Changed the calling code to resolve multiple schema files correctly.
- Modified the expected error code in some of the test cases. The error message is now issued by the JSON validator. - Stop validation code being called if no application configuration is given to validate. - Change test mock code to check for specific calls, instead of number of calls. - Derive absolute paths for JSON schema files before loading them, which seems to work better with the URI path resolution of the schema parser.
/morph build |
Build : SUCCESSBuild number : 1043 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 724 |
Test : SUCCESSBuild number : 850 |
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 the schema can be more restrictive, and therefore more helpful at pointing out errors.
"type": "object", | ||
"patternProperties": { | ||
"\\*": { | ||
"type": "object", |
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 should be the same as the pattern property below, "$ref": "#/target_override_entry"
"target_override_entry": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^\\S+$": {} |
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 should contain "$ref": "#/config_parameter_short"
, I think
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.
Let's get this in, and I'll submit another PR to make it more strict. @cmonr If you could do the honors
Description
The current configuration system allows a user to specify various compile time configuration options for various targets within JSON files in the projects directory mbed_app.json for applications, and mbed_lib.json for libraries. The parameters will be converted to a collection of macros that are defined when compiling the code. The format of the JSON file is defined here.
Currently, the process of the checking the validity of the config file is done through a series of manual checks in
tools/config/__init__.py
. This PR will replace the manual checks with a solution that uses JSON schema to validate the configuration files.Status
IN DEVELOPMENT
Todos
Steps to test or reproduce
Test the current validation test cases still all pass:
Linux:
$ PYTHONPATH=. python -m pytest tools/test/config/config_test.py
Windows:
$ set PYTHONPATH=. && python -m pytest tools/test/config/config_test.py