File tree Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,6 @@ pub fn main(lazy_gctx: &mut LazyContext) -> CliResult {
19
19
let args = cli ( ) . try_get_matches ( ) ?;
20
20
21
21
// Update the process-level notion of cwd
22
- // This must be completed before config is initialized
23
- assert_eq ! ( lazy_gctx. is_init( ) , false ) ;
24
22
if let Some ( new_cwd) = args. get_one :: < std:: path:: PathBuf > ( "directory" ) {
25
23
// This is a temporary hack. This cannot access `Config`, so this is a bit messy.
26
24
// This does not properly parse `-Z` flags that appear after the subcommand.
@@ -40,6 +38,7 @@ pub fn main(lazy_gctx: &mut LazyContext) -> CliResult {
40
38
. into ( ) ) ;
41
39
}
42
40
std:: env:: set_current_dir ( & new_cwd) . context ( "could not change to requested directory" ) ?;
41
+ lazy_gctx. get_mut ( ) . reload_cwd ( ) ?;
43
42
}
44
43
45
44
// CAUTION: Be careful with using `config` until it is configured below.
@@ -661,13 +660,6 @@ impl LazyContext {
661
660
Self { gctx : None }
662
661
}
663
662
664
- /// Check whether the config is loaded
665
- ///
666
- /// This is useful for asserts in case the environment needs to be setup before loading
667
- pub fn is_init ( & self ) -> bool {
668
- self . gctx . is_some ( )
669
- }
670
-
671
663
/// Get the config, loading it if needed
672
664
///
673
665
/// On error, the process is terminated
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ fn main() {
20
20
setup_logger ( ) ;
21
21
22
22
let mut lazy_gctx = cli:: LazyContext :: new ( ) ;
23
+ lazy_gctx. get ( ) ;
23
24
24
25
let result = if let Some ( lock_addr) = cargo:: ops:: fix_get_proxy_lock_addr ( ) {
25
26
cargo:: ops:: fix_exec_rustc ( lazy_gctx. get ( ) , & lock_addr) . map_err ( |e| CliError :: from ( e) )
Original file line number Diff line number Diff line change @@ -565,6 +565,25 @@ impl GlobalContext {
565
565
self . search_stop_path = Some ( path) ;
566
566
}
567
567
568
+ /// Switches the working directory to [`std::env::current_dir`]
569
+ ///
570
+ /// There is not a need to also call [`Self::reload_rooted_at`].
571
+ pub fn reload_cwd ( & mut self ) -> CargoResult < ( ) > {
572
+ let cwd = env:: current_dir ( )
573
+ . with_context ( || "couldn't get the current directory of the process" ) ?;
574
+ let homedir = homedir ( & cwd) . ok_or_else ( || {
575
+ anyhow ! (
576
+ "Cargo couldn't find your home directory. \
577
+ This probably means that $HOME was not set."
578
+ )
579
+ } ) ?;
580
+
581
+ self . cwd = cwd;
582
+ self . home_path = Filesystem :: new ( homedir) ;
583
+ self . reload_rooted_at ( self . cwd . clone ( ) ) ?;
584
+ Ok ( ( ) )
585
+ }
586
+
568
587
/// Reloads on-disk configuration values, starting at the given path and
569
588
/// walking up its ancestors.
570
589
pub fn reload_rooted_at < P : AsRef < Path > > ( & mut self , path : P ) -> CargoResult < ( ) > {
You can’t perform that action at this time.
0 commit comments