mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 12:38:30 +00:00
Make standard optional, allow empty src_disable, and add none/custom kinds
This commit is contained in:
@@ -37,9 +37,6 @@ pub fn collect_sources(
|
||||
collect_sources_rec(root, extensions, &mut sources, exclude_dirs, include_paths)?;
|
||||
}
|
||||
sources.sort();
|
||||
if sources.is_empty() {
|
||||
return Err(format!("No source files found in {}", format_roots(roots)));
|
||||
}
|
||||
Ok(sources)
|
||||
}
|
||||
|
||||
@@ -89,17 +86,6 @@ fn collect_sources_rec(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_roots(roots: &[PathBuf]) -> String {
|
||||
if roots.is_empty() {
|
||||
return "<none>".to_string();
|
||||
}
|
||||
let mut out = Vec::new();
|
||||
for root in roots {
|
||||
out.push(root.to_string_lossy().to_string());
|
||||
}
|
||||
out.join(", ")
|
||||
}
|
||||
|
||||
pub fn is_excluded(path: &Path, exclude_dirs: &[PathBuf], include_paths: &[String]) -> bool {
|
||||
if matches_patterns(path, include_paths, true) {
|
||||
return false;
|
||||
@@ -624,7 +610,8 @@ mod tests {
|
||||
let result = collect_sources(&roots, &["c"], &[], &include);
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
|
||||
assert!(result.is_err(), "empty src should return error");
|
||||
let sources = result.expect("empty src should return Ok");
|
||||
assert!(sources.is_empty(), "empty src should return empty vec");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -27,7 +27,15 @@ const DEFAULT_LANGUAGE: &str = "c";
|
||||
const DEFAULT_STANDARD: &str = "c11";
|
||||
const DEFAULT_COMPILER: &str = "clang";
|
||||
const DEFAULT_KIND: &str = "bin";
|
||||
const VALID_KINDS: &[&str] = &["bin", "staticlib", "sharedlib", "efi", "elf"];
|
||||
const VALID_KINDS: &[&str] = &[
|
||||
"bin",
|
||||
"staticlib",
|
||||
"sharedlib",
|
||||
"efi",
|
||||
"elf",
|
||||
"none",
|
||||
"custom",
|
||||
];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
@@ -101,7 +109,8 @@ pub struct PackageConfig {
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct BuildConfig {
|
||||
pub language: LanguageConfig,
|
||||
pub standard: String,
|
||||
#[serde(default)]
|
||||
pub standard: Option<String>,
|
||||
#[serde(default)]
|
||||
pub cxx_standard: Option<String>,
|
||||
pub compiler: String,
|
||||
@@ -353,7 +362,14 @@ impl Config {
|
||||
}
|
||||
|
||||
validate_language_config(&build.language, "build.language")?;
|
||||
if build.standard.trim().is_empty() {
|
||||
let lang_is_asm = match &build.language {
|
||||
LanguageConfig::One(s) => s.trim().eq_ignore_ascii_case("asm"),
|
||||
LanguageConfig::Many(v) => v.len() == 1 && v[0].trim().eq_ignore_ascii_case("asm"),
|
||||
};
|
||||
if let Some(ref std) = build.standard
|
||||
&& std.trim().is_empty()
|
||||
&& !lang_is_asm
|
||||
{
|
||||
return Err(ConfigError::Invalid("build.standard is empty".into()));
|
||||
}
|
||||
if build.compiler.trim().is_empty() {
|
||||
@@ -754,7 +770,9 @@ fn format_toml(value: &Value) -> Result<String, ConfigError> {
|
||||
} else {
|
||||
out.push_str(&format!("language = \"{language}\"\n"));
|
||||
}
|
||||
out.push_str(&format!("standard = \"{standard}\"\n"));
|
||||
if !standard.is_empty() {
|
||||
out.push_str(&format!("standard = \"{standard}\"\n"));
|
||||
}
|
||||
out.push_str(&format!("compiler = \"{compiler}\"\n"));
|
||||
let kind = build
|
||||
.get("kind")
|
||||
|
||||
Reference in New Issue
Block a user