コード例 #1
0
ファイル: project.go プロジェクト: coreroller/coreroller
func (project *Project) mustTask(name string) (*Project, *Task, string) {
	if name == "" {
		panic("Cannot get task for empty string")
	}

	proj := project

	// use root
	if strings.HasPrefix(name, "/") {
		name = name[1:]
		for true {
			if proj.parent != nil {
				proj = proj.parent
			} else {
				break
			}
		}
	} else {
		proj = project
	}

	taskName := "default"
	parts := strings.Split(name, ":")

	if len(parts) == 1 {
		taskName = parts[0]
	} else {
		namespace := ""

		for i := 0; i < len(parts)-1; i++ {

			if namespace != "" {
				namespace += ":"
			}
			ns := parts[i]
			namespace += ns

			proj = proj.Namespace[ns]
			if proj == nil {
				util.Panic("ERR", "Could not find project having namespace \"%s\"\n", namespace)
			}
		}
		taskName = parts[len(parts)-1]
	}

	task := proj.Tasks[taskName]
	if task == nil {
		util.Panic("ERR", `"%s" task is not defined`+"\n", name)
	}
	return proj, task, taskName
}
コード例 #2
0
ファイル: project.go プロジェクト: coreroller/coreroller
// TaskD adds a task which runs other dependencies with no handler.
func (project *Project) TaskD(name string, dependencies Dependency) *Task {
	task := NewTask(name, project.contextArgm)

	if dependencies == nil {
		util.Panic("godo", "Task %s requires a dependency or handler\n", name)
	}

	task.dependencies = append(task.dependencies, dependencies)
	project.Tasks[name] = task
	return task
}
コード例 #3
0
ファイル: project.go プロジェクト: coreroller/coreroller
// Task1 adds a simple task to the project.
func (project *Project) Task1(name string, handler func(*Context)) *Task {
	task := NewTask(name, project.contextArgm)

	if handler == nil {
		util.Panic("godo", "Task %s requires a dependency or handler\n", name)
	}

	task.Handler = HandlerFunc(handler)

	project.Tasks[name] = task
	return task
}
コード例 #4
0
ファイル: main.go プロジェクト: coreroller/coreroller
func runAndWatch(godoFile string) {
	done := make(chan bool, 1)
	run := func(forceBuild bool) (*exec.Cmd, string) {
		cmd, exe := buildCommand(godoFile, forceBuild)
		cmd.Start()
		go func() {
			err := cmd.Wait()
			done <- true
			if err != nil {
				if isVerbose {
					util.Debug("godo", "godo process killed\n")
				}
			}
		}()
		return cmd, exe
	}

	bufferSize := 2048
	watchr, err := watcher.NewWatcher(bufferSize)
	if err != nil {
		util.Panic("project", "%v\n", err)
	}
	godoDir := filepath.Dir(godoFile)
	watchr.WatchRecursive(godoDir)
	watchr.ErrorHandler = func(err error) {
		util.Error("godo", "Watcher error %v\n", err)
	}

	cmd, exe := run(false)
	// this function will block forever, Ctrl+C to quit app
	// var lastHappenedTime int64
	watchr.Start()
	util.Info("godo", "watching %s ...\n", godoDir)

	<-time.After(godo.GetWatchDelay() + (300 * time.Millisecond))

	// forloop:
	for {
		select {
		case event := <-watchr.Event:
			if event.Path == exe {
				continue
			}
			util.Debug("watchmain", "%+v\n", event)
			syscall.Kill(cmd.Process.Pid, syscall.SIGQUIT)
			cmd.Process.Kill()
			<-done
			cmd, _ = run(true)
		}
	}

}
コード例 #5
0
ファイル: project.go プロジェクト: coreroller/coreroller
func (project *Project) watchTask(task *Task, root string, logName string, handler func(e *watcher.FileEvent)) {
	ignorePathFn := func(p string) bool {
		return watcher.DefaultIgnorePathFn(p) || !task.isWatchedFile(p)
	}

	// if len(task.EffectiveWatchRegexps) == 0 {
	// 	util.Error("godo", "EffectiveWatchRegexps should not be zero")
	// } else {
	// 	ignorePathFn = func(p string) bool {
	// 		return watcher.DefaultIgnorePathFn(p) || !task.isWatchedFile(p)
	// 	}
	// }

	bufferSize := 2048
	watchr, err := watcher.NewWatcher(bufferSize)
	if err != nil {
		util.Panic("project", "%v\n", err)
	}
	watchr.IgnorePathFn = ignorePathFn
	watchr.ErrorHandler = func(err error) {
		util.Error("project", "Watcher error %v\n", err)
	}
	watchr.WatchRecursive(root)

	// this function will block forever, Ctrl+C to quit app
	// var lastHappenedTime int64
	util.Info(logName, "watching %s ...\n", root)

	// not sure why this need to be unbuffered, but it was blocking
	// on cquit <- true
	cquit := make(chan bool, 1)
	project.Lock()
	project.cwatchTasks[cquit] = true
	project.Unlock()
	watchr.Start()
forloop:
	for {
		select {
		case event := <-watchr.Event:
			//util.Debug("DBG", "handling watchr.Event %+v\n", event)
			handler(event)
		case <-cquit:
			watchr.Stop()
			break forloop
		}
	}
}
コード例 #6
0
ファイル: project.go プロジェクト: coreroller/coreroller
// Task adds a task to the project with dependencies and handler.
func (project *Project) Task(name string, dependencies Dependency, handler func(*Context)) *Task {
	task := NewTask(name, project.contextArgm)

	if handler == nil && dependencies == nil {
		util.Panic("godo", "Task %s requires a dependency or handler\n", name)
	}

	if handler != nil {
		task.Handler = HandlerFunc(handler)
	}
	if dependencies != nil {
		task.dependencies = append(task.dependencies, dependencies)
	}

	project.Tasks[name] = task
	return task
}