14
14
15
15
use compiler:: { Cacheable , ColorMode , Compiler , CompilerArguments , CompileCommand , CompilerHasher , CompilerKind ,
16
16
Compilation , HashResult } ;
17
- use compiler:: pkg;
18
17
use dist;
18
+ #[ cfg( feature = "dist-client" ) ]
19
+ use dist:: pkg;
19
20
use futures:: Future ;
20
21
use futures_cpupool:: CpuPool ;
21
22
use mock_command:: CommandCreatorSync ;
22
23
use std:: borrow:: Cow ;
23
24
use std:: collections:: { HashMap , HashSet } ;
24
25
use std:: ffi:: { OsStr , OsString } ;
25
26
use std:: fmt;
26
- use std:: fs:: File ;
27
+ #[ cfg( feature = "dist-client" ) ]
28
+ #[ cfg( all( target_os = "linux" , target_arch = "x86_64" ) ) ]
29
+ use std:: fs;
27
30
use std:: hash:: Hash ;
31
+ #[ cfg( feature = "dist-client" ) ]
28
32
use std:: io;
29
33
use std:: path:: { Path , PathBuf } ;
30
34
use std:: process;
31
- use tar;
32
35
use util:: { HashToDigest , Digest } ;
33
36
34
37
use errors:: * ;
@@ -120,6 +123,7 @@ impl Language {
120
123
/// A generic implementation of the `Compilation` trait for C/C++ compilers.
121
124
struct CCompilation < I : CCompilerImpl > {
122
125
parsed_args : ParsedArguments ,
126
+ #[ cfg( feature = "dist-client" ) ]
123
127
preprocessed_input : Vec < u8 > ,
124
128
executable : PathBuf ,
125
129
compiler : I ,
@@ -262,6 +266,7 @@ impl<T, I> CompilerHasher<T> for CCompilerHasher<I>
262
266
key : key,
263
267
compilation : Box :: new ( CCompilation {
264
268
parsed_args : parsed_args,
269
+ #[ cfg( feature = "dist-client" ) ]
265
270
preprocessed_input : preprocessor_result. stdout ,
266
271
executable : executable,
267
272
compiler : compiler,
@@ -293,34 +298,22 @@ impl<I: CCompilerImpl> Compilation for CCompilation<I> {
293
298
fn generate_compile_commands ( & self , path_transformer : & mut dist:: PathTransformer )
294
299
-> Result < ( CompileCommand , Option < dist:: CompileCommand > , Cacheable ) >
295
300
{
296
- let CCompilation { ref parsed_args, ref executable, ref compiler, preprocessed_input : _ , ref cwd, ref env_vars } = * self ;
301
+ let CCompilation { ref parsed_args, ref executable, ref compiler, ref cwd, ref env_vars, .. } = * self ;
297
302
compiler. generate_compile_commands ( path_transformer, executable, parsed_args, cwd, env_vars)
298
303
}
299
304
300
305
#[ cfg( feature = "dist-client" ) ]
301
- fn into_dist_inputs_creator ( self : Box < Self > , path_transformer : & mut dist:: PathTransformer ) -> Result < ( Box < FnMut ( & mut io :: Write ) + Send > , Box < pkg:: CompilerPackager > ) > {
306
+ fn into_dist_packagers ( self : Box < Self > , path_transformer : & mut dist:: PathTransformer ) -> Result < ( Box < pkg :: InputsPackager > , Box < pkg:: ToolchainPackager > ) > {
302
307
let CCompilation { parsed_args, cwd, preprocessed_input, executable, .. } = * { self } ;
303
308
trace ! ( "Dist inputs: {:?}" , parsed_args. input) ;
304
309
305
310
let input_path = cwd. join ( & parsed_args. input ) ;
306
311
let input_path = pkg:: simplify_path ( & input_path) ?;
307
312
let dist_input_path = path_transformer. to_dist ( & input_path) . unwrap ( ) ;
308
- let preprocessed_input = preprocessed_input;
309
-
310
- let toolchain_creator = Box :: new ( CCompilerPackager { executable } ) ;
311
- let inputs_creator = Box :: new ( move |wtr : & mut io:: Write | {
312
- let mut builder = tar:: Builder :: new ( wtr) ;
313
313
314
- let mut file_header = pkg:: make_tar_header ( & input_path, & dist_input_path) . unwrap ( ) ;
315
- file_header. set_size ( preprocessed_input. len ( ) as u64 ) ; // The metadata is from non-preprocessed
316
- file_header. set_cksum ( ) ;
317
- builder. append ( & file_header, preprocessed_input. as_slice ( ) ) . unwrap ( ) ;
318
-
319
- // Finish archive
320
- let _ = builder. into_inner ( ) . unwrap ( ) ;
321
- } ) ;
322
-
323
- Ok ( ( inputs_creator, toolchain_creator) )
314
+ let inputs_packager = Box :: new ( CInputsPackager { input_path, dist_input_path, preprocessed_input } ) ;
315
+ let toolchain_packager = Box :: new ( CToolchainPackager { executable } ) ;
316
+ Ok ( ( inputs_packager, toolchain_packager) )
324
317
}
325
318
326
319
fn outputs < ' a > ( & ' a self ) -> Box < Iterator < Item =( & ' a str , & ' a Path ) > + ' a >
@@ -329,17 +322,44 @@ impl<I: CCompilerImpl> Compilation for CCompilation<I> {
329
322
}
330
323
}
331
324
332
- struct CCompilerPackager {
333
- #[ allow( dead_code) ]
325
+ #[ cfg( feature = "dist-client" ) ]
326
+ struct CInputsPackager {
327
+ input_path : PathBuf ,
328
+ dist_input_path : String ,
329
+ preprocessed_input : Vec < u8 > ,
330
+ }
331
+
332
+ #[ cfg( feature = "dist-client" ) ]
333
+ impl pkg:: InputsPackager for CInputsPackager {
334
+ fn write_inputs ( self : Box < Self > , wtr : & mut io:: Write ) -> Result < ( ) > {
335
+ use tar;
336
+
337
+ let CInputsPackager { input_path, dist_input_path, preprocessed_input } = * { self } ;
338
+
339
+ let mut builder = tar:: Builder :: new ( wtr) ;
340
+
341
+ let mut file_header = pkg:: make_tar_header ( & input_path, & dist_input_path) ?;
342
+ file_header. set_size ( preprocessed_input. len ( ) as u64 ) ; // The metadata is from non-preprocessed
343
+ file_header. set_cksum ( ) ;
344
+ builder. append ( & file_header, preprocessed_input. as_slice ( ) ) ?;
345
+
346
+ // Finish archive
347
+ let _ = builder. into_inner ( ) ;
348
+ Ok ( ( ) )
349
+ }
350
+ }
351
+
352
+ #[ cfg( feature = "dist-client" ) ]
353
+ #[ allow( unused) ]
354
+ struct CToolchainPackager {
334
355
executable : PathBuf ,
335
356
}
336
357
337
358
#[ cfg( feature = "dist-client" ) ]
338
359
#[ cfg( all( target_os = "linux" , target_arch = "x86_64" ) ) ]
339
- impl pkg:: CompilerPackager for CCompilerPackager {
340
- fn write_pkg ( self : Box < Self > , f : File ) -> Result < ( ) > {
360
+ impl pkg:: ToolchainPackager for CToolchainPackager {
361
+ fn write_pkg ( self : Box < Self > , f : fs :: File ) -> Result < ( ) > {
341
362
use std:: env;
342
- use std:: fs;
343
363
use std:: os:: unix:: ffi:: OsStrExt ;
344
364
345
365
info ! ( "Packaging C compiler" ) ;
@@ -354,7 +374,7 @@ impl pkg::CompilerPackager for CCompilerPackager {
354
374
let file_line = output. stdout . split ( |& b| b == b'\n' ) . find ( |line| line. starts_with ( b"creating " ) ) . unwrap ( ) ;
355
375
let filename = & file_line[ b"creating " . len ( ) ..] ;
356
376
let filename = OsStr :: from_bytes ( filename) ;
357
- io:: copy ( & mut File :: open ( filename) . unwrap ( ) , & mut { f} ) . unwrap ( ) ;
377
+ io:: copy ( & mut fs :: File :: open ( filename) . unwrap ( ) , & mut { f} ) . unwrap ( ) ;
358
378
fs:: remove_file ( filename) . unwrap ( ) ;
359
379
env:: set_current_dir ( curdir) . unwrap ( ) ;
360
380
Ok ( ( ) )
0 commit comments