pub fn merge_kconfig_fragments<'a>(
baked: &'a str,
extra: Option<&str>,
) -> Cow<'a, str>Expand description
Merge the user-supplied --extra-kconfig fragment on top of
EMBEDDED_KCONFIG for the configure pass. Returns a
std::borrow::Cow so the no-extras branch borrows baked
without allocating; only the Some branch heaps the merged
String.
The user fragment is appended AFTER the baked-in fragment so
kbuild’s last-wins rule
(scripts/kconfig/confdata.c::conf_read_simple —
“If conflicting CONFIG options are given from an input file,
the last one wins.”) makes user values override baked-in ones
on conflict.
A single \n separator is interleaved between the two
fragments. EMBEDDED_KCONFIG ends in a newline today, so the
interleaved \n produces a blank line between the segments —
kbuild’s .config parser ignores blank lines (every
if (!line[0]) short-circuit in conf_read_simple), so the
blank line is harmless. The separator is mandatory for the
adversarial case where the operator hand-crafts an
EMBEDDED_KCONFIG without a trailing newline AND a user
fragment that starts with CONFIG_X — without the
interleaved \n, the two would concatenate into a single
malformed line. Always emit the separator so the merge is
safe regardless of either side’s terminator.
The production configure path in
crate::cli::kernel_build_pipeline calls this helper to build
the bytes handed to configure_kernel. Tests that assert
merge-ordering invariants call it directly so the production
byte sequence is what kbuild’s last-wins rule operates on.
(Note: cache_key_suffix_with_extra hashes extra ALONE for
its xkc{...} segment — it doesn’t pass through this helper —
so the cache-key suffix and the merged-fragment content evolve
independently. The cache-key segment exists to discriminate
extras-vs-no-extras at the cache layer; the merge ordering
exists to give kbuild the right final value.)