@@ -591,16 +591,6 @@ impl<'cfg> Workspace<'cfg> {
591
591
/// Returns an error if `manifest_path` isn't actually a valid manifest or
592
592
/// if some other transient error happens.
593
593
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
-
604
594
{
605
595
let current = self . packages . load ( manifest_path) ?;
606
596
match * current. workspace_config ( ) {
@@ -1643,6 +1633,10 @@ impl WorkspaceRootConfig {
1643
1633
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
1644
1634
Ok ( res)
1645
1635
}
1636
+
1637
+ pub fn inheritable ( & self ) -> & InheritableFields {
1638
+ & self . inheritable_fields
1639
+ }
1646
1640
}
1647
1641
1648
1642
/// A group of fields that are inheritable by members of the workspace
@@ -1832,7 +1826,53 @@ impl InheritableFields {
1832
1826
}
1833
1827
}
1834
1828
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 > (
1836
1876
manifest_path : & ' a Path ,
1837
1877
config : & ' a Config ,
1838
1878
) -> impl Iterator < Item = PathBuf > + ' a {
0 commit comments