@@ -14,7 +14,11 @@ use watchexec::{
14
14
Shell ,
15
15
} ;
16
16
17
- pub fn set_commands ( builder : & mut ConfigBuilder , matches : & ArgMatches ) {
17
+ /// Sets all the requested commands on the passed-in `builder`.
18
+ ///
19
+ /// If no commands are provided, this defaults to `cargo check`, and returns `true` to indicate
20
+ /// that it used the default.
21
+ pub fn set_commands ( builder : & mut ConfigBuilder , matches : & ArgMatches ) -> bool {
18
22
let mut commands: Vec < String > = Vec :: new ( ) ;
19
23
20
24
// --features are injected just after applicable cargo subcommands
@@ -114,17 +118,23 @@ pub fn set_commands(builder: &mut ConfigBuilder, matches: &ArgMatches) {
114
118
}
115
119
116
120
// Default to `cargo check`
117
- if commands. is_empty ( ) {
121
+ let default_command = if commands. is_empty ( ) {
118
122
let mut cmd: String = "cargo check" . into ( ) ;
119
123
if let Some ( features) = features. as_ref ( ) {
120
124
cmd. push_str ( " --features " ) ;
121
125
cmd. push_str ( features) ;
122
126
}
123
127
commands. push ( cmd) ;
124
- }
128
+
129
+ true
130
+ } else {
131
+ false
132
+ } ;
125
133
126
134
debug ! ( "Commands: {:?}" , commands) ;
127
135
builder. cmd ( commands) ;
136
+
137
+ default_command
128
138
}
129
139
130
140
pub fn set_ignores ( builder : & mut ConfigBuilder , matches : & ArgMatches ) {
@@ -192,8 +202,13 @@ pub fn set_debounce(builder: &mut ConfigBuilder, matches: &ArgMatches) {
192
202
}
193
203
}
194
204
195
- fn find_local_deps ( ) -> Result < Vec < PathBuf > , String > {
205
+ fn find_local_deps ( filter_platform : Option < String > ) -> Result < Vec < PathBuf > , String > {
206
+ let options: Vec < String > = filter_platform
207
+ . map ( |platform| format ! ( "--filter-platform={}" , platform) )
208
+ . into_iter ( )
209
+ . collect ( ) ;
196
210
let metadata = MetadataCommand :: new ( )
211
+ . other_options ( options)
197
212
. exec ( )
198
213
. map_err ( |e| format ! ( "Failed to execute `cargo metadata`: {}" , e) ) ?;
199
214
@@ -250,7 +265,7 @@ fn find_local_deps() -> Result<Vec<PathBuf>, String> {
250
265
Ok ( local_deps. into_iter ( ) . collect :: < Vec < PathBuf > > ( ) )
251
266
}
252
267
253
- pub fn set_watches ( builder : & mut ConfigBuilder , matches : & ArgMatches ) {
268
+ pub fn set_watches ( builder : & mut ConfigBuilder , matches : & ArgMatches , only_default_command : bool ) {
254
269
let mut watches = Vec :: new ( ) ;
255
270
if matches. is_present ( "watch" ) {
256
271
for watch in values_t ! ( matches, "watch" , String ) . unwrap_or_else ( |e| e. exit ( ) ) {
@@ -260,7 +275,12 @@ pub fn set_watches(builder: &mut ConfigBuilder, matches: &ArgMatches) {
260
275
261
276
if watches. is_empty ( ) {
262
277
if !matches. is_present ( "skip-local-deps" ) {
263
- match find_local_deps ( ) {
278
+ let filter_platform = if only_default_command {
279
+ Some ( crate :: rustc:: host_triple ( ) )
280
+ } else {
281
+ None
282
+ } ;
283
+ match find_local_deps ( filter_platform) {
264
284
Ok ( dirs) => {
265
285
if dirs. is_empty ( ) {
266
286
debug ! ( "Found no local deps" ) ;
@@ -322,8 +342,8 @@ pub fn get_options(matches: &ArgMatches) -> Config {
322
342
323
343
set_ignores ( & mut builder, matches) ;
324
344
set_debounce ( & mut builder, matches) ;
325
- set_watches ( & mut builder, matches) ;
326
- set_commands ( & mut builder, matches) ;
345
+ let only_default_command = set_commands ( & mut builder, matches) ;
346
+ set_watches ( & mut builder, matches, only_default_command ) ;
327
347
328
348
let mut args = builder. build ( ) . unwrap ( ) ;
329
349
args. once = matches. is_present ( "once" ) ;
0 commit comments