Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update environment.lua #6

Closed
wants to merge 5 commits into from
Closed

Conversation

sosie-js
Copy link

Adds the possibility to change $PREFIX from os ENV.

This responds to the doc $PREFIX and my need described in #5

Adds the possibility to change $PREFIX from os ENV
@gvvaughan
Copy link
Owner

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

Hopefully you can proceed without the need for this given my response in #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” added 2 commits July 25, 2024 20:18
…e: PREFIX="--local" ./build-aux/luke lukefile install all
@sosie-js
Copy link
Author

sosie-js commented Jul 25, 2024

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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.

@sosie-js sosie-js closed this Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants