Merge pull request #3120 from gilles-peskine-arm/check-windows-files

Check Windows files for sanity as well
This commit is contained in:
Gilles Peskine 2020-04-20 13:59:27 +02:00 committed by GitHub
commit 5a2710e9af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1119 additions and 1077 deletions

View file

@ -18,7 +18,8 @@
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup> <SOURCES>
<ItemGroup>
<SOURCES>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="mbedTLS.vcxproj">

View file

@ -125,10 +125,10 @@ sub gen_app {
$path =~ s!/!\\!g;
(my $appname = $path) =~ s/.*\\//;
my $srcs = "\n <ClCompile Include=\"..\\..\\programs\\$path.c\" \/>\r";
my $srcs = "<ClCompile Include=\"..\\..\\programs\\$path.c\" \/>";
if( $appname eq "ssl_client2" or $appname eq "ssl_server2" or
$appname eq "query_compile_time_config" ) {
$srcs .= "\n <ClCompile Include=\"..\\..\\programs\\test\\query_config.c\" \/>\r";
$srcs .= "\r\n <ClCompile Include=\"..\\..\\programs\\test\\query_config.c\" \/>";
}
my $content = $template;

View file

@ -100,6 +100,12 @@ class LineIssueTracker(FileIssueTracker):
for i, line in enumerate(iter(f.readline, b"")):
self.check_file_line(filepath, line, i + 1)
def is_windows_file(filepath):
_root, ext = os.path.splitext(filepath)
return ext in ('.dsp', '.sln', '.vcxproj')
class PermissionIssueTracker(FileIssueTracker):
"""Track files with bad permissions.
@ -132,26 +138,43 @@ class Utf8BomIssueTracker(FileIssueTracker):
heading = "UTF-8 BOM present:"
files_exemptions = frozenset([".vcxproj", ".sln"])
def check_file_for_issue(self, filepath):
with open(filepath, "rb") as f:
if f.read().startswith(codecs.BOM_UTF8):
self.files_with_issues[filepath] = None
class LineEndingIssueTracker(LineIssueTracker):
class UnixLineEndingIssueTracker(LineIssueTracker):
"""Track files with non-Unix line endings (i.e. files with CR)."""
heading = "Non Unix line endings:"
heading = "Non-Unix line endings:"
def should_check_file(self, filepath):
return not is_windows_file(filepath)
def issue_with_line(self, line, _filepath):
return b"\r" in line
class WindowsLineEndingIssueTracker(LineIssueTracker):
"""Track files with non-Windows line endings (i.e. CR or LF not in CRLF)."""
heading = "Non-Windows line endings:"
def should_check_file(self, filepath):
return is_windows_file(filepath)
def issue_with_line(self, line, _filepath):
return not line.endswith(b"\r\n") or b"\r" in line[:-2]
class TrailingWhitespaceIssueTracker(LineIssueTracker):
"""Track lines with trailing whitespace."""
heading = "Trailing whitespace:"
files_exemptions = frozenset(".md")
files_exemptions = frozenset([".dsp", ".md"])
def issue_with_line(self, line, _filepath):
return line.rstrip(b"\r\n") != line.rstrip()
@ -162,9 +185,10 @@ class TabIssueTracker(LineIssueTracker):
heading = "Tabs present:"
files_exemptions = frozenset([
"Makefile",
"Makefile.inc",
"generate_visualc_files.pl",
".sln",
"/Makefile",
"/Makefile.inc",
"/generate_visualc_files.pl",
])
def issue_with_line(self, line, _filepath):
@ -199,11 +223,27 @@ class IntegrityChecker:
self.check_repo_path()
self.logger = None
self.setup_logger(log_file)
self.files_to_check = (
".c", ".h", ".sh", ".pl", ".py", ".md", ".function", ".data",
"Makefile", "Makefile.inc", "CMakeLists.txt", "ChangeLog"
self.extensions_to_check = (
".c",
".data",
".dsp",
".function",
".h",
".md",
".pl",
".py",
".sh",
".sln",
".vcxproj",
"/CMakeLists.txt",
"/ChangeLog",
"/Makefile",
"/Makefile.inc",
)
self.excluded_directories = ['.git', 'mbed-os']
self.excluded_directories = [
'.git',
'mbed-os',
]
self.excluded_paths = list(map(os.path.normpath, [
'cov-int',
'examples',
@ -212,7 +252,8 @@ class IntegrityChecker:
PermissionIssueTracker(),
EndOfFileNewlineIssueTracker(),
Utf8BomIssueTracker(),
LineEndingIssueTracker(),
UnixLineEndingIssueTracker(),
WindowsLineEndingIssueTracker(),
TrailingWhitespaceIssueTracker(),
TabIssueTracker(),
MergeArtifactIssueTracker(),
@ -245,7 +286,7 @@ class IntegrityChecker:
dirs[:] = sorted(d for d in dirs if not self.prune_branch(root, d))
for filename in sorted(files):
filepath = os.path.join(root, filename)
if not filepath.endswith(self.files_to_check):
if not filepath.endswith(self.extensions_to_check):
continue
for issue_to_check in self.issues_to_check:
if issue_to_check.should_check_file(filepath):