示例#1
0
func printTempDirs(state *core.BuildState, duration float64) {
	fmt.Printf("Temp directories prepared, total time %0.2fs:\n", duration)
	for _, label := range state.ExpandOriginalTargets() {
		target := state.Graph.TargetOrDie(label)
		cmd := build.ReplaceSequences(target, target.GetCommand())
		env := core.BuildEnvironment(state, target, false)
		fmt.Printf("  %s: %s\n", label, target.TmpDir())
		fmt.Printf("    Command: %s\n", cmd)
		fmt.Printf("   Expanded: %s\n", os.Expand(cmd, core.ReplaceEnvironment(env)))
	}
}
示例#2
0
func runTest(state *core.BuildState, target *core.BuildTarget) ([]byte, error) {
	replacedCmd := build.ReplaceTestSequences(target, target.GetTestCommand())
	env := core.BuildEnvironment(state, target, true)
	if len(state.TestArgs) > 0 {
		args := strings.Join(state.TestArgs, " ")
		replacedCmd += " " + args
		env = append(env, "TESTS="+args)
	}
	log.Debug("Running test %s\nENVIRONMENT:\n%s\n%s", target.Label, strings.Join(env, "\n"), replacedCmd)
	_, out, err := core.ExecWithTimeoutShell(target.TestDir(), env, target.TestTimeout, state.Config.Test.Timeout, state.ShowAllOutput, replacedCmd)
	return out, err
}
示例#3
0
func runContainerisedTest(state *core.BuildState, target *core.BuildTarget) ([]byte, error) {
	testDir := path.Join(core.RepoRoot, target.TestDir())
	replacedCmd := build.ReplaceTestSequences(target, target.GetTestCommand())
	replacedCmd += " " + strings.Join(state.TestArgs, " ")
	containerName := state.Config.Docker.DefaultImage
	if target.ContainerSettings != nil && target.ContainerSettings.DockerImage != "" {
		containerName = target.ContainerSettings.DockerImage
	}
	// Gentle hack: remove the absolute path from the command
	replacedCmd = strings.Replace(replacedCmd, testDir, "/tmp/test", -1)
	// Fiddly hack follows to handle docker run --rm failing saying "Cannot destroy container..."
	// "Driver aufs failed to remove root filesystem... device or resource busy"
	cidfile := path.Join(testDir, ".container_id")
	// Using C.UTF-8 for LC_ALL because it works. Not sure it's strictly
	// correct to mix that with LANG=en_GB.UTF-8
	command := []string{"docker", "run", "--cidfile", cidfile, "-e", "LC_ALL=C.UTF-8"}
	if target.ContainerSettings != nil {
		if target.ContainerSettings.DockerRunArgs != "" {
			command = append(command, strings.Split(target.ContainerSettings.DockerRunArgs, " ")...)
		}
		if target.ContainerSettings.DockerUser != "" {
			command = append(command, "-u", target.ContainerSettings.DockerUser)
		}
	} else {
		command = append(command, state.Config.Docker.RunArgs...)
	}
	for _, env := range core.BuildEnvironment(state, target, true) {
		command = append(command, "-e", strings.Replace(env, testDir, "/tmp/test", -1))
	}
	replacedCmd = "mkdir -p /tmp/test && cp -r /tmp/test_in/* /tmp/test && cd /tmp/test && " + replacedCmd
	command = append(command, "-v", testDir+":/tmp/test_in", "-w", "/tmp/test_in", containerName, "bash", "-o", "pipefail", "-c", replacedCmd)
	log.Debug("Running containerised test %s: %s", target.Label, strings.Join(command, " "))
	_, out, err := core.ExecWithTimeout(target.TestDir(), nil, target.TestTimeout, state.Config.Test.Timeout, state.ShowAllOutput, command)
	retrieveResultsAndRemoveContainer(target, cidfile, err == context.DeadlineExceeded)
	return out, err
}