Repository navigation
Set environment variables through the workspace - #1147
Conversation
|
The feature itself is good, but I'm a bit concerned that we don't do dependency tracking at the env level. It seems to me that we should really be implementing dependency on env vars first, and then have ways of setting them. |
|
What do you mean by dependency tracking at the env level? |
Just that changing the environment in the env stanza will trigger a rebuild. |
What about |
As discussed in #205, this environment will also be used during the build (I haven't added a test for this yet). |
|
Well, build commands are also executed. There's also |
|
OK, I'll first deal with tracking |
1261ebd to
5338a1f
Compare
|
I just rebased now that env tracking works correctly. I have two questions:
Thanks! |
It's to represent i.e. to allow the user to customize individual build contexts.
Like this: field "env_vars" ~default:[] (Syntax.since syntax (1, 4) >>> list ...) |
d814b60 to
b4e1eaa
Compare
|
Thanks for the answers @diml. I added some tests for variables set from |
|
I'm coming late to the discussion, but will this feature allow setting variables such as |
|
@nojb yes that's the plan. However for PATH there might be some particular handling to do since PATH is also interpreted by dune itself. |
4cb241a to
29d1257
Compare
|
@emillon the context specific variables are more specific, so they should have precedence over the workspace ones |
29d1257 to
778b4b6
Compare
|
Do we need a test case for setting the env-vars in an env stanza of a dune file? Or is that tested elsewhere? |
|
Right, that would be nice. Plus, we need some docs and that should be good. |
|
Ah yes, the docs are definitely required for this to go in the release. Up to you if you want to do them in a separate PR or not. |
|
@emillon could you give this a rebase? I'd like to have a look on top of the up to date code. |
| { flags : Ordered_set_lang.Unexpanded.t | ||
| ; ocamlc_flags : Ordered_set_lang.Unexpanded.t | ||
| ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t | ||
| ; env_vars : (string * string) list |
There was a problem hiding this comment.
Wouldn't it be better if it was just Env.t?
778b4b6 to
add0783
Compare
|
@rgrinberg I just rebased. I'm changing to use Env.t and add other tests (such as what happens when there are duplicate keys). |
|
Setting env vars from dune files is trickier since this relies on the supercontext for the dir -> env_node mapping, so I'll leave that part out of the PR. |
3968bcf to
98329f8
Compare
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Closes #205 Signed-off-by: Etienne Millon <[email protected]>
98329f8 to
5479f2e
Compare
* Set environment variables through the workspace Closes ocaml#205 Signed-off-by: Etienne Millon <[email protected]>
env vars defined in a (context ...) stanza are documented to have higher precedence than env vars defined in the root env stanza of a workspace. The prose in the cram test also indicates this, but the test asserted incorrect precedence. This seems to have been indicated in a review comment [here] and marked done, but may have been undone by an incorrect rebase or something. Only consumers of Super_context.context_env like `dune exec` were affected by this. Rules were not affected since they resolved their environment separately through `Env_node.external_env` which is not affected by this bug. [here]: ocaml#1147 (comment)
env vars defined in a (context ...) stanza are documented to have higher precedence than env vars defined in the root env stanza of a workspace. The prose in the cram test also indicates this, but the test asserted incorrect precedence. This seems to have been indicated in a review comment [here] and marked done, but may have been undone by an incorrect rebase or something. Only consumers of Super_context.context_env like `dune exec` were affected by this. Rules were not affected since they resolved their environment separately through `Env_node.external_env` which is not affected by this bug. [here]: ocaml#1147 (comment) Signed-off-by: Puneeth Chaganti <[email protected]>
<!-- Thank you for contributing to dune! For general guidelines on contributing to dune, see https://github.com/ocaml/dune/blob/main/CONTRIBUTING.md#developing-dune --> ## Description <!-- Briefly describe your changes --> env vars defined in a (context ...) stanza are documented to have higher precedence than env vars defined in the root env stanza of a workspace. The prose in the cram test also indicates this, but the test asserted incorrect precedence. This seems to have been indicated in a review comment [here] and marked done, but may have been undone by an incorrect rebase or something. Only consumers of Super_context.context_env like `dune exec` were affected by this. Rules were not affected since they resolved their environment separately through `Env_node.external_env` which is not affected by this bug. [here]: #1147 (comment) ## Related Issue and Motivation <!-- Why is this change required? What problem does it solve? --> <!-- If it closes an open issue, link to the issue here. --> <!-- Non-trivial contributions are expected to be preceded by an issue, as per CONTRIBUTING.md. --> This issue was discovered while working on #15381 ## Checklist - [ ] Tests added, if applicable. - [x] [Change log entry added](../CONTRIBUTING.md#updating-the-changelog) for any user-facing changes. - [ ] Documentation added for any user-facing changes.
This is a first step towards #205.
The idea is that we add some extra environment variables to
context.envinContext.create. These are sourced from(env).Outstanding problems for now:
(env (_ (env (k v)))).environment_variablesis precise but too long. Maybeenv_varscould work?Super_contextlevel, but we don't have a super-context when doingdune exec. Shall I moveEnv_nodeout ofSuper_contextso that we can use that inheritance inContextas well?env_nodes, there is aworkspacecomponent and acontextcomponent.workspacecorresponds to what is set indune-workspace, but what is thecontextone?Thanks!