mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-22 11:39:42 +00:00
docs: add and clean up AI-generated rustdoc comments (grok-4.5)
This commit is contained in:
@@ -18,6 +18,12 @@
|
||||
use crate::core::build_config::Config;
|
||||
use crate::utils::build::{get_config_str, normalize_target_os, profile_table};
|
||||
|
||||
/// Retrieves a raw TOML value from the config using a prioritized lookup order based on target, profile, and base sections.
|
||||
///
|
||||
/// The keys are checked in this order:
|
||||
/// {section}.{target}.{profile}.{field}, {section}.{profile}.{target}.{field}, {section}.{target}.{field}, {section}.{profile}.{field}, {section}.{field}
|
||||
///
|
||||
/// Returns the value if found, otherwise None.
|
||||
pub(crate) fn get_config_value_raw(
|
||||
config: &Config,
|
||||
section: &str,
|
||||
@@ -57,6 +63,9 @@ pub(crate) fn get_config_value_raw(
|
||||
None
|
||||
}
|
||||
|
||||
/// Checks if the 'inherit' flag is enabled for the given section, profile, and target.
|
||||
///
|
||||
/// Returns true by default if the flag is not set.
|
||||
pub(crate) fn get_inherit(
|
||||
config: &Config,
|
||||
section: &str,
|
||||
@@ -68,6 +77,9 @@ pub(crate) fn get_inherit(
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Extracts a trimmed non-empty string value from the config.
|
||||
///
|
||||
/// Returns Some(value) if found, None otherwise.
|
||||
pub(crate) fn get_config_value(
|
||||
config: &Config,
|
||||
section: &str,
|
||||
@@ -80,6 +92,9 @@ pub(crate) fn get_config_value(
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
/// Fetches a string value from the build section, inheriting from base if enabled.
|
||||
///
|
||||
/// Returns the value or default empty string if not inheriting.
|
||||
pub(crate) fn get_string_with_profile_and_target(
|
||||
config: &Config,
|
||||
field: &str,
|
||||
@@ -94,10 +109,12 @@ pub(crate) fn get_string_with_profile_and_target(
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a build string value for the given profile without a target.
|
||||
pub fn get_build_string_with_profile(config: &Config, field: &str, profile: &str) -> String {
|
||||
get_string_with_profile_and_target(config, field, profile, None)
|
||||
}
|
||||
|
||||
/// Gets a string value from the language-specific build.{lang} section.
|
||||
pub(crate) fn get_lang_string(
|
||||
config: &Config,
|
||||
lang: &str,
|
||||
@@ -108,6 +125,7 @@ pub(crate) fn get_lang_string(
|
||||
get_config_value(config, &format!("build.{lang}"), field, profile, target)
|
||||
}
|
||||
|
||||
/// Gets a list of strings from the language-specific build.{lang} section.
|
||||
pub(crate) fn get_lang_list(
|
||||
config: &Config,
|
||||
lang: &str,
|
||||
@@ -121,6 +139,7 @@ pub(crate) fn get_lang_list(
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a TOML array into a Vec<String>, erroring if not an array of strings.
|
||||
pub(crate) fn parse_string_array(value: &toml::Value, key: &str) -> Result<Vec<String>, String> {
|
||||
let arr = value
|
||||
.as_array()
|
||||
@@ -135,6 +154,9 @@ pub(crate) fn parse_string_array(value: &toml::Value, key: &str) -> Result<Vec<S
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Collects a list of strings from config, supporting inheritance from base and profile/target overrides.
|
||||
///
|
||||
/// If inherit is true, starts with the base list and appends custom entries if defined.
|
||||
pub(crate) fn get_list_with_profile_and_target(
|
||||
config: &Config,
|
||||
field: &str,
|
||||
@@ -154,6 +176,7 @@ pub(crate) fn get_list_with_profile_and_target(
|
||||
.get(&format!("build.{field}"))
|
||||
.map(|v| v == &val)
|
||||
.unwrap_or(false);
|
||||
// Skip re-adding the base list when this is the base definition to prevent duplication
|
||||
if !is_base {
|
||||
let custom = parse_string_array(&val, &format!("build.{field}"))?;
|
||||
if inherit {
|
||||
@@ -184,6 +207,7 @@ pub(crate) fn get_list_with_profile_and_target(
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Gets the list of strings for the given profile without a target.
|
||||
pub(crate) fn get_list_with_profile(
|
||||
config: &Config,
|
||||
field: &str,
|
||||
@@ -192,10 +216,21 @@ pub(crate) fn get_list_with_profile(
|
||||
get_list_with_profile_and_target(config, field, profile, None)
|
||||
}
|
||||
|
||||
/// Returns the list of targets for the given profile.
|
||||
pub(crate) fn get_targets(config: &Config, profile: &str) -> Result<Vec<String>, String> {
|
||||
get_list_with_profile(config, "targets", profile)
|
||||
}
|
||||
|
||||
/// Parses the config value as a list of strings.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `config`: Project config.
|
||||
/// - `key`: Dot-path key (e.g. `build.sources`).
|
||||
///
|
||||
/// # Returns
|
||||
/// - `Ok([])` if the key is missing.
|
||||
/// - `Ok(vec)` for an array of strings.
|
||||
/// - `Err` if present but not an array of strings.
|
||||
pub(crate) fn get_config_list(config: &Config, key: &str) -> Result<Vec<String>, String> {
|
||||
let value = match config.get(key) {
|
||||
Some(v) => v,
|
||||
|
||||
Reference in New Issue
Block a user