From 4e45f58852313e3dde5f617e2c26bbda5e9437c1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 11 Feb 2022 22:22:38 -0800 Subject: [PATCH] Unstable --keep-going flag --- src/bin/cargo/commands/package.rs | 1 + src/bin/cargo/commands/publish.rs | 1 + src/cargo/core/compiler/build_config.rs | 4 +++ src/cargo/core/compiler/job_queue.rs | 5 ++-- src/cargo/ops/cargo_compile.rs | 4 ++- src/cargo/ops/cargo_fetch.rs | 9 ++++++- src/cargo/ops/cargo_package.rs | 10 +++++++- src/cargo/ops/registry.rs | 2 ++ src/cargo/util/command_prelude.rs | 21 +++++++++++++++- src/doc/man/cargo-bench.md | 1 + src/doc/man/cargo-build.md | 1 + src/doc/man/cargo-check.md | 1 + src/doc/man/cargo-doc.md | 1 + src/doc/man/cargo-fix.md | 1 + src/doc/man/cargo-install.md | 1 + src/doc/man/cargo-package.md | 1 + src/doc/man/cargo-publish.md | 1 + src/doc/man/cargo-run.md | 1 + src/doc/man/cargo-rustc.md | 1 + src/doc/man/cargo-rustdoc.md | 1 + src/doc/man/cargo-test.md | 1 + src/doc/man/generated_txt/cargo-bench.txt | 5 ++++ src/doc/man/generated_txt/cargo-build.txt | 5 ++++ src/doc/man/generated_txt/cargo-check.txt | 5 ++++ src/doc/man/generated_txt/cargo-doc.txt | 5 ++++ src/doc/man/generated_txt/cargo-fix.txt | 5 ++++ src/doc/man/generated_txt/cargo-install.txt | 5 ++++ src/doc/man/generated_txt/cargo-package.txt | 5 ++++ src/doc/man/generated_txt/cargo-publish.txt | 5 ++++ src/doc/man/generated_txt/cargo-run.txt | 5 ++++ src/doc/man/generated_txt/cargo-rustc.txt | 5 ++++ src/doc/man/generated_txt/cargo-rustdoc.txt | 5 ++++ src/doc/man/generated_txt/cargo-test.txt | 5 ++++ src/doc/man/includes/options-keep-going.md | 5 ++++ src/doc/src/commands/cargo-bench.md | 6 +++++ src/doc/src/commands/cargo-build.md | 6 +++++ src/doc/src/commands/cargo-check.md | 6 +++++ src/doc/src/commands/cargo-doc.md | 6 +++++ src/doc/src/commands/cargo-fix.md | 6 +++++ src/doc/src/commands/cargo-install.md | 6 +++++ src/doc/src/commands/cargo-package.md | 6 +++++ src/doc/src/commands/cargo-publish.md | 6 +++++ src/doc/src/commands/cargo-run.md | 6 +++++ src/doc/src/commands/cargo-rustc.md | 6 +++++ src/doc/src/commands/cargo-rustdoc.md | 6 +++++ src/doc/src/commands/cargo-test.md | 6 +++++ src/doc/src/reference/unstable.md | 23 ++++++++++++++++- src/etc/_cargo | 1 + src/etc/cargo.bashcomp.sh | 28 ++++++++++----------- src/etc/man/cargo-bench.1 | 7 ++++++ src/etc/man/cargo-build.1 | 7 ++++++ src/etc/man/cargo-check.1 | 7 ++++++ src/etc/man/cargo-doc.1 | 7 ++++++ src/etc/man/cargo-fix.1 | 7 ++++++ src/etc/man/cargo-install.1 | 7 ++++++ src/etc/man/cargo-package.1 | 7 ++++++ src/etc/man/cargo-publish.1 | 7 ++++++ src/etc/man/cargo-run.1 | 7 ++++++ src/etc/man/cargo-rustc.1 | 7 ++++++ src/etc/man/cargo-rustdoc.1 | 7 ++++++ src/etc/man/cargo-test.1 | 7 ++++++ tests/testsuite/check.rs | 16 ++++++++++++ 62 files changed, 337 insertions(+), 21 deletions(-) create mode 100644 src/doc/man/includes/options-keep-going.md diff --git a/src/bin/cargo/commands/package.rs b/src/bin/cargo/commands/package.rs index 5584052e909..1209edc8f2e 100644 --- a/src/bin/cargo/commands/package.rs +++ b/src/bin/cargo/commands/package.rs @@ -53,6 +53,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { to_package: specs, targets: args.targets(), jobs: args.jobs()?, + keep_going: args.keep_going(), cli_features: args.cli_features()?, }, )?; diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index f1cdcc2c19d..8db737504d1 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -45,6 +45,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { to_publish: args.packages_from_flags()?, targets: args.targets(), jobs: args.jobs()?, + keep_going: args.keep_going(), dry_run: args.is_present("dry-run"), registry, cli_features: args.cli_features()?, diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 31cd3e3da53..d9c555c8088 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -15,6 +15,8 @@ pub struct BuildConfig { pub requested_kinds: Vec, /// Number of rustc jobs to run in parallel. pub jobs: u32, + /// Do not abort the build as soon as there is an error. + pub keep_going: bool, /// Build profile pub requested_profile: InternedString, /// The mode we are compiling in. @@ -56,6 +58,7 @@ impl BuildConfig { pub fn new( config: &Config, jobs: Option, + keep_going: bool, requested_targets: &[String], mode: CompileMode, ) -> CargoResult { @@ -84,6 +87,7 @@ impl BuildConfig { Ok(BuildConfig { requested_kinds, jobs, + keep_going, requested_profile: InternedString::new("dev"), mode, message_format: MessageFormat::Human, diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index e30431caad6..a63949b69d1 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -825,13 +825,14 @@ impl<'cfg> DrainState<'cfg> { // // After a job has finished we update our internal state if it was // successful and otherwise wait for pending work to finish if it failed - // and then immediately return. + // and then immediately return (or keep going, if requested by the build + // config). let mut errors = ErrorsDuringDrain { count: 0 }; // CAUTION! Do not use `?` or break out of the loop early. Every error // must be handled in such a way that the loop is still allowed to // drain event messages. loop { - if errors.count == 0 { + if errors.count == 0 || cx.bcx.build_config.keep_going { if let Err(e) = self.spawn_work_if_possible(cx, jobserver_helper, scope) { self.handle_error(&mut cx.bcx.config.shell(), &mut errors, e); } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 51f104ca1fe..0d28f51696f 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -85,8 +85,10 @@ pub struct CompileOptions { impl CompileOptions { pub fn new(config: &Config, mode: CompileMode) -> CargoResult { + let jobs = None; + let keep_going = false; Ok(CompileOptions { - build_config: BuildConfig::new(config, None, &[], mode)?, + build_config: BuildConfig::new(config, jobs, keep_going, &[], mode)?, cli_features: CliFeatures::new_all(false), spec: ops::Packages::Packages(Vec::new()), filter: CompileFilter::Default { diff --git a/src/cargo/ops/cargo_fetch.rs b/src/cargo/ops/cargo_fetch.rs index 1e0d855d0d1..ae43f9b6fe9 100644 --- a/src/cargo/ops/cargo_fetch.rs +++ b/src/cargo/ops/cargo_fetch.rs @@ -20,8 +20,15 @@ pub fn fetch<'a>( let (packages, resolve) = ops::resolve_ws(ws)?; let jobs = Some(1); + let keep_going = false; let config = ws.config(); - let build_config = BuildConfig::new(config, jobs, &options.targets, CompileMode::Build)?; + let build_config = BuildConfig::new( + config, + jobs, + keep_going, + &options.targets, + CompileMode::Build, + )?; let data = RustcTargetData::new(ws, &build_config.requested_kinds)?; let mut fetched_packages = HashSet::new(); let mut deps_to_fetch = ws.members().map(|p| p.package_id()).collect::>(); diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index ab1a6180cb3..a863e413a90 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -30,6 +30,7 @@ pub struct PackageOpts<'cfg> { pub allow_dirty: bool, pub verify: bool, pub jobs: Option, + pub keep_going: bool, pub to_package: ops::Packages, pub targets: Vec, pub cli_features: CliFeatures, @@ -177,6 +178,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult