health-check: Add check for newline at ends of files

Fixes a couple of files that were missing them.

BUG=b:242605601
TEST=./tools/health-check --fix

Change-Id: I620d6a939cb824e014002152584aacfc5dfdf7e8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3835648
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2022-08-17 19:59:27 +00:00 committed by crosvm LUCI
parent 38b9268cb8
commit 7a4d4d6b2a
14 changed files with 42 additions and 22 deletions

View file

@ -52,4 +52,4 @@ runner = "wine64"
[env]
PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-gnueabihf = "/usr/arm-linux-gnueabihf"
PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-gnu = "/usr/aarch64_linux_gnu"
PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-gnu = "/usr/x86_64-w64-mingw32"
PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-gnu = "/usr/x86_64-w64-mingw32"

View file

@ -72,4 +72,4 @@
</request>
</interface>
</protocol>
</protocol>

View file

@ -5,4 +5,4 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XShm.h>
#include <X11/keysymdef.h>
#include <X11/keysymdef.h>

View file

@ -24,4 +24,4 @@ wmi = { version = "^0.9" }
[build-dependencies]
protoc-rust = "2.24"
protoc-rust = "2.24"

View file

@ -100,4 +100,4 @@ message EmulatorChildProcessExitDetails {
message EmulatorDllDetails {
optional string dll_base_name = 1;
}
}

View file

@ -58,4 +58,4 @@ utimensat: 1
prctl: arg0 == PR_SET_NAME || arg0 == PR_SET_SECUREBITS || arg0 == PR_GET_SECUREBITS
capget: 1
capset: 1
unshare: 1
unshare: 1

View file

@ -10,4 +10,4 @@
@include /usr/share/policy/crosvm/serial.policy
# From vhost_user.policy.
lseek: arg2 == SEEK_END
lseek: arg2 == SEEK_END

View file

@ -11,4 +11,4 @@
# From vvu.policy
pread64: 1
pwrite64: 1
pwrite64: 1

View file

@ -11,4 +11,4 @@ getdents64: 1
ioctl: arg1 == SIOCGIFFLAGS || arg1 == SIOCSIFFLAGS || arg1 == TCGETS
prctl: arg0 == PR_SET_NAME
socket: arg0 == AF_UNIX
socketpair: 1
socketpair: 1

View file

@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
import sys
from datetime import datetime
@ -10,15 +11,7 @@ from pathlib import Path
from typing import List
from impl.check_code_hygiene import has_crlf_line_endings
from impl.common import (
CROSVM_ROOT,
argh,
chdir,
cmd,
cwd_context,
parallel,
run_main,
)
from impl.common import CROSVM_ROOT, argh, chdir, cmd, cwd_context, parallel, run_main
from impl.health_check import Check, CheckContext, run_checks
@ -146,6 +139,24 @@ def check_infra_tests(context: CheckContext):
recipes("test run --py3-only").fg(quiet=True)
def check_file_ends_with_newline(context: CheckContext):
"Checks if files end with a newline."
for file_path in context.modified_files:
with file_path.open("rb") as file:
# Skip empty files
file.seek(0, os.SEEK_END)
if file.tell() == 0:
continue
# Check last byte of the file
file.seek(-1, os.SEEK_END)
file_end = file.read(1)
if file_end.decode("utf-8") != "\n":
if context.fix:
file_path.write_text(file_path.read_text() + "\n")
else:
raise Exception(f"File does not end with a newline {file_path}")
# List of all checks and on which files they should run.
CHECKS: List[Check] = [
Check(
@ -202,6 +213,10 @@ CHECKS: List[Check] = [
],
can_fix=True,
),
Check(
check_file_ends_with_newline,
exclude=["**.h264", "**.vp8", "**.bin", "**.png", "**.min.js", "infra/**.json"],
),
Check(check_crlf_line_endings),
]

View file

@ -573,7 +573,10 @@ def add_verbose_args(parser: argparse.ArgumentParser):
def all_tracked_files():
return (Path(f) for f in cmd("git ls-files").lines())
for line in cmd("git ls-files").lines():
file = Path(line)
if file.is_file():
yield file
def find_source_files(extension: str, ignore: List[str] = []):

View file

@ -69,7 +69,9 @@ def list_file_diff():
if upstream:
for line in git("diff --name-status", upstream).lines():
parts = line.split("\t", 1)
yield (parts[0].strip(), Path(parts[1].strip()))
file = Path(parts[1].strip())
if file.is_file():
yield (parts[0].strip(), file)
else:
print("WARNING: Not tracking a branch. Checking all files.")
for file in all_tracked_files():

View file

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[dependencies]

View file

@ -14,4 +14,4 @@ wio = "*"
sync = { path = "../common/sync" }
thiserror = "*"
metrics = { path = "../metrics"}
once_cell = "1.7.2"
once_cell = "1.7.2"