vars

package
v0.0.0-...-ff9afc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package vars implement lucicfg.var() support.

See lucicfg.var() doc for more info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultRewriter

func GetDefaultRewriter() *build.Rewriter

GetDefaultRewriter will return the default rewriter with basic rewriter properties

Types

type ID

type ID int

ID is an opaque starlark value that represents a lucifg.var() variable.

It is just a unique identifier for this particular variable, used as a key in a map with variables values.

func (ID) Freeze

func (v ID) Freeze()

func (ID) Hash

func (v ID) Hash() (uint32, error)

func (ID) String

func (v ID) String() string

func (ID) Truth

func (v ID) Truth() starlark.Bool

func (ID) Type

func (v ID) Type() string

type Vars

type Vars struct {
	// DeclaredExposeAsAliases is a set of all `exposeAs` passed to Declare.
	DeclaredExposeAsAliases stringset.Set
	// contains filtered or unexported fields
}

Vars holds definitions and current state of lucicfg.var() variables.

It exposes OpenScope/CloseScope that should be connected to PreExec/PostExec interpreter hooks. They "open" and "close" scopes for variables: all changes made to vars state within a scope (i.e. within single exec-ed module) are discarded when the scope is closed.

func (*Vars) ClearValues

func (v *Vars) ClearValues()

ClearValues resets values of all variables, in all scopes.

Should be used only from tests that want a clean slate.

func (*Vars) CloseScope

func (v *Vars) CloseScope(th *starlark.Thread)

CloseScope discards changes made to variables since the matching OpenScope.

func (*Vars) Declare

func (v *Vars) Declare(th *starlark.Thread, exposeAs string, presetVal starlark.Value) (ID, error)

Declare allocates a new variable, setting it right away to 'presetVal' value if 'exposeAs' not empty.

Variables that were pre-set during declaration are essentially immutable throughout lifetime of the interpreter.

Returns an error if a variable with the same `exposeAs` name has already been exposed.

func (*Vars) Get

func (v *Vars) Get(th *starlark.Thread, id ID, def starlark.Value) (starlark.Value, error)

Get returns the value of a variable, auto-initializing it to 'def' if it was unset before.

Variable can be assigned or read only from threads that perform 'exec' calls, NOT when loading library modules via 'load' (the library modules must not have side effects or depend on a transient state in vars), or executing callbacks (callbacks do not have enough context to safely use vars).

func (*Vars) OpenScope

func (v *Vars) OpenScope(th *starlark.Thread)

OpenScope opens a new scope for variables.

All changes to variables' values made within this scope are discarded when it is closed.

func (*Vars) Set

func (v *Vars) Set(th *starlark.Thread, id ID, value starlark.Value) error

Set sets the value of a variable within the current scope iff the variable was unset before (in the current or any parent scopes).

Variable can be assigned or read only from threads that perform 'exec' calls, NOT when loading library modules via 'load' (the library modules must not have side effects or depend on a transient state in vars), or executing callbacks (callbacks do not have enough context to safely use vars).

Freezes the value as a side effect.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL