From 7a4d4d6b2acc9f535ad20cbe86d28fd7132a9a45 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Wed, 17 Aug 2022 19:59:27 +0000 Subject: [PATCH] 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 Tested-by: Dennis Kempin Commit-Queue: Dennis Kempin --- .cargo/config.toml | 2 +- .../protocol/virtio-gpu-metadata-v1.xml | 2 +- gpu_display/src/generated/xlib_wrapper.h | 2 +- metrics/Cargo.toml | 2 +- metrics/protos/event_details.proto | 2 +- seccomp/x86_64/fs_device.policy | 2 +- .../x86_64/serial_device_vhost_user.policy | 2 +- seccomp/x86_64/serial_device_vvu.policy | 2 +- seccomp/x86_64/vvu_proxy_device.policy | 2 +- tools/health-check | 33 ++++++++++++++----- tools/impl/common.py | 5 ++- tools/impl/health_check.py | 4 ++- tracing/Cargo.toml | 2 +- win_audio/Cargo.toml | 2 +- 14 files changed, 42 insertions(+), 22 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 76bfdc0a4e..ae3985080c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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" \ No newline at end of file +PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-gnu = "/usr/x86_64-w64-mingw32" diff --git a/gpu_display/protocol/virtio-gpu-metadata-v1.xml b/gpu_display/protocol/virtio-gpu-metadata-v1.xml index 2aca85b513..196f33d446 100644 --- a/gpu_display/protocol/virtio-gpu-metadata-v1.xml +++ b/gpu_display/protocol/virtio-gpu-metadata-v1.xml @@ -72,4 +72,4 @@ - \ No newline at end of file + diff --git a/gpu_display/src/generated/xlib_wrapper.h b/gpu_display/src/generated/xlib_wrapper.h index 6908db4aab..9d3911d845 100644 --- a/gpu_display/src/generated/xlib_wrapper.h +++ b/gpu_display/src/generated/xlib_wrapper.h @@ -5,4 +5,4 @@ #include #include #include -#include \ No newline at end of file +#include diff --git a/metrics/Cargo.toml b/metrics/Cargo.toml index 98779d225d..96e9dc446f 100644 --- a/metrics/Cargo.toml +++ b/metrics/Cargo.toml @@ -24,4 +24,4 @@ wmi = { version = "^0.9" } [build-dependencies] -protoc-rust = "2.24" \ No newline at end of file +protoc-rust = "2.24" diff --git a/metrics/protos/event_details.proto b/metrics/protos/event_details.proto index aab47a0664..bde668214c 100644 --- a/metrics/protos/event_details.proto +++ b/metrics/protos/event_details.proto @@ -100,4 +100,4 @@ message EmulatorChildProcessExitDetails { message EmulatorDllDetails { optional string dll_base_name = 1; -} \ No newline at end of file +} diff --git a/seccomp/x86_64/fs_device.policy b/seccomp/x86_64/fs_device.policy index 61aeaaf21e..6393c8f7e6 100644 --- a/seccomp/x86_64/fs_device.policy +++ b/seccomp/x86_64/fs_device.policy @@ -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 \ No newline at end of file +unshare: 1 diff --git a/seccomp/x86_64/serial_device_vhost_user.policy b/seccomp/x86_64/serial_device_vhost_user.policy index a936ce9feb..82ff418910 100644 --- a/seccomp/x86_64/serial_device_vhost_user.policy +++ b/seccomp/x86_64/serial_device_vhost_user.policy @@ -10,4 +10,4 @@ @include /usr/share/policy/crosvm/serial.policy # From vhost_user.policy. -lseek: arg2 == SEEK_END \ No newline at end of file +lseek: arg2 == SEEK_END diff --git a/seccomp/x86_64/serial_device_vvu.policy b/seccomp/x86_64/serial_device_vvu.policy index 570a354b55..932060916c 100644 --- a/seccomp/x86_64/serial_device_vvu.policy +++ b/seccomp/x86_64/serial_device_vvu.policy @@ -11,4 +11,4 @@ # From vvu.policy pread64: 1 -pwrite64: 1 \ No newline at end of file +pwrite64: 1 diff --git a/seccomp/x86_64/vvu_proxy_device.policy b/seccomp/x86_64/vvu_proxy_device.policy index 434193cf76..ccf1241c6b 100644 --- a/seccomp/x86_64/vvu_proxy_device.policy +++ b/seccomp/x86_64/vvu_proxy_device.policy @@ -11,4 +11,4 @@ getdents64: 1 ioctl: arg1 == SIOCGIFFLAGS || arg1 == SIOCSIFFLAGS || arg1 == TCGETS prctl: arg0 == PR_SET_NAME socket: arg0 == AF_UNIX -socketpair: 1 \ No newline at end of file +socketpair: 1 diff --git a/tools/health-check b/tools/health-check index b79a21c682..3e8cd98232 100755 --- a/tools/health-check +++ b/tools/health-check @@ -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), ] diff --git a/tools/impl/common.py b/tools/impl/common.py index 09b4eb94c7..99ebb01c2c 100644 --- a/tools/impl/common.py +++ b/tools/impl/common.py @@ -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] = []): diff --git a/tools/impl/health_check.py b/tools/impl/health_check.py index 7d2e8c8215..2398a025e7 100644 --- a/tools/impl/health_check.py +++ b/tools/impl/health_check.py @@ -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(): diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index 784508d510..39a0f6b916 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] \ No newline at end of file +[dependencies] diff --git a/win_audio/Cargo.toml b/win_audio/Cargo.toml index acdd746e1a..4f0a5e0549 100644 --- a/win_audio/Cargo.toml +++ b/win_audio/Cargo.toml @@ -14,4 +14,4 @@ wio = "*" sync = { path = "../common/sync" } thiserror = "*" metrics = { path = "../metrics"} -once_cell = "1.7.2" \ No newline at end of file +once_cell = "1.7.2"