Files
masyunis/wasm/scripts/lib.sh
T
sol_bot Bot e07de898cd Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3).
Masyunis customizations are re-applied in the following commits.
2026-11-28 14:52:26 +03:00

39 lines
1.3 KiB
Bash

# shellcheck shell=bash
# BSD `find` has no `-printf` flag, so you have to get file timestamps from
# `stat`. Beautifully, both `stat` implementations differ in how these
# timestamps are extracted. Figure out which flag you need with a small test
# because people can run BSD coreutils (or busybox?).
if stat -f '%m' . >/dev/null 2>&1; then
stat_mtime_args=(-f '%m')
else
stat_mtime_args=(-c '%Y')
fi
# Implements the subset of `find -printf` that's actually needed here.
mtimes() {
find "$@" -exec stat "${stat_mtime_args[@]}" {} +
}
# all_populated PATTERN DIR... succeeds when every DIR holds at least one file
# matching PATTERN. Timestamps alone can't answer "are the artifacts there?":
# a run that dies partway through leaves one output directory filled and the
# next one empty, and every source file is older than whatever that run managed
# to write. Check that the files exist before believing the clock.
all_populated() {
local pattern="${1}"
shift
local dir
for dir in "$@"; do
compgen -G "${dir}/${pattern}" >/dev/null || return 1
done
}
# node_runs_wasm succeeds when node is installed and can be trusted to run the
# binaryen modules. On the riscv64 CI host (isa rv64imafdcsu) it cannot: node
# dies with SIGILL partway through wasm-opt, every time.
node_runs_wasm() {
command -v node >/dev/null 2>&1 && [ "$(uname -m)" != "riscv64" ]
}