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
24 changes: 14 additions & 10 deletions cpp-linter/src/cli/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,13 @@ impl From<&Cli> for ClangParams {
let ignore_format: Vec<&str> = ignore_format.iter().map(|s| s.as_str()).collect();
FileFilter::new(&ignore_format, &extensions, Some("clang-format"))
});
let repo_root = args.source_options.repo_root.clone();
// A relative database path is relative to the working directory (like v1),
// not to the repo root.
let database = args
.tidy_options
.database
.as_ref()
.map(PathBuf::from)
.map(|db| {
if db.is_relative() {
repo_root.join(db)
} else {
db
}
});
.map(|db| std::path::absolute(db).unwrap_or_else(|_| db.to_path_buf()));
ClangParams {
tidy_checks: args.tidy_options.tidy_checks.clone(),
lines_changed_only: args.source_options.lines_changed_only.clone(),
Expand All @@ -296,7 +290,7 @@ impl From<&Cli> for ClangParams {
clang_format_command: None,
tidy_filter,
format_filter,
repo_root,
repo_root: args.source_options.repo_root.clone(),
gen_patch: args.feedback_options.pr_review
|| args.feedback_options.gen_patch
|| args.feedback_options.gen_patch_path.is_some(),
Expand Down Expand Up @@ -510,4 +504,14 @@ mod test {
let clang_params = ClangParams::from(&cli);
assert_eq!(clang_params.database, Some(tmp_dir.path().to_path_buf()));
}

#[test]
fn relative_db_path() {
let cli = Cli::parse_from(["cpp-linter", "--repo-root", "sub", "--database", "build"]);
let clang_params = ClangParams::from(&cli);
assert_eq!(
clang_params.database,
Some(std::env::current_dir().unwrap().join("build"))
);
}
}
3 changes: 2 additions & 1 deletion cpp-linter/tests/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
"--ignore-format=src/some source.c".to_string(),
format!("--thread-comments={}", test_params.thread_comments),
format!("--no-lgtm={}", test_params.no_lgtm),
"-p=build".to_string(),
// a relative database path is resolved against the working directory
format!("-p={}", tmp_dir.path().join("build").to_str().unwrap()),
"-i=build/**".to_string(),
format!("--repo-root={}", tmp_dir.path().to_str().unwrap()),
format!(
Expand Down
3 changes: 2 additions & 1 deletion cpp-linter/tests/reviews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) ->
format!("--pr-review={}", test_params.pr_review),
format!("--passive-reviews={}", test_params.passive_reviews),
format!("--no-lgtm={}", test_params.no_lgtm),
"-p=build".to_string(),
// a relative database path is resolved against the working directory
format!("-p={}", tmp_dir.path().join("build").to_str().unwrap()),
"-i=build/**".to_string(),
format!("--repo-root={}", tmp_dir.path().to_str().unwrap()),
];
Expand Down
Loading