2016-11-16 02:42:22 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
2016-11-29 00:15:49 +01:00
|
|
|
package compiler
|
2016-11-16 02:42:22 +01:00
|
|
|
|
|
|
|
import (
|
2016-11-16 18:29:44 +01:00
|
|
|
"github.com/marapongo/mu/pkg/ast"
|
2016-11-29 00:15:49 +01:00
|
|
|
"github.com/marapongo/mu/pkg/compiler/backends"
|
2016-11-29 22:42:39 +01:00
|
|
|
"github.com/marapongo/mu/pkg/util"
|
2016-11-16 02:42:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Context holds all state available to any templates or code evaluated at compile-time.
|
|
|
|
type Context struct {
|
2016-11-29 22:42:39 +01:00
|
|
|
Cluster *ast.Cluster // the cluster that we will deploy to.
|
2016-11-29 00:15:49 +01:00
|
|
|
Arch backends.Arch // the target cloud architecture.
|
2016-11-25 21:58:29 +01:00
|
|
|
Properties ast.PropertyBag // properties supplied at stack construction time.
|
|
|
|
}
|
|
|
|
|
2016-11-29 22:42:39 +01:00
|
|
|
// NewContext returns a new, empty context.
|
|
|
|
func NewContext() *Context {
|
|
|
|
return &Context{
|
|
|
|
Properties: make(ast.PropertyBag),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithClusterArch returns a clone of this Context with the given cluster and architecture attached to it.
|
|
|
|
func (c *Context) WithClusterArch(cl *ast.Cluster, a backends.Arch) *Context {
|
|
|
|
util.Assert(cl != nil)
|
|
|
|
return &Context{
|
|
|
|
Cluster: cl,
|
|
|
|
Arch: a,
|
|
|
|
Properties: c.Properties,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithProps returns a clone of this Context with the given properties attached to it.
|
2016-11-25 21:58:29 +01:00
|
|
|
func (c *Context) WithProps(props ast.PropertyBag) *Context {
|
2016-11-29 22:42:39 +01:00
|
|
|
util.Assert(props != nil)
|
2016-11-25 21:58:29 +01:00
|
|
|
return &Context{
|
2016-11-29 22:42:39 +01:00
|
|
|
Cluster: c.Cluster,
|
|
|
|
Arch: c.Arch,
|
2016-11-25 21:58:29 +01:00
|
|
|
Properties: props,
|
|
|
|
}
|
2016-11-16 02:42:22 +01:00
|
|
|
}
|