-
Notifications
You must be signed in to change notification settings - Fork 376
fix: Override environment variables based on priority #3940
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
fix: Override environment variables based on priority #3940
Conversation
|
I find the priority order of As required, we need to change the priority order. So I need to pass the second parameter to To test whether the override function works, I constructed a hash map called opt_map, it has the key "CMAKE_ARGS" and the value "Foo123". Before After Expected behavior: |
c963cd4 to
0886b67
Compare
|
This change will introduce an issue for a use case we supported previously. That is the use of environment variables as arguments for functions. e.g.: [tasks.start]
cmd = "echo $ARG"
env = { ARG="default" }Usage: Users could define their task like that. With this change that use-case will break and will always have the default value. We currently support arguments. But these are not named, only positional. So to get something like this working: [tasks.problem]
cmd = "echo {{ ARG1}} {{ ARG2 }} {{ ARG3 }}"
args = [
{arg = "ARG1", default = "default1"},
{arg = "ARG2", default = "default2"},
{arg = "ARG3", default = "default3"}
]You need to run the following The problem arrises when you only want to override the 3 option. you need to do: I think before we break that other behavior we need to improve the ux of tasks. As there is no way to define named variables right now. There is one more trick people could use: [tasks.trick]
cmd = "echo {{ ARG }}"
args = [{arg = "ARG", default = "$ARG"}]This would bring back the use of environment variables. But it doesn't allow a user to set a default as the evaluation happens after the template replacement. ProposalI think we can already improve this experience with a few convincing features:
@Hofer-Julian & @magentaqin please let me know what you think. When we merge this we should see if it introduces really non-working setups and work to improve the UX of tasks as required. |
b6a5b74 to
9186613
Compare
|
Hi, @ruben-arts! Thanks for your suggestion. My Question
If you run
From my understanding, this satisfies our expectation.
My ProposalBased on your proposal, my proposal is: Then when you run like this:
2.Support both default value and environment variable. Then when you run like this:
3.Support
|
5c63837 to
c8bc900
Compare
e96b34a to
c8bc900
Compare
Hofer-Julian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks promising at first glance.
Added a few comments for now, one of them might be the cause of your Windows struggles.
Will do a more extensive review next round
382b459 to
35cdb9f
Compare
acb9791 to
1499388
Compare
Hofer-Julian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clean up the tests a bit. Will then focus on the actual implementation.
Good work so far!
|
I think there are more than one problem here for windows and in general for the logic of priority listing.
Should be more than enough. This will also limit the COMMAND_ENV and TASK_SPECIFIC_ENVS additions where you can safely delete them and just get them from the activation/runtime instead.
etc. before exporting them as combined env variables (before export push str) |
|
(^▽^)わくわく, @zelosleone! Thanks for your great effort on this PR and nice suggestion.👍🏻 1.For the exported script, I agree with u. Now I update my strategy: only export the statement that has key in Based on the above updates, the test pipeline on windows passed! 👏🏻
|
304022c to
b74990b
Compare
[skip ci]
[skip ci]
|
EDIT: never mind, I think we can get by with positional args there |
Hi, Julian. I saw the test you added! |
The test is about variable expansion and that needs to work before we can merge this PR :) |
|
@Hofer-Julian So now the priority should be |
I don't think there is anything to do with priority that needs changing! The problem is that
So I think there is just a bug in the evaluation/expansion of env var values which has been introduced in this PR. |
| // Extract variable name | ||
| fn extract_variable_name(value: &str) -> Option<&str> { | ||
| if let Some(inner) = value.strip_prefix('$') { | ||
| Some(inner) | ||
| } else if let Some(inner) = value.strip_prefix('%').and_then(|s| s.strip_suffix('%')) { | ||
| Some(inner) | ||
| } else if let Some(inner) = value.strip_prefix("${").and_then(|s| s.strip_suffix('}')) { | ||
| Some(inner) | ||
| } else { | ||
| None | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hofer-Julian do you know if we already have something like this elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least after a quick look at our code base, I wouldn't be able to find it
|
@Hofer-Julian @lucascolley I think the doc would be better if we put it into
|
|
I think we should keep the migration guidance under tasks as it replaces what is made obsolete by this PR, and we can link out to the examples and full description of priority in the env var section. I can push a commit! |
|
let me know if that looks okay to you @magentaqin ! |
Hofer-Julian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @magentaqin!
Thanks also to @lucascolley for reviewing!
It looks good to me! Thanks! |
Thanks @Hofer-Julian @lucascolley and @zelosleone for reviewing! ❤️ |
…-dev#3940)" This reverts commit 23fa3f5.


Description
This PR is created to solve Environment variable of tasks are broken when defined in surrounding scope , Unit tests and integration
What functionality changes I made
1.Change the priority of environment variables
Original Order(highest to lowest):
activation scripts > activation.env > activation scripts of dependencies > environment variables > task specific envs
Current Order(highest to lowest):
task specific envs > activation scripts > activation.env > activation scripts of dependencies > environment variables
2.What code changes I made
1)
get_export_specific_task_envfunction refactor inexecutable_task.rs.Previously,
std::env::varhas deterministic issues. So I updatedget_export_specific_task_envto let it explicitly receive the parametercommand_env.priorityarray: store the keys of the environment variable map. For extension, as in the future, there may be other kinds of environment variable map passing in.env_mapmap:and we can merge the map according to the priority order. Finally, we get the
export_mergedarray and export all the environment variables to the shell.I also add escape logic and exclude environment variables that can't be overidden.
2)
run_activationinactivation.rsprocess the
activator.run_activation()result and handling the overidden stuff.TO FIX
Test compatibility issues on windows platform, which causes the pipeline fails.