@@ -91,17 +91,6 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
9191 rangeFunc := getRangeFunc (c .Dir )
9292
9393 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- }
10594
10695 for k , v := range c .TaskfileEnv .All () {
10796 if err := rangeFunc (k , v ); err != nil {
@@ -119,6 +108,22 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
119108 return nil , err
120109 }
121110 }
111+
112+ // NOTE: Calculate the task.Dir and taskRangeFunc here, after
113+ // IncludeVars have been added to the templater. The call to SmartJoin()
114+ // will then work as expected (i.e. when `dir` becomes an absolute path
115+ // after the templater.Replace() call).
116+ // NOTE: taskRangeFunc() will be available to subsequent calls
117+ // in this function despite the convoluted code structure here.
118+ cache := & templater.Cache {Vars : result }
119+ dir := templater .Replace (t .Dir , cache )
120+ t .Dir = filepathext .SmartJoin (t .IncludeDir , dir )
121+ if err := cache .Err (); err != nil {
122+ return nil , err
123+ }
124+ dir = filepathext .SmartJoin (c .Dir , dir )
125+ taskRangeFunc = getRangeFunc (dir )
126+
122127 for k , v := range t .IncludedTaskfileVars .All () {
123128 if err := taskRangeFunc (k , v ); err != nil {
124129 return nil , err
0 commit comments