Exemplo n.º 1
0
func collect(options RunOptions, state *collectionState) (*TaskCollection, error) {
	for _, taskname := range options.Tasks {
		taskname := task.ParseName(taskname)
		resourceName := taskname.Resource()
		resource, ok := options.Config.Resources[resourceName]
		if !ok {
			return nil, fmt.Errorf("resource %q does not exist", resourceName)
		}

		taskConfig, err := buildTaskConfig(resourceName, taskname.Action(), resource)
		if err != nil {
			return nil, err
		}

		// TODO: cache tasksConfigs until an env resource invalidates them

		if state.taskStack.Contains(taskConfig.Name()) {
			return nil, fmt.Errorf(
				"Invalid dependency cycle: %s", strings.Join(state.taskStack.Names(), ", "))
		}
		state.taskStack.Push(taskConfig.Name())

		options.Tasks = taskConfig.Dependencies()
		if _, err := collect(options, state); err != nil {
			return nil, err
		}
		state.tasks.add(taskConfig)
		state.taskStack.Pop()
	}
	return state.tasks, nil
}
Exemplo n.º 2
0
func hasModifiedDeps(ctx *context.ExecuteContext, deps []string) bool {
	for _, dep := range deps {
		taskName := task.ParseName(dep)
		if ctx.IsModified(taskName) {
			return true
		}
	}
	return false
}
Exemplo n.º 3
0
// RemoveDeps returns the dependencies for the remove action
func RemoveDeps(conf config.Resource) func() []string {
	return func() []string {
		confDeps := conf.Dependencies()
		deps := []string{}
		for i := len(confDeps); i > 0; i-- {
			taskname := task.ParseName(confDeps[i-1])
			deps = append(deps, taskname.Resource()+":"+"rm")
		}
		return deps
	}
}
Exemplo n.º 4
0
// ValidateResourcesExist checks that the list of resources is defined in the
// config and returns an error if a resources is not defined.
func ValidateResourcesExist(path pth.Path, c *Config, names []string) error {
	missing := []string{}
	for _, name := range names {
		resource := task.ParseName(name).Resource()
		if _, ok := c.Resources[resource]; !ok {
			missing = append(missing, resource)
		}
	}
	if len(missing) != 0 {
		return pth.Errorf(path, "missing dependencies: %s", strings.Join(missing, ", "))
	}
	return nil
}