Igalia / pflua

Packet filtering in Lua
Other
313 stars 39 forks source link

Add an env script so that tools can be run from any directory. #169

Closed kbara closed 9 years ago

wingo commented 9 years ago

Do you think it's better to generate it? For me it could make sense to just check it into git. Dunno. E.g. I have this for one of my projects:

#!/bin/bash

function prepend {
    local var=$1; shift
    local sep=$1; shift
    local i; for i in "$@"; do
        if test -z "${!var}"; then
            export "$var=$i"
        else
            export "$var=$i$sep${!var}"
        fi
    done
}

thisdir=$(cd $(dirname $0) && pwd)

prepend PACKAGES ' ' $(basename $thisdir)
prepend PKG_CONFIG_PATH : $thisdir/lib/pkgconfig
prepend LTDL_LIBRARY_PATH : $thisdir/lib
prepend LD_LIBRARY_PATH : $thisdir/lib
prepend PATH : $thisdir/bin
prepend ACLOCAL_FLAGS ' ' "-I $thisdir/share/aclocal"

exec "$@"

We'd only need PATH and LUAPATH of course. And there are ways to do it without the prepend helper. But it does make sense to be sure to augment the paths, instead of re-setting them.

kbara commented 9 years ago

The question, to me, is "do we want an env script (yet), or not?"

If we do, and we're happy to use shell, your suggested one is superior in every way. I fully agree about prepending. This patch generates the script because the equivalent of setting $thisdir is really ugly in Lua, as far as I can tell; if we use shell instead, that's a non-issue, and it doesn't break if someone moves the directory.

kbara commented 9 years ago

This is obsolete; I've created https://github.com/Igalia/pflua/pull/173 , based on the template you provided. :)