@@ -1,10 +1,17 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
# Usage: create a file foo.c, make foo a symlink to this script | # Usage: create a file foo.c, make foo a symlink to this script | ||||
# When foo is executed, this script silently compiles foo.c into .make-and-exec-binaries/foo and execs that with the arguments provided. | |||||
# The compilation goes through make, so later invocations directly exec the binary with little delay. | |||||
# When foo is executed, this script silently compiles foo.c into .make-and-exec-binaries/foo (if necessary) and execs that with the arguments provided. | |||||
# Making a symlink named foo-dbg causes it to compile foo.c with -DDEBUG. | |||||
# To customise the compilation, you can set a CFLAGS env var before running foo. | # To customise the compilation, you can set a CFLAGS env var before running foo. | ||||
set -e | |||||
name="$(basename "$0")" | |||||
cd "$(dirname "$0")" | |||||
make --file .make-and-exec-Makefile --silent ".make-and-exec-binaries/${name}" | |||||
exec "./.make-and-exec-binaries/${name}" "$@" | |||||
sourcename="${0%-dbg}.c" | |||||
if [[ "$0" == *-dbg ]]; then opt='-O0 -DDEBUG'; else opt='-O3'; fi | |||||
targetfile="$(dirname "$0")/.make-and-exec-binaries/$(basename "$0")" | |||||
if [[ ! -f "${targetfile}" || "${sourcename}" -nt "${targetfile}" ]]; then | |||||
mkdir -p "$(dirname "$0")/.make-and-exec-binaries" | |||||
gcc ${opt} ${CFLAGS} -o "${targetfile}" "${sourcename}" || exit | |||||
testfile="$(dirname "$0")/.$(basename "${0%-dbg}")-test" | |||||
if [[ -f "${testfile}" ]]; then | |||||
"${testfile}" || { st=$?; touch -d '1970-01-01T00:00:00Z' "${targetfile}"; exit "${st}"; } | |||||
fi | |||||
fi | |||||
exec "${targetfile}" "$@" |
@@ -1,4 +0,0 @@ | |||||
.make-and-exec-binaries/%: %.c | |||||
mkdir -p .make-and-exec-binaries | |||||
$(CC) -O3 -o $@ $< $(CFLAGS) | |||||
[ -f ./.$(notdir $(@))-test ] && ./.$(notdir $(@))-test || true |
@@ -1,11 +1,12 @@ | |||||
#!/usr/bin/python3 | #!/usr/bin/python3 | ||||
import io | import io | ||||
import itertools | import itertools | ||||
import os.path | |||||
import subprocess | import subprocess | ||||
def test(input, output): | def test(input, output): | ||||
p = subprocess.Popen(['./.make-and-exec-binaries/urldecode'], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE) | |||||
p = subprocess.Popen([os.path.join(os.path.dirname(__file__), '.make-and-exec-binaries', 'urldecode')], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE) | |||||
stdout, stderr = p.communicate(input) | stdout, stderr = p.communicate(input) | ||||
assert not stderr | assert not stderr | ||||
assert stdout == output | assert stdout == output | ||||
@@ -1,10 +1,11 @@ | |||||
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
import itertools | import itertools | ||||
import os.path | |||||
import subprocess | import subprocess | ||||
def test(input, lines): | def test(input, lines): | ||||
p = subprocess.Popen(['./.make-and-exec-binaries/youtube-extract-rapid'], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE) | |||||
p = subprocess.Popen([os.path.join(os.path.dirname(__file__), '.make-and-exec-binaries', 'youtube-extract-rapid'], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE) | |||||
stdout, stderr = p.communicate(input) | stdout, stderr = p.communicate(input) | ||||
assert not stderr | assert not stderr | ||||
stdout = stdout.split(b'\n') | stdout = stdout.split(b'\n') | ||||