pub struct Vars { /* private fields */ }Expand description
Wrap a HashMap and a default blank value, providing an easy way to get variables, handling
special and automatic variables properly.
Implementations§
Source§impl Vars
impl Vars
Sourcepub fn new<const N: usize>(init: [(&str, &str); N]) -> Self
pub fn new<const N: usize>(init: [(&str, &str); N]) -> Self
Primary interface for configuring a new instance. We also create some cached values that live for the lifetime of this instance to reduce the number of allocations.
Sourcepub fn new_without_builtins<const N: usize>(init: [(&str, &str); N]) -> Self
pub fn new_without_builtins<const N: usize>(init: [(&str, &str); N]) -> Self
Like new, but omits make’s built-in tool variables (CC, CFLAGS,
COMPILE.c, …) for -R/--no-builtin-variables. The operational specials
(.RECIPEPREFIX, .SHELLFLAGS, SHELL, and the suffix list) are always defined so make
can still run recipes; env/makefile/command-line definitions are unaffected.
Sourcepub fn get(&self, k: impl AsRef<str>) -> &Var
pub fn get(&self, k: impl AsRef<str>) -> &Var
Public interface for getting variables. For unknown keys, the blank object is returned. We
should try to keep this interface as fast/simple as possible since it’s used far more often
than set (e.g., used for each line to check for recipe prefix).
Sourcepub fn is_set(&self, k: impl AsRef<str>) -> bool
pub fn is_set(&self, k: impl AsRef<str>) -> bool
Whether a variable is currently defined (including defaults and environment). Used to
implement ?= (set-if-undefined) and to pick +=’s behavior.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &Var)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &Var)>
Iterate over every defined variable as (name, &Var). Used by export-all and $(...)
introspection.
Sourcepub fn remove(&mut self, k: impl AsRef<str>) -> Option<Var>
pub fn remove(&mut self, k: impl AsRef<str>) -> Option<Var>
Remove a variable (for the undefine directive). Returns its prior Var, if any.
Sourcepub fn clear_call_params(&mut self)
pub fn clear_call_params(&mut self)
Remove the positional call parameters ($(0), $(1), …): every variable whose name is
all ASCII digits. $(call ...) uses this so a nested call does not inherit higher-numbered
parameters from the enclosing call.
Sourcepub fn set<S: Into<String>>(
&mut self,
k: S,
v: S,
recursive: bool,
) -> Result<(), String>
pub fn set<S: Into<String>>( &mut self, k: S, v: S, recursive: bool, ) -> Result<(), String>
Public interface for setting variables. The origin is recorded as File (a makefile
assignment); use Vars::set_origin for other origins.
Sourcepub fn set_origin<S: Into<String>>(
&mut self,
k: S,
v: S,
recursive: bool,
origin: Origin,
) -> Result<(), String>
pub fn set_origin<S: Into<String>>( &mut self, k: S, v: S, recursive: bool, origin: Origin, ) -> Result<(), String>
Set a variable, recording where it came from (for $(origin ...)).
Sourcepub fn set_exported(&mut self, k: impl AsRef<str>)
pub fn set_exported(&mut self, k: impl AsRef<str>)
Mark a variable exported into recipe child environments (a target-specific export VAR).
The variable is expected to already exist; if not, this is a no-op.
Source§impl Vars
impl Vars
Sourcepub fn from_env(env: Env, builtin_vars: bool, env_override: bool) -> Self
pub fn from_env(env: Env, builtin_vars: bool, env_override: bool) -> Self
Build the variable set from the OS environment. builtin_vars is false under -R, which
omits make’s built-in variables so they do not shadow (or appear as) real definitions.
env_override is true under -e, which ranks environment variables above makefile
assignments: a later unconditional makefile assignment to an environment variable is
rejected and its origin becomes EnvironmentOverride (see
set_origin).