@@ -13,7 +13,7 @@ use std::str::FromStr;
1313use rustc_serialize:: { Encodable , Encoder } ;
1414use toml;
1515use core:: shell:: { Verbosity , ColorConfig } ;
16- use core:: { MultiShell , Workspace } ;
16+ use core:: MultiShell ;
1717use util:: { CargoResult , CargoError , ChainError , Rustc , internal, human} ;
1818use util:: { Filesystem , LazyCell } ;
1919
@@ -28,7 +28,6 @@ pub struct Config {
2828 values : LazyCell < HashMap < String , ConfigValue > > ,
2929 cwd : PathBuf ,
3030 rustdoc : LazyCell < PathBuf > ,
31- target_dir : RefCell < Option < Filesystem > > ,
3231 extra_verbose : Cell < bool > ,
3332 frozen : Cell < bool > ,
3433 locked : Cell < bool > ,
@@ -37,23 +36,18 @@ pub struct Config {
3736impl Config {
3837 pub fn new ( shell : MultiShell ,
3938 cwd : PathBuf ,
40- homedir : PathBuf ) -> CargoResult < Config > {
41- let mut cfg = Config {
39+ homedir : PathBuf ) -> Config {
40+ Config {
4241 home_path : Filesystem :: new ( homedir) ,
4342 shell : RefCell :: new ( shell) ,
4443 rustc : LazyCell :: new ( ) ,
4544 cwd : cwd,
4645 values : LazyCell :: new ( ) ,
4746 rustdoc : LazyCell :: new ( ) ,
48- target_dir : RefCell :: new ( None ) ,
4947 extra_verbose : Cell :: new ( false ) ,
5048 frozen : Cell :: new ( false ) ,
5149 locked : Cell :: new ( false ) ,
52- } ;
53-
54- try!( cfg. scrape_target_dir_config ( ) ) ;
55-
56- Ok ( cfg)
50+ }
5751 }
5852
5953 pub fn default ( ) -> CargoResult < Config > {
@@ -65,7 +59,7 @@ impl Config {
6559 human ( "Cargo couldn't find your home directory. \
6660 This probably means that $HOME was not set.")
6761 } ) ) ;
68- Config :: new ( shell, cwd, homedir)
62+ Ok ( Config :: new ( shell, cwd, homedir) )
6963 }
7064
7165 pub fn home ( & self ) -> & Filesystem { & self . home_path }
@@ -108,14 +102,15 @@ impl Config {
108102
109103 pub fn cwd ( & self ) -> & Path { & self . cwd }
110104
111- pub fn target_dir ( & self , ws : & Workspace ) -> Filesystem {
112- self . target_dir . borrow ( ) . clone ( ) . unwrap_or_else ( || {
113- Filesystem :: new ( ws. root ( ) . join ( "target" ) )
114- } )
115- }
116-
117- pub fn set_target_dir ( & self , path : Filesystem ) {
118- * self . target_dir . borrow_mut ( ) = Some ( path) ;
105+ pub fn target_dir ( & self ) -> CargoResult < Option < Filesystem > > {
106+ if let Some ( dir) = env:: var_os ( "CARGO_TARGET_DIR" ) {
107+ Ok ( Some ( Filesystem :: new ( self . cwd . join ( dir) ) ) )
108+ } else if let Some ( val) = try!( self . get_path ( "build.target-dir" ) ) {
109+ let val = self . cwd . join ( val. val ) ;
110+ Ok ( Some ( Filesystem :: new ( val) ) )
111+ } else {
112+ Ok ( None )
113+ }
119114 }
120115
121116 fn get ( & self , key : & str ) -> CargoResult < Option < ConfigValue > > {
@@ -292,8 +287,11 @@ impl Config {
292287 locked : bool ) -> CargoResult < ( ) > {
293288 let extra_verbose = verbose >= 2 ;
294289 let verbose = if verbose == 0 { None } else { Some ( true ) } ;
295- let cfg_verbose = try!( self . get_bool ( "term.verbose" ) ) . map ( |v| v. val ) ;
296- let cfg_color = try!( self . get_string ( "term.color" ) ) . map ( |v| v. val ) ;
290+
291+ // Ignore errors in the configuration files.
292+ let cfg_verbose = self . get_bool ( "term.verbose" ) . unwrap_or ( None ) . map ( |v| v. val ) ;
293+ let cfg_color = self . get_string ( "term.color" ) . unwrap_or ( None ) . map ( |v| v. val ) ;
294+
297295 let color = color. as_ref ( ) . or ( cfg_color. as_ref ( ) ) ;
298296
299297 let verbosity = match ( verbose, cfg_verbose, quiet) {
@@ -369,16 +367,6 @@ impl Config {
369367 }
370368 }
371369
372- fn scrape_target_dir_config ( & mut self ) -> CargoResult < ( ) > {
373- if let Some ( dir) = env:: var_os ( "CARGO_TARGET_DIR" ) {
374- * self . target_dir . borrow_mut ( ) = Some ( Filesystem :: new ( self . cwd . join ( dir) ) ) ;
375- } else if let Some ( val) = try!( self . get_path ( "build.target-dir" ) ) {
376- let val = self . cwd . join ( val. val ) ;
377- * self . target_dir . borrow_mut ( ) = Some ( Filesystem :: new ( val) ) ;
378- }
379- Ok ( ( ) )
380- }
381-
382370 fn get_tool ( & self , tool : & str ) -> CargoResult < PathBuf > {
383371 let var = tool. chars ( ) . flat_map ( |c| c. to_uppercase ( ) ) . collect :: < String > ( ) ;
384372 if let Some ( tool_path) = env:: var_os ( & var) {
0 commit comments