Skip to content

Commit 54e923a

Browse files
authored
Merge pull request #4274 from tgross35/backport-chanterelle
[0.2] Backports
2 parents 32f65a8 + 3e2fb17 commit 54e923a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+951
-663
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
target
22
Cargo.lock
33
*~
4-
style

ci/run.sh

+13-6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if [ -n "${QEMU:-}" ]; then
8181
fi
8282

8383
cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}"
84+
test_flags="--skip check_style"
8485

8586
# Run tests in the `libc` crate
8687
case "$target" in
@@ -101,25 +102,31 @@ if [ "$target" = "s390x-unknown-linux-gnu" ]; then
101102
passed=0
102103
until [ $n -ge $N ]; do
103104
if [ "$passed" = "0" ]; then
104-
if $cmd --no-default-features; then
105+
# shellcheck disable=SC2086
106+
if $cmd --no-default-features -- $test_flags; then
105107
passed=$((passed+1))
106108
continue
107109
fi
108110
elif [ "$passed" = "1" ]; then
109-
if $cmd; then
111+
# shellcheck disable=SC2086
112+
if $cmd -- $test_flags; then
110113
passed=$((passed+1))
111114
continue
112115
fi
113116
elif [ "$passed" = "2" ]; then
114-
if $cmd --features extra_traits; then
117+
# shellcheck disable=SC2086
118+
if $cmd --features extra_traits -- $test_flags; then
115119
break
116120
fi
117121
fi
118122
n=$((n+1))
119123
sleep 1
120124
done
121125
else
122-
$cmd --no-default-features
123-
$cmd
124-
$cmd --features extra_traits
126+
# shellcheck disable=SC2086
127+
$cmd --no-default-features -- $test_flags
128+
# shellcheck disable=SC2086
129+
$cmd -- $test_flags
130+
# shellcheck disable=SC2086
131+
$cmd --features extra_traits -- $test_flags
125132
fi

ci/runtest-android.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::env;
2-
use std::process::Command;
32
use std::path::{Path, PathBuf};
3+
use std::process::Command;
44

55
fn main() {
66
let args = env::args_os()
77
.skip(1)
8-
.filter(|arg| arg != "--quiet")
8+
.filter(|arg| arg != "--quiet" && arg != "--skip" && arg != "check_style")
99
.collect::<Vec<_>>();
1010
assert_eq!(args.len(), 1);
1111
let test = PathBuf::from(&args[0]);
@@ -36,14 +36,16 @@ fn main() {
3636
let stdout = String::from_utf8_lossy(&output.stdout);
3737
let stderr = String::from_utf8_lossy(&output.stderr);
3838

39-
println!("status: {}\nstdout ---\n{}\nstderr ---\n{}",
40-
output.status,
41-
stdout,
42-
stderr);
39+
println!(
40+
"status: {}\nstdout ---\n{}\nstderr ---\n{}",
41+
output.status, stdout, stderr
42+
);
4343

44-
if !stderr.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok"))
45-
&& !stdout.lines().any(|l| (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok"))
46-
{
44+
if !stderr.lines().any(|l| {
45+
(l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok")
46+
}) && !stdout.lines().any(|l| {
47+
(l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok")
48+
}) {
4749
panic!("failed to find successful test run");
4850
};
4951
}

ci/style.rs

-213
This file was deleted.

ci/style.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ -n "${CI:-}" ]; then
99
check="--check"
1010
fi
1111

12-
rustc ci/style.rs && ./style src
12+
cargo test --manifest-path libc-test/Cargo.toml --test style -- --nocapture
1313

1414
command -v rustfmt
1515
rustfmt -V

libc-test/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ path = ".."
1717
version = "0.2.169"
1818
default-features = false
1919

20+
[dev-dependencies]
21+
syn = { version = "2.0.91", features = ["full", "visit"] }
22+
proc-macro2 = { version = "1.0.92", features = ["span-locations"] }
23+
glob = "0.3.2"
24+
annotate-snippets = { version = "0.11.5", features = ["testing-colors"] }
25+
2026
[build-dependencies]
2127
cc = "1.0.83"
2228
# FIXME: Use fork ctest until the maintainer gets back.
@@ -93,3 +99,13 @@ harness = false
9399
name = "primitive_types"
94100
path = "test/primitive_types.rs"
95101
harness = true
102+
103+
[[test]]
104+
name = "style"
105+
path = "test/check_style.rs"
106+
harness = true
107+
108+
[[test]]
109+
name = "style_tests"
110+
path = "test/style_tests.rs"
111+
harness = true

libc-test/test/check_style.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Simple script to verify the coding style of this library.
2+
//!
3+
//! ## How to run
4+
//!
5+
//! The first argument to this script is the directory to run on, so running
6+
//! this script should be as simple as:
7+
//!
8+
//! ```notrust
9+
//! cargo test --test style
10+
//! ```
11+
12+
pub mod style;
13+
14+
use std::env;
15+
use std::path::Path;
16+
17+
use style::{Result, StyleChecker};
18+
19+
#[test]
20+
fn check_style() {
21+
let root_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../src");
22+
walk(&root_dir).unwrap();
23+
eprintln!("good style!");
24+
}
25+
26+
fn walk(root_dir: &Path) -> Result<()> {
27+
let mut style_checker = StyleChecker::new();
28+
29+
for entry in glob::glob(&format!(
30+
"{}/**/*.rs",
31+
root_dir.to_str().expect("dir should be valid UTF-8")
32+
))? {
33+
let entry = entry?;
34+
35+
let name = entry
36+
.file_name()
37+
.expect("file name should not end in ..")
38+
.to_str()
39+
.expect("file name should be valid UTF-8");
40+
if let "lib.rs" | "macros.rs" = &name[..] {
41+
continue;
42+
}
43+
44+
let path = entry.as_path();
45+
style_checker.check_file(path)?;
46+
style_checker.reset_state();
47+
}
48+
49+
style_checker.finalize()
50+
}

0 commit comments

Comments
 (0)