-
Notifications
You must be signed in to change notification settings - Fork 507
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
Consider making just
variables environment variables 🔥
#313
Comments
just
variables environment variables 🔥
I like that the Or maybe command line switch with that sort of functionality. But that would be more cumbersome. I use |
Here's an interesting idea, how about if prefixing a recipe argument with a
This would allow users to choose if they wanted arguments to be exported. It would also fix the asymmetry where it's possible to export variables with |
@cc Fleshgrinder |
This was in #245 where I was talking about it. GNU make does not pollute the environment by default unless there is a lonely It’s own environment does get polluted with the shell’s environment but I’ve never in more than 10 years had a problem with that. Either one allows overrides ( There are also per target variables and exports:
|
@Fleshgrinder What do you think about
|
Would my example from above work with your idea?
In other words, is |
Not by default. You'd have to use the much messier:
Something like:
Is difficult to support in the parser, since after the parser sees For scoped variables on a per recipe basis, possibilities include modules:
In a possible future with modules, Some way of introducing a scope on a per-recipe basis in which variables can be constructed is a feature that's been requested a few times. It could be supported with something like:
or
I think I am warming up to a |
I see, I think that
Looks a little weird with the many dollar signs… Regarding scopes, I assume the recipe in your last example would need to be called as
|
The export keyword is very readable, and I think would still serve an important purpose if more
Anonymous scopes in that case are a bit unintuitive for me. It's not immediately obvious to me why recipes in that scope escape, but variables don't. I think that's why I favor syntax that puts the recipe name outside of the block:
|
But what if I would like to share certain variables in a scope with multiple recipes? This is possible in GNU make:
|
Thanks, that's an interesting example. That's pretty nutty, I didn't know about the extra I'm not entirely sure how that would be best supported. I can see how that's a useful feature for make though. I can't think of another language that has similar functionality, i.e. a statement that makes values visible in other constructs selectively. It's almost like an
Make's syntax for this could not be adopted directly. Since make doesn't have arguments, in I would probably reach for some kind of block syntax:
But again, we would have unbounded lookahead to disambiguate between Commas might be the answer:
Since then |
The extra colon is a pretty handy feature in general. I mostly use make as a task runner (that’s why I like just [besides the fact that it’s made with Rust]) and almost all my targets are using double colons because it also makes the target unconditional. Kind of invalidates the argument against make in the just README. 😋 |
Yeah, but it's probably better not to have to learn the obscure and non-obvious difference between |
💯% agree, GNU make is a very weird piece of software but as to date the most efficient task runner available. Now we just have to make sure that just becomes more efficient. 😉 |
I reread the issue, and it sounds like you propose two features. 1. Importing environment variables by default and making them just variables and 2. exporting variables by default making just variables available to sub-processes. I'm mostly against importing variables into just because that means that hidden state from the environment leaks into your build process. If you on the other hand are required to specify them as arguments they will always be obvious. For exporting variables to sub-processes I think it would make sense to have some special syntax to avoid polluting the sub-process with unintended variables. |
@NickeZ Thanks for clarifying. I think 1. isn't necessary, since we have the For 2., I updated the issue with a proposal for a setting which would make trigger export for all variables and parameters, namely:
(I recently added the This would be a fairly simple feature, and would be convenient for people who wanted to opt into export for an entire justfile. I'm definitely sympathetic to the argument that it's not ideal for just to pollute sub-processes with variables that they won't use. However, the quoting issue seems rather thorny, i.e. that variable interpolations with spaces and special characters must be quoted. Switching to environment variables would effectively solve the quoting problem, and although polluting downstream environments with extra variables is not ideal, I'm not sure if it's something which often has a negative effect or causes usability problems in practice. I could see |
I think I'm going to close this. I personally find the argument of not polluting subprocess environments to be compelling. I would however like some syntax for exporting recipe arguments (Like |
I just released v0.8.6, with two features that allow exporting more Just variables as environment variables. Parameters can now be prefixed with foo $bar:
echo $bar And adding set export
a := "foo"
baz $b:
echo $a
echo $b |
Also, there's another good reason not to make just variables environment variables. Just a few days ago, @alefbragin mentioned that it would be nice if there was a way to pass arguments as positional arguments. If this is implemented, this will provide another way of dealing with hard-to-escape values, i.e. refer to them as positional arguments, e.g. |
I've long thought that it was good for
just
variables to be distinct from environment variables. However, I've grown increasingly unsure of that decision.Pros of
just
variables being distinct from environment variables:{{..}}
are reported at compile time, not at runtime. (However, because just invokessh
with the-u
flag, misspelled variables would produce an error at runtime, instead of evaluating to the empty string.)"{{VAR}}"
instead ofimport os; os.getenv("VAR")
.export
.echo foo
instead ofecho $variable_name
.Cons of
just
variables being distinct from environment variables:a=b just foo
to set variablea
, must usejust a=b foo
orjust --set a b foo
.{{VAR}}
instead of the shorter and more common$VAR
.FOO
is empty, thencmd {{FOO}} a b c
will runcmd a b c
, whereas ifFOO
were an environment variable,cmd $FOO a b c
would runcmd "" a b c
.On balance, I think it's better for
just
variables to be environment variables. The benefits aren't huge, and quoting and escaping feel like a thorny issue.My current thinking is that this should be supported with a per-justfile setting, and a command line flag, either of which would trigger export of all variables and parameters:
This way, users who preferred this behavior could opt in to it. Eventually, if we so desired, it could be made the default behavior after a deprecation period.
What do people think? There was an issue that I can't find at the moment where someone wanted this (I think it was @Fleshgrinder) and I argued for the opposite, but I've started to come around.
The text was updated successfully, but these errors were encountered: