Enable clippy on windows

Also fixes few warning introduced during upstream which linux clippy
run does not catch.

test: py tools\clippy
bug: 226966790
Change-Id: I6979f87be5d6d34727afabafcaccb57631975567
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3553401
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
Vikram Auradkar 2022-03-25 13:44:28 -07:00 committed by Chromeos LUCI
parent 6a8f656f9d
commit de1f006a08
7 changed files with 47 additions and 13 deletions

View file

@ -42,6 +42,7 @@ cfg_if::cfg_if! {
pub use wait_context::{EventToken, EventType, TriggeredEvent, WaitContext};
} else if #[cfg(windows)] {
pub use windows as platform;
pub use tube::{set_duplicate_handle_tube, set_alias_pid, DuplicateHandleTube};
} else {
compile_error!("Unsupported platform");
}

View file

@ -139,7 +139,7 @@ impl Tube {
}
pub fn recv<T: DeserializeOwned>(&self) -> Result<T> {
deserialize_and_recv(|buf| (&*&self.socket).read(buf))
deserialize_and_recv(|buf| (&self.socket).read(buf))
}
/// NOTE: On Windows this will only succeed if called on a server pipe. See #pair

View file

@ -451,7 +451,7 @@ mod test {
let writer = std::thread::spawn(move || {
let buf = [0u8; 100];
for _ in 0..NUM_OPS {
writer.write(&buf).unwrap();
assert_eq!(writer.write(&buf).unwrap(), buf.len());
}
writer
});

View file

@ -41,6 +41,12 @@ rustc --version
echo [%TIME%] Python version:
py --version
py -m pip install argh --user
echo [%TIME%] Calling crosvm\tools\clippy
py .\tools\clippy
if %ERRORLEVEL% neq 0 ( exit /b %ERRORLEVEL% )
echo [%TIME%] Calling crosvm\build_test.py
py ./tools\impl/test_runner.py --arch x86_64 -v
if %ERRORLEVEL% neq 0 ( exit /b %ERRORLEVEL% )

View file

@ -841,11 +841,13 @@ impl<S: VhostUserSlaveReqHandler, E: Endpoint<MasterReq>> SlaveReqHandler<S, E>
}
fn set_slave_req_fd(&mut self, files: Option<Vec<File>>) -> Result<()> {
#[cfg(windows)]
unimplemented!();
let file = take_single_file(files).ok_or(Error::InvalidMessage)?;
self.backend.set_slave_req_fd(file);
Ok(())
if cfg!(windows) {
unimplemented!();
} else {
let file = take_single_file(files).ok_or(Error::InvalidMessage)?;
self.backend.set_slave_req_fd(file);
Ok(())
}
}
fn handle_vring_fd_request(

View file

@ -9,28 +9,54 @@
# To fix violations where possible:
# $ ./tools/clippy --fix
import os
import sys
sys.path.append(os.path.join(sys.path[0], "impl"))
from impl.common import CROSVM_ROOT, cwd, run_main, cmd, chdir
from impl.test_runner import get_workspace_excludes
clippy = cmd("cargo clippy")
if os.name == "posix":
EXCLUDED_CRATES: list[str] = []
EXCLUDED_CRATES_ARGS: list[str] = []
FEATURES: str = "--features=all-linux"
elif os.name == "nt":
EXCLUDED_CRATES: list[str] = list(get_workspace_excludes("x86_64"))
EXCLUDED_CRATES_ARGS: list[str] = [f"--exclude={crate}" for crate in EXCLUDED_CRATES]
FEATURES: str = ""
else:
raise Exception(f"Unsupported build target: {os.name}")
def is_crate_excluded(crate: str) -> bool:
return crate in EXCLUDED_CRATES
def main(fix: bool = False):
chdir(CROSVM_ROOT)
# Note: Clippy checks are configured in .cargo/config.toml
clippy_args = [
common_args = [
"--fix" if fix else None,
"--all-targets",
"--",
"-Dwarnings",
]
print("Clippy crosvm workspace")
clippy("--workspace", "--features=all-linux", *clippy_args).fg()
clippy("--workspace", FEATURES, *EXCLUDED_CRATES_ARGS, *common_args).fg()
for crate in CROSVM_ROOT.glob("common/*/Cargo.toml"):
print("Clippy", crate.parent.relative_to(CROSVM_ROOT))
with cwd(crate.parent):
clippy("--all-features", *clippy_args).fg()
if not is_crate_excluded(crate.parent.name):
print("Clippy", crate.parent.relative_to(CROSVM_ROOT))
with cwd(crate.parent):
clippy("--all-features", *common_args).fg()
else:
print("Skipping crate", crate.parent.relative_to(CROSVM_ROOT))
run_main(main)

View file

@ -21,7 +21,6 @@ import testvm
from test_config import CRATE_OPTIONS, TestOption, BUILD_FEATURES
from check_code_hygiene import (
has_platform_dependent_code,
is_sys_util_independent,
has_crlf_line_endings,
)