func graphDotAddRoot(buf *bytes.Buffer, n *depgraph.Noun) {
	buf.WriteString(fmt.Sprintf("\t\"%s\" [shape=circle];\n", "root"))

	for _, e := range n.Edges() {
		target := e.Tail()
		buf.WriteString(fmt.Sprintf(
			"\t\"%s\" -> \"%s\";\n",
			"root",
			target))
	}
}
Beispiel #2
0
// nounAddVariableDeps updates the dependencies of a noun given
// a set of associated variable values
func nounAddVariableDeps(
	g *depgraph.Graph,
	n *depgraph.Noun,
	vars map[string]config.InterpolatedVariable,
	removeSelf bool) {
	for _, v := range vars {
		// Only resource variables impose dependencies
		rv, ok := v.(*config.ResourceVariable)
		if !ok {
			continue
		}

		// Find the target
		target := g.Noun(rv.ResourceId())
		if target == nil {
			continue
		}

		// If we're ignoring self-references, then don't add that
		// dependency.
		if removeSelf && n == target {
			continue
		}

		// Build the dependency
		dep := &depgraph.Dependency{
			Name:   rv.ResourceId(),
			Source: n,
			Target: target,
		}

		n.Deps = append(n.Deps, dep)
	}
}
Beispiel #3
0
func graphWriteEdges(
	buf *bytes.Buffer, n *depgraph.Noun, opts *GraphDotOpts) {
	tab := strings.Repeat("\t", opts.depth+1)

	uniqueName := graphUniqueName(n, opts)
	var ltail string
	if _, ok := n.Meta.(*GraphNodeModule); ok && graphExpand(opts) {
		ltail = "cluster_" + uniqueName
		uniqueName = uniqueName + "_hidden"
	}

	for _, e := range n.Edges() {
		target := e.Tail()
		targetN := target.(*depgraph.Noun)
		uniqueTarget := graphUniqueName(targetN, opts)

		var lhead string
		if _, ok := targetN.Meta.(*GraphNodeModule); ok && graphExpand(opts) {
			lhead = "cluster_" + uniqueTarget
			uniqueTarget = uniqueTarget + "_hidden"
		}

		var attrs string
		if lhead != "" || ltail != "" {
			var attrList []string
			if lhead != "" {
				attrList = append(attrList, fmt.Sprintf(
					"lhead=\"%s\"", lhead))
			}
			if ltail != "" {
				attrList = append(attrList, fmt.Sprintf(
					"ltail=\"%s\"", ltail))
			}

			attrs = fmt.Sprintf(" [%s]", strings.Join(attrList, ","))
		}

		buf.WriteString(fmt.Sprintf(
			"%s\"%s\" -> \"%s\"%s;\n",
			tab,
			uniqueName,
			uniqueTarget,
			attrs))
	}
}