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

No environment variable reordering with profiles #985

Open
stormshield-guillaumed opened this issue Nov 7, 2023 · 4 comments
Open

No environment variable reordering with profiles #985

stormshield-guillaumed opened this issue Nov 7, 2023 · 4 comments
Assignees

Comments

@stormshield-guillaumed
Copy link
Contributor

Describe The Bug

Unlike what is written here in the README, variable evaluation doesn't seem to be reordered with profiles.

To Reproduce

Assuming you have cargo-make 0.37.4 installed, use this Makefile.toml :

[env]
VAR1="${VAR2}"

[env.prod]
VAR2=2

[env.devel]
VAR2=3

[tasks.hello]
command = "echo"
args = ["VAR1=${VAR1}", "VAR2=${VAR2}"]

And use those commands :

cargo make -p test hello
cargo make -p prod hello
cargo make -p devel hello

Expected behavior

cargo-make prints :

$ cargo make -p test hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: test
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=${VAR2}" "VAR2=${VAR2}"
VAR1=${VAR2} VAR2=${VAR2}
[cargo-make] INFO - Build Done in 0.14 seconds.

$ cargo make -p prod hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: prod
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=2" "VAR2=2"
VAR1=2 VAR2=2
[cargo-make] INFO - Build Done in 0.13 seconds.

$ cargo make -p devel hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: devel
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=3" "VAR2=3"
VAR1=3 VAR2=3
[cargo-make] INFO - Build Done in 0.13 seconds.

Actual behavior

cargo-make prints :

$ cargo make -p test hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: test
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=${VAR2}" "VAR2=${VAR2}"
VAR1=${VAR2} VAR2=${VAR2}
[cargo-make] INFO - Build Done in 0.14 seconds.

$ cargo make -p prod hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: prod
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=${VAR2}" "VAR2=2"
VAR1=${VAR2} VAR2=2
[cargo-make] INFO - Build Done in 0.13 seconds.

$ cargo make -p devel hello
[cargo-make] INFO - cargo make 0.37.4
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: hello
[cargo-make] INFO - Profile: devel
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "echo" "VAR1=${VAR2}" "VAR2=3"
VAR1=${VAR2} VAR2=3
[cargo-make] INFO - Build Done in 0.13 seconds.

Related issue

I can open another issue if you want, but maybe this is related to the same thing. The first example in the same section of the README works unless you use the ${VAR:} syntax like so :

[env]
VAR1="${VAR2:}"
VAR2=2
@sagiegurari
Copy link
Owner

I'll check it. i have to admit, i can't remember how this works as this changed so many times.
however, i don't remember ever having or documenting ${VAR:} as supported

@stormshield-guillaumed
Copy link
Contributor Author

I admit I dug the source code to find the ${VAR:default} syntax was available here, but I didn't find it in the documentation

@sagiegurari
Copy link
Owner

@stormshield-guillaumed that place calls envmnt which is another lib of mine and there i do have some support for it (forgot about it).
and the support there is for ${var:some default} and can't remember if i supported empty strings.

@stormshield-guillaumed
Copy link
Contributor Author

The substitution by the empty string when the variable is unset seems to work, it just breaks the reordering of variables.
As for the first problem, I didn't took the time to dig the code to try to find the problem, did you had time ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants