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

Build by PackageIdSpec, not name, to avoid ambiguity #12015

Merged
merged 4 commits into from
May 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Determine pkg-spec from workspace, not original package which may be …
…a git url
  • Loading branch information
tedinski committed May 1, 2023
commit e97cc80d9a1dbb273a3ea7c379ce6598ca690f30
21 changes: 12 additions & 9 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,8 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
}
};

// When we build this package, we want to build the *specified* package only,
// and avoid building e.g. workspace default-members instead. Do so by constructing
// specialized compile options specific to the identified package.
// See test `path_install_workspace_root_despite_default_members`.
let mut opts = original_opts.clone();
let pkgidspec = PackageIdSpec::from_package_id(pkg.package_id());
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);

let (ws, rustc, target) = make_ws_rustc_target(config, &opts, &source_id, pkg.clone())?;
let (ws, rustc, target) =
make_ws_rustc_target(config, &original_opts, &source_id, pkg.clone())?;
// If we're installing in --locked mode and there's no `Cargo.lock` published
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
if config.locked() && !ws.root().join("Cargo.lock").exists() {
Expand All @@ -195,6 +188,16 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
ws.current()?.clone()
};

// When we build this package, we want to build the *specified* package only,
// and avoid building e.g. workspace default-members instead. Do so by constructing
// specialized compile options specific to the identified package.
// See test `path_install_workspace_root_despite_default_members`.
let mut opts = original_opts.clone();
// Unlike install source tracking (for --git, see above), use the spec url from the
// build workspace (hence unconditional `ws.current()` instead of `pkg` to get `package_id()`).
weihanglo marked this conversation as resolved.
Show resolved Hide resolved
let pkgidspec = PackageIdSpec::from_package_id(ws.current()?.package_id());
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);

if from_cwd {
if pkg.manifest().edition() == Edition::Edition2015 {
config.shell().warn(
Expand Down