Skip to content
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

nxstyle include check is too strict #606

Open
patacongo opened this issue Mar 22, 2020 · 2 comments
Open

nxstyle include check is too strict #606

patacongo opened this issue Mar 22, 2020 · 2 comments
Labels
Type: Bug Something isn't working Type: Enhancement New feature or request

Comments

@patacongo
Copy link
Contributor

As a rule, all #include pre-processor commands must appear in the "Included Files" section: That section header must be in the file and all of the #include commands must follow.

However, there are exceptions. For example:

$ tools/nxstyle.exe arch/arm/include/xmc4/irq.h
arch/arm/include/xmc4/irq.h:81:3: warning: #include outside of 'Included Files' section
arch/arm/include/xmc4/irq.h:83:3: warning: #include outside of 'Included Files' section
arch/arm/include/xmc4/irq.h:85:3: warning: #include outside of 'Included Files' section

This kind of problem is the case with many architectures. I have been ignoring this error in the past, but it is harder to ignore with this automated style checker.

And in this case, the #include cannot be moved because it depends on a #define that must precede it. And you cannot move the #define or your will get a similar error. I think that there is no alternative but you use good engineering judgement and accept the change as is.

This kind of logic is very common in architecure specific code:

Set up some definitions, then
include some architecture specific code

You will see this a lot in arch/xyz/include and arch/src/xyz/hardware directories. This usually occurs int he "Pre-processor Definitions" section, and not in the "Included Files" section.

Ideally, then all #include's should be in the "Included Files" section. But there are exceptions where it makes sense to relax this requirement. So example iss one and there are several others.

I don't know of any way to programmatically "relax" the requirement other than inspecting the nxstyle complaint and then making a good, informed engineering decision. One possibility to to assure that "Included Files" was encountered sometime prior to the #include command. That would allow the #include to occur in any section after the "Included Files" section but would have the odd side-effect of requiring that an "Included Files" section is present even when there are no other files to include. That would, however, be rare.

@patacongo patacongo added Type: Bug Something isn't working Type: Enhancement New feature or request labels Mar 22, 2020
@yamt
Copy link
Contributor

yamt commented Mar 23, 2020

i had to make a change to similar construct: 63395b2

And you cannot move the #define or your will get a similar error.

really? in my case, i moved #define and it worked.

how about allowing an optional "Conditionally Included Files" section?

@patacongo
Copy link
Contributor Author

I've worked around this in a few files by putting multiple "Included Files" section headers. That will eliminate the warning buf is probably not the right way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants