@@ -1549,18 +1549,23 @@ impl TomlManifest {
15491549 let project = & mut project. ok_or_else ( || anyhow ! ( "no `package` section found" ) ) ?;
15501550
15511551 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 ( ) ;
15541554 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 (
15571557 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 ,
15611561 & 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)
15641569 }
15651570 ( None , root) => WorkspaceConfig :: Member {
15661571 root : root. cloned ( ) ,
@@ -2206,18 +2211,23 @@ impl TomlManifest {
22062211 . map ( |r| ResolveBehavior :: from_manifest ( r) )
22072212 . transpose ( ) ?;
22082213 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 ( ) ;
22112216 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 (
22142219 root,
2215- & config . members ,
2216- & config . default_members ,
2217- & config . exclude ,
2220+ & toml_config . members ,
2221+ & toml_config . default_members ,
2222+ & toml_config . exclude ,
22182223 & 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)
22212231 }
22222232 None => {
22232233 bail ! ( "virtual manifests must be configured with [workspace]" ) ;
@@ -2334,16 +2344,30 @@ impl TomlManifest {
23342344
23352345fn inheritable_from_path (
23362346 config : & Config ,
2337- resolved_path : PathBuf ,
2347+ workspace_path : PathBuf ,
23382348) -> 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) ?;
23422360 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+ }
23442368 _ => bail ! (
23452369 "root of a workspace inferred but wasn't a root: {}" ,
2346- resolved_path . display( )
2370+ workspace_path . display( )
23472371 ) ,
23482372 }
23492373}
0 commit comments