The compiler looked for std/ and include/ inside its build directory, not beside it as install-user and a checkout lay them out, so it only found them where it was built. A prebuilt build tree in another checkout then missed every standard module. It now looks beside bin and beside the build directory, a test checks a moved compiler, and the setup action links the directories into the build tree for compilers that do not.
84 lines
2.4 KiB
Bash
84 lines
2.4 KiB
Bash
#!/bin/sh
|
|
# Without a project, std/NAME and plain NAME imports find the standard
|
|
# modules that came with the compiler; no --module-path is needed.
|
|
set -eu
|
|
|
|
ziran=$1
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT HUP INT TERM
|
|
unset ZIRAN_STD
|
|
|
|
cat > "$work/app.zi" <<'ZI'
|
|
#import "std/vec";
|
|
#import "std/option";
|
|
#import "text";
|
|
|
|
#program_export
|
|
Answer :: () -> s32 {
|
|
values: Vec(s32);
|
|
VecPush(values, 20);
|
|
VecPush(values, 22);
|
|
total: s32 = 0;
|
|
i: s64 = 0;
|
|
while i < values.count { total += VecGet(values, i).value; i += 1; }
|
|
if !StartsWithFoldASCII("Ziran", "zi") { return 0; }
|
|
return total;
|
|
}
|
|
ZI
|
|
"$ziran" check --root "$work" "$work/app.zi"
|
|
"$ziran" bundle --root "$work" --entry app:Answer -o "$work/app.zx" "$work/app.zi"
|
|
test "$("$ziran" run "$work/app.zx")" = 42
|
|
|
|
# A compiler moved with its build directory beside std/, as `make
|
|
# install-user` and a prebuilt CI checkout lay it out, uses that std/ and not
|
|
# the source checkout it was built in: only the moved std/ has this module.
|
|
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
mkdir -p "$work/moved/build/bin" "$work/moved/std"
|
|
for tool in "$(dirname -- "$ziran")"/zi*; do
|
|
cp "$tool" "$work/moved/build/bin/"
|
|
done
|
|
for module in "$repo"/std/*; do
|
|
ln -s "$module" "$work/moved/std/"
|
|
done
|
|
cat > "$work/moved/std/moved_probe.zi" <<'ZI'
|
|
MovedAnswer :: () -> s32 {
|
|
return 42;
|
|
}
|
|
ZI
|
|
cat > "$work/moved.zi" <<'ZI'
|
|
#import "moved_probe";
|
|
|
|
#program_export
|
|
Answer :: () -> s32 {
|
|
return MovedAnswer();
|
|
}
|
|
ZI
|
|
"$work/moved/build/bin/ziran" check --root "$work" "$work/moved.zi"
|
|
|
|
# ZIRAN_STD names another standard directory; one without the standard
|
|
# modules makes the import fail instead of silently using another.
|
|
mkdir "$work/empty"
|
|
if ZIRAN_STD="$work/empty" "$ziran" check --root "$work" "$work/app.zi" 2> "$work/empty.err"; then
|
|
echo 'an unusable ZIRAN_STD was ignored' >&2
|
|
exit 1
|
|
fi
|
|
grep -q 'cannot find imported module' "$work/empty.err"
|
|
|
|
# Passing the Vec's address gets a hint instead of a cascade.
|
|
cat > "$work/address.zi" <<'ZI'
|
|
#import "std/vec";
|
|
main :: () {
|
|
values: Vec(s32);
|
|
VecPush(*values, 1);
|
|
}
|
|
ZI
|
|
if "$ziran" check --root "$work" "$work/address.zi" 2> "$work/address.err"; then
|
|
echo 'VecPush of an address was accepted' >&2
|
|
exit 1
|
|
fi
|
|
grep -q 'pass the Vec variable itself' "$work/address.err"
|
|
if grep -q 'element type mismatch' "$work/address.err"; then
|
|
echo 'VecPush reported a follow-on element error' >&2
|
|
exit 1
|
|
fi
|