From 8a9fb693e30ba411b6d1e9f16a20e4fd04cea770 Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 20 Feb 2025 23:06:50 +0100 Subject: [PATCH] =?UTF-8?q?refactor(sterni/bl=C3=ABrg):=20runExecline=20is?= =?UTF-8?q?=20dead,=20long=20live=20Run=20Execline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remember //nix/escapeExecline? Well, this is worse (for some possible meanings of the word). Instead of taking a list and escaping/rendering it to an execline script, Execline reimplements part of execlineb(1): It takes a (nested) list where any enclosed list signifies an execline block and produces the corresponding execline argv form as described in execline-block(7). This means the result of Execline can directly be executed using •SH without the need for execlineb(1). Consequently, execlineb(1)'s management of positional parameters and the environment are not available. This is fine for the intended purpose of Execline (glueing together shell commands efficiently without messing around with the FFI in BQN for pipe(2) etc.). Change-Id: Ief69b1bab919c16b6e39c3f5dc3db628766c5a8c Reviewed-on: https://cl.tvl.fyi/c/depot/+/13180 Reviewed-by: sterni Autosubmit: sterni Tested-by: BuildkiteCI --- users/sterni/blërg/blërg.bqn | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/users/sterni/blërg/blërg.bqn b/users/sterni/blërg/blërg.bqn index c111690e4..7c25647bd 100755 --- a/users/sterni/blërg/blërg.bqn +++ b/users/sterni/blërg/blërg.bqn @@ -39,6 +39,16 @@ Run ← { R ← {𝕊 exit‿stdout‿stderr: stderr!0=exit ⋄ stdout}∘Run LR ← Lines∘R +# see execline-block(7) +Execline ← ∾ { + # Not a string nor any other list + 𝕩: 0≠•Type𝕩? ⋈•Fmt 𝕩; + # List, but not a string (i.e. block) + 𝕩: 2≠•Type⊑𝕩? ⟨""⟩∾˜∾(' '⊸∾¨ 𝕊)¨𝕩; + # String (i.e. arg) + ⋈𝕩 +}¨ + GetEnv ← {R "importas"‿"env"‿𝕩‿"printf"‿"%s"‿"$env"} RelPath ← •wdpath⊸•file.At @@ -88,9 +98,8 @@ converters ← ⍉>⟨ ⟨"org", "pandoc"‿"-f"‿"org"‿"-t"‿"html5"⟩, ⟩ -# TODO(sterni): don't assemble blocks in this ad hoc fashion # TODO(sterni): pipefail -PipelineCmd ← {⟨"pipeline"⟩∾(' '⊸∾¨𝕨)∾⟨""⟩∾𝕩} +PipelineCmd ← {Execline "pipeline"‿𝕨∾𝕩} GitBackend ← {𝕊 config: repo ← RelPath config j.ObjGet "repository"