Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Aug 15, 2024
1 parent 9433b4d commit d69c588
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 349 deletions.
23 changes: 16 additions & 7 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + Sync + 'static {
cwd: &Path,
env_vars: &[(OsString, OsString)],
rewrite_includes_only: bool,
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
) -> Result<(
Box<dyn CompileCommand<T>>,
Option<dist::CompileCommand>,
Cacheable,
)>
where
T: CommandCreatorSync;
}
Expand Down Expand Up @@ -420,15 +424,16 @@ where
}

if can_use_preprocessor_cache_mode && !use_preprocessor_cache_mode {
debug!("parse_arguments: Disabling preprocessor cache because SCCACHE_DIRECT=false");
debug!(
"parse_arguments: Disabling preprocessor cache because SCCACHE_DIRECT=false"
);
}

use_preprocessor_cache_mode
};

// Disable preprocessor cache when doing distributed compilation
let mut preprocessor_key = if use_preprocessor_cache_mode
{
let mut preprocessor_key = if use_preprocessor_cache_mode {
preprocessor_cache_entry_hash_key(
&executable_digest,
parsed_args.language,
Expand Down Expand Up @@ -1146,7 +1151,11 @@ impl<T: CommandCreatorSync, I: CCompilerImpl> Compilation<T> for CCompilation<I>
&self,
path_transformer: &mut dist::PathTransformer,
rewrite_includes_only: bool,
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(
Box<dyn CompileCommand<T>>,
Option<dist::CompileCommand>,
Cacheable,
)> {
let CCompilation {
ref parsed_args,
ref executable,
Expand Down Expand Up @@ -1374,9 +1383,9 @@ impl pkg::ToolchainPackager for CToolchainPackager {
add_named_file(&mut package_builder, "liblto_plugin.so")?;
}

CCompilerKind::Cicc => {},
CCompilerKind::Cicc => {}

CCompilerKind::Ptxas => {},
CCompilerKind::Ptxas => {}

CCompilerKind::Nvcc => {
// Various programs called by the nvcc front end.
Expand Down
107 changes: 63 additions & 44 deletions src/compiler/cicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
#![allow(unused_imports, dead_code, unused_variables)]

use crate::compiler::args::*;
use crate::compiler::{Cacheable, ColorMode, CompileCommand, CCompileCommand, CompilerArguments, Language, SingleCompileCommand};
use crate::compiler::c::{ArtifactDescriptor, CCompilerImpl, CCompilerKind, ParsedArguments};
use crate::compiler::{
CCompileCommand, Cacheable, ColorMode, CompileCommand, CompilerArguments, Language,
SingleCompileCommand,
};
use crate::{counted_array, dist};

use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};

use async_trait::async_trait;

use std::fs;
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};
use std::process;

Expand All @@ -43,11 +46,17 @@ impl CCompilerImpl for Cicc {
fn kind(&self) -> CCompilerKind {
CCompilerKind::Cicc
}
fn plusplus(&self) -> bool { true }
fn plusplus(&self) -> bool {
true
}
fn version(&self) -> Option<String> {
self.version.clone()
}
fn parse_arguments(&self, arguments: &[OsString], cwd: &Path) -> CompilerArguments<ParsedArguments> {
fn parse_arguments(
&self,
arguments: &[OsString],
cwd: &Path,
) -> CompilerArguments<ParsedArguments> {
parse_arguments(arguments, cwd, Language::Ptx, &ARGS[..])
}
#[allow(clippy::too_many_arguments)]
Expand All @@ -65,7 +74,11 @@ impl CCompilerImpl for Cicc {
where
T: CommandCreatorSync,
{
trace!("cicc preprocessed input file: cwd={:?} path={:?}", cwd, &parsed_args.input);
trace!(
"cicc preprocessed input file: cwd={:?} path={:?}",
cwd,
&parsed_args.input
);
preprocess(cwd, parsed_args).await
}
fn generate_compile_commands<T>(
Expand All @@ -76,22 +89,19 @@ impl CCompilerImpl for Cicc {
cwd: &Path,
env_vars: &[(OsString, OsString)],
_rewrite_includes_only: bool,
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
) -> Result<(
Box<dyn CompileCommand<T>>,
Option<dist::CompileCommand>,
Cacheable,
)>
where
T: CommandCreatorSync,
{
generate_compile_commands(
path_transformer,
executable,
parsed_args,
cwd,
env_vars
generate_compile_commands(path_transformer, executable, parsed_args, cwd, env_vars).map(
|(command, dist_command, cacheable)| {
(CCompileCommand::new(command), dist_command, cacheable)
},
)
.map(|(command, dist_command, cacheable)| (
CCompileCommand::new(command),
dist_command,
cacheable
))
}
}

Expand All @@ -106,7 +116,7 @@ where
{
let mut args = arguments.to_vec();
let input_loc = arguments.len() - 3;
let input = args.splice(input_loc..input_loc+1, []).next().unwrap();
let input = args.splice(input_loc..input_loc + 1, []).next().unwrap();

let mut take_next = false;
let mut extra_inputs = vec![];
Expand All @@ -122,13 +132,19 @@ where
Some(PassThrough(_)) => {
take_next = false;
&mut common_args
},
}
Some(Output(o)) => {
take_next = false;
let path = cwd.join(o);
outputs.insert("obj", ArtifactDescriptor { path, optional: false });
continue
},
outputs.insert(
"obj",
ArtifactDescriptor {
path,
optional: false,
},
);
continue;
}
Some(UnhashedInput(o)) => {
take_next = false;
let path = cwd.join(o);
Expand All @@ -142,34 +158,39 @@ where
take_next = false;
let path = cwd.join(o);
if let Some(flag) = arg.flag_str() {
outputs.insert(flag, ArtifactDescriptor { path, optional: false });
outputs.insert(
flag,
ArtifactDescriptor {
path,
optional: false,
},
);
}
&mut unhashed_args
}
Some(UnhashedFlag)
| Some(Unhashed(_)) => {
Some(UnhashedFlag) | Some(Unhashed(_)) => {
take_next = false;
&mut unhashed_args
},
}
None => match arg {
Argument::Raw(ref p) => {
if take_next {
take_next = false;
&mut common_args
} else {
continue
continue;
}
}
Argument::UnknownFlag(ref p) => {
let s = p.to_string_lossy();
take_next = s.starts_with('-');
&mut common_args
},
}
_ => unreachable!(),
},
};
args.extend(arg.iter_os_strings());
},
}
_ => continue,
};
}
Expand All @@ -192,29 +213,23 @@ where
profile_generate: false,
color_mode: ColorMode::Off,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: None
too_hard_for_preprocessor_cache_mode: None,
})
}

pub async fn preprocess(
cwd: &Path,
parsed_args: &ParsedArguments,
) -> Result<process::Output>
{
pub async fn preprocess(cwd: &Path, parsed_args: &ParsedArguments) -> Result<process::Output> {
// cicc and ptxas expect input to be an absolute path
let input = if parsed_args.input.is_absolute() {
parsed_args.input.clone()
} else {
cwd.join(&parsed_args.input)
};
std::fs::read(input)
.map_err(|e| { anyhow::Error::new(e) })
.map(|s| {
process::Output {
status: process::ExitStatus::default(),
stdout: s.to_vec(),
stderr: vec![],
}
.map_err(|e| anyhow::Error::new(e))
.map(|s| process::Output {
status: process::ExitStatus::default(),
stdout: s.to_vec(),
stderr: vec![],
})
}

Expand All @@ -224,7 +239,11 @@ pub fn generate_compile_commands(
parsed_args: &ParsedArguments,
cwd: &Path,
env_vars: &[(OsString, OsString)],
) -> Result<(SingleCompileCommand, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(
SingleCompileCommand,
Option<dist::CompileCommand>,
Cacheable,
)> {
// Unused arguments
#[cfg(not(feature = "dist-client"))]
{
Expand All @@ -245,7 +264,7 @@ pub fn generate_compile_commands(
arguments.extend(vec![
(&parsed_args.input).into(),
"-o".into(),
out_file.into()
out_file.into(),
]);

let command = SingleCompileCommand {
Expand Down
18 changes: 10 additions & 8 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::compiler::args::*;
use crate::compiler::c::{ArtifactDescriptor, CCompilerImpl, CCompilerKind, ParsedArguments};
use crate::compiler::gcc::ArgData::*;
use crate::compiler::{
gcc, write_temp_file, Cacheable, CompileCommand, CCompileCommand, CompilerArguments, Language
gcc, write_temp_file, CCompileCommand, Cacheable, CompileCommand, CompilerArguments, Language,
};
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
Expand Down Expand Up @@ -152,9 +152,13 @@ impl CCompilerImpl for Clang {
cwd: &Path,
env_vars: &[(OsString, OsString)],
rewrite_includes_only: bool,
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
) -> Result<(
Box<dyn CompileCommand<T>>,
Option<dist::CompileCommand>,
Cacheable,
)>
where
T: CommandCreatorSync
T: CommandCreatorSync,
{
gcc::generate_compile_commands(
path_transformer,
Expand All @@ -165,11 +169,9 @@ impl CCompilerImpl for Clang {
self.kind(),
rewrite_includes_only,
)
.map(|(command, dist_command, cacheable)| (
CCompileCommand::new(command),
dist_command,
cacheable
))
.map(|(command, dist_command, cacheable)| {
(CCompileCommand::new(command), dist_command, cacheable)
})
}
}

Expand Down
Loading

0 comments on commit d69c588

Please sign in to comment.