aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/link-commands.js13
-rwxr-xr-xscripts/qemu/guest/run-tests.sh2
-rw-r--r--scripts/run-bun-tests-bounded.js2
-rw-r--r--scripts/run-gnu-tests.js36
-rw-r--r--scripts/run-memory-bounded.js2
-rwxr-xr-xscripts/run-qemu-root-smoke.sh2
6 files changed, 29 insertions, 28 deletions
diff --git a/scripts/link-commands.js b/scripts/link-commands.js
index 617f64e..e595f88 100755
--- a/scripts/link-commands.js
+++ b/scripts/link-commands.js
@@ -2,18 +2,17 @@
import { chmod, mkdir, writeFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
-import { commandNames } from "../src/coreutils.js";
+import { commandNames } from "../src/shared/catalog.js";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const targetDir = resolve(process.argv[2] ?? "dist/bin");
-const bnu = resolve(root, "bin/bnu.js");
const bun = shellQuote(process.execPath);
-const bnuScript = shellQuote(bnu);
await mkdir(targetDir, { recursive: true });
for (const command of commandNames) {
const path = resolve(targetDir, command);
+ const commandScript = shellQuote(resolve(root, "src/commands", `${command}.js`));
const script = command === "pwd"
? `#!/bin/sh
saved_pwd=$PWD
@@ -21,9 +20,9 @@ actual_pwd=$(command pwd -P 2>/dev/null || :)
test -n "$actual_pwd" && saved_pwd=$actual_pwd
if [ \${#saved_pwd} -gt 4000 ]; then
cd / || exit 1
- BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} ${bnuScript} pwd "$@"
+ BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} ${commandScript} "$@"
fi
-exec ${bun} ${bnuScript} pwd "$@"
+exec ${bun} ${commandScript} "$@"
`
: command === "tail" || command === "tac" || command === "timeout"
? `#!/bin/sh
@@ -31,9 +30,9 @@ if [ ! -e /proc/$$/fd/0 ]; then
BNU_STDIN_CLOSED=1
export BNU_STDIN_CLOSED
fi
-exec ${bun} ${bnuScript} ${command} "$@"
+exec ${bun} ${commandScript} "$@"
`
- : `#!/bin/sh\nexec ${bun} ${bnuScript} ${command} "$@"\n`;
+ : `#!/bin/sh\nexec ${bun} ${commandScript} "$@"\n`;
await writeFile(path, script);
await chmod(path, 0o755);
}
diff --git a/scripts/qemu/guest/run-tests.sh b/scripts/qemu/guest/run-tests.sh
index efbb26e..653336f 100755
--- a/scripts/qemu/guest/run-tests.sh
+++ b/scripts/qemu/guest/run-tests.sh
@@ -16,7 +16,7 @@ chmod -R a+rX "$work"
common=(
"$work/bun" "$work/scripts/run-gnu-tests.js"
--tarball "$work/coreutils-9.11.tar.xz"
- --very-expensive --timeout 300s --rss-limit 1024MiB --memory-limit 3GiB
+ --very-expensive --timeout 300s --rss-limit 1024MiB --memory-limit 4GiB
)
case $mode in
nonroot)
diff --git a/scripts/run-bun-tests-bounded.js b/scripts/run-bun-tests-bounded.js
index 5864a4c..ecbf4f8 100644
--- a/scripts/run-bun-tests-bounded.js
+++ b/scripts/run-bun-tests-bounded.js
@@ -21,7 +21,7 @@ for (let index = 0; index < names.length; index++) {
process.execPath,
join(root, "scripts/run-memory-bounded.js"),
"--rss-limit", process.env.BNU_TEST_RSS_LIMIT ?? "1GiB",
- "--memory-limit", process.env.BNU_TEST_MEMORY_LIMIT ?? "3GiB",
+ "--memory-limit", process.env.BNU_TEST_MEMORY_LIMIT ?? "4GiB",
"--",
process.execPath,
"test",
diff --git a/scripts/run-gnu-tests.js b/scripts/run-gnu-tests.js
index 7eeed23..0ff4f4a 100644
--- a/scripts/run-gnu-tests.js
+++ b/scripts/run-gnu-tests.js
@@ -3,7 +3,7 @@ import { access, chmod, mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
-import { commandNames } from "../src/coreutils.js";
+import { commandNames } from "../src/shared/catalog.js";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const args = process.argv.slice(2);
@@ -34,7 +34,7 @@ const rssLimitBytes = parseByteSize(takeValue("--rss-limit") ?? "1536MiB");
// JSC reserves more than 2 GiB of virtual address space for some otherwise
// ~120 MiB workloads. Three GiB keeps those valid tests runnable while still
// preventing the unbounded 11 GiB heap growth that motivated this guard.
-const memoryLimitBytes = parseByteSize(takeValue("--memory-limit") ?? "3GiB");
+const memoryLimitBytes = parseByteSize(takeValue("--memory-limit") ?? "4GiB");
const tarball = takeValue("--tarball") ?? join(root, "coreutils-9.11.tar.xz");
const work = await mkdtemp(join(tmpdir(), "bnu-gnu-tests-"));
// Root-only GNU tests deliberately drop to an unprivileged account. mkdtemp
@@ -870,7 +870,7 @@ async function prepareExtractedHarness(dir) {
mkdir -p "$ROOT$(dirname ${runtimeBun})" "$ROOT"${runtimeRoot}/bin "$ROOT"${runtimeRoot}/src || framework_failure_
cp ${runtimeBun} "$ROOT"${runtimeBun} || framework_failure_
cp ${runtimeRoot}/bin/bnu.js "$ROOT"${runtimeRoot}/bin/bnu.js || framework_failure_
-cp ${runtimeRoot}/src/coreutils.js "$ROOT"${runtimeRoot}/src/coreutils.js || framework_failure_
+cp -R ${runtimeRoot}/src/. "$ROOT"${runtimeRoot}/src/ || framework_failure_
cp k.so $ROOT || framework_failure_`)
.replace(
'NPROC() { LD_PRELOAD=$LD_PRELOAD:./k.so chroot $ROOT /nproc "$@"; }',
@@ -1297,8 +1297,8 @@ get_min_ulimit_v_() { return 1; }
async function installWrappers(dir) {
await mkdir(dir, { recursive: true });
const bnu = join(root, "bin/bnu.js");
+ const commandRoot = join(root, "src/commands");
const bun = shellQuote(process.execPath);
- const coreutils = pathToFileURL(join(root, "src/coreutils.js")).href;
const metaFastPath = `if [ "$#" -eq 1 ] && [ "$1" = "--version" ]; then
text='bnu 9.11'
if ! printf '%s\\n' "$text" 2>/dev/null; then
@@ -1318,11 +1318,13 @@ fi
`;
for (const command of commandNames) {
const path = join(dir, command);
+ const commandEntry = join(commandRoot, `${command}.js`);
+ const commandUrl = pathToFileURL(commandEntry).href;
const wrapperMetaFastPath = ["cksum", "df", "echo", "false", "test"].includes(command) ? "" : metaFastPath;
const script = command === "printenv"
? `#!${process.execPath}
import { readFileSync } from "node:fs";
-import { main } from ${JSON.stringify(coreutils)};
+import command from ${JSON.stringify(commandUrl)};
function rawScriptArgs() {
try {
@@ -1333,13 +1335,13 @@ function rawScriptArgs() {
return Bun.argv.slice(2);
}
-process.exit(await main([${JSON.stringify(command)}, ...rawScriptArgs()]));
+process.exit(await command(rawScriptArgs()));
`
: command === "env"
? `#!/bin/sh
${wrapperMetaFastPath}case "$1" in
- ""|-*|*=*) exec ${bun} "${bnu}" env "$@" ;;
- *" "*) exec ${bun} "${bnu}" env "$@" ;;
+ ""|-*|*=*) exec ${bun} "${commandEntry}" "$@" ;;
+ *" "*) exec ${bun} "${commandEntry}" "$@" ;;
*) exec "$@" ;;
esac
`
@@ -1350,7 +1352,7 @@ if [ "$name" != coreutils ]; then
exec ${bun} "${bnu}" coreutils --coreutils-prog="$name" "$@"
fi
${wrapperMetaFastPath}
-exec ${bun} "${bnu}" coreutils "$@"
+exec ${bun} "${commandEntry}" "$@"
`
: command === "pwd"
? `#!/bin/sh
@@ -1359,9 +1361,9 @@ actual_pwd=$(command pwd -P 2>/dev/null || :)
test -n "$actual_pwd" && saved_pwd=$actual_pwd
if [ \${#saved_pwd} -gt 4000 ]; then
cd / || exit 1
- BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} "${bnu}" pwd "$@"
+ BNU_LONG_PWD=$saved_pwd PWD=$saved_pwd exec ${bun} "${commandEntry}" "$@"
fi
-exec ${bun} "${bnu}" pwd "$@"
+exec ${bun} "${commandEntry}" "$@"
`
: command === "tail" || command === "tac" || command === "timeout"
? `#!/bin/sh
@@ -1369,7 +1371,7 @@ ${wrapperMetaFastPath}if [ ! -e /proc/$$/fd/0 ]; then
BNU_STDIN_CLOSED=1
export BNU_STDIN_CLOSED
fi
-exec ${bun} "${bnu}" ${shellQuote(command)} "$@"
+exec ${bun} "${commandEntry}" "$@"
`
: command === "ls"
? `#!/usr/bin/env perl
@@ -1378,19 +1380,19 @@ use warnings;
my $cwd_ok = defined eval { require Cwd; Cwd::getcwd(); };
exit 0 if !$cwd_ok && @ARGV == 0;
chdir "/" if !$cwd_ok;
-exec ${JSON.stringify(process.execPath)}, ${JSON.stringify(bnu)}, "ls", @ARGV;
+exec ${JSON.stringify(process.execPath)}, ${JSON.stringify(commandEntry)}, @ARGV;
die "exec ls failed: $!\\n";
`
- : `#!/bin/sh\n${wrapperMetaFastPath}exec ${bun} "${bnu}" ${shellQuote(command)} "$@"\n`;
+ : `#!/bin/sh\n${wrapperMetaFastPath}exec ${bun} "${commandEntry}" "$@"\n`;
await writeFile(path, script);
await chmod(path, 0o755);
}
await writeFile(join(dir, "env-js"), `#!${process.execPath}
-import { main } from ${JSON.stringify(coreutils)};
-process.exit(await main(["env", ...Bun.argv.slice(2)]));
+import command from ${JSON.stringify(pathToFileURL(join(commandRoot, "env.js")).href)};
+process.exit(await command(Bun.argv.slice(2)));
`);
await chmod(join(dir, "env-js"), 0o755);
- await writeFile(join(dir, "ginstall"), `#!/bin/sh\n${metaFastPath}exec ${bun} "${bnu}" ginstall "$@"\n`);
+ await writeFile(join(dir, "ginstall"), `#!/bin/sh\n${metaFastPath}exec ${bun} "${join(commandRoot, "ginstall.js")}" "$@"\n`);
await chmod(join(dir, "ginstall"), 0o755);
await writeFile(join(dir, "getlimits"), `#!/bin/sh
cat <<'EOF'
diff --git a/scripts/run-memory-bounded.js b/scripts/run-memory-bounded.js
index 9dc74c2..b9ba2e7 100644
--- a/scripts/run-memory-bounded.js
+++ b/scripts/run-memory-bounded.js
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
const args = process.argv.slice(2);
const rssLimit = parseByteSize(takeValue("--rss-limit") ?? "1GiB");
-const memoryLimit = parseByteSize(takeValue("--memory-limit") ?? "3GiB");
+const memoryLimit = parseByteSize(takeValue("--memory-limit") ?? "4GiB");
if (args[0] === "--") args.shift();
if (args.length === 0) {
console.error("usage: run-memory-bounded.js [--rss-limit SIZE] [--memory-limit SIZE] -- COMMAND [ARG]...");
diff --git a/scripts/run-qemu-root-smoke.sh b/scripts/run-qemu-root-smoke.sh
index 0aa1790..07ec01f 100755
--- a/scripts/run-qemu-root-smoke.sh
+++ b/scripts/run-qemu-root-smoke.sh
@@ -43,7 +43,7 @@ fi
mkdir -p "$root/opt/bnu/bin" "$root/opt/bnu/src" "$root/usr/bin"
cp "$bun" "$root/usr/bin/bun"
cp "$repo/bin/bnu.js" "$root/opt/bnu/bin/bnu.js"
-cp "$repo/src/coreutils.js" "$root/opt/bnu/src/coreutils.js"
+cp -R "$repo/src/." "$root/opt/bnu/src/"
ldd "$bun" | awk '/=> \/[^ ]+/ { print $3 } /^\// { print $1 }' | while IFS= read -r library; do
test -n "$library" || continue