@@ -5,8 +5,8 @@ use std::{env, fs};
55
66use crate :: core:: compiler:: { CompileKind , DefaultExecutor , Executor , UnitOutput } ;
77use crate :: core:: { Dependency , Edition , Package , PackageId , Source , SourceId , Workspace } ;
8- use crate :: ops:: CompileFilter ;
98use crate :: ops:: { common_for_install_and_uninstall:: * , FilterRule } ;
9+ use crate :: ops:: { CompileFilter , Packages } ;
1010use crate :: sources:: { GitSource , PathSource , SourceConfigMap } ;
1111use crate :: util:: errors:: CargoResult ;
1212use crate :: util:: { Config , Filesystem , Rustc , ToSemver , VersionReqExt } ;
@@ -37,7 +37,7 @@ impl Drop for Transaction {
3737
3838struct InstallablePackage < ' cfg , ' a > {
3939 config : & ' cfg Config ,
40- opts : & ' a ops:: CompileOptions ,
40+ opts : ops:: CompileOptions ,
4141 root : Filesystem ,
4242 source_id : SourceId ,
4343 vers : Option < & ' a str > ,
@@ -60,7 +60,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
6060 source_id : SourceId ,
6161 from_cwd : bool ,
6262 vers : Option < & ' a str > ,
63- opts : & ' a ops:: CompileOptions ,
63+ original_opts : & ' a ops:: CompileOptions ,
6464 force : bool ,
6565 no_track : bool ,
6666 needs_update_if_source_is_index : bool ,
@@ -145,7 +145,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
145145 dep. clone ( ) ,
146146 & mut source,
147147 config,
148- opts ,
148+ original_opts ,
149149 & root,
150150 & dst,
151151 force,
@@ -167,7 +167,14 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
167167 }
168168 } ;
169169
170- let ( ws, rustc, target) = make_ws_rustc_target ( config, opts, & source_id, pkg. clone ( ) ) ?;
170+ // When we build this package, we want to build the *specified* package only,
171+ // and avoid building e.g. workspace default-members instead. Do so by constructing
172+ // specialized compile options specific to the identified package.
173+ // See test `path_install_workspace_root_despite_default_members`.
174+ let mut opts = original_opts. clone ( ) ;
175+ opts. spec = Packages :: Packages ( vec ! [ pkg. name( ) . to_string( ) ] ) ;
176+
177+ let ( ws, rustc, target) = make_ws_rustc_target ( config, & opts, & source_id, pkg. clone ( ) ) ?;
171178 // If we're installing in --locked mode and there's no `Cargo.lock` published
172179 // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
173180 if config. locked ( ) && !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
@@ -235,7 +242,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
235242 // Check for conflicts.
236243 ip. no_track_duplicates ( & dst) ?;
237244 } else if is_installed (
238- & ip. pkg , config, opts, & ip. rustc , & ip. target , & ip. root , & dst, force,
245+ & ip. pkg , config, & ip . opts , & ip. rustc , & ip. target , & ip. root , & dst, force,
239246 ) ? {
240247 let msg = format ! (
241248 "package `{}` is already installed, use --force to override" ,
@@ -297,7 +304,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
297304 self . check_yanked_install ( ) ?;
298305
299306 let exec: Arc < dyn Executor > = Arc :: new ( DefaultExecutor ) ;
300- let compile = ops:: compile_ws ( & self . ws , self . opts , & exec) . with_context ( || {
307+ let compile = ops:: compile_ws ( & self . ws , & self . opts , & exec) . with_context ( || {
301308 if let Some ( td) = td_opt. take ( ) {
302309 // preserve the temporary directory, so the user can inspect it
303310 td. into_path ( ) ;
@@ -372,7 +379,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
372379 & dst,
373380 & self . pkg ,
374381 self . force ,
375- self . opts ,
382+ & self . opts ,
376383 & self . target ,
377384 & self . rustc . verbose_version ,
378385 ) ?;
@@ -439,7 +446,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
439446 & self . pkg ,
440447 & successful_bins,
441448 self . vers . map ( |s| s. to_string ( ) ) ,
442- self . opts ,
449+ & self . opts ,
443450 & self . target ,
444451 & self . rustc . verbose_version ,
445452 ) ;
0 commit comments