зеркало из https://github.com/mozilla/sccache.git
Added option for conditionally enabling -frewrite-includes
This commit is contained in:
Родитель
f1b5b7886b
Коммит
8b83309723
|
@ -173,6 +173,7 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + 'static {
|
|||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync;
|
||||
|
@ -185,6 +186,7 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + 'static {
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)>;
|
||||
}
|
||||
|
||||
|
@ -250,6 +252,7 @@ where
|
|||
env_vars: Vec<(OsString, OsString)>,
|
||||
may_dist: bool,
|
||||
pool: &CpuPool,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<HashResult> {
|
||||
let me = *self;
|
||||
let CCompilerHasher {
|
||||
|
@ -265,6 +268,7 @@ where
|
|||
&cwd,
|
||||
&env_vars,
|
||||
may_dist,
|
||||
rewrite_includes_only,
|
||||
);
|
||||
let out_pretty = parsed_args.output_pretty().into_owned();
|
||||
let result = result.map_err(move |e| {
|
||||
|
@ -373,6 +377,7 @@ impl<I: CCompilerImpl> Compilation for CCompilation<I> {
|
|||
fn generate_compile_commands(
|
||||
&self,
|
||||
path_transformer: &mut dist::PathTransformer,
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
let CCompilation {
|
||||
ref parsed_args,
|
||||
|
@ -382,7 +387,14 @@ impl<I: CCompilerImpl> Compilation for CCompilation<I> {
|
|||
ref env_vars,
|
||||
..
|
||||
} = *self;
|
||||
compiler.generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars)
|
||||
compiler.generate_compile_commands(
|
||||
path_transformer,
|
||||
executable,
|
||||
parsed_args,
|
||||
cwd,
|
||||
env_vars,
|
||||
rewrite_includes_only,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "dist-client")]
|
||||
|
|
|
@ -55,6 +55,7 @@ impl CCompilerImpl for Clang {
|
|||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync,
|
||||
|
@ -67,6 +68,7 @@ impl CCompilerImpl for Clang {
|
|||
env_vars,
|
||||
may_dist,
|
||||
self.kind(),
|
||||
rewrite_includes_only,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -77,8 +79,16 @@ impl CCompilerImpl for Clang {
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
gcc::generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars)
|
||||
gcc::generate_compile_commands(
|
||||
path_transformer,
|
||||
executable,
|
||||
parsed_args,
|
||||
cwd,
|
||||
env_vars,
|
||||
rewrite_includes_only,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ where
|
|||
env_vars: Vec<(OsString, OsString)>,
|
||||
may_dist: bool,
|
||||
pool: &CpuPool,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<HashResult>;
|
||||
|
||||
/// Return the state of any `--color` option passed to the compiler.
|
||||
|
@ -162,7 +163,18 @@ where
|
|||
Ok(Some(_)) => true,
|
||||
_ => false,
|
||||
};
|
||||
let result = self.generate_hash_key(&creator, cwd.clone(), env_vars, may_dist, &pool);
|
||||
let rewrite_includes_only = match dist_client {
|
||||
Ok(Some(ref client)) => client.rewrite_includes_only(),
|
||||
_ => false,
|
||||
};
|
||||
let result = self.generate_hash_key(
|
||||
&creator,
|
||||
cwd.clone(),
|
||||
env_vars,
|
||||
may_dist,
|
||||
&pool,
|
||||
rewrite_includes_only,
|
||||
);
|
||||
Box::new(result.then(move |res| -> SFuture<_> {
|
||||
debug!(
|
||||
"[{}]: generate_hash_key took {}",
|
||||
|
@ -390,7 +402,7 @@ where
|
|||
{
|
||||
let mut path_transformer = dist::PathTransformer::new();
|
||||
let compile_commands = compilation
|
||||
.generate_compile_commands(&mut path_transformer)
|
||||
.generate_compile_commands(&mut path_transformer, true)
|
||||
.chain_err(|| "Failed to generate compile commands");
|
||||
let (compile_cmd, _dist_compile_cmd, cacheable) = match compile_commands {
|
||||
Ok(cmds) => cmds,
|
||||
|
@ -420,9 +432,13 @@ where
|
|||
use futures::future;
|
||||
use std::io;
|
||||
|
||||
let rewrite_includes_only = match dist_client {
|
||||
Ok(Some(ref client)) => client.rewrite_includes_only(),
|
||||
_ => false,
|
||||
};
|
||||
let mut path_transformer = dist::PathTransformer::new();
|
||||
let compile_commands = compilation
|
||||
.generate_compile_commands(&mut path_transformer)
|
||||
.generate_compile_commands(&mut path_transformer, rewrite_includes_only)
|
||||
.chain_err(|| "Failed to generate compile commands");
|
||||
let (compile_cmd, dist_compile_cmd, cacheable) = match compile_commands {
|
||||
Ok(cmds) => cmds,
|
||||
|
@ -585,6 +601,7 @@ pub trait Compilation {
|
|||
fn generate_compile_commands(
|
||||
&self,
|
||||
path_transformer: &mut dist::PathTransformer,
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)>;
|
||||
|
||||
/// Create a function that will create the inputs used to perform a distributed compilation
|
||||
|
@ -1748,6 +1765,9 @@ mod test_dist {
|
|||
) -> SFuture<(Toolchain, Option<String>)> {
|
||||
f_err("put toolchain failure")
|
||||
}
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorAllocJobClient {
|
||||
|
@ -1790,6 +1810,9 @@ mod test_dist {
|
|||
) -> SFuture<(Toolchain, Option<String>)> {
|
||||
f_ok((self.tc.clone(), None))
|
||||
}
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorSubmitToolchainClient {
|
||||
|
@ -1848,6 +1871,9 @@ mod test_dist {
|
|||
) -> SFuture<(Toolchain, Option<String>)> {
|
||||
f_ok((self.tc.clone(), None))
|
||||
}
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorRunJobClient {
|
||||
|
@ -1908,6 +1934,9 @@ mod test_dist {
|
|||
) -> SFuture<(Toolchain, Option<String>)> {
|
||||
f_ok((self.tc.clone(), Some("/overridden/compiler".to_owned())))
|
||||
}
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OneshotClient {
|
||||
|
@ -1989,5 +2018,8 @@ mod test_dist {
|
|||
) -> SFuture<(Toolchain, Option<String>)> {
|
||||
f_ok((self.tc.clone(), Some("/overridden/compiler".to_owned())))
|
||||
}
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ impl CCompilerImpl for Diab {
|
|||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
_rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync,
|
||||
|
@ -68,6 +69,7 @@ impl CCompilerImpl for Diab {
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
_rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars)
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ impl CCompilerImpl for GCC {
|
|||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync,
|
||||
|
@ -64,6 +65,7 @@ impl CCompilerImpl for GCC {
|
|||
env_vars,
|
||||
may_dist,
|
||||
self.kind(),
|
||||
rewrite_includes_only,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -74,8 +76,16 @@ impl CCompilerImpl for GCC {
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars)
|
||||
generate_compile_commands(
|
||||
path_transformer,
|
||||
executable,
|
||||
parsed_args,
|
||||
cwd,
|
||||
env_vars,
|
||||
rewrite_includes_only,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -445,6 +455,7 @@ pub fn preprocess<T>(
|
|||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
kind: CCompilerKind,
|
||||
rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync,
|
||||
|
@ -465,14 +476,16 @@ where
|
|||
if !may_dist && !parsed_args.profile_generate {
|
||||
cmd.arg("-P");
|
||||
}
|
||||
match kind {
|
||||
CCompilerKind::Clang => {
|
||||
cmd.arg("-frewrite-includes");
|
||||
if rewrite_includes_only {
|
||||
match kind {
|
||||
CCompilerKind::Clang => {
|
||||
cmd.arg("-frewrite-includes");
|
||||
}
|
||||
CCompilerKind::GCC => {
|
||||
cmd.arg("-fdirectives-only");
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
CCompilerKind::GCC => {
|
||||
cmd.arg("-fdirectives-only");
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
cmd.arg(&parsed_args.input)
|
||||
.args(&parsed_args.preprocessor_args)
|
||||
|
@ -493,6 +506,7 @@ pub fn generate_compile_commands(
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
#[cfg(not(feature = "dist-client"))]
|
||||
let _ = path_transformer;
|
||||
|
@ -534,12 +548,16 @@ pub fn generate_compile_commands(
|
|||
#[cfg(feature = "dist-client")]
|
||||
let dist_command = (|| {
|
||||
// https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Overall-Options.html
|
||||
let language = match parsed_args.language {
|
||||
let mut language: String = match parsed_args.language {
|
||||
Language::C => "c",
|
||||
Language::Cxx => "c++",
|
||||
Language::ObjectiveC => "objective-c",
|
||||
Language::ObjectiveCxx => "objective-c++",
|
||||
};
|
||||
}
|
||||
.into();
|
||||
if !rewrite_includes_only {
|
||||
language.push_str("-cpp-output");
|
||||
}
|
||||
let mut arguments: Vec<String> = vec![
|
||||
"-x".into(),
|
||||
language.into(),
|
||||
|
@ -1150,6 +1168,7 @@ mod test {
|
|||
&parsed_args,
|
||||
f.tempdir.path(),
|
||||
&[],
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
#[cfg(feature = "dist-client")]
|
||||
|
|
|
@ -63,6 +63,7 @@ impl CCompilerImpl for MSVC {
|
|||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
may_dist: bool,
|
||||
_rewrite_includes_only: bool,
|
||||
) -> SFuture<process::Output>
|
||||
where
|
||||
T: CommandCreatorSync,
|
||||
|
@ -85,6 +86,7 @@ impl CCompilerImpl for MSVC {
|
|||
parsed_args: &ParsedArguments,
|
||||
cwd: &Path,
|
||||
env_vars: &[(OsString, OsString)],
|
||||
_rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars)
|
||||
}
|
||||
|
|
|
@ -997,6 +997,7 @@ where
|
|||
env_vars: Vec<(OsString, OsString)>,
|
||||
_may_dist: bool,
|
||||
pool: &CpuPool,
|
||||
_rewrite_includes_only: bool,
|
||||
) -> SFuture<HashResult> {
|
||||
let me = *self;
|
||||
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/3759
|
||||
|
@ -1260,6 +1261,7 @@ impl Compilation for RustCompilation {
|
|||
fn generate_compile_commands(
|
||||
&self,
|
||||
path_transformer: &mut dist::PathTransformer,
|
||||
_rewrite_includes_only: bool,
|
||||
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
|
||||
let RustCompilation {
|
||||
ref executable,
|
||||
|
@ -2692,6 +2694,7 @@ c:/foo/bar.rs:
|
|||
.to_vec(),
|
||||
false,
|
||||
&pool,
|
||||
false,
|
||||
)
|
||||
.wait()
|
||||
.unwrap();
|
||||
|
@ -2777,6 +2780,7 @@ c:/foo/bar.rs:
|
|||
env_vars.to_owned(),
|
||||
false,
|
||||
&pool,
|
||||
false,
|
||||
)
|
||||
.wait()
|
||||
.unwrap()
|
||||
|
|
|
@ -383,6 +383,7 @@ pub struct DistConfig {
|
|||
pub cache_dir: PathBuf,
|
||||
pub toolchains: Vec<DistToolchainConfig>,
|
||||
pub toolchain_cache_size: u64,
|
||||
pub rewrite_includes_only: bool,
|
||||
}
|
||||
|
||||
impl Default for DistConfig {
|
||||
|
@ -393,6 +394,7 @@ impl Default for DistConfig {
|
|||
cache_dir: default_dist_cache_dir(),
|
||||
toolchains: Default::default(),
|
||||
toolchain_cache_size: default_toolchain_cache_size(),
|
||||
rewrite_includes_only: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1087,6 +1087,7 @@ mod client {
|
|||
client_async: Arc<Mutex<reqwest::r#async::Client>>,
|
||||
pool: CpuPool,
|
||||
tc_cache: Arc<cache::ClientToolchains>,
|
||||
rewrite_includes_only: bool,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
@ -1097,6 +1098,7 @@ mod client {
|
|||
cache_size: u64,
|
||||
toolchain_configs: &[config::DistToolchainConfig],
|
||||
auth_token: String,
|
||||
rewrite_includes_only: bool,
|
||||
) -> Result<Self> {
|
||||
let timeout = Duration::new(REQUEST_TIMEOUT_SECS, 0);
|
||||
let connect_timeout = Duration::new(CONNECT_TIMEOUT_SECS, 0);
|
||||
|
@ -1121,6 +1123,7 @@ mod client {
|
|||
client_async: Arc::new(Mutex::new(client_async)),
|
||||
pool: pool.clone(),
|
||||
tc_cache: Arc::new(client_toolchains),
|
||||
rewrite_includes_only: rewrite_includes_only,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1300,5 +1303,9 @@ mod client {
|
|||
tc_cache.put_toolchain(&compiler_path, &weak_key, toolchain_packager)
|
||||
}))
|
||||
}
|
||||
|
||||
fn rewrite_includes_only(&self) -> bool {
|
||||
self.rewrite_includes_only
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -747,4 +747,5 @@ pub trait Client {
|
|||
weak_key: &str,
|
||||
toolchain_packager: Box<dyn pkg::ToolchainPackager>,
|
||||
) -> SFuture<(Toolchain, Option<String>)>;
|
||||
fn rewrite_includes_only(&self) -> bool;
|
||||
}
|
||||
|
|
|
@ -147,6 +147,7 @@ struct DistClientConfig {
|
|||
cache_dir: PathBuf,
|
||||
toolchain_cache_size: u64,
|
||||
toolchains: Vec<config::DistToolchainConfig>,
|
||||
rewrite_includes_only: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "dist-client")]
|
||||
|
@ -196,6 +197,7 @@ impl DistClientContainer {
|
|||
cache_dir: config.dist.cache_dir.clone(),
|
||||
toolchain_cache_size: config.dist.toolchain_cache_size,
|
||||
toolchains: config.dist.toolchains.clone(),
|
||||
rewrite_includes_only: config.dist.rewrite_includes_only,
|
||||
};
|
||||
let state = Self::create_state(config);
|
||||
Self {
|
||||
|
@ -348,6 +350,7 @@ impl DistClientContainer {
|
|||
config.toolchain_cache_size,
|
||||
&config.toolchains,
|
||||
auth_token,
|
||||
config.rewrite_includes_only,
|
||||
);
|
||||
let dist_client = try_or_retry_later!(
|
||||
dist_client.chain_err(|| "failure during dist client creation")
|
||||
|
|
|
@ -194,6 +194,7 @@ pub fn sccache_client_cfg(tmpdir: &Path) -> sccache::config::FileConfig {
|
|||
cache_dir: tmpdir.join(dist_cache_relpath),
|
||||
toolchains: vec![],
|
||||
toolchain_cache_size: TC_CACHE_SIZE,
|
||||
rewrite_includes_only: false, // TODO
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ fn config_with_dist_auth(
|
|||
cache_dir: tmpdir.join("unused-cache"),
|
||||
toolchains: vec![],
|
||||
toolchain_cache_size: 0,
|
||||
rewrite_includes_only: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче