* Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. "github.com/aphistic/gomol" "github.com/mohae/deepcopy" "bitbucket.org/rw_grim/convey/environment" "bitbucket.org/rw_grim/convey/state" "bitbucket.org/rw_grim/convey/tasks" "bitbucket.org/rw_grim/convey/yaml" Task string `yaml:"task"` Environment yaml.StringOrSlice `yaml:"environment"` // A copy of the extended task. Must be public so that deepcopy // can serialize it properly in case an extended task is extended // itself (when private the innerTask is nil and causes a bad // data access exception). func (e *Extend) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error { // We want the extending environment to take precedence over the extended // task environment (if it exists). In order to get the correct precedence, // we stash it onto the state's environment. Once we're done executing the // inner task we'll restore it to the previous values. Notice that we merge // in what appears at first as backwards - we don't want to override command // line arguments, so we let state keep a higher precedence. stashed := st.Environment st.Environment = environment.Merge(e.Environment, st.Environment) err := e.InnerTask.Execute(name, logger, env, st) func (e *Extend) New() tasks.Task { func (e *Extend) Valid() error { func (e *Extend) Dependencies() []string { func (e *Extend) Resolve(taskMap map[string]tasks.Task) error { task, ok := taskMap[e.Task] // Should never happen due to dependency order return fmt.Errorf("Extending undeclared task '%s'", e.Task) // Some tasks may set their own fields, e.g. when mapping things // to the correct runtime environment. In order to make sure that // the inner task doesn't cache something from another run, we // do a clone of the task here so we get our own copy to muck with. e.InnerTask = deepcopy.Copy(task).(tasks.Task)