@@ -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,23 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
119108 return nil , err
120109 }
121110 }
111+ // Calculate the t.Dir.
112+ cache := & templater.Cache {Vars : result }
113+ rangeDir := c .Dir
114+ if len (t .Dir ) == 0 {
115+ // Use the saved include task.Dir.
116+ t .Dir = templater .Replace (t .IncludeTaskDir , cache )
117+ } else {
118+ // Calculate based on include.Dir and t.Dir.
119+ t .Dir = templater .Replace (t .Dir , cache )
120+ rangeDir = filepathext .SmartJoin (c .Dir , t .Dir ) // This first, before t.Dir is finalized (it may be a relative path).
121+ t .Dir = filepathext .SmartJoin (t .IncludeDir , t .Dir )
122+ }
123+ if err := cache .Err (); err != nil {
124+ return nil , err
125+ }
126+ taskRangeFunc = getRangeFunc (rangeDir )
127+
122128 for k , v := range t .IncludedTaskfileVars .All () {
123129 if err := taskRangeFunc (k , v ); err != nil {
124130 return nil , err
0 commit comments