Skip to content

Commit

Permalink
Merge branch 'master' into yerke/negative_jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke committed Aug 1, 2022
2 parents 7c932a4 + 85e79fc commit 767368f
Show file tree
Hide file tree
Showing 242 changed files with 1,570 additions and 1,008 deletions.
18 changes: 13 additions & 5 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,14 @@ impl Execs {
p.build_command()
}

pub fn masquerade_as_nightly_cargo(&mut self) -> &mut Self {
/// Enables nightly features for testing
///
/// The list of reasons should be why nightly cargo is needed. If it is
/// becuase of an unstable feature put the name of the feature as the reason,
/// e.g. `&["print-im-a-teapot"]`
pub fn masquerade_as_nightly_cargo(&mut self, reasons: &[&str]) -> &mut Self {
if let Some(ref mut p) = self.process_builder {
p.masquerade_as_nightly_cargo();
p.masquerade_as_nightly_cargo(reasons);
}
self
}
Expand Down Expand Up @@ -1139,17 +1144,20 @@ fn _process(t: &OsStr) -> ProcessBuilder {

/// Enable nightly features for testing
pub trait ChannelChanger {
fn masquerade_as_nightly_cargo(self) -> Self;
/// The list of reasons should be why nightly cargo is needed. If it is
/// becuase of an unstable feature put the name of the feature as the reason,
/// e.g. `&["print-im-a-teapot"]`.
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self;
}

impl ChannelChanger for &mut ProcessBuilder {
fn masquerade_as_nightly_cargo(self) -> Self {
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
}
}

impl ChannelChanger for snapbox::cmd::Command {
fn masquerade_as_nightly_cargo(self) -> Self {
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self {
self.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly")
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::Instant;

use cargo::core::dependency::DepKind;
use cargo::core::resolver::{self, ResolveOpts, VersionPreferences};
use cargo::core::source::{GitReference, SourceId};
use cargo::core::source::{GitReference, QueryKind, SourceId};
use cargo::core::Resolve;
use cargo::core::{Dependency, PackageId, Registry, Summary};
use cargo::util::{CargoResult, Config, Graph, IntoUrl};
Expand Down Expand Up @@ -128,11 +128,15 @@ pub fn resolve_with_config_raw(
fn query(
&mut self,
dep: &Dependency,
kind: QueryKind,
f: &mut dyn FnMut(Summary),
fuzzy: bool,
) -> Poll<CargoResult<()>> {
for summary in self.list.iter() {
if fuzzy || dep.matches(summary) {
let matched = match kind {
QueryKind::Exact => dep.matches(summary),
QueryKind::Fuzzy => true,
};
if matched {
self.used.insert(summary.package_id());
f(summary.clone());
}
Expand Down
7 changes: 7 additions & 0 deletions src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo::ops::cargo_add::add;
use cargo::ops::cargo_add::AddOptions;
use cargo::ops::cargo_add::DepOp;
use cargo::ops::cargo_add::DepTable;
use cargo::ops::resolve_ws;
use cargo::util::command_prelude::*;
use cargo::util::interning::InternedString;
use cargo::CargoResult;
Expand Down Expand Up @@ -193,6 +194,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
};
add(&ws, &options)?;

if !dry_run {
// Reload the workspace since we've changed dependencies
let ws = args.workspace(config)?;
resolve_ws(&ws)?;
}

Ok(())
}

Expand Down
5 changes: 4 additions & 1 deletion src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ pub fn cli() -> App {
.arg(flag("no-track", "Do not save tracking information"))
.arg_features()
.arg_profile("Install artifacts with the specified profile")
.arg(flag("debug", "Build in debug mode instead of release mode"))
.arg(flag(
"debug",
"Build in debug mode (with the 'dev' profile) instead of release mode",
))
.arg_targets_bins_examples(
"Install only the specified binary",
"Install all binaries",
Expand Down
5 changes: 1 addition & 4 deletions src/bin/cargo/commands/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn cli() -> App {
.arg(multi_opt(
CRATE_TYPE_ARG_NAME,
"CRATE-TYPE",
"Comma separated list of types of crates for the compiler to emit (unstable)",
"Comma separated list of types of crates for the compiler to emit",
))
.arg_target_dir()
.arg_manifest_path()
Expand Down Expand Up @@ -88,9 +88,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
compile_opts.target_rustc_crate_types = if crate_types.is_empty() {
None
} else {
config
.cli_unstable()
.fail_if_stable_opt(CRATE_TYPE_ARG_NAME, 10083)?;
Some(crate_types)
};
ops::compile(&ws, &compile_opts)?;
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/compiler/compile_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::core::Target;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::{Config, StableHasher};
use anyhow::{bail, Context as _};
use anyhow::Context as _;
use serde::Serialize;
use std::collections::BTreeSet;
use std::fs;
Expand Down Expand Up @@ -65,9 +65,6 @@ impl CompileKind {
};

if !targets.is_empty() {
if targets.len() > 1 && !config.cli_unstable().multitarget {
bail!("specifying multiple `--target` flags requires `-Zmultitarget`")
}
return dedup(targets);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Support for future-incompatible warning reporting.
use crate::core::compiler::BuildContext;
use crate::core::{Dependency, PackageId, Workspace};
use crate::core::{Dependency, PackageId, QueryKind, Workspace};
use crate::sources::SourceConfigMap;
use crate::util::{iter_join, CargoResult, Config};
use anyhow::{bail, format_err, Context};
Expand Down Expand Up @@ -293,7 +293,7 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
Ok(dep) => dep,
Err(_) => return false,
};
match source.query_vec(&dep) {
match source.query_vec(&dep, QueryKind::Exact) {
Poll::Ready(Ok(sum)) => {
summaries.push((pkg_id, sum));
false
Expand Down
10 changes: 7 additions & 3 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
//! `CliUnstable. Remove the `(unstable)` note in the clap help text if
//! necessary.
//! 2. Remove `masquerade_as_nightly_cargo` from any tests, and remove
//! `cargo-features` from `Cargo.toml` test files if any.
//! `cargo-features` from `Cargo.toml` test files if any. You can
//! quickly find what needs to be removed by searching for the name
//! of the feature, e.g. `print_im_a_teapot`
//! 3. Update the docs in unstable.md to move the section to the bottom
//! and summarize it similar to the other entries. Update the rest of the
//! documentation to add the new feature.
Expand Down Expand Up @@ -414,7 +416,7 @@ features! {
(unstable, profile_rustflags, "", "reference/unstable.html#profile-rustflags-option"),

// Allow specifying rustflags directly in a profile
(unstable, workspace_inheritance, "", "reference/unstable.html#workspace-inheritance"),
(stable, workspace_inheritance, "1.64", "reference/unstable.html#workspace-inheritance"),
}

pub struct Feature {
Expand Down Expand Up @@ -720,6 +722,8 @@ const STABILISED_NAMESPACED_FEATURES: &str = "Namespaced features are now always

const STABILIZED_TIMINGS: &str = "The -Ztimings option has been stabilized as --timings.";

const STABILISED_MULTITARGET: &str = "Multiple `--target` options are now always available.";

fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down Expand Up @@ -920,7 +924,7 @@ impl CliUnstable {
self.features = Some(feats);
}
"separate-nightlies" => self.separate_nightlies = parse_empty(k, v)?,
"multitarget" => self.multitarget = parse_empty(k, v)?,
"multitarget" => stabilized_warn(k, "1.64", STABILISED_MULTITARGET),
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
"sparse-registry" => self.sparse_registry = parse_empty(k, v)?,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::package_id_spec::PackageIdSpec;
pub use self::registry::Registry;
pub use self::resolver::{Resolve, ResolveVersion};
pub use self::shell::{Shell, Verbosity};
pub use self::source::{GitReference, Source, SourceId, SourceMap};
pub use self::source::{GitReference, QueryKind, Source, SourceId, SourceMap};
pub use self::summary::{FeatureMap, FeatureValue, Summary};
pub use self::workspace::{
find_workspace_root, resolve_relative_path, MaybePackage, Workspace, WorkspaceConfig,
Expand Down
31 changes: 11 additions & 20 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
use std::task::Poll;

use crate::core::PackageSet;
use crate::core::{Dependency, PackageId, Source, SourceId, SourceMap, Summary};
use crate::core::{Dependency, PackageId, QueryKind, Source, SourceId, SourceMap, Summary};
use crate::sources::config::SourceConfigMap;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
Expand All @@ -19,14 +19,13 @@ pub trait Registry {
fn query(
&mut self,
dep: &Dependency,
kind: QueryKind,
f: &mut dyn FnMut(Summary),
fuzzy: bool,
) -> Poll<CargoResult<()>>;

fn query_vec(&mut self, dep: &Dependency, fuzzy: bool) -> Poll<CargoResult<Vec<Summary>>> {
fn query_vec(&mut self, dep: &Dependency, kind: QueryKind) -> Poll<CargoResult<Vec<Summary>>> {
let mut ret = Vec::new();
self.query(dep, &mut |s| ret.push(s), fuzzy)
.map_ok(|()| ret)
self.query(dep, kind, &mut |s| ret.push(s)).map_ok(|()| ret)
}

fn describe_source(&self, source: SourceId) -> String;
Expand Down Expand Up @@ -327,7 +326,7 @@ impl<'cfg> PackageRegistry<'cfg> {
.get_mut(dep.source_id())
.expect("loaded source not present");

let summaries = match source.query_vec(dep)? {
let summaries = match source.query_vec(dep, QueryKind::Exact)? {
Poll::Ready(deps) => deps,
Poll::Pending => {
deps_pending.push(dep_remaining);
Expand Down Expand Up @@ -483,7 +482,7 @@ impl<'cfg> PackageRegistry<'cfg> {
for &s in self.overrides.iter() {
let src = self.sources.get_mut(s).unwrap();
let dep = Dependency::new_override(dep.package_name(), s);
let mut results = match src.query_vec(&dep) {
let mut results = match src.query_vec(&dep, QueryKind::Exact) {
Poll::Ready(results) => results?,
Poll::Pending => return Poll::Pending,
};
Expand Down Expand Up @@ -575,8 +574,8 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
fn query(
&mut self,
dep: &Dependency,
kind: QueryKind,
f: &mut dyn FnMut(Summary),
fuzzy: bool,
) -> Poll<CargoResult<()>> {
assert!(self.patches_locked);
let (override_summary, n, to_warn) = {
Expand Down Expand Up @@ -671,11 +670,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
}
f(lock(locked, all_patches, summary))
};
return if fuzzy {
source.fuzzy_query(dep, callback)
} else {
source.query(dep, callback)
};
return source.query(dep, kind, callback);
}

// If we have an override summary then we query the source
Expand All @@ -694,11 +689,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
n += 1;
to_warn = Some(summary);
};
let pend = if fuzzy {
source.fuzzy_query(dep, callback)?
} else {
source.query(dep, callback)?
};
let pend = source.query(dep, kind, callback);
if pend.is_pending() {
return Poll::Pending;
}
Expand Down Expand Up @@ -889,7 +880,7 @@ fn summary_for_patch(
// No summaries found, try to help the user figure out what is wrong.
if let Some(locked) = locked {
// Since the locked patch did not match anything, try the unlocked one.
let orig_matches = match source.query_vec(orig_patch) {
let orig_matches = match source.query_vec(orig_patch, QueryKind::Exact) {
Poll::Pending => return Poll::Pending,
Poll::Ready(deps) => deps,
}
Expand All @@ -914,7 +905,7 @@ fn summary_for_patch(
// Try checking if there are *any* packages that match this by name.
let name_only_dep = Dependency::new_override(orig_patch.package_name(), orig_patch.source_id());

let name_summaries = match source.query_vec(&name_only_dep) {
let name_summaries = match source.query_vec(&name_only_dep, QueryKind::Exact) {
Poll::Pending => return Poll::Pending,
Poll::Ready(deps) => deps,
}
Expand Down
16 changes: 7 additions & 9 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::core::resolver::{
ActivateError, ActivateResult, CliFeatures, RequestedFeatures, ResolveOpts, VersionOrdering,
VersionPreferences,
};
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
use crate::core::{
Dependency, FeatureValue, PackageId, PackageIdSpec, QueryKind, Registry, Summary,
};
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;

Expand Down Expand Up @@ -100,13 +102,9 @@ impl<'a> RegistryQueryer<'a> {
}

let mut ret = Vec::new();
let ready = self.registry.query(
dep,
&mut |s| {
ret.push(s);
},
false,
)?;
let ready = self.registry.query(dep, QueryKind::Exact, &mut |s| {
ret.push(s);
})?;
if ready.is_pending() {
self.registry_cache.insert(dep.clone(), Poll::Pending);
return Poll::Pending;
Expand All @@ -127,7 +125,7 @@ impl<'a> RegistryQueryer<'a> {
dep.version_req()
);

let mut summaries = match self.registry.query_vec(dep, false)? {
let mut summaries = match self.registry.query_vec(dep, QueryKind::Exact)? {
Poll::Ready(s) => s.into_iter(),
Poll::Pending => {
self.registry_cache.insert(dep.clone(), Poll::Pending);
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use std::task::Poll;

use crate::core::{Dependency, PackageId, Registry, Summary};
use crate::core::{Dependency, PackageId, QueryKind, Registry, Summary};
use crate::util::lev_distance::lev_distance;
use crate::util::{Config, VersionExt};
use anyhow::Error;
Expand Down Expand Up @@ -228,7 +228,7 @@ pub(super) fn activation_error(
new_dep.set_version_req(all_req);

let mut candidates = loop {
match registry.query_vec(&new_dep, false) {
match registry.query_vec(&new_dep, QueryKind::Exact) {
Poll::Ready(Ok(candidates)) => break candidates,
Poll::Ready(Err(e)) => return to_resolve_err(e),
Poll::Pending => match registry.block_until_ready() {
Expand Down Expand Up @@ -294,7 +294,7 @@ pub(super) fn activation_error(
// Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
let mut candidates = loop {
match registry.query_vec(&new_dep, true) {
match registry.query_vec(&new_dep, QueryKind::Fuzzy) {
Poll::Ready(Ok(candidates)) => break candidates,
Poll::Ready(Err(e)) => return to_resolve_err(e),
Poll::Pending => match registry.block_until_ready() {
Expand Down
7 changes: 4 additions & 3 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ impl ResolveBehavior {
}
}

pub fn to_manifest(&self) -> Option<String> {
pub fn to_manifest(&self) -> String {
match self {
ResolveBehavior::V1 => None,
ResolveBehavior::V2 => Some("2".to_string()),
ResolveBehavior::V1 => "1",
ResolveBehavior::V2 => "2",
}
.to_owned()
}
}

Expand Down
Loading

0 comments on commit 767368f

Please sign in to comment.