mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 16:19:37 +00:00
fix code format
This commit is contained in:
@@ -126,19 +126,27 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
||||
let chars: Vec<char> = text.chars().collect();
|
||||
for i in 0..chars.len() {
|
||||
if chars[i] == ':' {
|
||||
if i == 1 && chars[0].is_ascii_alphabetic() && i + 1 < chars.len() && (chars[i+1] == '\\' || chars[i+1] == '/') {
|
||||
if i == 1
|
||||
&& chars[0].is_ascii_alphabetic()
|
||||
&& i + 1 < chars.len()
|
||||
&& (chars[i + 1] == '\\' || chars[i + 1] == '/')
|
||||
{
|
||||
continue; // Windows drive letter
|
||||
}
|
||||
target_end = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let deps_str = if target_end > 0 { &text[target_end..] } else { &text };
|
||||
|
||||
|
||||
let deps_str = if target_end > 0 {
|
||||
&text[target_end..]
|
||||
} else {
|
||||
&text
|
||||
};
|
||||
|
||||
let mut current_path = String::new();
|
||||
let mut in_escape = false;
|
||||
|
||||
|
||||
for c in deps_str.chars() {
|
||||
if in_escape {
|
||||
if c != '\n' && c != '\r' {
|
||||
@@ -162,7 +170,6 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
||||
deps
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -214,7 +221,10 @@ mod tests {
|
||||
let src = dir.join("test.c");
|
||||
fs::write(&src, "int main() {}").unwrap();
|
||||
let obj = dir.join("test.o");
|
||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
||||
assert!(needs_rebuild(
|
||||
&src.to_string_lossy(),
|
||||
&obj.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -226,7 +236,10 @@ mod tests {
|
||||
// Sleep briefly to ensure mtime difference
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
fs::write(&obj, "").unwrap();
|
||||
assert!(!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
||||
assert!(!needs_rebuild(
|
||||
&src.to_string_lossy(),
|
||||
&obj.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -237,7 +250,10 @@ mod tests {
|
||||
fs::write(&obj, "").unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
fs::write(&src, "int main() { return 1; }").unwrap();
|
||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()));
|
||||
assert!(needs_rebuild(
|
||||
&src.to_string_lossy(),
|
||||
&obj.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -380,16 +396,26 @@ mod tests {
|
||||
fs::write(&header, "#define A 1").unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
fs::write(&obj, "").unwrap();
|
||||
|
||||
let d_content = format!("{}: {} {}", obj.to_string_lossy(), src.to_string_lossy(), header.to_string_lossy());
|
||||
|
||||
let d_content = format!(
|
||||
"{}: {} {}",
|
||||
obj.to_string_lossy(),
|
||||
src.to_string_lossy(),
|
||||
header.to_string_lossy()
|
||||
);
|
||||
fs::write(&d_file, d_content).unwrap();
|
||||
|
||||
assert!(!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()), "should be fresh");
|
||||
assert!(
|
||||
!needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
||||
"should be fresh"
|
||||
);
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||
fs::write(&header, "#define A 2").unwrap(); // modify header
|
||||
|
||||
assert!(needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()), "changed header should trigger rebuild");
|
||||
assert!(
|
||||
needs_rebuild(&src.to_string_lossy(), &obj.to_string_lossy()),
|
||||
"changed header should trigger rebuild"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,20 +212,21 @@ fn build_objects(
|
||||
let output = cmd.output().map_err(|err| format!("Build failed: {err}"))?;
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
|
||||
let mut headers = Vec::new();
|
||||
let mut clean_stdout = String::new();
|
||||
for line in stdout.lines() {
|
||||
if let Some(stripped) = line.strip_prefix("Note: including file:") {
|
||||
headers.push(stripped.trim().to_string());
|
||||
} else if let Some(stripped) = line.strip_prefix("Примечание: включение файла:") {
|
||||
} else if let Some(stripped) = line.strip_prefix("Примечание: включение файла:")
|
||||
{
|
||||
headers.push(stripped.trim().to_string());
|
||||
} else {
|
||||
clean_stdout.push_str(line);
|
||||
clean_stdout.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
eprint!("{}", clean_stdout);
|
||||
eprint!("{}", stderr);
|
||||
@@ -233,7 +234,10 @@ fn build_objects(
|
||||
} else {
|
||||
let trimmed_out = clean_stdout.trim();
|
||||
let trimmed_err = stderr.trim();
|
||||
let src_filename = Path::new(source).file_name().and_then(|v| v.to_str()).unwrap_or("");
|
||||
let src_filename = Path::new(source)
|
||||
.file_name()
|
||||
.and_then(|v| v.to_str())
|
||||
.unwrap_or("");
|
||||
if !trimmed_out.is_empty() && trimmed_out != src_filename {
|
||||
print!("{}", clean_stdout);
|
||||
}
|
||||
@@ -241,7 +245,7 @@ fn build_objects(
|
||||
eprintln!("{}", trimmed_err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let d_path = Path::new(&obj_path).with_extension("d");
|
||||
let mut d_content = format!("{}: \\\n", obj_path.replace('\\', "/"));
|
||||
for h in headers {
|
||||
|
||||
@@ -588,4 +588,3 @@ mod tests {
|
||||
assert!(config.check(), "valid config should return true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bin_path_release() {
|
||||
assert_eq!(
|
||||
bin_path("release", "hello", None),
|
||||
"./target/release/hello"
|
||||
);
|
||||
assert_eq!(bin_path("release", "hello", None), "./target/release/hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,4 +72,3 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user