Skip to content
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

Closed
wants to merge 99 commits into from

Conversation

antoniospg
Copy link

What does this PR try to resolve?

Fixes #13952

  • Similar to what was explained in the issue page, I've tried to preserve location information in Workspace::root_patch and use it in registry::patch to improve the error messages.
  • I've also updated the tests to take this change in consideration.

@rustbot
Copy link
Collaborator

rustbot commented Aug 31, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver A-lockfile Area: Cargo.lock issues A-registries Area: registries A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 31, 2024
@antoniospg antoniospg changed the title Preserve loc patches Add location information in patch error messages Aug 31, 2024
@@ -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`
Copy link
Contributor

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

Comment on lines 468 to 470
for dep in deps.iter().map(|(d, _)| d) {
build_dep(dep, ws, &mut ret, &mut visited);
}
Copy link
Contributor

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.

Comment on lines 532 to 567
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(),
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was

  1. manifest
  2. config
  3. config
  4. manifest

But became

  1. config
  2. manifest
  3. manifest
  4. config
  5. manifest
  6. config
  7. 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.

@@ -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) {
Copy link
Contributor

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.

Comment on lines +835 to +836
for dep_with_location in patches {
let (dep, _) = dep_with_location;
Copy link
Contributor

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

Comment on lines 541 to 566
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(),
);
}
Copy link
Contributor

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.

Copy link
Author

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_envcall 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)>>> {
Copy link
Contributor

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.

Copy link
Author

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.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-semver Area: semver specifications, version matching, etc. Command-update labels Sep 8, 2024
renovate bot and others added 11 commits September 7, 2024 22:09
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-completions Area: shell completions A-configuration Area: cargo config files and env vars A-console-output Area: Terminal output, colors, progress bar, etc. A-dependency-resolution Area: dependency resolution and the resolver A-documenting-cargo-itself Area: Cargo's documentation A-environment-variables Area: environment variables A-future-incompat Area: future incompatible reporting A-git Area: anything dealing with git A-home Area: the `home` crate A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. A-interacts-with-crates.io Area: interaction with registries A-layout Area: target output directory layout, naming, and organization A-lockfile Area: Cargo.lock issues A-manifest Area: Cargo.toml issues A-rebuild-detection Area: rebuild detection and fingerprinting A-registries Area: registries A-semver Area: semver specifications, version matching, etc. A-sparse-registry Area: http sparse registries A-testing-cargo-itself Area: cargo's tests A-timings Area: timings A-unstable Area: nightly unstable support A-workspaces Area: workspaces Command-add Command-bench Command-build Command-check Command-clean Command-doc Command-fetch Command-fix Command-generate-lockfile Command-info Command-metadata Command-package Command-pkgid Command-publish Command-remove Command-run Command-rustc Command-rustdoc Command-test Command-tree Command-update Command-vendor S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Location of patch information