mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Every script a build runs with bash, devvm's own and the user's layers, now gets the prelude as one line, eval $'…', in place of its #! line, so bash's errors and $LINENO give the script's own line numbers. A script without a #! line is one line further down. - shell.QuoteLine: ANSI-C quoting for bash, on one line of printable ASCII; every other byte as \xHH, so a multibyte locale's lead byte (Shift-JIS, GBK, GB18030, Big5) can't swallow the backslash escaping a quote, and a NUL panics as a caller's bug. image's layer rule allows internal/shell, a leaf. - image.WithPrelude, the one place the prelude and a script are joined (OwnScript calls it), used by base.sh, apt.sh, the built-in layers and features, the user's layers, shared-tools/build.sh and oci/build.sh. Every devvm script has a #! line. A leading UTF-8 BOM goes before the #! check. - A build's exports for a company proxy (lima's proxyExports) and the user's CAs (trust's exports) end in "; ", not a newline, so they share the first line and move no line either; backend.Trust.Env says so. - The stub logs a bash -s script's second line, which is the script's own second line with or without the prelude. - Keys: every build script's bytes change, so base, every image and every shared tool image are built again once; the CHANGELOG's After you upgrade says so with git-lfs, and what VMs say until devvm update, and Breaking has its own heading. - Tests: TestQuoteLine (every byte but NUL, a break-out word, in /bin/bash 3.2 and PATH's bash, in C and each of ja_JP.SJIS, zh_CN.GBK, zh_CN.GB18030 and zh_TW.Big5 that locale -a has), TestQuoteLineNUL, TestWithPrelude's shebang and BOM cases, TestWithPreludeRuns (the real prelude's line gives the prelude back; a layer under set -euo pipefail gets the names, keeps its function and its line numbers, with and without exports before it). - e2e nix: the layer copy no longer adds the prelude itself. - Docs: images.md's prelude section, Customizing's layer bullet, structure.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
136 lines
4.4 KiB
Plaintext
136 lines
4.4 KiB
Plaintext
# assets/prelude.sh, sourced with each of devvm's scripts' pins: the architecture and C library it
|
|
# finds, and the pin devvm_sha picks for each download, on arm64 and amd64, gnu and musl.
|
|
env STUB_UNAME_M=aarch64
|
|
exec bash pins.sh gnu
|
|
cmp stdout arm64-gnu.want
|
|
exec bash pins.sh musl
|
|
cmp stdout arm64-musl.want
|
|
|
|
# macOS's name for arm64 too.
|
|
env STUB_UNAME_M=arm64
|
|
exec bash pins.sh gnu
|
|
cmp stdout arm64-gnu.want
|
|
|
|
env STUB_UNAME_M=x86_64
|
|
exec bash pins.sh gnu
|
|
cmp stdout amd64-gnu.want
|
|
exec bash pins.sh musl
|
|
cmp stdout amd64-musl.want
|
|
|
|
# Another architecture stops the script.
|
|
env STUB_UNAME_M=riscv64
|
|
! exec bash -c 'source "$DEVVM_REPO/assets/prelude.sh"; echo ran'
|
|
! stdout ran
|
|
stderr '^devvm: devvm''s downloads have no build for riscv64$'
|
|
|
|
# A download the script doesn't pin fails, naming the pin.
|
|
env STUB_UNAME_M=x86_64
|
|
! exec bash -c 'source "$DEVVM_REPO/assets/prelude.sh"; devvm_sha crane'
|
|
! stdout .
|
|
stderr '^devvm: this script pins no crane_sha256_amd64$'
|
|
|
|
# A user's layer after the prelude, on bash's standard input (the build's one-line form is
|
|
# image.WithPrelude's, which its Go tests run). Its own pins pick its download, the _musl one on
|
|
# Alpine where it pins one, under the layer's set -u.
|
|
env STUB_UNAME_M=aarch64
|
|
exec bash layer.sh gnu mailpit.sh
|
|
stdout '^mailpit arm64 gnu sum-arm64$'
|
|
env STUB_UNAME_M=x86_64
|
|
exec bash layer.sh gnu mailpit.sh
|
|
stdout '^mailpit amd64 gnu sum-amd64$'
|
|
exec bash layer.sh musl mailpit.sh
|
|
stdout '^mailpit amd64 musl sum-amd64-musl$'
|
|
env STUB_UNAME_M=aarch64
|
|
exec bash layer.sh musl mailpit.sh
|
|
stdout '^mailpit arm64 musl sum-arm64$'
|
|
|
|
# A layer that sets a devvm_ name of its own keeps it: the prelude came first.
|
|
exec bash layer.sh gnu own.sh
|
|
stdout '^own x86_64 mine$'
|
|
|
|
-- layer.sh --
|
|
# layer.sh LIBC SCRIPT: SCRIPT after the prelude on bash -s's standard input. musl is Alpine's:
|
|
# apk on PATH.
|
|
set -euo pipefail
|
|
if [[ $1 == musl ]]; then
|
|
mkdir -p alpine; printf '#!/bin/sh\n' > alpine/apk; chmod 755 alpine/apk
|
|
PATH=$PWD/alpine:$PATH
|
|
fi
|
|
cat "$DEVVM_REPO/assets/prelude.sh" "$2" | bash -s
|
|
-- mailpit.sh --
|
|
#!/bin/bash
|
|
set -euo pipefail
|
|
mailpit_sha256_arm64=sum-arm64
|
|
mailpit_sha256_amd64=sum-amd64
|
|
mailpit_sha256_amd64_musl=sum-amd64-musl
|
|
echo "mailpit $devvm_arch $devvm_libc $(devvm_sha mailpit)"
|
|
-- own.sh --
|
|
#!/bin/bash
|
|
set -euo pipefail
|
|
devvm_arch=x86_64
|
|
devvm_sha() { echo mine; }
|
|
echo "own $devvm_arch $(devvm_sha mailpit)"
|
|
-- pins.sh --
|
|
# pins.sh LIBC: for each script and download, which of its pins devvm_sha gives. musl is
|
|
# Alpine's: apk on PATH.
|
|
set -euo pipefail
|
|
if [[ $1 == musl ]]; then
|
|
mkdir -p alpine; printf '#!/bin/sh\n' > alpine/apk; chmod 755 alpine/apk
|
|
PATH=$PWD/alpine:$PATH
|
|
fi
|
|
source "$DEVVM_REPO/assets/prelude.sh"
|
|
echo "$devvm_arch $devvm_libc"
|
|
while read -r script tools; do
|
|
(
|
|
eval "$(grep -E '^[a-z_]+_sha256(_[a-z0-9]+)*=[0-9a-f]{64}$' "$DEVVM_REPO/assets/$script")"
|
|
for tool in $tools; do
|
|
sum=$(devvm_sha "$tool")
|
|
for v in $(compgen -v | grep -E "^${tool}_sha256_"); do
|
|
[[ ${!v} != "$sum" ]] || echo "$script $tool $v"
|
|
done
|
|
done
|
|
)
|
|
done <<'LIST'
|
|
layers/base.sh mise
|
|
layers/nix.sh nix direnv
|
|
features/cli-tools.sh eza tealdeer
|
|
shared-tools/build.sh rustup
|
|
oci/build.sh crane
|
|
LIST
|
|
-- arm64-gnu.want --
|
|
arm64 gnu
|
|
layers/base.sh mise mise_sha256_arm64
|
|
layers/nix.sh nix nix_sha256_arm64
|
|
layers/nix.sh direnv direnv_sha256_arm64
|
|
features/cli-tools.sh eza eza_sha256_arm64
|
|
features/cli-tools.sh tealdeer tealdeer_sha256_arm64
|
|
shared-tools/build.sh rustup rustup_sha256_arm64
|
|
oci/build.sh crane crane_sha256_arm64
|
|
-- arm64-musl.want --
|
|
arm64 musl
|
|
layers/base.sh mise mise_sha256_arm64_musl
|
|
layers/nix.sh nix nix_sha256_arm64
|
|
layers/nix.sh direnv direnv_sha256_arm64
|
|
features/cli-tools.sh eza eza_sha256_arm64
|
|
features/cli-tools.sh tealdeer tealdeer_sha256_arm64
|
|
shared-tools/build.sh rustup rustup_sha256_arm64_musl
|
|
oci/build.sh crane crane_sha256_arm64
|
|
-- amd64-gnu.want --
|
|
amd64 gnu
|
|
layers/base.sh mise mise_sha256_amd64
|
|
layers/nix.sh nix nix_sha256_amd64
|
|
layers/nix.sh direnv direnv_sha256_amd64
|
|
features/cli-tools.sh eza eza_sha256_amd64
|
|
features/cli-tools.sh tealdeer tealdeer_sha256_amd64
|
|
shared-tools/build.sh rustup rustup_sha256_amd64
|
|
oci/build.sh crane crane_sha256_amd64
|
|
-- amd64-musl.want --
|
|
amd64 musl
|
|
layers/base.sh mise mise_sha256_amd64_musl
|
|
layers/nix.sh nix nix_sha256_amd64
|
|
layers/nix.sh direnv direnv_sha256_amd64
|
|
features/cli-tools.sh eza eza_sha256_amd64
|
|
features/cli-tools.sh tealdeer tealdeer_sha256_amd64
|
|
shared-tools/build.sh rustup rustup_sha256_amd64_musl
|
|
oci/build.sh crane crane_sha256_amd64
|