Skip to content

Commit 6e108d5

Browse files
authored
Unrolled build for rust-lang#132649
Rollup merge of rust-lang#132649 - klensy:pa-clippy-ci, r=onur-ozkan add ./x clippy ci This is rebase of rust-lang#126321 also https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29 for context
2 parents c82e0df + cdd948c commit 6e108d5

File tree

6 files changed

+120
-29
lines changed

6 files changed

+120
-29
lines changed

src/bootstrap/src/core/build_steps/clean.rs

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ where
226226
Err(ref e) if e.kind() == ErrorKind::PermissionDenied => {
227227
let m = t!(path.symlink_metadata());
228228
let mut p = m.permissions();
229+
// this os not unix, so clippy gives FP
230+
#[expect(clippy::permissions_set_readonly_false)]
229231
p.set_readonly(false);
230232
t!(fs::set_permissions(path, p));
231233
f(path).unwrap_or_else(|e| {

src/bootstrap/src/core/build_steps/clippy.rs

+108-20
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[
2020
"wrong_self_convention",
2121
];
2222

23-
fn lint_args(builder: &Builder<'_>, ignored_rules: &[&str]) -> Vec<String> {
23+
fn lint_args(builder: &Builder<'_>, config: &LintConfig, ignored_rules: &[&str]) -> Vec<String> {
2424
fn strings<'a>(arr: &'a [&str]) -> impl Iterator<Item = String> + 'a {
2525
arr.iter().copied().map(String::from)
2626
}
2727

28-
let Subcommand::Clippy { fix, allow_dirty, allow_staged, allow, deny, warn, forbid } =
29-
&builder.config.cmd
30-
else {
28+
let Subcommand::Clippy { fix, allow_dirty, allow_staged, .. } = &builder.config.cmd else {
3129
unreachable!("clippy::lint_args can only be called from `clippy` subcommands.");
3230
};
3331

@@ -53,12 +51,12 @@ fn lint_args(builder: &Builder<'_>, ignored_rules: &[&str]) -> Vec<String> {
5351

5452
args.extend(strings(&["--"]));
5553

56-
if deny.is_empty() && forbid.is_empty() {
54+
if config.deny.is_empty() && config.forbid.is_empty() {
5755
args.extend(strings(&["--cap-lints", "warn"]));
5856
}
5957

6058
let all_args = std::env::args().collect::<Vec<_>>();
61-
args.extend(get_clippy_rules_in_order(&all_args, allow, deny, warn, forbid));
59+
args.extend(get_clippy_rules_in_order(&all_args, config));
6260

6361
args.extend(ignored_rules.iter().map(|lint| format!("-Aclippy::{}", lint)));
6462
args.extend(builder.config.free_args.clone());
@@ -68,21 +66,17 @@ fn lint_args(builder: &Builder<'_>, ignored_rules: &[&str]) -> Vec<String> {
6866
/// We need to keep the order of the given clippy lint rules before passing them.
6967
/// Since clap doesn't offer any useful interface for this purpose out of the box,
7068
/// we have to handle it manually.
71-
pub(crate) fn get_clippy_rules_in_order(
72-
all_args: &[String],
73-
allow_rules: &[String],
74-
deny_rules: &[String],
75-
warn_rules: &[String],
76-
forbid_rules: &[String],
77-
) -> Vec<String> {
69+
pub fn get_clippy_rules_in_order(all_args: &[String], config: &LintConfig) -> Vec<String> {
7870
let mut result = vec![];
7971

8072
for (prefix, item) in
81-
[("-A", allow_rules), ("-D", deny_rules), ("-W", warn_rules), ("-F", forbid_rules)]
73+
[("-A", &config.allow), ("-D", &config.deny), ("-W", &config.warn), ("-F", &config.forbid)]
8274
{
8375
item.iter().for_each(|v| {
8476
let rule = format!("{prefix}{v}");
85-
let position = all_args.iter().position(|t| t == &rule || t == v).unwrap();
77+
// Arguments added by bootstrap in LintConfig won't show up in the all_args list, so
78+
// put them at the end of the command line.
79+
let position = all_args.iter().position(|t| t == &rule || t == v).unwrap_or(usize::MAX);
8680
result.push((position, rule));
8781
});
8882
}
@@ -91,9 +85,42 @@ pub(crate) fn get_clippy_rules_in_order(
9185
result.into_iter().map(|v| v.1).collect()
9286
}
9387

88+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
89+
pub struct LintConfig {
90+
pub allow: Vec<String>,
91+
pub warn: Vec<String>,
92+
pub deny: Vec<String>,
93+
pub forbid: Vec<String>,
94+
}
95+
96+
impl LintConfig {
97+
fn new(builder: &Builder<'_>) -> Self {
98+
match builder.config.cmd.clone() {
99+
Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
100+
Self { allow, warn, deny, forbid }
101+
}
102+
_ => unreachable!("LintConfig can only be called from `clippy` subcommands."),
103+
}
104+
}
105+
106+
fn merge(&self, other: &Self) -> Self {
107+
let merged = |self_attr: &[String], other_attr: &[String]| -> Vec<String> {
108+
self_attr.iter().cloned().chain(other_attr.iter().cloned()).collect()
109+
};
110+
// This is written this way to ensure we get a compiler error if we add a new field.
111+
Self {
112+
allow: merged(&self.allow, &other.allow),
113+
warn: merged(&self.warn, &other.warn),
114+
deny: merged(&self.deny, &other.deny),
115+
forbid: merged(&self.forbid, &other.forbid),
116+
}
117+
}
118+
}
119+
94120
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
95121
pub struct Std {
96122
pub target: TargetSelection,
123+
config: LintConfig,
97124
/// Whether to lint only a subset of crates.
98125
crates: Vec<String>,
99126
}
@@ -108,7 +135,8 @@ impl Step for Std {
108135

109136
fn make_run(run: RunConfig<'_>) {
110137
let crates = std_crates_for_run_make(&run);
111-
run.builder.ensure(Std { target: run.target, crates });
138+
let config = LintConfig::new(run.builder);
139+
run.builder.ensure(Std { target: run.target, config, crates });
112140
}
113141

114142
fn run(self, builder: &Builder<'_>) {
@@ -138,7 +166,7 @@ impl Step for Std {
138166
run_cargo(
139167
builder,
140168
cargo,
141-
lint_args(builder, IGNORED_RULES_FOR_STD_AND_RUSTC),
169+
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
142170
&libstd_stamp(builder, compiler, target),
143171
vec![],
144172
true,
@@ -150,6 +178,7 @@ impl Step for Std {
150178
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
151179
pub struct Rustc {
152180
pub target: TargetSelection,
181+
config: LintConfig,
153182
/// Whether to lint only a subset of crates.
154183
crates: Vec<String>,
155184
}
@@ -165,7 +194,8 @@ impl Step for Rustc {
165194

166195
fn make_run(run: RunConfig<'_>) {
167196
let crates = run.make_run_crates(Alias::Compiler);
168-
run.builder.ensure(Rustc { target: run.target, crates });
197+
let config = LintConfig::new(run.builder);
198+
run.builder.ensure(Rustc { target: run.target, config, crates });
169199
}
170200

171201
/// Lints the compiler.
@@ -212,7 +242,7 @@ impl Step for Rustc {
212242
run_cargo(
213243
builder,
214244
cargo,
215-
lint_args(builder, IGNORED_RULES_FOR_STD_AND_RUSTC),
245+
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
216246
&librustc_stamp(builder, compiler, target),
217247
vec![],
218248
true,
@@ -232,6 +262,7 @@ macro_rules! lint_any {
232262
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
233263
pub struct $name {
234264
pub target: TargetSelection,
265+
config: LintConfig,
235266
}
236267

237268
impl Step for $name {
@@ -243,8 +274,10 @@ macro_rules! lint_any {
243274
}
244275

245276
fn make_run(run: RunConfig<'_>) {
277+
let config = LintConfig::new(run.builder);
246278
run.builder.ensure($name {
247279
target: run.target,
280+
config,
248281
});
249282
}
250283

@@ -281,7 +314,7 @@ macro_rules! lint_any {
281314
run_cargo(
282315
builder,
283316
cargo,
284-
lint_args(builder, &[]),
317+
lint_args(builder, &self.config, &[]),
285318
&stamp,
286319
vec![],
287320
true,
@@ -319,3 +352,58 @@ lint_any!(
319352
Tidy, "src/tools/tidy", "tidy";
320353
TestFloatParse, "src/etc/test-float-parse", "test-float-parse";
321354
);
355+
356+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
357+
pub struct CI {
358+
target: TargetSelection,
359+
config: LintConfig,
360+
}
361+
362+
impl Step for CI {
363+
type Output = ();
364+
const DEFAULT: bool = false;
365+
366+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
367+
run.alias("ci")
368+
}
369+
370+
fn make_run(run: RunConfig<'_>) {
371+
let config = LintConfig::new(run.builder);
372+
run.builder.ensure(CI { target: run.target, config });
373+
}
374+
375+
fn run(self, builder: &Builder<'_>) -> Self::Output {
376+
builder.ensure(Bootstrap {
377+
target: self.target,
378+
config: self.config.merge(&LintConfig {
379+
allow: vec![],
380+
warn: vec![],
381+
deny: vec!["warnings".into()],
382+
forbid: vec![],
383+
}),
384+
});
385+
let library_clippy_cfg = LintConfig {
386+
allow: vec!["clippy::all".into()],
387+
warn: vec![],
388+
deny: vec!["clippy::correctness".into()],
389+
forbid: vec![],
390+
};
391+
let compiler_clippy_cfg = LintConfig {
392+
allow: vec!["clippy::all".into()],
393+
warn: vec![],
394+
deny: vec!["clippy::correctness".into(), "clippy::clone_on_ref_ptr".into()],
395+
forbid: vec![],
396+
};
397+
398+
builder.ensure(Std {
399+
target: self.target,
400+
config: self.config.merge(&library_clippy_cfg),
401+
crates: vec![],
402+
});
403+
builder.ensure(Rustc {
404+
target: self.target,
405+
config: self.config.merge(&compiler_clippy_cfg),
406+
crates: vec![],
407+
});
408+
}
409+
}

src/bootstrap/src/core/builder/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ impl<'a> Builder<'a> {
839839
clippy::RustInstaller,
840840
clippy::TestFloatParse,
841841
clippy::Tidy,
842+
clippy::CI,
842843
),
843844
Kind::Check | Kind::Fix => describe!(
844845
check::Std,

src/bootstrap/src/core/config/tests.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::Deserialize;
99

1010
use super::flags::Flags;
1111
use super::{ChangeIdWrapper, Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
12-
use crate::core::build_steps::clippy::get_clippy_rules_in_order;
12+
use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
1313
use crate::core::build_steps::llvm;
1414
use crate::core::config::{LldMode, Target, TargetSelection, TomlConfig};
1515

@@ -309,9 +309,10 @@ fn order_of_clippy_rules() {
309309
];
310310
let config = Config::parse(Flags::parse(&args));
311311

312-
let actual = match &config.cmd {
312+
let actual = match config.cmd.clone() {
313313
crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
314-
get_clippy_rules_in_order(&args, &allow, &deny, &warn, &forbid)
314+
let cfg = LintConfig { allow, deny, warn, forbid };
315+
get_clippy_rules_in_order(&args, &cfg)
315316
}
316317
_ => panic!("invalid subcommand"),
317318
};
@@ -332,9 +333,10 @@ fn clippy_rule_separate_prefix() {
332333
vec!["clippy".to_string(), "-A clippy:all".to_string(), "-W clippy::style".to_string()];
333334
let config = Config::parse(Flags::parse(&args));
334335

335-
let actual = match &config.cmd {
336+
let actual = match config.cmd.clone() {
336337
crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
337-
get_clippy_rules_in_order(&args, &allow, &deny, &warn, &forbid)
338+
let cfg = LintConfig { allow, deny, warn, forbid };
339+
get_clippy_rules_in_order(&args, &cfg)
338340
}
339341
_ => panic!("invalid subcommand"),
340342
};

src/bootstrap/src/utils/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<
145145

146146
#[cfg(windows)]
147147
fn symlink_dir_inner(target: &Path, junction: &Path) -> io::Result<()> {
148-
junction::create(&target, &junction)
148+
junction::create(target, junction)
149149
}
150150
}
151151

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ ENV SCRIPT \
5050
python3 ../x.py check --stage 0 --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \
5151
/scripts/check-default-config-profiles.sh && \
5252
python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
53-
python3 ../x.py clippy bootstrap -Dwarnings && \
54-
python3 ../x.py clippy library -Aclippy::all -Dclippy::correctness && \
55-
python3 ../x.py clippy compiler -Aclippy::all -Dclippy::correctness -Dclippy::clone_on_ref_ptr && \
53+
python3 ../x.py clippy ci && \
5654
python3 ../x.py build --stage 0 src/tools/build-manifest && \
5755
python3 ../x.py test --stage 0 src/tools/compiletest && \
5856
python3 ../x.py test --stage 0 core alloc std test proc_macro && \

0 commit comments

Comments
 (0)