environment(): Allow stacking append() and prepend() (#8547)
* environment(): Allow stacking append() and prepend() * Update docs/markdown/Reference-manual.md Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>pull/8573/head
parent
de9df5128c
commit
1be13710ad
9 changed files with 48 additions and 43 deletions
@ -0,0 +1,16 @@ |
||||
## Multiple append() and prepend() in `environment()` object |
||||
|
||||
`append()` and `prepend()` methods can now be called multiple times |
||||
on the same `varname`. Earlier Meson versions would warn and only the last |
||||
opperation was taking effect. |
||||
|
||||
```meson |
||||
env = environment() |
||||
|
||||
# MY_PATH will be '0:1:2:3' |
||||
env.set('MY_PATH', '1') |
||||
env.append('MY_PATH', '2') |
||||
env.append('MY_PATH', '3') |
||||
env.prepend('MY_PATH', '0') |
||||
``` |
||||
|
@ -0,0 +1,6 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os |
||||
|
||||
assert os.environ['MY_PATH'] == os.pathsep.join(['0', '1', '2']) |
||||
|
@ -1,12 +0,0 @@ |
||||
project('test env var stacking') |
||||
|
||||
testenv = environment() |
||||
testenv.set('TEST_VAR_SET', 'some-value') |
||||
testenv.set('TEST_VAR_APPEND', 'some-value') |
||||
testenv.set('TEST_VAR_PREPEND', 'some-value') |
||||
|
||||
testenv.append('TEST_VAR_APPEND', 'another-value-append', separator: ':') |
||||
testenv.prepend('TEST_VAR_PREPEND', 'another-value-prepend', separator: ':') |
||||
testenv.set('TEST_VAR_SET', 'another-value-set') |
||||
|
||||
test('check env', find_program('script.py'), env: testenv) |
@ -1,9 +0,0 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os |
||||
|
||||
for name in ('append', 'prepend', 'set'): |
||||
envname = 'TEST_VAR_' + name.upper() |
||||
value = 'another-value-' + name |
||||
envvalue = os.environ[envname] |
||||
assert (envvalue == value), (name, envvalue) |
Loading…
Reference in new issue