Skip to content

Commit 586c308

Browse files
authored
C/C++: add extra input files via environment SCCACHE_EXTRAFILES (#1125)
This is similar to CCACHE_EXTRAFILES and ICECC_EXTRAFILES: the extra files are hashed for caching and packaged for sccache-dist. Possibly the same variable CCACHE_EXTRAFILES could be used instead of a distinct one? This can be implemented in one place for the C/C++ compilers, but not also for Rust, which currently doesn't have extra_hash_files, so that remains TODO.
1 parent e8c9ca0 commit 586c308

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/compiler/c.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,22 @@ impl<T: CommandCreatorSync, I: CCompilerImpl> Compiler<T> for CCompiler<I> {
252252
&self,
253253
arguments: &[OsString],
254254
cwd: &Path,
255+
env_vars: &[(OsString, OsString)],
255256
) -> CompilerArguments<Box<dyn CompilerHasher<T> + 'static>> {
256257
match self.compiler.parse_arguments(arguments, cwd) {
257-
CompilerArguments::Ok(args) => CompilerArguments::Ok(Box::new(CCompilerHasher {
258-
parsed_args: args,
259-
executable: self.executable.clone(),
260-
executable_digest: self.executable_digest.clone(),
261-
compiler: self.compiler.clone(),
262-
})),
258+
CompilerArguments::Ok(mut args) => {
259+
for (k, v) in env_vars.iter() {
260+
if k.as_os_str() == OsStr::new("SCCACHE_EXTRAFILES") {
261+
args.extra_hash_files.extend(std::env::split_paths(&v))
262+
}
263+
}
264+
CompilerArguments::Ok(Box::new(CCompilerHasher {
265+
parsed_args: args,
266+
executable: self.executable.clone(),
267+
executable_digest: self.executable_digest.clone(),
268+
compiler: self.compiler.clone(),
269+
}))
270+
}
263271
CompilerArguments::CannotCache(why, extra_info) => {
264272
CompilerArguments::CannotCache(why, extra_info)
265273
}

src/compiler/compiler.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ where
126126
&self,
127127
arguments: &[OsString],
128128
cwd: &Path,
129+
env_vars: &[(OsString, OsString)],
129130
) -> CompilerArguments<Box<dyn CompilerHasher<T> + 'static>>;
130131
fn box_clone(&self) -> Box<dyn Compiler<T>>;
131132
}
@@ -1348,7 +1349,7 @@ LLVM version: 6.0",
13481349
&creator,
13491350
Ok(MockChild::new(exit_status(0), "preprocessor output", "")),
13501351
);
1351-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1352+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
13521353
CompilerArguments::Ok(h) => h,
13531354
o => panic!("Bad result from parse_arguments: {:?}", o),
13541355
};
@@ -1422,7 +1423,7 @@ LLVM version: 6.0",
14221423
});
14231424
let cwd = f.tempdir.path();
14241425
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1425-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1426+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
14261427
CompilerArguments::Ok(h) => h,
14271428
o => panic!("Bad result from parse_arguments: {:?}", o),
14281429
};
@@ -1527,7 +1528,7 @@ LLVM version: 6.0",
15271528
));
15281529
let cwd = f.tempdir.path();
15291530
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1530-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1531+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
15311532
CompilerArguments::Ok(h) => h,
15321533
o => panic!("Bad result from parse_arguments: {:?}", o),
15331534
};
@@ -1638,7 +1639,7 @@ LLVM version: 6.0",
16381639
});
16391640
let cwd = f.tempdir.path();
16401641
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1641-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1642+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
16421643
CompilerArguments::Ok(h) => h,
16431644
o => panic!("Bad result from parse_arguments: {:?}", o),
16441645
};
@@ -1719,7 +1720,7 @@ LLVM version: 6.0",
17191720
}
17201721
let cwd = f.tempdir.path();
17211722
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1722-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1723+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
17231724
CompilerArguments::Ok(h) => h,
17241725
o => panic!("Bad result from parse_arguments: {:?}", o),
17251726
};
@@ -1824,7 +1825,7 @@ LLVM version: 6.0",
18241825
);
18251826
let cwd = f.tempdir.path();
18261827
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1827-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1828+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
18281829
CompilerArguments::Ok(h) => h,
18291830
o => panic!("Bad result from parse_arguments: {:?}", o),
18301831
};
@@ -1908,7 +1909,7 @@ LLVM version: 6.0",
19081909
}
19091910
let cwd = f.tempdir.path();
19101911
let arguments = ovec!["-c", "foo.c", "-o", "foo.o"];
1911-
let hasher = match c.parse_arguments(&arguments, ".".as_ref()) {
1912+
let hasher = match c.parse_arguments(&arguments, ".".as_ref(), &[]) {
19121913
CompilerArguments::Ok(h) => h,
19131914
o => panic!("Bad result from parse_arguments: {:?}", o),
19141915
};

src/compiler/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ where
474474
&self,
475475
arguments: &[OsString],
476476
cwd: &Path,
477+
_env_vars: &[(OsString, OsString)],
477478
) -> CompilerArguments<Box<dyn CompilerHasher<T> + 'static>> {
478479
match parse_arguments(arguments, cwd) {
479480
CompilerArguments::Ok(args) => CompilerArguments::Ok(Box::new(RustHasher {

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ where
10551055
debug!("check_compiler: Supported compiler");
10561056
// Now check that we can handle this compiler with
10571057
// the provided commandline.
1058-
match c.parse_arguments(&cmd, &cwd) {
1058+
match c.parse_arguments(&cmd, &cwd, &env_vars) {
10591059
CompilerArguments::Ok(hasher) => {
10601060
debug!("parse_arguments: Ok: {:?}", cmd);
10611061
stats.requests_executed += 1;

0 commit comments

Comments
 (0)