Repository navigation
custom_script: add inline script support - #159
Conversation
|
|
| "( [ -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 " |
There was a problem hiding this comment.
Do not extend existing build rule. It is already looks complex enough. Add a new rule, tailored for inline_script specifically
There was a problem hiding this comment.
Hi @lorc, done. An additional 'cs_inline_build' rule was added.
| "echo $b64config | base64 -d - >> $config_file", | ||
| "if [ -n \"$inline_b64_script\" ]; then " | ||
| "echo $inline_b64_script | base64 -d - > " | ||
| "$quoted_inline_script_file_name; fi", |
There was a problem hiding this comment.
What is $quoted_inline_script_file_name is already exist in the directory. Use tmpfile instead
There was a problem hiding this comment.
Hi @lorc, done. I've switched the implementation to use a tempfile.
| # 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") |
There was a problem hiding this comment.
Why do you need this black magic with storing b64-encoded data in Ninja files, when Misha added API to cover cases like this?
There was a problem hiding this comment.
Hi @lorc, done. I've switched the implementation to the use of the utility dispatch mechanism.
a0c6d33 to
9ad7520
Compare
There was a problem hiding this comment.
Please ensure that user can use any scripting language they want
| stream.write(inline_script) | ||
|
|
||
| os.chmod(script_file, 0o700) | ||
| result = subprocess.run(["bash", script_file, *_get_inline_script_args(conf), config_file]) |
There was a problem hiding this comment.
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.
1443c12 to
df095be
Compare
There was a problem hiding this comment.
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>
df095be to
6620fa8
Compare
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.