rust_version: support rustup; see #418
This commit is contained in:
		
							parent
							
								
									2b307eefd8
								
							
						
					
					
						commit
						ddecb91a0f
					
				| 
						 | 
					@ -2329,12 +2329,10 @@ prompt_rust_version() {
 | 
				
			||||||
      dir=${dir:h}
 | 
					      dir=${dir:h}
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  local rustc=$commands[rustc] so
 | 
					  local rustc=${commands[rustc]:A} toolchain deps=()
 | 
				
			||||||
  if (( $+commands[ldd] )); then
 | 
					  if (( $+commands[ldd] )); then
 | 
				
			||||||
    if _p9k_cache_stat_get $0_so $rustc; then
 | 
					    if ! _p9k_cache_stat_get $0_so $rustc; then
 | 
				
			||||||
      so=$_p9k_cache_val[1]
 | 
					      local line match so
 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      local line match
 | 
					 | 
				
			||||||
      for line in "${(@f)$(ldd $rustc 2>/dev/null)}"; do
 | 
					      for line in "${(@f)$(ldd $rustc 2>/dev/null)}"; do
 | 
				
			||||||
        [[ $line == (#b)[[:space:]]#librustc_driver[^[:space:]]#.so' => '(*)' (0x'[[:xdigit:]]#')' ]] || continue
 | 
					        [[ $line == (#b)[[:space:]]#librustc_driver[^[:space:]]#.so' => '(*)' (0x'[[:xdigit:]]#')' ]] || continue
 | 
				
			||||||
        so=$match[1]
 | 
					        so=$match[1]
 | 
				
			||||||
| 
						 | 
					@ -2342,8 +2340,36 @@ prompt_rust_version() {
 | 
				
			||||||
      done
 | 
					      done
 | 
				
			||||||
      _p9k_cache_stat_set "$so"
 | 
					      _p9k_cache_stat_set "$so"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					    deps+=$_p9k_cache_val[1]
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  if ! _p9k_cache_stat_get $0_v $rustc $so; then
 | 
					  if (( $+commands[rustup] )); then
 | 
				
			||||||
 | 
					    local rustup=${commands[rustup]:A}
 | 
				
			||||||
 | 
					    local rustup_home=${RUSTUP_HOME:-~/.rustup}
 | 
				
			||||||
 | 
					    local cfg=($rustup_home/settings.toml(.N))
 | 
				
			||||||
 | 
					    deps+=($cfg $rustup_home/update-hashes/*(.N))
 | 
				
			||||||
 | 
					    if [[ -z ${toolchain::=$RUSTUP_TOOLCHAIN} ]]; then
 | 
				
			||||||
 | 
					      if ! _p9k_cache_stat_get $0_overrides $rustup $cfg; then
 | 
				
			||||||
 | 
					        local lines=(${(f)"$(rustup override list 2>/dev/null)"})
 | 
				
			||||||
 | 
					        local keys=(/ ${lines%%[[:space:]]#[^[:space:]]#})
 | 
				
			||||||
 | 
					        local vals=(_ ${lines##*[[:space:]]})
 | 
				
			||||||
 | 
					        _p9k_cache_stat_set ${keys:^vals}
 | 
				
			||||||
 | 
					      fi
 | 
				
			||||||
 | 
					      local -A overrides=($_p9k_cache_val)
 | 
				
			||||||
 | 
					      local dir=$_p9k_pwd_a
 | 
				
			||||||
 | 
					      while true; do
 | 
				
			||||||
 | 
					        if (( $+overrides[$dir] )); then
 | 
				
			||||||
 | 
					          toolchain=$overrides[$dir]
 | 
				
			||||||
 | 
					          break
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        if [[ -r $dir/rust-toolchain ]]; then
 | 
				
			||||||
 | 
					          { toolchain="$(<$dir/rust-toolchain)" } 2>/dev/null
 | 
				
			||||||
 | 
					          break
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        dir=${dir:h}
 | 
				
			||||||
 | 
					      done
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					  if ! _p9k_cache_stat_get $0_v$toolchain $rustc $deps; then
 | 
				
			||||||
    _p9k_cache_stat_set "$($rustc --version 2>/dev/null)"
 | 
					    _p9k_cache_stat_set "$($rustc --version 2>/dev/null)"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  local v=${${_p9k_cache_val[1]#rustc }%% *}
 | 
					  local v=${${_p9k_cache_val[1]#rustc }%% *}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue