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

Constants overwrite environment #2448

Closed
JonathanDoughty opened this issue Nov 2, 2024 · 4 comments
Closed

Constants overwrite environment #2448

JonathanDoughty opened this issue Nov 2, 2024 · 4 comments

Comments

@JonathanDoughty
Copy link

While testing some recipes that rely on environment variables

env:
    @env | sort

being the simplest example I can use I unexpectedly encountered

HEX=0123456789abcdef 
HEXLOWER=0123456789abcdef
HEXUPPER=0123456789ABCDEF

Curious as to where these came from I eventually tracked them down -- not to some tool that was part of my normal environment set up but to just internals added in ##2054

just being able to provide constants is, I suppose, fine (though why these merit a special definition is unclear; HEXLOWER and HEXUPPER seem superfluous to me and I wonder what slippery slope of constants may be in just's future). Exporting justconstants to recipes seems like a surprise waiting to happen, however. Under the current implementation, if the project environment I set up happens to use one of just's current or future constants then the result of set export is that my expected environment gets over-ridden in those cases. Future additions to just constants causing changed recipe execution is the scenario I anticipate.

Possible alternatives:

  1. not export constants into the environment; or
  2. constants not override any key already in the environment that set export creates; or
  3. provide an explicit set export-constants or set export-no-constants for users who want/don't want that.

I don't know how easy any of those would be given rust's apparent OnceLock implementation. At the least, in my opinion, just's documentation on Constants should mention that these overwrite other environment definitions, and that users can override just "constants" with variable definitions if necessary.

@casey
Copy link
Owner

casey commented Nov 2, 2024

Thanks for the report! This is definitely a bug. Constants are supposed to be just variables only, i.e., not exported to the environment.

@casey
Copy link
Owner

casey commented Nov 2, 2024

Ahh, okay, do you have set export somewhere in your justfile? I suspect that's what's causing them to be exported. In any case, it's still a bug, since even with set export, I don't think constants that the user did not define should be exported.

@casey
Copy link
Owner

casey commented Nov 2, 2024

Fixed in #2449!

@casey casey closed this as completed Nov 2, 2024
@casey
Copy link
Owner

casey commented Nov 2, 2024

The purpose of these constants, by the way is, with the choose(n, alphabet) function, which chooses n characters from the string alphabet. So you can generate a hex string, for example, with choose(32, HEXLOWER).

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

No branches or pull requests

2 participants