Skip to content

fix(kernel-config): append missing newline to .config before edits#9681

Merged
igorpecovnik merged 2 commits intomainfrom
fix/kernel-config-trailing-newline
Apr 16, 2026
Merged

fix(kernel-config): append missing newline to .config before edits#9681
igorpecovnik merged 2 commits intomainfrom
fix/kernel-config-trailing-newline

Conversation

@iav
Copy link
Copy Markdown
Contributor

@iav iav commented Apr 16, 2026

Summary

Issue #9680 report: kernel_config_set_* calls from custom_kernel_config hooks silently lost, "fixed" by adding a blank line to the defconfig. Two independent bugs combine into this behaviour:

  1. Text-level (commit 1): ./scripts/config --enable X appends new options via echo >>. A defconfig shipped without a trailing newline ends up with the first new option glued onto the last line (# CONFIG_OLDOPT is not setCONFIG_NEWOPT=y), which make olddefconfig then discards. 93 files in config/kernel/*.config currently lack a trailing newline. Normalise .config once after copying.

  2. Cache-level (commit 2): kernel_config_modifying_hashes was declare -a local to artifact_kernel_prepare_version(), and the kernel_config_set_{y,n,m,string,val} helpers never appended to it. Hook-driven config changes never reached the cache fingerprint, so a cached artifact built without the hook got reused even after the hook was added. Declare the array globally, push from every setter, and initialise it defensively in call_extensions_kernel_config. Co-authored with EvilOlaf, who identified the cache path in the issue thread.

Fixes #9680

Test plan

  • Reproduced bug 1 locally (scripts/config --enable NEW on a no-trailing-newline input produces # CONFIG_OLDOPT is not setCONFIG_NEWOPT=y).
  • Built kernel artifact for BOARD=nanopi-r6s BRANCH=vendor (uses linux-rk35xx-vendor.config, the exact defconfig from the issue report) with ARTIFACT_IGNORE_CACHE=yes.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed kernel configuration handling to prevent configuration options from being incorrectly concatenated
    • Enhanced initialization of configuration tracking to ensure proper build artifact versioning
    • Improved configuration change recording for consistent build results

Kernel's ./scripts/config appends via `echo >>`; configs without a
trailing newline end up with the first new option glued to the last
line, silently dropping subsequent custom_kernel_config hooks.

Fixes: #9680
@iav iav requested a review from a team as a code owner April 16, 2026 04:07
@iav iav requested review from catalinii and martinayotte and removed request for a team April 16, 2026 04:07
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

📝 Walkthrough

Walkthrough

Added a trailing-newline sed in kernel_config_initialize and ensured kernel_config_modifying_hashes is initialized/globally declared so kernel config setters can record modifications; also updated per-option kernel_config_set_* helpers to append their change entries to that hashing array.

Changes

Cohort / File(s) Summary
Kernel config newline & guard
lib/functions/compilation/kernel-config.sh
Appended in-place sed to ensure ${kernel_work_dir}/.config ends with a newline after copying base config; added a guard that declares/initializes kernel_config_modifying_hashes (if undeclared) before calling extension hooks.
Artifact versioning scope
lib/functions/artifacts/artifact-kernel.sh
Changed kernel_config_modifying_hashes from a local (declare -a) to a global indexed array (declare -ga) so entries added by extensions persist for version hashing.
Per-option hash entries
lib/functions/compilation/armbian-kernel.sh
Each helper (kernel_config_set_m, _set_y, _set_n, _set_string, _set_val) now appends an option=value style entry to kernel_config_modifying_hashes in addition to invoking ./scripts/config/host commands.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged the config with a gentle line-feed cheer,
So appended options no longer cling or smear.
I mark each tweak with a hash in a row,
Now builds can know what changed — hop, off we go! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: appending a missing newline to .config before edits to prevent option concatenation issues.
Linked Issues check ✅ Passed The PR fully addresses issue #9680: ensures kernel_config_set_* calls work reliably when defconfig lacks a trailing newline by normalizing the .config file after copying and tracking modifications for artifact versioning.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the kernel configuration newline issue and supporting artifact cache tracking; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/kernel-config-trailing-newline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size/small PR with less then 50 lines 05 Milestone: Second quarter release Needs review Seeking for review Framework Framework components labels Apr 16, 2026
@iav iav added the Bugfix Pull request is fixing a bug label Apr 16, 2026
kernel_config_modifying_hashes was declared locally in
artifact_kernel_prepare_version(), and the kernel_config_set_{y,n,m,string,val}
helpers never wrote to it. Hooks that used those helpers (e.g.
custom_kernel_config) would be applied to .config but invisible to
the kernel-artifact cache fingerprint, so a cached artifact built
without the hook could be reused for a later build that added one.

Declare the array globally, make every setter append its change, and
initialize the array in call_extensions_kernel_config as a safety net
for non-artifact call paths.

Refs: #9680
Co-authored-by: EvilOlaf <50047739+EvilOlaf@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/functions/compilation/armbian-kernel.sh (1)

693-730: Note: Duplicate hash entries when using opts_ arrays (harmless).*

With the new hash tracking in kernel_config_set_* helpers, options processed via opts_* arrays are now recorded twice:

  1. Explicitly at lines 697-711 (first pass)
  2. Again when kernel_config_set_* is called at lines 715-729 (second pass)

This is harmless because:

  • The deduplication step in artifact-kernel.sh (lines 133-135) uses sort -uk 1,1 to keep only one entry per key
  • During version calculation, .config doesn't exist, so the second pass doesn't run—no duplicates
  • During actual builds, duplicates occur but the hash has already been calculated

No action needed; just flagging for awareness. If you want to eliminate the redundancy, you could remove the explicit additions in the first pass and rely solely on the helper functions, but the current approach is clearer and the overhead is negligible.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/functions/compilation/armbian-kernel.sh` around lines 693 - 730, The
first pass in armbian_kernel_config_apply_opts_from_arrays is redundantly
appending entries to kernel_config_modifying_hashes for
opts_n/opts_y/opts_m/opts_val and then the kernel_config_set_* helpers append
them again; to eliminate duplicate hash entries remove the explicit first-pass
loops that do kernel_config_modifying_hashes+=("${...}") for opts_n, opts_y,
opts_m and the opts_val loop, and rely on
kernel_config_set_n/kernel_config_set_y/kernel_config_set_m/kernel_config_set_val
to record changes, keeping the second-pass application of .config intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/functions/compilation/armbian-kernel.sh`:
- Around line 693-730: The first pass in
armbian_kernel_config_apply_opts_from_arrays is redundantly appending entries to
kernel_config_modifying_hashes for opts_n/opts_y/opts_m/opts_val and then the
kernel_config_set_* helpers append them again; to eliminate duplicate hash
entries remove the explicit first-pass loops that do
kernel_config_modifying_hashes+=("${...}") for opts_n, opts_y, opts_m and the
opts_val loop, and rely on
kernel_config_set_n/kernel_config_set_y/kernel_config_set_m/kernel_config_set_val
to record changes, keeping the second-pass application of .config intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dc2c93eb-3605-4bca-acfa-a13a7e4ec479

📥 Commits

Reviewing files that changed from the base of the PR and between bc9a20d and 95d410e.

📒 Files selected for processing (3)
  • lib/functions/artifacts/artifact-kernel.sh
  • lib/functions/compilation/armbian-kernel.sh
  • lib/functions/compilation/kernel-config.sh

@iav
Copy link
Copy Markdown
Contributor Author

iav commented Apr 16, 2026

693-730: Note: Duplicate hash entries...

First pass is load-bearing for artifact_kernel_prepare_version.config doesn't exist there, so the second pass (and the setter-side hash pushes) is skipped. Remove it and opts_y/n/m/val stop contributing to the fingerprint. Duplicates on the apply path are collapsed by the sort -s -t '=' -uk 1,1 dedupe in artifact-kernel.sh:134.

@EvilOlaf EvilOlaf requested a review from rpardini April 16, 2026 05:18
@iav
Copy link
Copy Markdown
Contributor Author

iav commented Apr 16, 2026

The author of the original bug report closed it, but if I understand what's happening correctly, it still makes sense to fix it. Invalidating the cache is the right thing to do.

@github-actions github-actions bot added the Ready to merge Reviewed, tested and ready for merge label Apr 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions bot removed the Needs review Seeking for review label Apr 16, 2026
@igorpecovnik igorpecovnik merged commit 338bfe9 into main Apr 16, 2026
13 checks passed
@igorpecovnik igorpecovnik deleted the fix/kernel-config-trailing-newline branch April 16, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Bugfix Pull request is fixing a bug Framework Framework components Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

[Bug]: A blank line needs to be added at the end of the kernel's defconfig file for the custom_kernel_config hook to take effect.

2 participants