From f143cca6b356d5f947fec09ef3c040f1e00895e8 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sat, 31 Oct 2026 01:12:42 +0000 Subject: [PATCH 1/2] fix: resolve a relative `--database` against the working directory --- cpp-linter/src/cli/structs.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/cpp-linter/src/cli/structs.rs b/cpp-linter/src/cli/structs.rs index 9c2a91fb..508f58a5 100644 --- a/cpp-linter/src/cli/structs.rs +++ b/cpp-linter/src/cli/structs.rs @@ -264,19 +264,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(), @@ -288,7 +282,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, } } @@ -450,4 +444,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")) + ); + } } From 11af512e173215e1a01810f8850fca9835c07b7e Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Sat, 31 Oct 2026 07:32:23 +0000 Subject: [PATCH 2/2] test: pass an absolute database path in integration tests --- cpp-linter/tests/comments.rs | 3 ++- cpp-linter/tests/reviews.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp-linter/tests/comments.rs b/cpp-linter/tests/comments.rs index c55fec9d..1a02d212 100644 --- a/cpp-linter/tests/comments.rs +++ b/cpp-linter/tests/comments.rs @@ -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!( diff --git a/cpp-linter/tests/reviews.rs b/cpp-linter/tests/reviews.rs index 79f32e62..f5d7f231 100644 --- a/cpp-linter/tests/reviews.rs +++ b/cpp-linter/tests/reviews.rs @@ -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()), ];