* [PATCH] fix: preserve indentation in dracut module-setup.sh
@ 2025-12-16 10:19 'Rakesh Kumar' via isar-users
2025-12-18 11:26 ` Anton Mikanovich
0 siblings, 1 reply; 2+ messages in thread
From: 'Rakesh Kumar' via isar-users @ 2025-12-16 10:19 UTC (permalink / raw)
To: isar-users; +Cc: jan.kiszka, cedric.hombourger, Rakesh Kumar
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.
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] fix: preserve indentation in dracut module-setup.sh
2025-12-16 10:19 [PATCH] fix: preserve indentation in dracut module-setup.sh 'Rakesh Kumar' via isar-users
@ 2025-12-18 11:26 ` Anton Mikanovich
0 siblings, 0 replies; 2+ messages in thread
From: Anton Mikanovich @ 2025-12-18 11:26 UTC (permalink / raw)
To: Rakesh Kumar, isar-users; +Cc: jan.kiszka, cedric.hombourger
16/12/2025 12:19, 'Rakesh Kumar' via isar-users wrote:
> 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>
Applied to next, thanks.
--
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/dbabc543-57dc-495e-ab31-3c79c0e28bc4%40ilbers.de.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-18 11:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-16 10:19 [PATCH] fix: preserve indentation in dracut module-setup.sh 'Rakesh Kumar' via isar-users
2025-12-18 11:26 ` Anton Mikanovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox