diff --git a/Makefile b/Makefile index dd078c4..86b11e9 100644 --- a/Makefile +++ b/Makefile @@ -66,9 +66,15 @@ pkg-debug: @: $${L} $${T} make pkg-build L=$(L) T=$(T) CMD=bash +ifneq (,$(Z)) +NO_COMPRESS := +else +NO_COMPRESS := -Znone +endif + pkg-deb: @: $${L} $${T} - fakeroot dpkg-deb --build $(BUILD)/pkg $(BUILD)/$(DEB) + fakeroot dpkg-deb --build $(NO_COMPRESS) $(BUILD)/pkg $(BUILD)/$(DEB) pkg: pkg-clean pkg-build pkg-deb @@ -113,7 +119,7 @@ endif install: @: $${L} $${T} if [[ -z "$$(ls -A /var/lib/apt/lists)" ]]; then sudo apt update; fi - sudo apt reinstall -y ./$(BUILD)/$(DEB) + DEBIAN_FRONTEND=noninteractive sudo -E apt reinstall -y ./$(BUILD)/$(DEB) installs: @: $${L} diff --git a/backend/sandbox.bash b/backend/sandbox.bash index 051216f..31f96ff 100644 --- a/backend/sandbox.bash +++ b/backend/sandbox.bash @@ -15,16 +15,20 @@ function has { get "$@" | grep -vq '^null$' } +function riju-exec { + bash -c "set -euo pipefail; $1" +} + function daemon { - has daemon && eval "$(get daemon)" + has daemon && riju-exec "$(get daemon)" } function setup { - has setup && eval "$(get setup)" + has setup && riju-exec "$(get setup)" } function repl { - has repl && eval "$(get repl)" + has repl && riju-exec "$(get repl)" } function main { @@ -35,11 +39,11 @@ function main { } function compile { - has compile && echo "$(get compile)" && eval "$(get compile)" + has compile && echo "$(get compile)" && riju-exec "$(get compile)" } function run-only { - has run && echo "$(get run)" && eval "$(get run)" + has run && echo "$(get run)" && riju-exec "$(get run)" } function run { @@ -47,12 +51,12 @@ function run { } function format { - has format && echo "$(get format.run)" && eval "( $(get format.run) ) < $(get main)" + has format && echo "$(get format.run)" && riju-exec "( $(get format.run) ) < $(get main)" } function lsp { - has lsp.setup && echo "$(get lsp.setup)" && eval "$(get lsp.setup)" - has lsp && echo "$(get lsp.start)" && eval "$(get lsp.start)" + has lsp.setup && echo "$(get lsp.setup)" && riju-exec "$(get lsp.setup)" + has lsp && echo "$(get lsp.start)" && riju-exec "$(get lsp.start)" } if [[ -z "$NS" ]]; then diff --git a/backend/util.js b/backend/util.js index 42bb783..789f22c 100644 --- a/backend/util.js +++ b/backend/util.js @@ -114,7 +114,7 @@ export function privilegedTeardown({ uid, uuid }) { } export function bash(cmdline) { - if (!cmdline.match(/[;|&(){}=]/)) { + if (!cmdline.match(/[;|&(){}=\n]/)) { // Reduce number of subshells we generate, if we're just running a // single command (no shell logic). cmdline = "exec " + cmdline; diff --git a/langs/ada.yaml b/langs/ada.yaml index 9b30fae..4b381b2 100644 --- a/langs/ada.yaml +++ b/langs/ada.yaml @@ -33,9 +33,9 @@ install: wget https://dl.bintray.com/reznikmm/ada-language-server/linux-latest.tar.gz tar -xf linux-latest.tar.gz install -d "${pkg}/usr/local/bin" - install -d "${pkg}/usr/lib/x86_64-linux-gnu" + install -d "${pkg}/usr/local/lib/x86_64-linux-gnu" mv linux/ada_language_server "${pkg}/usr/local/bin/ada_language_server" - mv linux/*.so* "${pkg}/usr/lib/x86_64-linux-gnu/" + mv linux/*.so* "${pkg}/usr/local/lib/x86_64-linux-gnu/" main: "main.adb" template: | diff --git a/langs/ante.yaml b/langs/ante.yaml index 94200fe..b52c279 100644 --- a/langs/ante.yaml +++ b/langs/ante.yaml @@ -20,6 +20,8 @@ install: # error: unrecognized command-line option ‘-Wnewline-eof’. CC=/usr/bin/clang CXX=/usr/bin/clang++ llvmenv build-entry -G Makefile -j$(nproc) 10.0.0 llvmenv global 10.0.0 + apt: + - gcc manual: | git clone https://github.com/jfecher/ante.git pushd ante @@ -36,7 +38,7 @@ setup: | main: "main.an" template: | - puts("Hello, world!".cStr) + print "Hello, world!" compile: | ante main.an diff --git a/langs/aspectc++.yaml b/langs/aspectc++.yaml index aa07ba1..0d5a5bd 100644 --- a/langs/aspectc++.yaml +++ b/langs/aspectc++.yaml @@ -6,6 +6,7 @@ name: "AspectC++" install: apt: - aspectc++ + - libstdc++-9-dev main: "main.cpp" template: | @@ -17,6 +18,6 @@ template: | } compile: | - ag++ main.cpp -o main | (grep -v "TO BE FIXED" || true) + CPLUS_INCLUDE_PATH=/usr/include/c++/9 ag++ main.cpp -o main run: | ./main diff --git a/langs/battlestar.yaml b/langs/battlestar.yaml index 735f529..3dd29dd 100644 --- a/langs/battlestar.yaml +++ b/langs/battlestar.yaml @@ -24,6 +24,14 @@ install: - golang apt: - yasm + manual: | + install -d "${pkg}/usr/local/bin" + git clone https://github.com/xyproto/battlestar.git + pushd battlestar + make + cp cmd/battlestarc/battlestarc "${pkg}/usr/local/bin/" + cp scripts/bts.sh "${pkg}/usr/local/bin/bts" + popd main: "main.bts" template: | diff --git a/langs/beatnik.yaml b/langs/beatnik.yaml index 3ddfe3a..3daa2f8 100644 --- a/langs/beatnik.yaml +++ b/langs/beatnik.yaml @@ -1,6 +1,15 @@ id: "beatnik" name: "Beatnik" +install: + apt: + - python2 + manual: | + install -d "${pkg}/usr/local/bin" + git clone https://github.com/catseye/Beatnik.git + sed -i 's#env python#env python2#' Beatnik/script/beatnik.py + cp Beatnik/script/beatnik.py "${pkg}/usr/local/bin/beatnik" + info: impl: "Cat's Eye Beatnik" year: 2001 diff --git a/langs/befunge.yaml b/langs/befunge.yaml index df840f1..1a980b9 100644 --- a/langs/befunge.yaml +++ b/langs/befunge.yaml @@ -7,6 +7,34 @@ install: npm: - befunge93 - prompt-sync + scripts: + befunge: | + #!/usr/bin/env -S NODE_PATH=/opt/befunge93/lib/node_modules:/opt/prompt-sync/lib/node_modules node + const fs = require("fs"); + + const Befunge = require("befunge93"); + const prompt = require("prompt-sync")(); + + const befunge = new Befunge(); + befunge.onInput = prompt; + befunge.onOutput = (output) => { + if (typeof output === "string") { + process.stdout.write(output); + } else { + process.stdout.write(output + " "); + } + }; + + const args = process.argv.slice(2); + if (args.length !== 1) { + console.error("usage: befunge FILE"); + process.exit(1); + } + + befunge.run(fs.readFileSync(args[0], { encoding: "utf-8" })).catch((err) => { + console.error(err); + process.exit(1); + }); info: impl: "amicloud Befunge-93" @@ -39,4 +67,4 @@ template: | 64+"!dlrow ,olleH">:#,_@ run: | - befunge-repl main.be + befunge main.be diff --git a/tools/ci-run.bash b/tools/ci-run.bash index f9b0801..def5839 100755 --- a/tools/ci-run.bash +++ b/tools/ci-run.bash @@ -4,4 +4,4 @@ set -euo pipefail echo "${DOCKER_PASSWORD}" | sudo -E docker login --username "${DOCKER_USERNAME}" --password-stdin -make publish +make publish Z=1 diff --git a/tools/generate-build-script.js b/tools/generate-build-script.js index 5c05e36..3399343 100644 --- a/tools/generate-build-script.js +++ b/tools/generate-build-script.js @@ -1,3 +1,4 @@ +import nodePath from "path"; import process from "process"; import { Command } from "commander"; @@ -15,47 +16,72 @@ import { readLangConfig, readSharedDepConfig } from "./config.js"; // package riju-shared-foo rather than a language installation // package. function makeLangScript(langConfig, isShared) { - const { - id, - name, - install: { prepare, apt, riju, pip, manual, deb }, - } = langConfig; + const { id, name, install } = langConfig; let parts = []; parts.push(`\ #!/usr/bin/env bash set -euxo pipefail`); - if (prepare) { - const { apt, manual } = prepare; - if (apt && apt.length > 0) { - parts.push(`\ + let depends = []; + if (install) { + const { prepare, apt, riju, npm, pip, deb, scripts, manual } = install; + if (prepare) { + const { apt, manual } = prepare; + if (apt && apt.length > 0) { + parts.push(`\ export DEBIAN_FRONTEND=noninteractive sudo apt-get update sudo apt-get install -y ${apt.join(" ")}`); + } + if (manual) { + parts.push(manual); + } + } + if (npm) { + for (const fullname of npm) { + const basename = fullname.replace(/^[^\/]+\//g, ""); + parts.push(`\ +install -d "\${pkg}/usr/local/bin" +install -d "\${pkg}/opt/${basename}/lib" +npm install ${fullname} -g --prefix "\${pkg}/opt/${basename}" +if [[ -d "$\{pkg}/opt/${basename}/bin" ]]; then + ls "$\{pkg}/opt/${basename}/bin" | while read name; do + if readlink "\${pkg}/opt/${basename}/bin/\${name}" | grep -q '/${fullname}/'; then + ln -s "/opt/${basename}/bin/\${name}" "\${pkg}/usr/local/bin/\${name}" + fi + done +fi`); + } + } + if (deb) { + parts.push( + deb.map((deb) => `dpkg-deb --extract "${deb}" "\${pkg}"`).join("\n") + ); + } + if (scripts) { + for (const [script, contents] of Object.entries(scripts)) { + const path = "${pkg}" + nodePath.resolve("/usr/local/bin", script); + parts.push(`install -d "\${pkg}/usr/local/bin" +cat <<"RIJU-EOF" > "${path}" +${contents} +RIJU-EOF +chmod +x "${path}"`); + } } if (manual) { parts.push(manual); } - } - if (manual) { - parts.push(manual); - } - if (deb) { - parts.push( - deb.map((deb) => `dpkg-deb --extract "${deb}" "\${pkg}"`).join("\n") - ); - } - let depends = []; - if (apt) { - depends = depends.concat(apt); - } - if (riju) { - depends = depends.concat(riju.map((name) => `riju-shared-${name}`)); - } - if (deb) { - depends = depends.concat( - deb.map((fname) => `\$(dpkg-deb -f "${fname}" Depends)`) - ); + if (apt) { + depends = depends.concat(apt); + } + if (riju) { + depends = depends.concat(riju.map((name) => `riju-shared-${name}`)); + } + if (deb) { + depends = depends.concat( + deb.map((fname) => `\$(dpkg-deb -f "${fname}" Depends)`) + ); + } } parts.push(`depends=(${depends.map((dep) => `"${dep}"`).join(" ")})`); let debianControlData = `\