File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -552,6 +552,23 @@ impl<'cfg> Workspace<'cfg> {
552
552
} )
553
553
}
554
554
555
+ /// Reset "default build" behavior for non-virtual workspaces, so that a build in
556
+ /// the workspace root would build the root package, not the packages specified
557
+ /// in `workspace.default-members`.
558
+ pub fn ignore_default_members ( & mut self ) -> & mut Workspace < ' cfg > {
559
+ // If we're building a virtual workspace, then there is no root package to build
560
+ if self . is_virtual ( ) {
561
+ return self ;
562
+ }
563
+ // If we're not building the root package, then the default members do not matter
564
+ if self . current_manifest != self . root_manifest ( ) {
565
+ return self ;
566
+ }
567
+
568
+ self . default_members = vec ! [ self . current_manifest. clone( ) ] ;
569
+ self
570
+ }
571
+
555
572
/// Returns true if the package is a member of the workspace.
556
573
pub fn is_member ( & self , pkg : & Package ) -> bool {
557
574
self . member_ids . contains ( & pkg. package_id ( ) )
Original file line number Diff line number Diff line change @@ -734,6 +734,11 @@ fn make_ws_rustc_target<'cfg>(
734
734
ws. set_ignore_lock ( config. lock_update_allowed ( ) ) ;
735
735
ws. set_require_optional_deps ( false ) ;
736
736
737
+ // `cargo install` effectively does `cargo build` in `pkg`. But when this is the root
738
+ // of a non-virtual workspace, that would accidentally build `workspace.default-members`
739
+ // instead of `pkg` (possibly not even including `pkg` at all!)
740
+ ws. ignore_default_members ( ) ;
741
+
737
742
let rustc = config. load_global_rustc ( Some ( & ws) ) ?;
738
743
let target = match & opts. build_config . single_requested_kind ( ) ? {
739
744
CompileKind :: Host => rustc. host . as_str ( ) . to_owned ( ) ,
Original file line number Diff line number Diff line change @@ -1294,6 +1294,42 @@ fn use_path_workspace() {
1294
1294
assert_eq ! ( lock, lock2, "different lockfiles" ) ;
1295
1295
}
1296
1296
1297
+ #[ cargo_test]
1298
+ fn path_install_workspace_root_despite_default_members ( ) {
1299
+ let p = project ( )
1300
+ . file (
1301
+ "Cargo.toml" ,
1302
+ r#"
1303
+ [package]
1304
+ name = "ws-root"
1305
+ version = "0.1.0"
1306
+ authors = []
1307
+
1308
+ [workspace]
1309
+ members = ["ws-member"]
1310
+ default-members = ["ws-member"]
1311
+ "# ,
1312
+ )
1313
+ . file ( "src/main.rs" , "fn main() {}" )
1314
+ . file (
1315
+ "ws-member/Cargo.toml" ,
1316
+ r#"
1317
+ [package]
1318
+ name = "ws-member"
1319
+ version = "0.1.0"
1320
+ authors = []
1321
+ "# ,
1322
+ )
1323
+ . file ( "ws-member/src/main.rs" , "fn main() {}" )
1324
+ . build ( ) ;
1325
+
1326
+ p. cargo ( "install --path" ) . arg ( p. root ( ) ) . arg ( "ws-root" )
1327
+ . with_stderr_contains ( "[INSTALLED] package `ws-root v0.1.0 ([..])` (executable `ws-root[EXE]`)" )
1328
+ // Particularly avoid "Installed package `ws-root v0.1.0 ([..]])` (executable `ws-member`)":
1329
+ . with_stderr_does_not_contain ( "ws-member" )
1330
+ . run ( ) ;
1331
+ }
1332
+
1297
1333
#[ cargo_test]
1298
1334
fn dev_dependencies_no_check ( ) {
1299
1335
Package :: new ( "foo" , "1.0.0" ) . publish ( ) ;
You can’t perform that action at this time.
0 commit comments