Skip to content

Commit 5d4d6d3

Browse files
aidanhsluser
authored andcommitted
Rewrite .d files with correct paths after receiving them
1 parent 767c630 commit 5d4d6d3

File tree

9 files changed

+190
-49
lines changed

9 files changed

+190
-49
lines changed

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ pub fn run_command(cmd: Command) -> Result<i32> {
646646
}
647647
#[cfg(not(feature = "dist-client"))]
648648
Command::PackageToolchain(_executable, _out) => {
649-
bail!("Toolchain packaging not compiled in")
649+
bail!("Toolchain packaging not compiled in, please rebuild with the dist-client feature")
650650
}
651651
Command::Compile { exe, cmdline, cwd, env_vars } => {
652652
trace!("Command::Compile {{ {:?}, {:?}, {:?} }}", exe, cmdline, cwd);

src/compiler/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl<T: ArgumentValue> Argument<T> {
146146
}
147147

148148
/// Transforms a parsed argument into an iterator over strings, with transformed paths.
149+
#[cfg(feature = "dist-client")]
149150
pub fn iter_strings<F: FnMut(&Path) -> Option<String>>(&self, path_transformer: F) -> IterStrings<T, F> {
150151
IterStrings {
151152
arg: self,
@@ -206,12 +207,14 @@ impl<'a, T: ArgumentValue> Iterator for Iter<'a, T> {
206207
}
207208
}
208209

210+
#[cfg(feature = "dist-client")]
209211
pub struct IterStrings<'a, T: 'a, F> {
210212
arg: &'a Argument<T>,
211213
emitted: usize,
212214
path_transformer: F,
213215
}
214216

217+
#[cfg(feature = "dist-client")]
215218
impl<'a, T: ArgumentValue, F: FnMut(&Path) -> Option<String>> Iterator for IterStrings<'a, T, F> {
216219
type Item = ArgToStringResult;
217220

src/compiler/c.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
use compiler::{Cacheable, ColorMode, Compiler, CompilerArguments, CompileCommand, CompilerHasher, CompilerKind,
1616
Compilation, HashResult};
17+
#[cfg(feature = "dist-client")]
18+
use compiler::{NoopOutputsRewriter, OutputsRewriter};
1719
use dist;
1820
#[cfg(feature = "dist-client")]
1921
use dist::pkg;
@@ -307,14 +309,15 @@ impl<I: CCompilerImpl> Compilation for CCompilation<I> {
307309
}
308310

309311
#[cfg(feature = "dist-client")]
310-
fn into_dist_packagers(self: Box<Self>, path_transformer: dist::PathTransformer) -> Result<(Box<pkg::InputsPackager>, Box<pkg::ToolchainPackager>)> {
312+
fn into_dist_packagers(self: Box<Self>, path_transformer: dist::PathTransformer) -> Result<(Box<pkg::InputsPackager>, Box<pkg::ToolchainPackager>, Box<OutputsRewriter>)> {
311313
let CCompilation { parsed_args, cwd, preprocessed_input, executable, .. } = *{self};
312314
trace!("Dist inputs: {:?}", parsed_args.input);
313315

314316
let input_path = cwd.join(&parsed_args.input);
315317
let inputs_packager = Box::new(CInputsPackager { input_path, preprocessed_input, path_transformer });
316318
let toolchain_packager = Box::new(CToolchainPackager { executable });
317-
Ok((inputs_packager, toolchain_packager))
319+
let outputs_rewriter = Box::new(NoopOutputsRewriter);
320+
Ok((inputs_packager, toolchain_packager, outputs_rewriter))
318321
}
319322

320323
fn outputs<'a>(&'a self) -> Box<Iterator<Item=(&'a str, &'a Path)> + 'a>

src/compiler/compiler.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn dist_or_local_compile<T>(dist_client: Arc<dist::Client>,
362362
compilation.into_dist_packagers(path_transformer)
363363
.map(|packagers| (dist_compile_cmd, packagers, dist_output_paths))
364364
})
365-
.and_then(move |(mut dist_compile_cmd, (inputs_packager, toolchain_packager), dist_output_paths)| {
365+
.and_then(move |(mut dist_compile_cmd, (inputs_packager, toolchain_packager, outputs_rewriter), dist_output_paths)| {
366366
debug!("[{}]: Identifying dist toolchain for {:?}", compile_out_pretty2, local_executable);
367367
// TODO: put on a thread
368368
let (dist_toolchain, maybe_dist_compile_executable) =
@@ -404,12 +404,16 @@ fn dist_or_local_compile<T>(dist_client: Arc<dist::Client>,
404404
dist::RunJobResult::JobNotFound => panic!(),
405405
};
406406
info!("fetched {:?}", jc.outputs.iter().map(|&(ref p, ref bs)| (p, bs.lens().to_string())).collect::<Vec<_>>());
407+
let mut output_paths = vec![];
407408
for (path, output_data) in jc.outputs {
408409
let len = output_data.lens().actual;
409-
let mut file = File::create(path_transformer.to_local(&path)).unwrap();
410+
let local_path = path_transformer.to_local(&path);
411+
let mut file = File::create(&local_path).unwrap();
410412
let count = io::copy(&mut output_data.into_reader(), &mut file).unwrap();
411413
assert!(count == len);
414+
output_paths.push((path, local_path))
412415
}
416+
outputs_rewriter.handle_outputs(&path_transformer, output_paths).unwrap();
413417
jc.output.into()
414418
})
415419
)
@@ -439,7 +443,7 @@ pub trait Compilation {
439443
/// Create a function that will create the inputs used to perform a distributed compilation
440444
#[cfg(feature = "dist-client")]
441445
fn into_dist_packagers(self: Box<Self>, _path_transformer: dist::PathTransformer)
442-
-> Result<(Box<pkg::InputsPackager>, Box<pkg::ToolchainPackager>)> {
446+
-> Result<(Box<pkg::InputsPackager>, Box<pkg::ToolchainPackager>, Box<OutputsRewriter>)> {
443447

444448
bail!("distributed compilation not implemented")
445449
}
@@ -451,6 +455,22 @@ pub trait Compilation {
451455
fn outputs<'a>(&'a self) -> Box<Iterator<Item=(&'a str, &'a Path)> + 'a>;
452456
}
453457

458+
#[cfg(feature = "dist-client")]
459+
pub trait OutputsRewriter {
460+
fn handle_outputs(self: Box<Self>, path_transformer: &dist::PathTransformer, output_paths: Vec<(String, PathBuf)>)
461+
-> Result<()>;
462+
}
463+
464+
#[cfg(feature = "dist-client")]
465+
pub struct NoopOutputsRewriter;
466+
#[cfg(feature = "dist-client")]
467+
impl OutputsRewriter for NoopOutputsRewriter {
468+
fn handle_outputs(self: Box<Self>, _path_transformer: &dist::PathTransformer, _output_paths: Vec<(String, PathBuf)>)
469+
-> Result<()> {
470+
Ok(())
471+
}
472+
}
473+
454474
/// Result of generating a hash from a compiler command.
455475
pub struct HashResult {
456476
/// The hash key of the inputs.

src/compiler/gcc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ pub fn generate_compile_commands(path_transformer: &mut dist::PathTransformer,
402402
env_vars: &[(OsString, OsString)])
403403
-> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)>
404404
{
405+
#[cfg(not(feature = "dist-client"))]
406+
let _ = path_transformer;
407+
405408
trace!("compile");
406409

407410
let out_file = match parsed_args.outputs.get("obj") {
@@ -434,6 +437,9 @@ pub fn generate_compile_commands(path_transformer: &mut dist::PathTransformer,
434437
cwd: cwd.to_owned(),
435438
};
436439

440+
#[cfg(not(feature = "dist-client"))]
441+
let dist_command = None;
442+
#[cfg(feature = "dist-client")]
437443
let dist_command = (|| {
438444
// https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Overall-Options.html
439445
let language = match parsed_args.language {

src/compiler/msvc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ fn generate_compile_commands(path_transformer: &mut dist::PathTransformer,
547547
env_vars: &[(OsString, OsString)])
548548
-> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)>
549549
{
550+
#[cfg(not(feature = "dist-client"))]
551+
let _ = path_transformer;
552+
550553
trace!("compile");
551554
let out_file = match parsed_args.outputs.get("obj") {
552555
Some(obj) => obj,
@@ -585,6 +588,9 @@ fn generate_compile_commands(path_transformer: &mut dist::PathTransformer,
585588
cwd: cwd.to_owned(),
586589
};
587590

591+
#[cfg(not(feature = "dist-client"))]
592+
let dist_command = None;
593+
#[cfg(feature = "dist-client")]
588594
let dist_command = (|| {
589595
// http://releases.llvm.org/6.0.0/tools/clang/docs/UsersManual.html#clang-cl
590596
// TODO: Use /T... for language?

0 commit comments

Comments
 (0)