@@ -591,16 +591,6 @@ impl<'cfg> Workspace<'cfg> {
591591 /// Returns an error if `manifest_path` isn't actually a valid manifest or
592592 /// if some other transient error happens.
593593 fn find_root ( & mut self , manifest_path : & Path ) -> CargoResult < Option < PathBuf > > {
594- fn read_root_pointer ( member_manifest : & Path , root_link : & str ) -> PathBuf {
595- let path = member_manifest
596- . parent ( )
597- . unwrap ( )
598- . join ( root_link)
599- . join ( "Cargo.toml" ) ;
600- debug ! ( "find_root - pointer {}" , path. display( ) ) ;
601- paths:: normalize_path ( & path)
602- }
603-
604594 {
605595 let current = self . packages . load ( manifest_path) ?;
606596 match * current. workspace_config ( ) {
@@ -1643,6 +1633,10 @@ impl WorkspaceRootConfig {
16431633 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
16441634 Ok ( res)
16451635 }
1636+
1637+ pub fn inheritable ( & self ) -> & InheritableFields {
1638+ & self . inheritable_fields
1639+ }
16461640}
16471641
16481642/// A group of fields that are inheritable by members of the workspace
@@ -1832,7 +1826,53 @@ impl InheritableFields {
18321826 }
18331827}
18341828
1835- pub fn find_root_iter < ' a > (
1829+ fn parse_manifest ( manifest_path : & Path , config : & Config ) -> CargoResult < EitherManifest > {
1830+ let key = manifest_path. parent ( ) . unwrap ( ) ;
1831+ let source_id = SourceId :: for_path ( key) ?;
1832+ let ( manifest, _nested_paths) = read_manifest ( manifest_path, source_id, config) ?;
1833+ Ok ( manifest)
1834+ }
1835+
1836+ pub fn find_workspace_root ( manifest_path : & Path , config : & Config ) -> CargoResult < Option < PathBuf > > {
1837+ find_root_iter ( manifest_path, config)
1838+ . find_map ( |ances_manifest_path| {
1839+ let manifest = parse_manifest ( & ances_manifest_path, config) ;
1840+ match manifest {
1841+ Ok ( manifest) => match * manifest. workspace_config ( ) {
1842+ WorkspaceConfig :: Root ( ref ances_root_config) => {
1843+ debug ! ( "find_root - found a root checking exclusion" ) ;
1844+ if !ances_root_config. is_excluded ( manifest_path) {
1845+ debug ! ( "find_root - found!" ) ;
1846+ Some ( Ok ( ances_manifest_path) )
1847+ } else {
1848+ None
1849+ }
1850+ }
1851+ WorkspaceConfig :: Member {
1852+ root : Some ( ref path_to_root) ,
1853+ } => {
1854+ debug ! ( "find_root - found pointer" ) ;
1855+ Some ( Ok ( read_root_pointer ( & ances_manifest_path, path_to_root) ) )
1856+ }
1857+ WorkspaceConfig :: Member { .. } => None ,
1858+ } ,
1859+ Err ( e) => Some ( Err ( e) ) ,
1860+ }
1861+ } )
1862+ . transpose ( )
1863+ }
1864+
1865+ fn read_root_pointer ( member_manifest : & Path , root_link : & str ) -> PathBuf {
1866+ let path = member_manifest
1867+ . parent ( )
1868+ . unwrap ( )
1869+ . join ( root_link)
1870+ . join ( "Cargo.toml" ) ;
1871+ debug ! ( "find_root - pointer {}" , path. display( ) ) ;
1872+ paths:: normalize_path ( & path)
1873+ }
1874+
1875+ fn find_root_iter < ' a > (
18361876 manifest_path : & ' a Path ,
18371877 config : & ' a Config ,
18381878) -> impl Iterator < Item = PathBuf > + ' a {
0 commit comments