@@ -1549,18 +1549,23 @@ impl TomlManifest {
1549
1549
let project = & mut project. ok_or_else ( || anyhow ! ( "no `package` section found" ) ) ?;
1550
1550
1551
1551
let workspace_config = match ( me. workspace . as_ref ( ) , project. workspace . as_ref ( ) ) {
1552
- ( Some ( config ) , None ) => {
1553
- let mut inheritable = config . package . clone ( ) . unwrap_or_default ( ) ;
1552
+ ( Some ( toml_config ) , None ) => {
1553
+ let mut inheritable = toml_config . package . clone ( ) . unwrap_or_default ( ) ;
1554
1554
inheritable. update_ws_path ( package_root. to_path_buf ( ) ) ;
1555
- inheritable. update_deps ( config . dependencies . clone ( ) ) ;
1556
- WorkspaceConfig :: Root ( WorkspaceRootConfig :: new (
1555
+ inheritable. update_deps ( toml_config . dependencies . clone ( ) ) ;
1556
+ let ws_root_config = WorkspaceRootConfig :: new (
1557
1557
package_root,
1558
- & config . members ,
1559
- & config . default_members ,
1560
- & config . exclude ,
1558
+ & toml_config . members ,
1559
+ & toml_config . default_members ,
1560
+ & toml_config . exclude ,
1561
1561
& Some ( inheritable) ,
1562
- & config. metadata ,
1563
- ) )
1562
+ & toml_config. metadata ,
1563
+ ) ;
1564
+ config
1565
+ . ws_roots
1566
+ . borrow_mut ( )
1567
+ . insert ( package_root. to_path_buf ( ) , ws_root_config. clone ( ) ) ;
1568
+ WorkspaceConfig :: Root ( ws_root_config)
1564
1569
}
1565
1570
( None , root) => WorkspaceConfig :: Member {
1566
1571
root : root. cloned ( ) ,
@@ -2206,18 +2211,23 @@ impl TomlManifest {
2206
2211
. map ( |r| ResolveBehavior :: from_manifest ( r) )
2207
2212
. transpose ( ) ?;
2208
2213
let workspace_config = match me. workspace {
2209
- Some ( ref config ) => {
2210
- let mut inheritable = config . package . clone ( ) . unwrap_or_default ( ) ;
2214
+ Some ( ref toml_config ) => {
2215
+ let mut inheritable = toml_config . package . clone ( ) . unwrap_or_default ( ) ;
2211
2216
inheritable. update_ws_path ( root. to_path_buf ( ) ) ;
2212
- inheritable. update_deps ( config . dependencies . clone ( ) ) ;
2213
- WorkspaceConfig :: Root ( WorkspaceRootConfig :: new (
2217
+ inheritable. update_deps ( toml_config . dependencies . clone ( ) ) ;
2218
+ let ws_root_config = WorkspaceRootConfig :: new (
2214
2219
root,
2215
- & config . members ,
2216
- & config . default_members ,
2217
- & config . exclude ,
2220
+ & toml_config . members ,
2221
+ & toml_config . default_members ,
2222
+ & toml_config . exclude ,
2218
2223
& Some ( inheritable) ,
2219
- & config. metadata ,
2220
- ) )
2224
+ & toml_config. metadata ,
2225
+ ) ;
2226
+ config
2227
+ . ws_roots
2228
+ . borrow_mut ( )
2229
+ . insert ( root. to_path_buf ( ) , ws_root_config. clone ( ) ) ;
2230
+ WorkspaceConfig :: Root ( ws_root_config)
2221
2231
}
2222
2232
None => {
2223
2233
bail ! ( "virtual manifests must be configured with [workspace]" ) ;
@@ -2334,16 +2344,30 @@ impl TomlManifest {
2334
2344
2335
2345
fn inheritable_from_path (
2336
2346
config : & Config ,
2337
- resolved_path : PathBuf ,
2347
+ workspace_path : PathBuf ,
2338
2348
) -> CargoResult < InheritableFields > {
2339
- let key = resolved_path. parent ( ) . unwrap ( ) ;
2340
- let source_id = SourceId :: for_path ( key) ?;
2341
- let ( man, _) = read_manifest ( & resolved_path, source_id, config) ?;
2349
+ // Workspace path should have Cargo.toml at the end
2350
+ let workspace_path_root = workspace_path. parent ( ) . unwrap ( ) ;
2351
+
2352
+ // Let the borrow exit scope so that it can be picked up if there is a need to
2353
+ // read a manifest
2354
+ if let Some ( ws_root) = config. ws_roots . borrow ( ) . get ( workspace_path_root) {
2355
+ return Ok ( ws_root. inheritable ( ) . clone ( ) ) ;
2356
+ } ;
2357
+
2358
+ let source_id = SourceId :: for_path ( workspace_path_root) ?;
2359
+ let ( man, _) = read_manifest ( & workspace_path, source_id, config) ?;
2342
2360
match man. workspace_config ( ) {
2343
- WorkspaceConfig :: Root ( root) => Ok ( root. inheritable ( ) . clone ( ) ) ,
2361
+ WorkspaceConfig :: Root ( root) => {
2362
+ config
2363
+ . ws_roots
2364
+ . borrow_mut ( )
2365
+ . insert ( workspace_path, root. clone ( ) ) ;
2366
+ Ok ( root. inheritable ( ) . clone ( ) )
2367
+ }
2344
2368
_ => bail ! (
2345
2369
"root of a workspace inferred but wasn't a root: {}" ,
2346
- resolved_path . display( )
2370
+ workspace_path . display( )
2347
2371
) ,
2348
2372
}
2349
2373
}
0 commit comments