From: "'Rakesh Kumar' via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: jan.kiszka@siemens.com, cedric.hombourger@siemens.com,
Rakesh Kumar <kumar.rakesh@siemens.com>
Subject: [PATCH] fix: preserve indentation in dracut module-setup.sh
Date: Tue, 16 Dec 2025 15:49:36 +0530 [thread overview]
Message-ID: <20251216101936.3259099-1-kumar.rakesh@siemens.com> (raw)
The marker replacement logic treated the inserted file content
as plain text, which caused indentation to be lost in generated
scripts (e.g. module-setup.sh).
Update the replacement logic to detect the marker line’s
indentation and apply the same indentation to all non-empty lines
of the inserted content. This preserves the original formatting
and avoids syntax and readability issues in the generated files.
Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
---
doc/user_manual.md | 19 +++++++++++++---
meta/classes-recipe/dracut-module.bbclass | 27 +++++++++++++++++------
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/doc/user_manual.md b/doc/user_manual.md
index e7955c12..731e84f1 100644
--- a/doc/user_manual.md
+++ b/doc/user_manual.md
@@ -1763,9 +1763,22 @@ module in the initrd or as a dependency to other modules. It defaults to
`${PN}` without the prefix `dracut-`.
- `DRACUT_MODULE_PATH` contains the path to the installed module. It is set
to `${D}/usr/lib/dracut/modules.d/${DRACUT_MODULE_NO}${DRACUT_MODULE_NAME}/`
-
-The `install()` function is added by storing the file `install.sh` in the
-files directory of the dracut module.
+- `DRACUT_CHECK_CONTENT_FILE_NAME` contents for check() function
+- `DRACUT_DEPENDS_CONTENT_FILE_NAME` contents for depends() function
+- `DRACUT_CMDLINE_CONTENT_FILE_NAME` contents for cmdline() function
+- `DRACUT_INSTALL_CONTENT_FILE_NAME` contents for install() function
+- `DRACUT_INSTALLKERNEL_CONTENT_FILE_NAME` contents for installkernel() function
+
+Hook functions such as check(), depends(), cmdline(), install(), and
+installkernel() are provided by replacing placeholders in dracut module
+module-setup.sh template with content from individual files, selected via
+the corresponding `DRACUT_<FUNCTION>_CONTENT_FILE_NAME` variables.
+
+Example:
+
+The `install()` function can be provided by placing a file (for example,
+`install.sh`) in the dracut module’s files directory and assigning it to
+`DRACUT_INSTALL_CONTENT_FILE_NAME`.
Other files can by added to the module by coping them to the Module folder
with:
diff --git a/meta/classes-recipe/dracut-module.bbclass b/meta/classes-recipe/dracut-module.bbclass
index 364fb5b4..eb1e4fb6 100644
--- a/meta/classes-recipe/dracut-module.bbclass
+++ b/meta/classes-recipe/dracut-module.bbclass
@@ -37,15 +37,28 @@ def add_file_if_variable_is_set(d, variable_name, prefix):
return ''
def replace_marker_with_file_content(template_file, content_file, marker):
- with open(template_file, 'r') as template_fd:
- tmpl_content = template_fd.read()
+ import re, bb
- with open(content_file, 'r') as content_fd:
- content = content_fd.read()
+ tmpl = open(template_file).read()
+ content = open(content_file).read().rstrip('\n')
- new_tpml_content = tmpl_content.replace(marker, content)
- with open(template_file, 'w') as tmpl_fd:
- tmpl_fd.write(new_tpml_content)
+ # locate marker and its indentation
+ m = re.search(rf'^(?P<indent>\s*){re.escape(marker)}\s*$', tmpl, re.MULTILINE)
+ if not m:
+ bb.fatal(f"Marker '{marker}' not found in {template_file}")
+
+ indent = m.group('indent')
+
+ # indent all non-blank lines
+ indented = '\n'.join(
+ (indent + line) if line.strip() else ''
+ for line in content.splitlines()
+ )
+
+ # replace the exact marker line
+ new_tmpl = tmpl[:m.start()] + indented + tmpl[m.end():]
+
+ open(template_file, 'w').write(new_tmpl)
SRC_URI:append = " ${@ add_file_if_variable_is_set(d, 'DRACUT_CHECK_CONTENT_FILE_NAME', 'file://')} \
${@ add_file_if_variable_is_set(d, 'DRACUT_DEPENDS_CONTENT_FILE_NAME', 'file://')} \
--
2.39.5
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20251216101936.3259099-1-kumar.rakesh%40siemens.com.
next reply other threads:[~2025-12-16 10:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 10:19 'Rakesh Kumar' via isar-users [this message]
2025-12-18 11:26 ` Anton Mikanovich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251216101936.3259099-1-kumar.rakesh@siemens.com \
--to=isar-users@googlegroups.com \
--cc=cedric.hombourger@siemens.com \
--cc=jan.kiszka@siemens.com \
--cc=kumar.rakesh@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox