@@ -90,19 +90,6 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
9090 }
9191 rangeFunc := getRangeFunc (c .Dir )
9292
93- var taskRangeFunc func (k string , v ast.Var ) error
94- if t != nil {
95- // NOTE(@andreynering): We're manually joining these paths here because
96- // this is the raw task, not the compiled one.
97- cache := & templater.Cache {Vars : result }
98- dir := templater .Replace (t .Dir , cache )
99- if err := cache .Err (); err != nil {
100- return nil , err
101- }
102- dir = filepathext .SmartJoin (c .Dir , dir )
103- taskRangeFunc = getRangeFunc (dir )
104- }
105-
10693 for k , v := range c .TaskfileEnv .All () {
10794 if err := rangeFunc (k , v ); err != nil {
10895 return nil , err
@@ -113,31 +100,48 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
113100 return nil , err
114101 }
115102 }
103+
116104 if t != nil {
117105 for k , v := range t .IncludeVars .All () {
118106 if err := rangeFunc (k , v ); err != nil {
119107 return nil , err
120108 }
121109 }
110+
111+ // Calculate the t.Dir now based on values saved during AST parsing
112+ // and then get a Task RangeFunc.
113+ dir := c .Dir
114+ if len (t .Dir ) == 0 {
115+ // Use the saved include task.Dir.
116+ t .Dir = t .IncludeTaskDir
117+ } else {
118+ cache := & templater.Cache {Vars : result }
119+ taskDir := templater .Replace (t .Dir , cache )
120+ if err := cache .Err (); err != nil {
121+ return nil , err
122+ }
123+ t .Dir = filepathext .SmartJoin (t .IncludeDir , taskDir )
124+ // Update dir (esp. if taskDir is a relative path).
125+ dir = filepathext .SmartJoin (c .Dir , taskDir )
126+ }
127+ taskRangeFunc := getRangeFunc (dir )
128+
122129 for k , v := range t .IncludedTaskfileVars .All () {
123130 if err := taskRangeFunc (k , v ); err != nil {
124131 return nil , err
125132 }
126133 }
127- }
128-
129- if t == nil || call == nil {
130- return result , nil
131- }
132-
133- for k , v := range call .Vars .All () {
134- if err := rangeFunc (k , v ); err != nil {
135- return nil , err
134+ if call != nil {
135+ for k , v := range call .Vars .All () {
136+ if err := rangeFunc (k , v ); err != nil {
137+ return nil , err
138+ }
139+ }
136140 }
137- }
138- for k , v := range t . Vars . All () {
139- if err := taskRangeFunc ( k , v ); err != nil {
140- return nil , err
141+ for k , v := range t . Vars . All () {
142+ if err := taskRangeFunc ( k , v ); err != nil {
143+ return nil , err
144+ }
141145 }
142146 }
143147
0 commit comments