Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions cpp-linter/src/clang_tools/clang_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,22 @@ pub fn run_clang_format(
} else {
// clang-tidy was not run on this file,
// so just use the clang-format fixes as the patched content.
let cache_format_fixes = cache_path.join(&file.name);
fs::create_dir_all(
cache_format_fixes
.parent()
.ok_or(ClangCaptureError::UnknownCacheParentPath)?,
)
.map_err(ClangCaptureError::MkDirFailed)?;
fs::write(&cache_format_fixes, &output.stdout).map_err(|e| {
ClangCaptureError::WriteFileFailed {
file_name: cache_format_fixes.to_string_lossy().to_string(),
source: e,
}
})?;
file.patched_path = Some(cache_format_fixes);
if clang_params.gen_patch {
let cache_format_fixes = cache_path.join(&file.name);
fs::create_dir_all(
cache_format_fixes
.parent()
.ok_or(ClangCaptureError::UnknownCacheParentPath)?,
)
.map_err(ClangCaptureError::MkDirFailed)?;
fs::write(&cache_format_fixes, &output.stdout).map_err(|e| {
ClangCaptureError::WriteFileFailed {
file_name: cache_format_fixes.to_string_lossy().to_string(),
source: e,
}
})?;
file.patched_path = Some(cache_format_fixes);
}
}

file.format_advice = Some(format_advice);
Expand Down Expand Up @@ -447,7 +449,8 @@ mod tests {
let tmp_workspace = setup_tmp_workspace();
let tools_dir = tempfile::tempdir().unwrap();
let fake_format = make_fake_tool(tools_dir.path(), "clang-format", "");
let clang_params = make_clang_params(tmp_workspace.path(), fake_format);
let mut clang_params = make_clang_params(tmp_workspace.path(), fake_format);
clang_params.gen_patch = true;
// a directory where the patched file should be cached
fs::create_dir_all(clang_params.get_cache_path().join("demo/demo.cpp")).unwrap();
let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp")));
Expand All @@ -459,7 +462,8 @@ mod tests {
fn no_gen_patch() {
let tmp_workspace = setup_tmp_workspace();
let tools_dir = tempfile::tempdir().unwrap();
let fake_format = make_fake_tool(tools_dir.path(), "clang-format", "echo 'void main() {}'");
let fake_format =
make_fake_tool(tools_dir.path(), "clang-format", "echo 'void main() {}'");
let mut clang_params = make_clang_params(tmp_workspace.path(), fake_format);
clang_params.gen_patch = false;
let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp")));
Expand Down
3 changes: 2 additions & 1 deletion cpp-linter/src/clang_tools/clang_tidy/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ fn tidy_cache_not_writable() {
let tmp_workspace = crate::test_common::setup_tmp_workspace();
let tools_dir = tempfile::tempdir().unwrap();
let fake_tidy = crate::test_common::make_fake_tool(tools_dir.path(), "clang-tidy", "");
let clang_params = make_clang_params(tmp_workspace.path(), Some(fake_tidy));
let mut clang_params = make_clang_params(tmp_workspace.path(), Some(fake_tidy));
clang_params.gen_patch = true;
// a directory where the patched file should be cached
fs::create_dir_all(clang_params.get_cache_path().join("demo/demo.cpp")).unwrap();
let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp")));
Expand Down
Loading