Exemplo n.º 1
0
func Test_BuildState_BuildTargets_unsignable_target(t *testing.T) {
	// if we run an action that is supposed to build a target, but the
	// target is unreadable (doesn't exist, permission denied, ...),
	// then the build fails immediately
	snode := dag.NewStubNode("source")
	tnode := NewUnsignableNode("target")
	graph := dag.NewDAG()
	graph.AddNode(snode)
	graph.AddNode(tnode)
	graph.AddParent(tnode, snode)
	executed := addTrackingRules(graph)
	graph.MarkSources()

	sig := []byte{0}
	db := makeFakeDB(graph, sig)
	opts := BuildOptions{}
	bstate := NewBuildState(graph, db, opts)

	// target gets built; the build fails after that, calculating its
	// signature
	goal := graph.MakeNodeSet("target")
	expect := []buildexpect{
		{"target", dag.BUILT},
	}
	err := bstate.BuildTargets(goal)
	assert.Equal(t,
		"could not compute signature of target \"target\": nah", err.Error())
	assertBuild(t, graph, expect, *executed)
}
Exemplo n.º 2
0
// return a barebones Runtime with almost nothing in it -- variable
// assignment and lookup works, but not much else
func minimalRuntime() *Runtime {
	stack := types.NewValueStack()
	locals := types.NewValueMap()
	stack.Push(locals)
	return &Runtime{
		stack: &stack,
		dag:   dag.NewDAG(),
	}
}
Exemplo n.º 3
0
func Test_joinNodes(t *testing.T) {
	graph := dag.NewDAG()
	nodes := mknodelist(graph, "blargh", "merp", "whoosh", "fwob", "whee")

	assert.Equal(t,
		`"blargh", "merp", "whoosh", "fwob", "whee"`,
		joinNodes(", ", 10, nodes))
	assert.Equal(t,
		`"blargh", "merp", "whoosh", "fwob", "whee"`,
		joinNodes(", ", 5, nodes))
	assert.Equal(t,
		`"blargh", "merp", "whoosh", ...`,
		joinNodes(", ", 4, nodes))
	assert.Equal(t,
		`"blargh"!*!"merp"!*!...`,
		joinNodes("!*!", 3, nodes))
}
Exemplo n.º 4
0
func Test_BuildError_Error(t *testing.T) {
	graph := dag.NewDAG()
	err := &BuildError{}
	err.attempts = 43
	err.failed = mknodelist(
		graph, "foo", "bar", "baz")
	assert.Equal(t,
		`failed to build 3 of 43 targets: "foo", "bar", "baz"`, err.Error())
	err.attempts = -1
	assert.Equal(t,
		`failed to build target: "foo"`, err.Error())

	err.attempts = 17
	err.failed = mknodelist(
		graph, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k")
	assert.Equal(t,
		`failed to build 11 of 17 targets: "a", "b", "c", "d", "e", "f", "g", "h", "i", ...`,
		err.Error())
}
Exemplo n.º 5
0
func NewRuntime(
	options build.BuildOptions, script string, ast *dsl.ASTRoot) *Runtime {
	stack := types.NewValueStack()

	builtins := defineBuiltins()
	stack.Push(builtins)

	// Local variables are per-script, but we only support a single
	// script right now. So might as well initialize the script-local
	// namespace right here.
	locals := types.NewValueMap()
	stack.Push(locals)

	return &Runtime{
		options:  options,
		script:   script,
		ast:      ast,
		builtins: builtins,
		stack:    &stack,
		dag:      dag.NewDAG(),
	}
}