Skip to content

Conversation

@ptomato
Copy link
Contributor

@ptomato ptomato commented Jan 4, 2024

This adds two options, configureEnvironment and testEnvironment, allowing users to set particular environment variables during meson setup and meson test.

Closes: #9

@ptomato
Copy link
Contributor Author

ptomato commented Jan 4, 2024

I'm not really sure if this is the right way to do it, so please be zealous in reviewing it 😄

@PterX
Copy link

PterX commented Jan 29, 2024

any update here?

@tristan957
Copy link
Member

Yeah... that's my bad. Let me get to it this week.

@PterX
Copy link

PterX commented Jan 30, 2024

Yeah... that's my bad. Let me get to it this week.

thx

options: cp.ExecFileOptions = { shell: true },
) {
if (extraEnv) {
options.env = { ...(options.env ?? process.env), ...extraEnv };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I don't understand the node API here, if we pass an environment object, does it not also inherit the parent environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure. The documentation says, about the env option:

env: Environment key-value pairs. Default: process.env.

So because the default is process.env and not {}, I'd guess that options.env replaces the parent environment. (That also makes sense because otherwise, you couldn't delete environment variables.)

@tristan957
Copy link
Member

Just a few comments, and then it should be good to go. It would also be useful if you could add an entry in the CHANGELOG.md file. Otherwise, I can get to it after merge.

This setting allows setting extra environment variables during the
setup stage.
It's already possible to add environment variables in the 'options'
argument — but child_process.execFile() does not treat options.env as
extra environment variables to add. It replaces the environment with
options.env entirely. So, it's convenient to have an extraEnv argument
with variables to add.

This will be necessary for the testEnvironment setting added in the next
commit.
This setting allows setting extra environment variables while running
meson test, as well as individual tests.
Consistently replace 'Meson setup' -> 'setup' as pointed out in code
review. Improve phrasing for mesonbuild.buildFolder.
@ptomato ptomato force-pushed the 9-environment-variables branch from d02cfce to f44631d Compare February 12, 2024 03:37
@tristan957 tristan957 merged commit b7162ce into mesonbuild:main Mar 9, 2024
@ptomato ptomato deleted the 9-environment-variables branch March 9, 2024 16:41
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

Successfully merging this pull request may close these issues.

Custom environment variables for meson configuration

3 participants