Environment (env
)
This object is returned by environment()
and stores
detailed information about how environment variables should be set.
It should be passed as the env
keyword argument to tests and other functions.
Since 0.58.0 env.append()
and env.prepend()
can be called multiple times
on the same varname
. Earlier Meson versions would warn and only the last
operation took effect.
Returned by
Environment objects are returned by the following functions and methods:
Example
```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')
```
Environment methods
env.append()
appends the given values to
the old value of the environment variable, e.g. env.append('FOO', 'BAR', 'BAZ', separator : ';')
produces BOB;BAR;BAZ
if FOO
had
the value BOB
and plain BAR;BAZ
if the value was not defined.
Signature
# appends the given values to
void append(
str variable, # The variable to modify
str Value..., # The values to append
# Keyword arguments:
separator : str # The separator to use
)
Arguments
The method env.append()
accepts the following positional arguments:
Name | Type | Description | Tags |
---|---|---|---|
variable |
str |
The variable to modify |
|
Additionally, the
method accepts between 0
and infinity
variadic
arguments (Value...
) of type
.str
The values to append
Finally, env.append()
accepts the following keyword arguments:
Name | Type | Description | Tags |
---|---|---|---|
separator |
str |
The separator to use. If not explicitly specified, the default path separator for the host operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems. |
|
env.prepend()
Same as append
except that it writes to the beginning of the variable.
Signature
# Same as `append` except that it writes to the beginning of the variable
void prepend(
str variable, # The variable to modify
str Value..., # The values to prepend
# Keyword arguments:
separator : str # The separator to use
)
Arguments
The method env.prepend()
accepts the following positional arguments:
Name | Type | Description | Tags |
---|---|---|---|
variable |
str |
The variable to modify |
|
Additionally, the
method accepts between 0
and infinity
variadic
arguments (Value...
) of type
.str
The values to prepend
Finally, env.prepend()
accepts the following keyword arguments:
Name | Type | Description | Tags |
---|---|---|---|
separator |
str |
The separator to use. If not explicitly specified, the default path separator for the host operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems. |
|
env.set()
Sets the environment variable
specified in the first argument to the values in the varargs
joined by the separator. For instance, env.set('FOO', 'BAR'),
sets envvar
FOO
to value BAR
.
Signature
# Sets the environment variable
void set(
str variable, # The variable to modify
str Value..., # The values to set
# Keyword arguments:
separator : str # The separator to use
)
Arguments
The method env.set()
accepts the following positional arguments:
Name | Type | Description | Tags |
---|---|---|---|
variable |
str |
The variable to modify |
|
Additionally, the
method accepts between 0
and infinity
variadic
arguments (Value...
) of type
.str
The values to set
Finally, env.set()
accepts the following keyword arguments:
Name | Type | Description | Tags |
---|---|---|---|
separator |
str |
The separator to use. If not explicitly specified, the default path separator for the host operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems. |
|
env.unset()
Unset the specified environment variable. If this variable does not exist, nothing happens.
Signature
(since 1.4.0)
void unset()
The results of the search are