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

Backport 2.16: Check Windows files for sanity as well
This commit is contained in:
Gilles Peskine 2020-04-20 13:59:18 +02:00 committed by GitHub
commit 15316fdb94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 1057 additions and 1016 deletions

View file

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

View file

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

View file

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