LAUNCH-PROGRAM: Support augmenting the child process's environment
Add :ADDITIONAL-ENVIRONMENT argument to LAUNCH-PROGAM and RUN-PROGRAM. This must be an alist with string keys and values, representing environment variables to add to the child's environment.
Supported on ABCL, Allegro, Clozure, CMUCL, ECL, Lispworks, and SBCL.
Called this the rather verbose :ADDITIONAL-ENVIRONMENT so as to not have any collision with the corresponding argument in the implementation. This is for backwards compatibility, so that if someone is augmenting the environment using the implementation's native argument we don't stomp on their toes. Additionally, it makes super clear that the environment is augmented instead of replaced (something that's often ambiguous in the implementations).
- If you provide this argument on ECL, then ECL no longer searches the path for the COMMAND. PR https://gitlab.com/embeddable-common-lisp/ecl/-/merge_requests/272 submitted upstream to address this.
- On CMUCL, the default environment of the child is the same environment in which CMUCL started, not the current environment. This behavior persists when using :ADDITIONAL-ENVIRONMENT as well.
Documentation for supported implementations:
- ABCL: https://www.abcl.org/releases/1.9.0/abcl-1.9.0.pdf Page 84
- Allegro: https://franz.com/support/documentation/10.0/doc/operators/excl/run-shell-command.htm
- Clozure: https://ccl.clozure.com/docs/ccl.html#running-other-programs-as-subprocesses
- CMUCL: https://cmucl.org/docs/cmu-user/html/Running-Programs-from-Lisp.html
- ECL: Couldn't find. Needed to go into source code.
- Lispworks: http://www.lispworks.com/documentation/lw50/LWRM/html/lwref-708.htm
- SBCL: http://www.sbcl.org/manual/#Running-external-programs
Notes on unsupported implementations:
- MKCL: Appears to have no support at the moment. See: https://gitlab.common-lisp.net/mkcl/mkcl/-/blob/cbb4c7c0e7a08aa95c0e864204b72a3aae59e8ef/src/c/unixsys.c#L808
- SCL: Could probably be supported. Documentation at https://lisphub.jp/doc/scl/run-program.html shows it has an :ENVIRONMENT argument. But, there's not enough detail to know if it augments or replaces the current environment. Given SCL's lineage (fork of CMUCL), I expect it to replace the environment. But even if that were the case, I could not find any equivalent to CMUCL's EXT:ENVIRONMENT-LIST variable in SCL documentation.
I did not attempt to extend this to implementations not already supported by LAUNCH-PROGRAM, as those all currently fallback to something equivalent to system(3). I think that any effort spent on those implementations is better spent getting them to implement a proper API we can use via LAUNCH-PROGRAM instead of figuring out how to assemble a shell command that robustly sets the environment variables before running the user's command. Theoretically it wouldn't be too hard on POSIX OSes (just use /usr/bin/env), but I have zero clue on doing it properly in Windows.