mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
Add presubmit script
Consolidates the utility scripts from bin/ into tools/. Adds a 'presubmit' utility script to run a set of checks and tests. This won't be a git hook, but can be manually used to verify changes before uploading. BUG=b:199951064 TEST=./tools/presubmit --quick ./tools/dev_container ./tools/presubmit Change-Id: Iac7c11fca0beaa6d4f214319149ef385fa5ced70 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3225139 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
parent
18724772c2
commit
ee56b2ddec
8 changed files with 165 additions and 173 deletions
99
bin/clippy
99
bin/clippy
|
@ -1,99 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2019 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Run `cargo clippy` on all Rust code in crosvm with a mindful set of lints
|
||||
# suppressed.
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
USE_CACHE=false
|
||||
CLIPPY_ARGS=("$@")
|
||||
|
||||
# TODO: When we add more options, use a fancier parsing mechanism such as
|
||||
# getopts. Also use the Rust convention of -- separating the arguments for this
|
||||
# script itself from the ones for clippy.
|
||||
if (("$#" > 0)) && [[ "$1" == "--use-cache" ]]; then
|
||||
USE_CACHE=true
|
||||
CLIPPY_ARGS=("${CLIPPY_ARGS[@]:1}")
|
||||
fi
|
||||
|
||||
# Change into directory of script, which is crosvm/bin.
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
# Jump up to root directory of crosvm repo.
|
||||
cd ..
|
||||
|
||||
SUPPRESS=(
|
||||
# TODO(crbug/908640): To be resolved.
|
||||
collapsible_if
|
||||
comparison_chain
|
||||
missing_safety_doc
|
||||
wrong_self_convention
|
||||
# To be fixed in external libraries
|
||||
upper_case_acronyms
|
||||
from_over_into
|
||||
|
||||
# False positives affecting WlVfd @ `devices/src/virtio/wl.rs`.
|
||||
# Bug: https://github.com/rust-lang/rust-clippy/issues/6312
|
||||
field_reassign_with_default
|
||||
|
||||
# We don't care about these lints. Okay to remain suppressed globally.
|
||||
cast_lossless
|
||||
cognitive_complexity
|
||||
enum_variant_names
|
||||
identity_op
|
||||
len_without_is_empty
|
||||
len_zero
|
||||
match_bool
|
||||
match_wild_err_arm
|
||||
module_inception
|
||||
needless_bool
|
||||
new_without_default
|
||||
or_fun_call
|
||||
should_implement_trait
|
||||
single_char_pattern
|
||||
too_many_arguments
|
||||
trivially_copy_pass_by_ref
|
||||
type_complexity
|
||||
unreadable_literal
|
||||
useless_let_if_seq
|
||||
useless_transmute
|
||||
new-ret-no-self
|
||||
)
|
||||
|
||||
FEATURES=(
|
||||
default
|
||||
direct
|
||||
audio
|
||||
gpu
|
||||
plugin
|
||||
tpm
|
||||
usb
|
||||
video-decoder
|
||||
video-encoder
|
||||
wl-dmabuf
|
||||
x
|
||||
virgl_renderer_next
|
||||
composite-disk
|
||||
virgl_renderer
|
||||
gfxstream
|
||||
gdb
|
||||
)
|
||||
printf -v FEATURES_LIST '%s,' "${FEATURES[@]}"
|
||||
|
||||
# Needed or else clippy won't re-run on code that has already compiled.
|
||||
if [[ "${USE_CACHE}" == false ]]; then
|
||||
cargo clean
|
||||
fi
|
||||
|
||||
# Need to set pass --sysroot for cargo-clippy manually.
|
||||
# cf. https://github.com/rust-lang/rust-clippy/issues/3523
|
||||
RUST_SYSROOT=$(rustc --print sysroot)
|
||||
RUSTFLAGS="${RUSTFLAGS:-}"
|
||||
export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT"
|
||||
|
||||
cargo clippy --features ${FEATURES_LIST} --all-targets -- \
|
||||
${SUPPRESS[@]/#/-Aclippy::} "${CLIPPY_ARGS[@]}" -D warnings
|
1
bin/clippy
Symbolic link
1
bin/clippy
Symbolic link
|
@ -0,0 +1 @@
|
|||
../tools/clippy
|
|
@ -1,36 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
#
|
||||
# Calculates coverage for the specified crate only
|
||||
# Usage:
|
||||
# $ ./bin/crate_coverage arch [additional arguments for cargo test]
|
||||
# Requirements:
|
||||
# $ rustup toolchain install nightly
|
||||
# $ cargo install grcov rust-covfix
|
||||
set -ex
|
||||
cd "${0%/*}/../"
|
||||
|
||||
target_dir=$(
|
||||
cargo metadata --no-deps --format-version 1 |
|
||||
jq -r ".target_directory"
|
||||
)
|
||||
|
||||
# Delete old coverage profiles
|
||||
find "$target_dir/debug" -name "*.gcda" -delete
|
||||
|
||||
# Run test with coverage profiling
|
||||
(cd $1 && CARGO_INCREMENTAL=0 \
|
||||
RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off \
|
||||
-Zpanic_abort_tests" \
|
||||
cargo +nightly test "${@:2}")
|
||||
|
||||
# Calculate code coverage
|
||||
grcov "$target_dir/debug" -s . \
|
||||
--ignore "/*" --ignore-not-existing \
|
||||
-t lcov --llvm --branch \
|
||||
-o /tmp/lcov.info
|
||||
|
||||
# Apply code coverage fixes
|
||||
rust-covfix /tmp/lcov.info >lcov.info
|
29
bin/fmt
29
bin/fmt
|
@ -1,29 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2019 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Run `rustfmt` on all Rust code contained in crosvm. This is different from
|
||||
# `cargo fmt --all` which formats multiple crates but a single workspace only.
|
||||
# Crosvm consists of multiple workspaces.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# $ bin/fmt
|
||||
#
|
||||
# To print a diff and exit 1 if code is not formatted, but without changing any
|
||||
# files, use:
|
||||
#
|
||||
# $ bin/fmt --check
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Change into directory of script, which is crosvm/bin.
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
# Jump up to root directory of crosvm repo.
|
||||
cd ..
|
||||
|
||||
find . -name '*.rs' -print0 | grep -vz '^./target/' | xargs -0 rustfmt --edition=2018 "$@" --
|
1
bin/fmt
Symbolic link
1
bin/fmt
Symbolic link
|
@ -0,0 +1 @@
|
|||
../tools/fmt
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
SCRIPT_PATH="$(dirname "$(realpath "$0")")"
|
||||
exec "${SCRIPT_PATH}"/clippy --use-cache "$@"
|
101
tools/clippy
Executable file
101
tools/clippy
Executable file
|
@ -0,0 +1,101 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2019 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Run `cargo clippy` on all Rust code in crosvm with a mindful set of lints
|
||||
# suppressed.
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
USE_CACHE=false
|
||||
CLIPPY_ARGS=("$@")
|
||||
|
||||
# TODO: When we add more options, use a fancier parsing mechanism such as
|
||||
# getopts. Also use the Rust convention of -- separating the arguments for this
|
||||
# script itself from the ones for clippy.
|
||||
if (("$#" > 0)) && [[ "$1" == "--use-cache" ]]; then
|
||||
USE_CACHE=true
|
||||
CLIPPY_ARGS=("${CLIPPY_ARGS[@]:1}")
|
||||
fi
|
||||
|
||||
# Change into directory of script, which is crosvm/bin.
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
# Jump up to root directory of crosvm repo.
|
||||
cd ..
|
||||
|
||||
SUPPRESS=(
|
||||
# TODO(crbug/908640): To be resolved.
|
||||
collapsible_if
|
||||
comparison_chain
|
||||
missing_safety_doc
|
||||
wrong_self_convention
|
||||
# To be fixed in external libraries
|
||||
upper_case_acronyms
|
||||
from_over_into
|
||||
|
||||
# False positives affecting WlVfd @ `devices/src/virtio/wl.rs`.
|
||||
# Bug: https://github.com/rust-lang/rust-clippy/issues/6312
|
||||
field_reassign_with_default
|
||||
|
||||
# We don't care about these lints. Okay to remain suppressed globally.
|
||||
cast_lossless
|
||||
cognitive_complexity
|
||||
enum_variant_names
|
||||
identity_op
|
||||
len_without_is_empty
|
||||
len_zero
|
||||
match_bool
|
||||
match_wild_err_arm
|
||||
module_inception
|
||||
needless_bool
|
||||
new_without_default
|
||||
or_fun_call
|
||||
should_implement_trait
|
||||
single_char_pattern
|
||||
too_many_arguments
|
||||
trivially_copy_pass_by_ref
|
||||
type_complexity
|
||||
unreadable_literal
|
||||
useless_let_if_seq
|
||||
useless_transmute
|
||||
new-ret-no-self
|
||||
)
|
||||
|
||||
FEATURES=(
|
||||
default
|
||||
direct
|
||||
audio
|
||||
gpu
|
||||
plugin
|
||||
tpm
|
||||
usb
|
||||
video-decoder
|
||||
video-encoder
|
||||
wl-dmabuf
|
||||
x
|
||||
virgl_renderer_next
|
||||
composite-disk
|
||||
virgl_renderer
|
||||
gfxstream
|
||||
gdb
|
||||
)
|
||||
printf -v FEATURES_LIST '%s,' "${FEATURES[@]}"
|
||||
|
||||
# Needed or else clippy won't re-run on code that has already compiled.
|
||||
if [[ "${USE_CACHE}" == false ]]; then
|
||||
cargo clean
|
||||
fi
|
||||
|
||||
# Need to set pass --sysroot for cargo-clippy manually.
|
||||
# cf. https://github.com/rust-lang/rust-clippy/issues/3523
|
||||
RUST_SYSROOT=$(rustc --print sysroot)
|
||||
RUSTFLAGS="${RUSTFLAGS:-}"
|
||||
export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT"
|
||||
|
||||
# TODO(b/192373803): We are skipping a lot of crates by not running on
|
||||
# --workspace
|
||||
cargo clippy --features ${FEATURES_LIST} --all-targets -- \
|
||||
${SUPPRESS[@]/#/-Aclippy::} "${CLIPPY_ARGS[@]}" -D warnings
|
31
tools/fmt
Executable file
31
tools/fmt
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2019 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Run `rustfmt` on all Rust code contained in crosvm. This is different from
|
||||
# `cargo fmt --all` which formats multiple crates but a single workspace only.
|
||||
# Crosvm consists of multiple workspaces.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# $ bin/fmt
|
||||
#
|
||||
# To print a diff and exit 1 if code is not formatted, but without changing any
|
||||
# files, use:
|
||||
#
|
||||
# $ bin/fmt --check
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Change into directory of script, which is crosvm/bin.
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
# Jump up to root directory of crosvm repo.
|
||||
cd ..
|
||||
|
||||
find . -name '*.rs' -print0 \
|
||||
| grep -vz '^./target/' \
|
||||
| xargs -0 rustfmt --edition=2018 "$@" --
|
|
@ -38,6 +38,8 @@ sudo apt-get install --yes --no-install-recommends \
|
|||
screen \
|
||||
wayland-protocols
|
||||
|
||||
rustup component add clippy
|
||||
rustup component add rustfmt
|
||||
|
||||
# The bindgen tool is required to build a crosvm dependency.
|
||||
cargo install bindgen
|
||||
|
@ -45,4 +47,3 @@ cargo install bindgen
|
|||
# The mdbook and mdbook-mermaid tools are used to build the crosvm book.
|
||||
cargo install mdbook --no-default-features --version "^0.4.10"
|
||||
cargo install mdbook-mermaid --version "^0.8.3"
|
||||
|
||||
|
|
29
tools/presubmit
Executable file
29
tools/presubmit
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2021 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
set -e
|
||||
|
||||
cd "$(dirname $0)/.."
|
||||
|
||||
if [[ "$1" == "-q" ]] || [[ "$1" == "--quick" ]]; then
|
||||
QUICK=true
|
||||
fi
|
||||
|
||||
printf "\n\nRunning clippy...\n"
|
||||
./tools/clippy
|
||||
|
||||
printf "\n\nRunning formatter...\n"
|
||||
./tools/fmt --check
|
||||
|
||||
printf "\n\nRunning x86 tests...\n"
|
||||
./tools/run_tests --target=host
|
||||
|
||||
if [ "$QUICK" = true ] ; then
|
||||
exit
|
||||
fi
|
||||
|
||||
printf "\n\nRunning aarch64 tests...\n"
|
||||
./tools/run_tests --target=vm:aarch64
|
||||
|
||||
# TODO(b/203152778): Add armhf builds to presubmit
|
Loading…
Reference in a new issue