Skip to content

Commit e97cc80

Browse files
committed
Determine pkg-spec from workspace, not original package which may be a git url
1 parent 31d679e commit e97cc80

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,8 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
170170
}
171171
};
172172

173-
// When we build this package, we want to build the *specified* package only,
174-
// and avoid building e.g. workspace default-members instead. Do so by constructing
175-
// specialized compile options specific to the identified package.
176-
// See test `path_install_workspace_root_despite_default_members`.
177-
let mut opts = original_opts.clone();
178-
let pkgidspec = PackageIdSpec::from_package_id(pkg.package_id());
179-
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);
180-
181-
let (ws, rustc, target) = make_ws_rustc_target(config, &opts, &source_id, pkg.clone())?;
173+
let (ws, rustc, target) =
174+
make_ws_rustc_target(config, &original_opts, &source_id, pkg.clone())?;
182175
// If we're installing in --locked mode and there's no `Cargo.lock` published
183176
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
184177
if config.locked() && !ws.root().join("Cargo.lock").exists() {
@@ -195,6 +188,16 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
195188
ws.current()?.clone()
196189
};
197190

191+
// When we build this package, we want to build the *specified* package only,
192+
// and avoid building e.g. workspace default-members instead. Do so by constructing
193+
// specialized compile options specific to the identified package.
194+
// See test `path_install_workspace_root_despite_default_members`.
195+
let mut opts = original_opts.clone();
196+
// Unlike install source tracking (for --git, see above), use the spec url from the
197+
// build workspace (hence unconditional `ws.current()` instead of `pkg` to get `package_id()`).
198+
let pkgidspec = PackageIdSpec::from_package_id(ws.current()?.package_id());
199+
opts.spec = Packages::Packages(vec![pkgidspec.to_string()]);
200+
198201
if from_cwd {
199202
if pkg.manifest().edition() == Edition::Edition2015 {
200203
config.shell().warn(

0 commit comments

Comments
 (0)