@@ -90,60 +90,11 @@ impl LinkType {
90
90
}
91
91
}
92
92
93
- /// A glorified callback for executing calls to rustc. Rather than calling rustc
94
- /// directly, we'll use an `Executor`, giving clients an opportunity to intercept
95
- /// the build calls.
96
- pub trait Executor : Send + Sync + ' static {
97
- /// Called after a rustc process invocation is prepared up-front for a given
98
- /// unit of work (may still be modified for runtime-known dependencies, when
99
- /// the work is actually executed).
100
- fn init ( & self , _cx : & Context < ' _ , ' _ > , _unit : & Unit ) { }
101
-
102
- /// In case of an `Err`, Cargo will not continue with the build process for
103
- /// this package.
104
- fn exec (
105
- & self ,
106
- cmd : & ProcessBuilder ,
107
- id : PackageId ,
108
- target : & Target ,
109
- mode : CompileMode ,
110
- on_stdout_line : & mut dyn FnMut ( & str ) -> CargoResult < ( ) > ,
111
- on_stderr_line : & mut dyn FnMut ( & str ) -> CargoResult < ( ) > ,
112
- ) -> CargoResult < ( ) > ;
113
-
114
- /// Queried when queuing each unit of work. If it returns true, then the
115
- /// unit will always be rebuilt, independent of whether it needs to be.
116
- fn force_rebuild ( & self , _unit : & Unit ) -> bool {
117
- false
118
- }
119
- }
120
-
121
- /// A `DefaultExecutor` calls rustc without doing anything else. It is Cargo's
122
- /// default behaviour.
123
- #[ derive( Copy , Clone ) ]
124
- pub struct DefaultExecutor ;
125
-
126
- impl Executor for DefaultExecutor {
127
- fn exec (
128
- & self ,
129
- cmd : & ProcessBuilder ,
130
- _id : PackageId ,
131
- _target : & Target ,
132
- _mode : CompileMode ,
133
- on_stdout_line : & mut dyn FnMut ( & str ) -> CargoResult < ( ) > ,
134
- on_stderr_line : & mut dyn FnMut ( & str ) -> CargoResult < ( ) > ,
135
- ) -> CargoResult < ( ) > {
136
- cmd. exec_with_streaming ( on_stdout_line, on_stderr_line, false )
137
- . map ( drop)
138
- }
139
- }
140
-
141
93
fn compile < ' cfg > (
142
94
cx : & mut Context < ' _ , ' cfg > ,
143
95
jobs : & mut JobQueue < ' cfg > ,
144
96
plan : & mut BuildPlan ,
145
97
unit : & Unit ,
146
- exec : & Arc < dyn Executor > ,
147
98
force_rebuild : bool ,
148
99
) -> CargoResult < ( ) > {
149
100
let bcx = cx. bcx ;
@@ -163,15 +114,14 @@ fn compile<'cfg>(
163
114
// We run these targets later, so this is just a no-op for now.
164
115
Job :: new_fresh ( )
165
116
} else if build_plan {
166
- Job :: new_dirty ( rustc ( cx, unit, & exec . clone ( ) ) ?)
117
+ Job :: new_dirty ( rustc ( cx, unit) ?)
167
118
} else {
168
- let force = exec. force_rebuild ( unit) || force_rebuild;
169
- let mut job = fingerprint:: prepare_target ( cx, unit, force) ?;
119
+ let mut job = fingerprint:: prepare_target ( cx, unit, force_rebuild) ?;
170
120
job. before ( if job. freshness ( ) == Freshness :: Dirty {
171
121
let work = if unit. mode . is_doc ( ) || unit. mode . is_doc_scrape ( ) {
172
122
rustdoc ( cx, unit) ?
173
123
} else {
174
- rustc ( cx, unit, exec ) ?
124
+ rustc ( cx, unit) ?
175
125
} ;
176
126
work. then ( link_targets ( cx, unit, false ) ?)
177
127
} else {
@@ -198,7 +148,7 @@ fn compile<'cfg>(
198
148
// Be sure to compile all dependencies of this target as well.
199
149
let deps = Vec :: from ( cx. unit_deps ( unit) ) ; // Create vec due to mutable borrow.
200
150
for dep in deps {
201
- compile ( cx, jobs, plan, & dep. unit , exec , false ) ?;
151
+ compile ( cx, jobs, plan, & dep. unit , false ) ?;
202
152
}
203
153
if build_plan {
204
154
plan. add ( cx, unit) ?;
@@ -207,7 +157,7 @@ fn compile<'cfg>(
207
157
Ok ( ( ) )
208
158
}
209
159
210
- fn rustc ( cx : & mut Context < ' _ , ' _ > , unit : & Unit , exec : & Arc < dyn Executor > ) -> CargoResult < Work > {
160
+ fn rustc ( cx : & mut Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < Work > {
211
161
let mut rustc = prepare_rustc ( cx, & unit. target . rustc_crate_types ( ) , unit) ?;
212
162
let build_plan = cx. bcx . build_config . build_plan ;
213
163
@@ -248,10 +198,6 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
248
198
let mut output_options = OutputOptions :: new ( cx, unit) ;
249
199
let package_id = unit. pkg . package_id ( ) ;
250
200
let target = Target :: clone ( & unit. target ) ;
251
- let mode = unit. mode ;
252
-
253
- exec. init ( cx, unit) ;
254
- let exec = exec. clone ( ) ;
255
201
256
202
let root_output = cx. files ( ) . host_dest ( ) . to_path_buf ( ) ;
257
203
let target_dir = cx. bcx . ws . target_dir ( ) . into_path_unlocked ( ) ;
@@ -339,38 +285,37 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
339
285
if build_plan {
340
286
state. build_plan ( buildkey, rustc. clone ( ) , outputs. clone ( ) ) ;
341
287
} else {
342
- exec. exec (
343
- & rustc,
344
- package_id,
345
- & target,
346
- mode,
347
- & mut |line| on_stdout_line ( state, line, package_id, & target) ,
348
- & mut |line| {
349
- on_stderr_line (
350
- state,
351
- line,
352
- package_id,
353
- & manifest_path,
354
- & target,
355
- & mut output_options,
356
- )
357
- } ,
358
- )
359
- . map_err ( verbose_if_simple_exit_code)
360
- . with_context ( || {
361
- // adapted from rustc_errors/src/lib.rs
362
- let warnings = match output_options. warnings_seen {
363
- 0 => String :: new ( ) ,
364
- 1 => "; 1 warning emitted" . to_string ( ) ,
365
- count => format ! ( "; {} warnings emitted" , count) ,
366
- } ;
367
- let errors = match output_options. errors_seen {
368
- 0 => String :: new ( ) ,
369
- 1 => " due to previous error" . to_string ( ) ,
370
- count => format ! ( " due to {} previous errors" , count) ,
371
- } ;
372
- format ! ( "could not compile `{}`{}{}" , name, errors, warnings)
373
- } ) ?;
288
+ rustc
289
+ . exec_with_streaming (
290
+ & mut |line| on_stdout_line ( state, line, package_id, & target) ,
291
+ & mut |line| {
292
+ on_stderr_line (
293
+ state,
294
+ line,
295
+ package_id,
296
+ & manifest_path,
297
+ & target,
298
+ & mut output_options,
299
+ )
300
+ } ,
301
+ false ,
302
+ )
303
+ . map ( drop)
304
+ . map_err ( verbose_if_simple_exit_code)
305
+ . with_context ( || {
306
+ // adapted from rustc_errors/src/lib.rs
307
+ let warnings = match output_options. warnings_seen {
308
+ 0 => String :: new ( ) ,
309
+ 1 => "; 1 warning emitted" . to_string ( ) ,
310
+ count => format ! ( "; {} warnings emitted" , count) ,
311
+ } ;
312
+ let errors = match output_options. errors_seen {
313
+ 0 => String :: new ( ) ,
314
+ 1 => " due to previous error" . to_string ( ) ,
315
+ count => format ! ( " due to {} previous errors" , count) ,
316
+ } ;
317
+ format ! ( "could not compile `{}`{}{}" , name, errors, warnings)
318
+ } ) ?;
374
319
// Exec should never return with success *and* generate an error.
375
320
debug_assert_eq ! ( output_options. errors_seen, 0 ) ;
376
321
}
0 commit comments