Skip to content

Commit c574ca9

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

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/cargo/ops/cargo_install.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,7 @@ 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) = make_ws_rustc_target(config, &original_opts, &source_id, pkg.clone())?;
182174
// If we're installing in --locked mode and there's no `Cargo.lock` published
183175
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
184176
if config.locked() && !ws.root().join("Cargo.lock").exists() {
@@ -195,6 +187,16 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
195187
ws.current()?.clone()
196188
};
197189

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

0 commit comments

Comments
 (0)