-
Notifications
You must be signed in to change notification settings - Fork 3k
Add script to lint targets.json #4215
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
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.
The commit msg are brief compare to the description and importance of this patch?
@@ -0,0 +1,262 @@ | |||
"""A linting utility for targets.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.
license header 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.
Yep. Good catch.
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.
license header added.
tools/targets/lint.py
Outdated
from copy import copy | ||
from yaml import dump_all | ||
import argparse | ||
from tools.targets import Target, set_targets_json_location, TARGET_MAP |
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.
dont we do first local imports then system or other way around (anyway separated by an empty line) ?
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.
We do system then local (pylint prefers this style by default, and changing pylint's defaults seems bad). I'll add a newline.
@theotherjimmy Where we can document these requirements? It should come with this lint addition. Macros are shown as an error but are not specified in the description
How is this looked at, that LPC11U24_301 is not a board (in this case it is). I assume MCU -> Board. In this case it is just MCU (there's no board) ? |
Well, It looks an awful lot like an MCU: it defines most of the things that an MCU would define, and almost none of the things that a board would define. For reference: "LPC11U24_301": {
"inherits": ["LPCTarget"],
"core": "Cortex-M0",
"extra_labels": ["NXP", "LPC11UXX"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOCALFILESYSTEM", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SEMIHOST", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_name": "LPC11U24FHI33/301"
}, You would expect an mcu to define This linter is based on a discussion that @sg- and I had offline relating to how we would like targets.json to be used. It does not reflect the current structure of targets.json. |
Agreed. I'm typing them up and submitting the changes to the |
So @sg- , I and #3123 came to the same conclusion: that macros are a bad mechanism for defining configuration, and that config should be preferred. We could not come up with a valid use for the macros parameter, so I did not turn it on. |
Agree, my point was that I could not find "why" in the description above or in the commit messages (please add that to the documentation).
I got an answer (my question was not that clear, I was aiming at "how linter knows if its MCU or board"). Based on the answer, there are requirements what MCU defines and what boards should and thus we get Nice addition ! To have targets well-defined and a script to check - 👍 🍰 |
I'll add it to the description.
So the actual thing that happens is this: The linter looks for a transition point from "things that look like a board" to "things that look like an MCU" in the hierarchy, starting with the target. At each node (target, whataver), it checks the errors that would happen if it were both an MCU and a board. If there are more errors if it would be a board, then that's the transition point. |
bump @theotherjimmy get on this. geez |
@theotherjimmy bump again... |
@0xc0170 The docs and PR description have been updated to reflect the lack of macros. |
how shall we test this? When to run it (part of morph CI?) or just for every new target, or ? |
@theotherjimmy bump |
@0xc0170 We should have it run for every new target, and added in the comment thread. |
Does this need any other work ? Ready for being reviewed? |
It looks like it's ready for review. |
@theotherjimmy Get this review please. |
Just reviewed offline with @sg-. The commit came from that. Needs: work label added to update docs. |
Docs updated. PR description updated. |
To resolve jenkins CI, please rebase (there was a commit that is removing clientapp test for now that should avoid running it) |
7f496c3
to
18bca08
Compare
@0xc0170 Rebased. Moving to Testing. |
Will not be hit by any morph commands. Moving to ready for merge. |
Description
The linting script for targets.json (tools/targets/lint.py) is a utility for
avoiding common pit-falls of defining targets, and detecting style
inconsistencies between targets.
Rules Enforced
A target's inheritance must look like one of these:
For each of these target roles, some rules are in place:
core
extra_labels
features
bootloader_supported
device_name
post_binary_hook
default_tool chain
public
config
target_overrides
release_versions
supported_toolchains
default_lib
device_has
supported_form_factors
is_disk_virtual
detect_code
extra_labels
public
config
forced_reset_timeout
target_overrides
macros
is missing from this list. That is intentional: they do not provide any benefit overconfig
andtarget_overrides
but can be very difficult to use. In practice it is very difficult to override the value of a macro with a value.config
on the other hand, was designed for this.device_has
may only contain values from the following list:ANALOGIN
.ANALOGOUT
.CAN
.ETHERNET
.EMAC
.FLASH
.I2C
.I2CSLAVE
.I2C_ASYNCH
.INTERRUPTIN
.LOWPOWERTIMER
.PORTIN
.PORTINOUT
.PORTOUT
.PWMOUT
.RTC
.TRNG
.SERIAL
.SERIAL_ASYNCH
.SERIAL_FC
.SLEEP
.SPI
.SPI_ASYNCH
.SPISLAVE
.extra_labels
may not contain any target names.if
release_versions
contains 5, thensupported_toolchains
must contain allof
GCC_ARM
,ARM
andIAR
.Sample output
There are three commands,
targets
,all-targets
andorphans
. Thetargets
and
all-targets
commands both show errors within public inheritancehierarchies. The
orphans
command shows all targets that are not reachable froma public target.
python tools/targets/lint.py targets EFM32GG_STK3700 EFM32WG_STK3800 LPC11U24_301
python tools/targets/lint.py orphans
TODO