-
Notifications
You must be signed in to change notification settings - Fork 2.2k
scripts/build: add a python script for checking EoF markers across source tree #14107
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
Open
angelosa
wants to merge
1
commit into
master
Choose a base branch
from
script-eof-marker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/python3 | ||
## | ||
## license:BSD-3-Clause | ||
## copyright-holders:Angelo Salese | ||
"""Checks that all files in source code ends with a newline at end of file | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
CHAR_DEPTH = 2 if sys.platform in ["win32", "cygwin"] else 1 | ||
for r, _, f in os.walk("src"): | ||
FILEPATHS = [os.path.join(r, file) for file in f] | ||
for item in FILEPATHS: | ||
if not item.endswith((".cpp", ".h", ".mm", ".lua", ".py")): | ||
continue | ||
with open(item, mode="r", encoding="utf-8") as fh: | ||
try: | ||
fh.seek(0, os.SEEK_END) | ||
fh.seek(fh.tell() - CHAR_DEPTH, os.SEEK_SET) | ||
value = fh.read(CHAR_DEPTH) | ||
if value != os.linesep: | ||
raise ValueError(value, item) | ||
except UnicodeDecodeError: | ||
print(item, file=sys.stderr) | ||
raise | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 misses the various .ipp, .hxx, .lst, .inc, etc. files around the source tree.
I wonder if it wouldn’t be better to also check for various other stuff, perhaps:
I do wonder what performance would be like if it was written in Python, although considering how well makedep.py performs these days, it might not be too bad.
I doubt it would do much to deter the people who check this stuff in most frequently, but it would be nice to get a flag on PRs at least. But then #13937 was merged when it obviously couldn’t build due to the added
GAME
line having the same short name as an existing one. This gives the impression that people aren’t even checking the most basic things before merging stuff, so I don’t know how effective anything will be.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.
Roughly 0.17 seconds locally.
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.
Sounds like a different script type, one that cross checks .lst with .cpp files in
src/mame
(don't think there are any other file extensions that use aGAME
macro?)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, but made the regular “compile MAME” jobs fail anyway due to duplicate symbols, so the person creating the PR and the person merging it already weren’t looking at build results. Having another CI job fail won’t fix that.
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.
Clang has a compiler warning for this:
Automatic EOL handling in git is done via
.gitattributes
(updating an existing repo is fidgety though).Invalid UTF-8 sequences in comments are caught by Clang with
-Winvalid-utf8
. Detetcing such sequences in actual code is only in clang-tidy IIRC.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 won’t address things that aren’t C++ source files (e.g. Python, Lua, XML, and various inputs to source generator tools).
It’s already set, but that doesn’t stop people from not setting
core.autocrlf=true
or otherwise messing things up and checking in DOS line endings as happened in 81a9784.Also, none of that changes the fact that automated checks are useless if people just ignore the results.
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.
Can you protect master branch to avoid merging PRs if they fails for whatever reason? Needs admin rights in mamedev settings, around
Require status checks to pass before merging
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 see @Osso13 likes this idea. I guess it won’t be so bad as it would have been in the past now that CI runs don’t take as long as they used to (it used to be about three hours for macOS and over four hours for Windows, now it’s down to a bit over two hours for Windows).
What do other people think. @galibert?
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 wouldn't mind, I usually wait for CI when merging anything.
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.
OK, I tried enabling this rules that CI has to pass, but it won’t work at the moment. The trouble is, not all jobs apply to all code changes, so e.g. if I enable checking the
build-linux (gcc)
status, it will prevent merging a PR that only affects the docs (and vice versa forbuild-docs
status).To make this workable, we need dummy jobs that set status results for the inverse conditions.