give make a single call for the settings the CLI resolves
myos export prints every setting the requested stacks declare, in one process: 68 variables in half a second, where asking for them one at a time costs a process each and about ten seconds. The shim reads that once and includes it, so a .mk target sees HOST_FABIO_VERSION and the computed fabio tag without make knowing anything about how they are produced. --make quotes the values so make neither expands a $ nor starts a comment at a #.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#shellcheck shell=sh
|
||||
# myos export print every setting the requested stacks declare, as KEY=value.
|
||||
#
|
||||
# One call, so a Makefile can read the whole set at once:
|
||||
# $(eval $(shell myos export STACK=host))
|
||||
# Asking for each variable separately costs a process per variable.
|
||||
myos_cmd_export() {
|
||||
# shellcheck disable=SC2209 # these are literal format names, not commands
|
||||
_fmt=sh
|
||||
# shellcheck disable=SC2209
|
||||
case ${MYOS_ARGS:-}${MYOS_VARS:-} in *--make*) _fmt=make ;; esac
|
||||
for _v in $(myos_declared_defaults); do
|
||||
_val=$(myos_var "$_v")
|
||||
case $_fmt in
|
||||
make)
|
||||
# make would expand a $ and start a comment at a #, and := stops it
|
||||
# from expanding the value again later
|
||||
printf '%s := %s\n' "$_v" "$(printf '%s' "$_val" | sed -e 's/\$/$$/g' -e 's/#/\\#/g')" ;;
|
||||
*) printf '%s=%s\n' "$_v" "$_val" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# myos_declared_defaults the variables the loaded hooks declare
|
||||
myos_declared_defaults() {
|
||||
for _ref in $MYOS_STACKS; do
|
||||
for _d in $(myos_stack_dirs "$_ref"); do
|
||||
for _f in "$_d"/_stack.sh "$_d/$(myos_stack_name "$_ref").sh"; do
|
||||
[ -f "$_f" ] && sed -n 's/^myos_default_\([A-Za-z_][A-Za-z0-9_]*\)().*/\1/p' "$_f"
|
||||
done
|
||||
for _f in "$_d"/_stack.env "$_d/$(myos_stack_name "$_ref").env"; do
|
||||
[ -f "$_f" ] && myos_dotenv_parse "$_f" | sed 's/=.*//'
|
||||
done
|
||||
done
|
||||
done | sort -u
|
||||
}
|
||||
Reference in New Issue
Block a user