@@ -15,6 +15,7 @@ use crate::CargoResult;
15
15
use anyhow:: bail;
16
16
use cargo_util:: paths;
17
17
use std:: ffi:: { OsStr , OsString } ;
18
+ use std:: path:: Path ;
18
19
use std:: path:: PathBuf ;
19
20
20
21
pub use crate :: core:: compiler:: CompileMode ;
@@ -339,22 +340,7 @@ pub trait ArgMatchesExt {
339
340
}
340
341
341
342
fn root_manifest ( & self , config : & Config ) -> CargoResult < PathBuf > {
342
- if let Some ( path) = self . value_of_path ( "manifest-path" , config) {
343
- // In general, we try to avoid normalizing paths in Cargo,
344
- // but in this particular case we need it to fix #3586.
345
- let path = paths:: normalize_path ( & path) ;
346
- if !path. ends_with ( "Cargo.toml" ) && !crate :: util:: toml:: is_embedded ( & path) {
347
- anyhow:: bail!( "the manifest-path must be a path to a Cargo.toml file" )
348
- }
349
- if !path. exists ( ) {
350
- anyhow:: bail!(
351
- "manifest path `{}` does not exist" ,
352
- self . _value_of( "manifest-path" ) . unwrap( )
353
- )
354
- }
355
- return Ok ( path) ;
356
- }
357
- find_root_manifest_for_wd ( config. cwd ( ) )
343
+ root_manifest ( self . _value_of ( "manifest-path" ) . map ( Path :: new) , config)
358
344
}
359
345
360
346
fn workspace < ' a > ( & self , config : & ' a Config ) -> CargoResult < Workspace < ' a > > {
@@ -792,6 +778,24 @@ pub fn values_os(args: &ArgMatches, name: &str) -> Vec<OsString> {
792
778
args. _values_of_os ( name)
793
779
}
794
780
781
+ pub fn root_manifest ( manifest_path : Option < & Path > , config : & Config ) -> CargoResult < PathBuf > {
782
+ if let Some ( manifest_path) = manifest_path {
783
+ let path = config. cwd ( ) . join ( manifest_path) ;
784
+ // In general, we try to avoid normalizing paths in Cargo,
785
+ // but in this particular case we need it to fix #3586.
786
+ let path = paths:: normalize_path ( & path) ;
787
+ if !path. ends_with ( "Cargo.toml" ) && !crate :: util:: toml:: is_embedded ( & path) {
788
+ anyhow:: bail!( "the manifest-path must be a path to a Cargo.toml file" )
789
+ }
790
+ if !path. exists ( ) {
791
+ anyhow:: bail!( "manifest path `{}` does not exist" , manifest_path. display( ) )
792
+ }
793
+ Ok ( path)
794
+ } else {
795
+ find_root_manifest_for_wd ( config. cwd ( ) )
796
+ }
797
+ }
798
+
795
799
#[ track_caller]
796
800
pub fn ignore_unknown < T : Default > ( r : Result < T , clap:: parser:: MatchesError > ) -> T {
797
801
match r {
0 commit comments