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

Add env: argument to custom_target, run_target, run_command #2723

Closed
Salamandar opened this issue Dec 1, 2017 · 8 comments
Closed

Add env: argument to custom_target, run_target, run_command #2723

Salamandar opened this issue Dec 1, 2017 · 8 comments

Comments

@Salamandar
Copy link
Contributor

Salamandar commented Dec 1, 2017

The env argument available for tests would be really useful for custom_targets too.

index_html_tmp = custom_target('index.html.tmp',
  input : [ babl_html_dump, ],
  output: [ 'index.html.tmp', ],
  command: [ 'bash', '-c',
    'BABL_PATH="' + join_paths(meson.build_root(), 'extensions') +'"'
    + ' ' + babl_html_dump.full_path()
  ],
  capture: true,
)

would be changed to

index_html_tmp = custom_target('index.html.tmp',
  input : [ ],
  output: [ 'index.html.tmp', ],
  command: [ babl_html_dump ],
  env: [ 'BABL_PATH="' + join_paths(meson.build_root(), 'extensions') +'"' ],
  capture: true,
)
@TingPing
Copy link
Member

TingPing commented Dec 1, 2017

command: [ 'bash', '-c',
'BABL_PATH="' + join_paths(meson.build_root(), 'extensions') +'"'
+ ' ' + babl_html_dump.full_path()
],

In the short term use env not bash -c for obvious reasons.

command: [
  find_program('env'),
  'BABL_PATH=' + join_paths(meson.build_root(), 'extensions'),
  babl_html_dump
]

@Salamandar
Copy link
Contributor Author

Salamandar commented Dec 2, 2017

Great, that also allows to split the commands from a single string to multiple strings. (and even use '&&' !)
That's still a workaround though.

@jtojnar
Copy link
Contributor

jtojnar commented Jan 20, 2019

Apparently, the issue is that ninja does not have a way to set environment variables in cross-platform way: #541 (comment)

gnomesysadmins pushed a commit to GNOME/dia that referenced this issue Jan 28, 2019
  - This will help when custom_target will support custom environment
    mesonbuild/meson#2723
@gdesmott
Copy link

Dup of #266

@Salamandar
Copy link
Contributor Author

@gdesmott Not exactly, mine is about run_target too.

@marc-h38
Copy link
Contributor

marc-h38 commented Jan 17, 2020

Not exactly, mine is about run_target too.

Looking at what's been done already, it seems a different github issue/PR is needed for every command.

@rossburton
Copy link
Contributor

Had a quick look at this. For the simple case of run_target gaining an env argument, would a sensible approach be to extend commandrunner to take --env=FOO=BAR and simply pass the added environment variables to the invocation in the ninja generator. The commandrunner can then do the same as run_command to construct the final environment:

child_env = os.environ.copy()

elmarco added a commit to elmarco/qemu that referenced this issue Sep 11, 2020
The environment variables can't be passed through an env: argument
yet (meson#2723), use 'env' as suggested in:
mesonbuild/meson#2723 (comment)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
stsquad pushed a commit to stsquad/qemu that referenced this issue Sep 30, 2020
The environment variables can't be passed through an env: argument
yet (meson#2723), use 'env' as suggested in:
mesonbuild/meson#2723 (comment)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@eli-schwartz
Copy link
Member

Duplicate of #266, solved by #8235 and #8305

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

8 participants