File tree 2 files changed +34
-3
lines changed
2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -333,9 +333,6 @@ impl<'cfg> Workspace<'cfg> {
333
333
}
334
334
335
335
for path in paths:: ancestors ( manifest_path) . skip ( 2 ) {
336
- if self . config . home ( ) == path {
337
- return Ok ( None ) ;
338
- }
339
336
let ances_manifest_path = path. join ( "Cargo.toml" ) ;
340
337
debug ! ( "find_root - trying {}" , ances_manifest_path. display( ) ) ;
341
338
if ances_manifest_path. exists ( ) {
@@ -354,6 +351,15 @@ impl<'cfg> Workspace<'cfg> {
354
351
WorkspaceConfig :: Member { .. } => { }
355
352
}
356
353
}
354
+
355
+ // Don't walk across `CARGO_HOME` when we're looking for the
356
+ // workspace root. Sometimes a project will be organized with
357
+ // `CARGO_HOME` pointing inside of the workspace root or in the
358
+ // current project, but we don't want to mistakenly try to put
359
+ // crates.io crates into the workspace by accident.
360
+ if self . config . home ( ) == path {
361
+ break
362
+ }
357
363
}
358
364
359
365
Ok ( None )
Original file line number Diff line number Diff line change @@ -1782,3 +1782,28 @@ fn include_and_exclude() {
1782
1782
assert_that(&p.root().join("foo/bar/target"), existing_dir());
1783
1783
}
1784
1784
*/
1785
+
1786
+ #[ test]
1787
+ fn cargo_home_at_root_works ( ) {
1788
+ let p = project ( "lib" )
1789
+ . file ( "Cargo.toml" , r#"
1790
+ [package]
1791
+ name = "lib"
1792
+ version = "0.1.0"
1793
+
1794
+ [workspace]
1795
+ members = ["a"]
1796
+ "# )
1797
+ . file ( "src/lib.rs" , "" )
1798
+ . file ( "a/Cargo.toml" , r#"
1799
+ [package]
1800
+ name = "a"
1801
+ version = "0.1.0"
1802
+ "# )
1803
+ . file ( "a/src/lib.rs" , "" ) ;
1804
+ let p = p. build ( ) ;
1805
+
1806
+ assert_that ( p. cargo ( "build" ) , execs ( ) . with_status ( 0 ) ) ;
1807
+ assert_that ( p. cargo ( "build" ) . arg ( "--frozen" ) . env ( "CARGO_HOME" , p. root ( ) ) ,
1808
+ execs ( ) . with_status ( 0 ) ) ;
1809
+ }
You can’t perform that action at this time.
0 commit comments