Directory reorg: move code into redo/, generate binaries in bin/.

It's time to start preparing for a version of redo that doesn't work
unless we build it first (because it will rely on C modules, and
eventually be rewritten in C altogether).

To get rolling, remove the old-style symlinks to the main programs, and
rename those programs from redo-*.py to redo/cmd_*.py.  We'll also move
all library functions into the redo/ dir, which is a more python-style
naming convention.

Previously, install.do was generating wrappers for installing in
/usr/bin, which extend sys.path and then import+run the right file.
This made "installed" redo work quite differently from running redo
inside its source tree.  Instead, let's always generate the wrappers in
bin/, and not make anything executable except those wrappers.

Since we're generating wrappers anyway, let's actually auto-detect the
right version of python for the running system; distros can't seem to
agree on what to call their python2 binaries (sigh). We'll fill in the
right #! shebang lines.  Since we're doing that, we can stop using
/usr/bin/env, which will a) make things slightly faster, and b) let us
use "python -S", which tells python not to load a bunch of extra crap
we're not using, thus improving startup times.

Annoyingly, we now have to build redo using minimal/do, then run the
tests using bin/redo.  To make this less annoying, we add a toplevel
./do script that knows the right steps, and a Makefile (whee!) for
people who are used to typing 'make' and 'make test' and 'make clean'.
This commit is contained in:
Avery Pennarun 2018-12-03 21:39:15 -05:00
commit f6fe00db5c
140 changed files with 256 additions and 99 deletions

3
bin/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
list
redo
redo-*

3
bin/all.do Normal file
View file

@ -0,0 +1,3 @@
exec >&2
redo-ifchange ../redo/version/all ../redo/python list redo-sh
xargs redo-ifchange <list

1
bin/clean.do Normal file
View file

@ -0,0 +1 @@
rm -f redo redo-* list whichpython

33
bin/default.do Normal file
View file

@ -0,0 +1,33 @@
exec >&2
case $1 in
redo-sh)
redo-ifchange ../redo/sh
cat >$3 <<-EOF
#!/bin/sh
d=\$(dirname "\$0")/..
[ -x \$d/lib/redo/sh ] && exec \$d/lib/redo/sh "\$@"
[ -x \$d/redo/sh ] && exec \$d/redo/sh "\$@"
echo "\$0: fatal: can't find \$d/lib/redo/sh or \$d/redo/sh" >&2
exit 98
EOF
chmod a+x "$3"
;;
redo|redo-*)
redo-ifchange ../redo/whichpython
read py <../redo/whichpython
cmd=${1#redo-}
cat >$3 <<-EOF
#!$py -S
import sys, os;
exe = os.path.realpath(os.path.abspath(sys.argv[0]))
exedir = os.path.dirname(exe)
sys.path.insert(0, os.path.join(exedir, '../lib'))
sys.path.insert(0, os.path.join(exedir, '..'))
import redo.cmd_$cmd
redo.cmd_$cmd.main()
EOF
chmod a+x "$3"
;;
*) echo "$0: don't know how to build '$1'" >&2; exit 99 ;;
esac

16
bin/list.do Normal file
View file

@ -0,0 +1,16 @@
exec >&2
redo-always
(
cd ../redo
for d in cmd_*.py; do
d=${d#cmd_}
d=${d%.py}
if [ "$d" = "redo" ]; then
echo redo
else
echo "redo-${d%.py}"
fi
done
) >$3
redo-stamp <$3