-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add env kwarg in generator.process()
- Loading branch information
Showing
10 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## generator.process() gains 'env' keyword argument | ||
|
||
Like the kwarg of the same name in `custom_target()`, `env` allows | ||
you to set the environment in which the generator will process inputs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test cases/common/272 env in generator.process/generate_main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import sys | ||
|
||
ENV_VAR_VALUE = os.environ.get('ENV_VAR_VALUE') | ||
assert ENV_VAR_VALUE is not None | ||
|
||
with open(sys.argv[1], 'r') as infile, \ | ||
open(sys.argv[2], 'w') as outfile: | ||
|
||
outfile.write(infile.read().replace('ENV_VAR_VALUE', ENV_VAR_VALUE)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main(void) { | ||
return ENV_VAR_VALUE; | ||
} |
21 changes: 21 additions & 0 deletions
21
test cases/common/272 env in generator.process/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
project('test_env_in_generator_process', 'c') | ||
|
||
generate_main_py = find_program('generate_main.py') | ||
|
||
main_generator = generator(generate_main_py, | ||
arguments: ['@INPUT@', '@OUTPUT@'], | ||
output: '@BASENAME@' + '.c' | ||
) | ||
|
||
main_template = files('main.template') | ||
|
||
# With explicit values | ||
my_executable = executable('myexecutable', main_generator.process(main_template, env: {'ENV_VAR_VALUE': '0'})) | ||
test('explicit_value', my_executable) | ||
|
||
# With env object | ||
env = environment() | ||
env.set('ENV_VAR_VALUE', '0') | ||
|
||
my_executable2 = executable('myexecutable2', main_generator.process(main_template, env: env)) | ||
test('env_object', my_executable2) |