From 3ff8fdbc0a23b3db473d5157f1929948c2ed6400 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Fri, 26 Jan 2024 00:11:08 +0000 Subject: [PATCH] feat: add ROOT_TASKFILE special variable (#1469) --- docs/docs/api_reference.md | 5 +++-- internal/compiler/compiler.go | 2 ++ setup.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/docs/api_reference.md b/docs/docs/api_reference.md index aebc94c2..7a5e02c9 100644 --- a/docs/docs/api_reference.md +++ b/docs/docs/api_reference.md @@ -128,8 +128,9 @@ There are some special variables that is available on the templating system: | `CLI_ARGS` | Contain all extra arguments passed after `--` when calling Task through the CLI. | | `CLI_FORCE` | A boolean containing whether the `--force` or `--force-all` flags were set. | | `TASK` | The name of the current task. | -| `ROOT_DIR` | The absolute path of the root Taskfile. | -| `TASKFILE_DIR` | The absolute path of the included Taskfile. | +| `ROOT_TASKFILE` | The absolute path of the root Taskfile. | +| `ROOT_DIR` | The absolute path of the root Taskfile directory. | +| `TASKFILE_DIR` | The absolute path of the included Taskfile directory. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. | diff --git a/internal/compiler/compiler.go b/internal/compiler/compiler.go index 04558a5c..bc57e8a4 100644 --- a/internal/compiler/compiler.go +++ b/internal/compiler/compiler.go @@ -20,6 +20,7 @@ import ( type Compiler struct { Dir string + Entrypoint string UserWorkingDir string TaskfileEnv *ast.Vars @@ -214,6 +215,7 @@ func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) { return map[string]string{ "TASK": t.Task, + "ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint), "ROOT_DIR": c.Dir, "TASKFILE_DIR": taskfileDir, "USER_WORKING_DIR": c.UserWorkingDir, diff --git a/setup.go b/setup.go index bc8ae2d7..073ba0bd 100644 --- a/setup.go +++ b/setup.go @@ -189,6 +189,7 @@ func (e *Executor) setupCompiler() error { e.Compiler = &compiler.Compiler{ Dir: e.Dir, + Entrypoint: e.Entrypoint, UserWorkingDir: e.UserWorkingDir, TaskfileEnv: e.Taskfile.Env, TaskfileVars: e.Taskfile.Vars,