1
1
use crate :: command_prelude:: * ;
2
2
3
- use cargo:: core:: { GitReference , SourceId } ;
3
+ use cargo:: core:: { GitReference , SourceId , Workspace } ;
4
4
use cargo:: ops;
5
5
use cargo:: util:: IntoUrl ;
6
6
7
+ use cargo_util:: paths;
8
+
7
9
pub fn cli ( ) -> App {
8
10
subcommand ( "install" )
9
11
. about ( "Install a Rust binary. Default location is $HOME/.cargo/bin" )
@@ -80,13 +82,20 @@ pub fn cli() -> App {
80
82
}
81
83
82
84
pub fn exec ( config : & mut Config , args : & ArgMatches ) -> CliResult {
83
- if let Some ( path) = args. value_of_path ( "path" , config) {
85
+ let path = args. value_of_path ( "path" , config) ;
86
+ if let Some ( path) = & path {
84
87
config. reload_rooted_at ( path) ?;
85
88
} else {
86
89
// TODO: Consider calling set_search_stop_path(home).
87
90
config. reload_rooted_at ( config. home ( ) . clone ( ) . into_path_unlocked ( ) ) ?;
88
91
}
89
92
93
+ // In general, we try to avoid normalizing paths in Cargo,
94
+ // but in these particular cases we need it to fix rust-lang/cargo#10283.
95
+ // (Handle `SourceId::for_path` and `Workspace::new`,
96
+ // but not `Config::reload_rooted_at` which is always cwd)
97
+ let path = path. map ( |p| paths:: normalize_path ( & p) ) ;
98
+
90
99
let krates = args
91
100
. values_of ( "crate" )
92
101
. unwrap_or_default ( )
@@ -106,7 +115,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
106
115
GitReference :: DefaultBranch
107
116
} ;
108
117
SourceId :: for_git ( & url, gitref) ?
109
- } else if let Some ( path) = args . value_of_path ( " path" , config ) {
118
+ } else if let Some ( path) = & path {
110
119
SourceId :: for_path ( & path) ?
111
120
} else if krates. is_empty ( ) {
112
121
from_cwd = true ;
@@ -125,9 +134,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
125
134
// We only provide workspace information for local crate installation from
126
135
// one of the following sources:
127
136
// - From current working directory (only work for edition 2015).
128
- // - From a specific local file path.
129
- let workspace = if from_cwd || args. is_present ( "path" ) {
137
+ // - From a specific local file path (from `--path` arg).
138
+ //
139
+ // This workspace information is for emitting helpful messages from
140
+ // `ArgMatchesExt::compile_options` and won't affect the actual compilation.
141
+ let workspace = if from_cwd {
130
142
args. workspace ( config) . ok ( )
143
+ } else if let Some ( path) = & path {
144
+ Workspace :: new ( & path. join ( "Cargo.toml" ) , config) . ok ( )
131
145
} else {
132
146
None
133
147
} ;
0 commit comments