8000 custom_script: add inline script support by svlad-90 · Pull Request #159 · xen-troops/moulin · GitHub
[go: up one dir, main page]

Skip to content

custom_script: add inline script support - #159

Merged
lorc merged 1 commit into
xen-troops:mainfrom
svlad-90:issue158inline-custom-script
Jul 21, 2026
Merged

lorc merged 1 commit into
xen-troops:mainfrom
svlad-90:issue158inline-custom-script

Conversation

@svlad-90
Copy link
Copy Markdown

Allow small custom script bodies to be embedded directly in a Moulin configuration with inline_script. Keep script as the external script path mode, and reject configurations that set both or neither option.

Write inline_script content to a generated script file under work_dir and invoke it through bash before running post-build dependency generation. This lets YAML use normal shell quoting without feeding the script body through the Ninja rule command line.

Document the new option and add integration coverage for quotes, a trap, a subshell, target generation, and config-file argument passing.

@andr2000
Copy link
Copy Markdown

Tested-by: Oleksandr Andrushchenko <andr2000@gmail.com>

Comment thread moulin/builders/custom_script.py Outdated
"( [ -d $work_dir ] || mkdir $work_dir )",
"echo '# Code generated by moulin. All manual changes will be lost' > $config_file",
"echo $b64config | base64 -d - >> $config_file",
"if [ -n \"$inline_b64_script\" ]; then "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do not extend existing build rule. It is already looks complex enough. Add a new rule, tailored for inline_script specifically

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @lorc, done. An additional 'cs_inline_build' rule was added.

Comment thread moulin/builders/custom_script.py Outdated
"echo $b64config | base64 -d - >> $config_file",
"if [ -n \"$inline_b64_script\" ]; then "
"echo $inline_b64_script | base64 -d - > "
"$quoted_inline_script_file_name; fi",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is $quoted_inline_script_file_name is already exist in the directory. Use tmpfile instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @lorc, done. I've switched the implementation to use a tempfile.

Comment thread moulin/builders/custom_script.py Outdated
# Store the multiline inline script in a Ninja variable without
# exposing its shell syntax to the generated command.
script_bytes = inline_script_node.as_str.encode("utf-8")
inline_b64_script = base64.b64encode(script_bytes).decode("utf-8")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do you need this black magic with storing b64-encoded data in Ninja files, when Misha added API to cover cases like this?

472ac46

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @lorc, done. I've switched the implementation to the use of the utility dispatch mechanism.

@svlad-90
svlad-90 force-pushed the issue158inline-custom-script branch 2 times, most recently from a0c6d33 to 9ad7520 Compare July 19, 2026 14:46
@lorc lorc left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please ensure that user can use any scripting language they want

Comment thread moulin/builders/custom_script.py Outdated
stream.write(inline_script)

os.chmod(script_file, 0o700)
result = subprocess.run(["bash", script_file, *_get_inline_script_args(conf), config_file])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Whoa, not so fast. Non-inline variant support running any scripts (or any programs, honestly). Even documentation shows how to run a Python script. And here you are limiting functionality to bash scripts only with no apparent reason.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @lorc, done.

@svlad-90
svlad-90 force-pushed the issue158inline-custom-script branch 4 times, most recently from 1443c12 to df095be Compare July 20, 2026 16:11
@lorc lorc left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

Allow custom_script builders to embed script contents directly with an
inline_script field.

Moulin writes the content to an executable temporary file and runs it
through the generated config path. This lets shebangs select the
interpreter and keeps script output visible in the console.

Document the execution model and add integration coverage for successful
scripts, failure output, argument handling, and configuration errors.

Signed-off-by: Vladyslav Goncharuk <vladyslav_goncharuk@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
@svlad-90
svlad-90 force-pushed the issue158inline-custom-script branch from df095be to 6620fa8 Compare July 21, 2026 08:34
@lorc
lorc merged commit 071ea8a into xen-troops:main Jul 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0