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

dist tools: header guard checker #6438

Closed
wants to merge 4 commits into from

Conversation

OlegHahm
Copy link
Member

Addressing #6407 (comment):
fix freshly introduced header guards and providing a script to avoid reintroducing wrong guards (at least in main folders).

@OlegHahm OlegHahm added Area: CI Area: Continuous Integration of RIOT components Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools labels Jan 20, 2017
@OlegHahm OlegHahm added this to the Release 2017.01 milestone Jan 20, 2017
EXIT_CODE=0

# check files
if FILES=$(git grep -lE 'ifndef\ +(_.*|.*_H_$)' ${DIRS})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too broad. #ifndef __APPLE__ or #ifndef __WITH_AVRLIBC__ will also be triggered as an error with this regex. How about ^#ifndef\ +(_.*_H$|.*_H_$)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I already had this in my local copy, but forgot to push it.

# directory for more details.

# customizable
DIRS="core drivers pkg sys"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not boards? If we do the proposed vendor/ include structure, we might also be able to add cpu.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I saw some warnings and thought they were vendor specific, but actually they can and should be fixed. Will update.

EXIT_CODE=0

# check files
if FILES=$(git grep -lE 'ifndef\ +(_.*_H$|.*_H_$)' ${DIRS})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ^# *ifndef? Why not -n instead of -l (I think it's actually beneficial to see line number and the offending #ifndef as well)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ^# *ifndef?

What's the advantage?

Why not -n instead of -l (I think it's actually beneficial to see line number and the offending #ifndef as well)

My assessment was exactly the opposite. Too much cluttered information for my taste.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage?

Avoiding weird false-positives like e.g.

const struct someweirdtypenameifndef _MY_PRIVATE_CONSTANT_FOR_HEIGHT_H

My assessment was exactly the opposite. Too much cluttered information for my taste.

I'm already annoyed about the doc-checker, that tells me there is a problem in file x, but not what the problem is ;-)

@miri64
Copy link
Member

miri64 commented Jan 20, 2017

Mhhh this script can still be "tricked" if a contributor changes the ifndef, but not the define or the comment at the endif ;-)

@OlegHahm
Copy link
Member Author

Mhhh this script can still be "tricked" if a contributor changes the ifndef, but not the define or the comment at the endif ;-)

Yes, but if you change the ifndef and not the define the header guards is broken anyway. And regarding the endif - I have no idea how to check this in a sensible way. Suggestions?

@miri64
Copy link
Member

miri64 commented Jan 20, 2017

And regarding the endif - I have no idea how to check this in a sensible way. Suggestions?

Instinctively I would say to check for ^# *endif */\* *(_.*_H|.*_H_) *\*/, but also check if this line is in the vicinity of the end of the file (using the line number returned by git grep -n + wc -l on the respective file).

@OlegHahm
Copy link
Member Author

But I still have to verify that it matches the correct ifndef.

@miri64
Copy link
Member

miri64 commented Jan 20, 2017

Take it from the results of that search?

@OlegHahm
Copy link
Member Author

Is it safe to assume that the first ifndef is always the header guard?

@miri64
Copy link
Member

miri64 commented Jan 20, 2017

I would expect it to be, but I might be wrong. I don't see any functional requirement for such a thing, so we could just make it a convention.

@kaspar030
Copy link
Contributor

Is it safe to assume that the first ifndef is always the header guard?

I'd say, fairly safe if the following line contains the corresponding define.

@OlegHahm
Copy link
Member Author

Damn, this script seems to get way more complicated than initially intended.

@OlegHahm
Copy link
Member Author

Sorry, I won't have the time to address all the comments today.

@OlegHahm OlegHahm removed this from the Release 2017.01 milestone Jan 20, 2017
@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jan 20, 2017
@miri64
Copy link
Member

miri64 commented Mar 16, 2017

Needs rebase.

@miri64
Copy link
Member

miri64 commented May 23, 2017

I guess this is something coccinelle can take over, right @kaspar030?

@kaspar030
Copy link
Contributor

I guess this is something coccinelle can take over, right @kaspar030?

Nope. Coccinelle doesn't care about file names, define values, etc.

@kaspar030
Copy link
Contributor

I got bored today... -> #7095

@aabadie
Copy link
Contributor

aabadie commented Jun 23, 2017

since #7095 was merged, we can close this one (re-open if disagree).

@aabadie aabadie closed this Jun 23, 2017
@miri64 miri64 added Community: good first issue This issue is good for newcomers to RIOT to be addressed / implemented CI: needs squashing labels Sep 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CI Area: Continuous Integration of RIOT components Area: tools Area: Supplementary tools CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: good first issue This issue is good for newcomers to RIOT to be addressed / implemented Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants