mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Always rebuild targets when using cargo-fix
This commit is contained in:
parent
4f6943cdfa
commit
616e0ad3bf
@ -16,6 +16,8 @@ pub struct BuildConfig {
|
||||
pub mode: CompileMode,
|
||||
/// Whether to print std output in json format (for machine reading)
|
||||
pub message_format: MessageFormat,
|
||||
/// Force cargo to do a full rebuild and treat each target as changed.
|
||||
pub force_rebuild: bool,
|
||||
/// Output a build plan to stdout instead of actually compiling.
|
||||
pub build_plan: bool,
|
||||
/// Use Cargo itself as the wrapper around rustc, only used for `cargo fix`
|
||||
@ -79,6 +81,7 @@ impl BuildConfig {
|
||||
release: false,
|
||||
mode,
|
||||
message_format: MessageFormat::Human,
|
||||
force_rebuild: false,
|
||||
build_plan: false,
|
||||
cargo_as_rustc_wrapper: false,
|
||||
extra_rustc_env: Vec::new(),
|
||||
|
@ -132,6 +132,7 @@ fn compile<'a, 'cfg: 'a>(
|
||||
) -> CargoResult<()> {
|
||||
let bcx = cx.bcx;
|
||||
let build_plan = bcx.build_config.build_plan;
|
||||
let force_rebuild = bcx.build_config.force_rebuild;
|
||||
if !cx.compiled.insert(*unit) {
|
||||
return Ok(());
|
||||
}
|
||||
@ -164,7 +165,7 @@ fn compile<'a, 'cfg: 'a>(
|
||||
let dirty = work.then(link_targets(cx, unit, false)?).then(dirty);
|
||||
let fresh = link_targets(cx, unit, true)?.then(fresh);
|
||||
|
||||
if exec.force_rebuild(unit) {
|
||||
if exec.force_rebuild(unit) || force_rebuild {
|
||||
freshness = Freshness::Dirty;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,8 @@ pub fn fix(ws: &Workspace, opts: &mut FixOptions) -> CargoResult<()> {
|
||||
));
|
||||
let _started = lock_server.start()?;
|
||||
|
||||
opts.compile_opts.build_config.force_rebuild = true;
|
||||
|
||||
if opts.broken_code {
|
||||
let key = BROKEN_CODE_ENV.to_string();
|
||||
opts.compile_opts.build_config.extra_rustc_env.push((key, "1".to_string()));
|
||||
|
@ -950,3 +950,94 @@ For more information try --help
|
||||
.with_stderr(stderr)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_warnings_on_second_run_without_changes() {
|
||||
let p = project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
|
||||
pub fn foo() {
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --allow-no-vcs")
|
||||
.with_stderr_contains("[..]warning: unused import[..]")
|
||||
.run();
|
||||
|
||||
p.cargo("fix --allow-no-vcs")
|
||||
.with_stderr_contains("[..]warning: unused import[..]")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_warnings_on_second_run_without_changes_on_multiple_targets() {
|
||||
let p = project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
|
||||
pub fn a() -> u32 { 3 }
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/main.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
fn main() { println!("3"); }
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"tests/foo.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
#[test]
|
||||
fn foo_test() {
|
||||
println!("3");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"tests/bar.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
|
||||
#[test]
|
||||
fn foo_test() {
|
||||
println!("3");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"examples/fooxample.rs",
|
||||
r#"
|
||||
use std::default::Default;
|
||||
|
||||
fn main() {
|
||||
println!("3");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --allow-no-vcs --all-targets")
|
||||
.with_stderr_contains(" --> examples/fooxample.rs:2:21")
|
||||
.with_stderr_contains(" --> src/lib.rs:2:21")
|
||||
.with_stderr_contains(" --> src/main.rs:2:21")
|
||||
.with_stderr_contains(" --> tests/bar.rs:2:21")
|
||||
.with_stderr_contains(" --> tests/foo.rs:2:21")
|
||||
.run();
|
||||
|
||||
p.cargo("fix --allow-no-vcs --all-targets")
|
||||
.with_stderr_contains(" --> examples/fooxample.rs:2:21")
|
||||
.with_stderr_contains(" --> src/lib.rs:2:21")
|
||||
.with_stderr_contains(" --> src/main.rs:2:21")
|
||||
.with_stderr_contains(" --> tests/bar.rs:2:21")
|
||||
.with_stderr_contains(" --> tests/foo.rs:2:21")
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user