-
Notifications
You must be signed in to change notification settings - Fork 8
Allow sh_binary to use mktemp #11
Description
The existing implementation of sh_binary extracts the zip contents into the same directory as the script. This creates two issues: the script may have issues with concurrent use, and it potentially clutters up the location of the script.
Depending on how you are using the resulting script, this may or may not be a problem for you.
If it is a problem for you, the preamble to the generated script might be better implemented as:
#!/bin/bash
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR" EXIT INT TERM
unzip -qo "$0" -d "$TMP_DIR"The first step creates a temporary directory into which the script payload can be unpacked, the second temp ensures that temp dir is cleaned up on exit.
This would pair nicely with #3, if implemented as a helper function as discussed in thought-machine/please#2284, e.g.:
source $(dependency_path path/to/library.sh)This way scripts would be agnostic to the temporary directory.
This could be added as an option, e.g.
sh_binary(
name="script",
main="script.sh",
deps=[":lib"],
use_temp=True,
))