Skip to content

Commit 7f67da2

Browse files
committed
ci: fix build error
1 parent 62ad202 commit 7f67da2

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

.github/workflows/build_rust.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
- windows-latest
4141
- macOS-latest
4242
toolchain:
43-
- stable 9 months ago
4443
- stable
4544
- nightly
4645
runs-on: ${{ matrix.os }}

bear/src/semantic/interpreters/filter.rs

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ impl Filter {
113113
let mut should_filter_this_source = false;
114114
for variant_path in path_variants {
115115
for filter in source_filters {
116-
if variant_path.starts_with(&filter.path) {
116+
// Normalize both paths for comparison to handle platform differences
117+
let normalized_variant = self.normalize_path_for_comparison(&variant_path);
118+
let normalized_filter = self.normalize_path_for_comparison(&filter.path);
119+
120+
if normalized_variant.starts_with(&normalized_filter) {
117121
match filter.ignore {
118122
config::Ignore::Always => {
119123
should_filter_this_source = true;
@@ -173,6 +177,22 @@ impl Filter {
173177
variants
174178
}
175179

180+
/// Normalizes a path for cross-platform comparison by converting to absolute form
181+
/// and using consistent separators.
182+
fn normalize_path_for_comparison(&self, path: &Path) -> PathBuf {
183+
// Try to get the absolute path first
184+
match path.canonicalize() {
185+
Ok(canonical) => canonical,
186+
Err(_) => {
187+
// If canonicalize fails (e.g., path doesn't exist), try absolute
188+
match std::path::absolute(path) {
189+
Ok(abs) => abs,
190+
Err(_) => path.to_path_buf(),
191+
}
192+
}
193+
}
194+
}
195+
176196
/// Validates the compiler configuration.
177197
fn validate_compiler_configuration(
178198
compilers: &[config::Compiler],
@@ -707,4 +727,53 @@ mod tests {
707727
assert!(result_with_access_nonexisting.is_some());
708728
assert!(result_without_access_nonexisting.is_some());
709729
}
730+
731+
#[test]
732+
fn test_cross_platform_path_normalization() {
733+
use std::fs;
734+
use tempfile::tempdir;
735+
736+
let temp_dir = tempdir().unwrap();
737+
let temp_path = temp_dir.path();
738+
739+
// Create an existing file
740+
let existing_file = temp_path.join("test.c");
741+
fs::write(&existing_file, "test content").unwrap();
742+
743+
let compilers = vec![];
744+
let sources = SourceFilter {
745+
only_existing_files: true,
746+
paths: vec![DirectoryFilter {
747+
path: temp_path.to_path_buf(),
748+
ignore: Ignore::Always,
749+
}],
750+
};
751+
752+
let filter = Filter::try_from((compilers.as_slice(), &sources))
753+
.expect("Failed to create filter");
754+
755+
// Test with various path formats that might occur cross-platform
756+
let test_cases = vec![
757+
// Relative path
758+
"test.c",
759+
// Path with current directory reference
760+
"./test.c",
761+
];
762+
763+
for source_file in test_cases {
764+
let cmd = CompilerCommand::from_strings(
765+
temp_path.to_str().unwrap(),
766+
"/usr/bin/gcc",
767+
vec![(ArgumentKind::Source, vec![source_file])],
768+
);
769+
770+
let result = filter.should_filter_sources(&cmd, &filter.source_filters);
771+
assert!(
772+
result.is_some(),
773+
"Failed to filter source file: {} in temp dir: {:?}",
774+
source_file,
775+
temp_path
776+
);
777+
}
778+
}
710779
}

0 commit comments

Comments
 (0)