buildkit/build_llb/build_env.go
buildkit/build_llb/build_env.goBrowse 1970 files
285 tokens
1,185 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package build_llb2 3import (4 "maps"5 "slices"6)7 8type BuildEnvironment struct {9 PathList []string10 EnvVars map[string]string11}12 13func NewGraphEnvironment() BuildEnvironment {14 return BuildEnvironment{15 PathList: make([]string, 0),16 EnvVars: make(map[string]string),17 }18}19 20// Merges the other environment into the current environment21func (e *BuildEnvironment) Merge(other BuildEnvironment) {22 e.PathList = appendUniquePaths(e.PathList, other.PathList...)23 maps.Copy(e.EnvVars, other.EnvVars)24}25 26func appendUniquePaths(existing []string, additions ...string) []string {27 // Steps with shared ancestors inherit the same paths, so merging their outputs can28 // otherwise duplicate entries in downstream steps and the final image PATH. Keep29 // the first occurrence to preserve path precedence.30 for _, path := range additions {31 if slices.Contains(existing, path) {32 continue33 }34 existing = append(existing, path)35 }36 return existing37}38 39func (e *BuildEnvironment) PushPath(path string) {40 if slices.Contains(e.PathList, path) {41 return42 }43 e.PathList = append([]string{path}, e.PathList...)44}45 46func (e *BuildEnvironment) AddEnvVar(key, value string) {47 e.EnvVars[key] = value48}49