-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add location information in patch error messages #14473
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@@ -1437,7 +1437,7 @@ fn replace_with_crates_io() { | |||
.with_status(101) | |||
.with_stderr_data(str![[r#" | |||
[UPDATING] `dummy-registry` index | |||
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index` | |||
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index` specified in `[ROOT]/foo/Cargo.toml` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make all commits atomic which includes all tests must pass for each commit
src/cargo/core/resolver/encode.rs
Outdated
for dep in deps.iter().map(|(d, _)| d) { | ||
build_dep(dep, ws, &mut ret, &mut visited); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like for (dep, _) in deps
would be cleaner.
src/cargo/core/workspace.rs
Outdated
let patch_cv = self.gctx.get_cv_with_env(&ConfigKey::from_str("patch"))?; | ||
let manifest_path = PathOrDefinition::Path(self.root_manifest().into()); | ||
|
||
let patch_from_manifest = match self.root_maybe() { | ||
MaybePackage::Package(p) => p.manifest().patch(), | ||
MaybePackage::Virtual(vm) => vm.patch(), | ||
}; | ||
|
||
let from_config = self.config_patch()?; | ||
// Insert location information for each dep in the patch | ||
let mut from_config: HashMap<_, Vec<_>> = HashMap::new(); | ||
for (url, dep) in self.config_patch()? { | ||
from_config.insert( | ||
url, | ||
dep.iter() | ||
.map(|dep| { | ||
( | ||
dep.clone(), | ||
PathOrDefinition::Definition( | ||
patch_cv.as_ref().unwrap().definition().clone(), | ||
), | ||
) | ||
}) | ||
.collect(), | ||
); | ||
} | ||
|
||
let mut from_manifest: HashMap<_, Vec<_>> = HashMap::new(); | ||
for (url, dep) in patch_from_manifest { | ||
from_manifest.insert( | ||
url.clone(), | ||
dep.iter() | ||
.map(|dep| (dep.clone(), manifest_path.clone())) | ||
.collect(), | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was
- manifest
- config
- config
- manifest
But became
- config
- manifest
- manifest
- config
- manifest
- config
- manifest
Already the original code wasn't idea, it should either be completely parallel or consistently interleaved. As the code grows, I would suggest interleaving makes the code harder to follow and we should be completely parallel.
src/cargo/ops/resolve.rs
Outdated
@@ -813,7 +813,7 @@ fn register_patch_entries( | |||
) -> CargoResult<HashSet<PackageId>> { | |||
let mut avoid_patch_ids = HashSet::new(); | |||
for (url, patches) in ws.root_patch()?.iter() { | |||
for patch in patches { | |||
for patch in patches.iter().map(|(d, _)| d) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like for (patch, _) in patches
would be cleaner.
for dep_with_location in patches { | ||
let (dep, _) = dep_with_location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer destructuring the tuple in the for
and then re-creating it in the push
src/cargo/core/workspace.rs
Outdated
let mut from_config: HashMap<_, Vec<_>> = HashMap::new(); | ||
for (url, dep) in self.config_patch()? { | ||
from_config.insert( | ||
url, | ||
dep.iter() | ||
.map(|dep| { | ||
( | ||
dep.clone(), | ||
PathOrDefinition::Definition( | ||
patch_cv.as_ref().unwrap().definition().clone(), | ||
), | ||
) | ||
}) | ||
.collect(), | ||
); | ||
} | ||
|
||
let mut from_manifest: HashMap<_, Vec<_>> = HashMap::new(); | ||
for (url, dep) in patch_from_manifest { | ||
from_manifest.insert( | ||
url.clone(), | ||
dep.iter() | ||
.map(|dep| (dep.clone(), manifest_path.clone())) | ||
.collect(), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be done in the functions we call to get a patch? Please understand, this is a serious question and not an indirect way of saying what to do.
For manifests, its a little weird because it will always be the same path. However, it feels weird to be calling back into config to get the location. It feels like we are re-implementing things. Calling back into config can also have some negative performance implications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is what you said, but maybe it's better to move theget_cv_with_env
call to Workspace::config_patch
as it's already calling the config there with the following:
let config_patch: Option<
BTreeMap<String, BTreeMap<String, TomlDependency<ConfigRelativePath>>>,
> = self.gctx.get("patch")?;
But it would still have the negative performance implications. I'm not sure if there's a better way to get the config location.
@@ -506,13 +528,43 @@ impl<'gctx> Workspace<'gctx> { | |||
/// Returns the root `[patch]` section of this workspace. | |||
/// | |||
/// This may be from a virtual crate or an actual crate. | |||
pub fn root_patch(&self) -> CargoResult<HashMap<Url, Vec<Dependency>>> { | |||
let from_manifest = match self.root_maybe() { | |||
pub fn root_patch(&self) -> CargoResult<HashMap<Url, Vec<(Dependency, PathOrDefinition)>>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit mixed on tuple vs struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have a struct like:
#[derive(Clone, Debug)]
pub struct Patch {
dep: Dependency,
location: PathOrDefinition,
}
and have the PathOrDefinition::get_location_string
implemented for it instead. But I'm not sure what would be the other benefits, as we would still need to destructure it in a lot of places or keep using iter().map(|patch| patch.dep)
instead. But I'm open for better ideas.
2730b80
to
00f0c08
Compare
Between rust-lang/rust#126810 and rust-lang/rust#126810 the output of rustc for resolution errors is going to change in such a way that some existing cargo tests will fail. Change them to support both the current and future output, so that those PRs can land in `rustc`.
link flags, fixes rust-lang#14330. Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
In a discussion on an issue, it became confusing to talk about "resolved" manifests and dependency resolution, so I'm switching manifests to use the other term I considered, "normalized".
Starting from rust-lang/rust#128534 (nightly-2024-08-05), stnadard library has its own Cargo workspace. Hence `-Zbuild-std` no longer need to fake a virtual workspace. This also adjusts Cargo.toml in `mock-std` to align with std's Cargo.toml
It was designed for `-Zbuild-std`
What does this PR try to resolve?
Fixes #13952
Workspace::root_patch
and use it inregistry::patch
to improve the error messages.