gvvaughan / luke

A light-weight, self-bootstrapping software build utility.
MIT License
20 stars 3 forks source link

Update environment.lua #6

Closed sosie-js closed 2 months ago

sosie-js commented 2 months ago

Adds the possibility to change $PREFIX from os ENV.

This responds to the doc $PREFIX and my need described in https://github.com/gvvaughan/luke/issues/5

gvvaughan commented 2 months ago

Thanks for taking the time to propose a PR! You rock :-)

Hopefully you can proceed without the need for this given my response in https://github.com/gvvaughan/luke/issues/5. But to expand on that a bit, I don't think I'm the only one who has been bitten by programs that take arguments out of the environment that misbehave when they react to something I set for some other unrelated task weeks ago and forgot to remove from the environment when I changed tasks. Or by something that I had working for months break after staringt a fresh terminal because I lost some environment setting it was quietly depending on to work correctly.

I much prefer the approach that make, autoconf and now luke use by passing those VAR=value configurations explicitly in the invocation (although make still looks in the environment for otherwise unset VARs which is a shame).

sosie-js commented 2 months ago

Hello @gvvaughan

See my proposal, it fetches luarocks config and give a way to switch to local; PREFIX="--local" ./build-aux/luke lukefile install all a mimic of --local / --global behavior of luarock install but for luke. Handles as well the case if luarock is not present.

gvvaughan commented 2 months ago

I worry about letting the environment PREFIX value deeply affect the operation of luke. And supporting magic values that assume installation of luarocks might confuse our users too. If you want to use luke with luarocks, I recommend adding a rockspec and calling luke from there with PREFIX set appropriately.

Or alternatively, since the output of luarocks config is valid Lua code already, you can do this:

$ prefix=$(lua -e "$(luarocks config)" -e 'for k, v in next,rocks_trees do if v.name == "user" then print(v.root) end end')
$ echo $prefix
/Users/gvv/.luarocks
$ build-aux/luke PREFIX=${PREFIX-"$prefix"} all install

If you do this often, and don't want to type in all that code every time, you could put in your own wrapper script:

$ cat ~/bin/luke
#! /bin/sh
case $1 in
    --local) shift; name=user ;;
    --global) shift; name=system ;;
esac

test -z "$name" || {
    prefix=$(lua -e "$(luarocks config)" -e "for k, v in next,rocks_trees do if v.name == '$name' then print(v.root) end end")
    set -- PREFIX=${PREFIX-"$prefix"} ${1+"$@"}
}

exec build-aux/luke ${1+"$@"}

$ ~/bin/luke --local all install
gvvaughan commented 2 months ago

Aside: In case you find it interesting, here's my subprocess handler: https://github.com/gvvaughan/specl/blob/master/lib/specl/shell.lua#L111-L134

sosie-js commented 2 months ago

Seems we reached the same approach for launching a process, nice shot with you shell script which is easier to read. Thanks a lot for your advices and comments.