Skip to content

Conversation

@fhofherr
Copy link

@fhofherr fhofherr commented Feb 7, 2025

This commit adds the TASK_SOURCES variable to tasks. If a task defines the sources key, TASK_SOURCES contains the list of paths referenced by sources. Globs are expanded.

This was initially implemented by @hernandanielg in #1146 to fix #948. The PR seemed to have stalled since, which is why I'm now opening this new PR. In contrast to #1146 my changes set TASK_SOURCES to a list, which allows users to use template functions to transform the value of TASK_SOURCES. Additionally, I decided to name the variable TASK_SOURCES instead of SOURCES, as I wanted to make clear that this variable only exists for tasks.

I'm aware of this comment by @callegar which wondered if sources should be changed to accept the value of variables. However, this seemed like a bigger change to me (I may be wrong since I don't know the code in detail). Therefore I opted to stick with the original proposal.

The downside of my change is, that globs get expanded whenever the TASK_SOURCES variable is set. I'm not yet sure under which circumstances Compiler.FastGetVariables and Compiler.GetVariables are called. Both of those methods call the getVariables method which in turn calls the getSpecialVariables method I modified. Would it be enough to just pass evaluateShVars to getSpecialVariables (maybe renaming it to fast in the process) and skip glob expansion if it is true?

This commit adds the `TASK_SOURCES` variable to tasks. If a task defines
the `sources` key, `TASK_SOURCES` contains the list of paths referenced
by `sources`. Globs are expanded.

This was initially implemented by @hernandanielg in go-task#1146 to fix go-task#948.
@fhofherr fhofherr force-pushed the 948-uses-sources-as-variable branch from ef9ffda to 191cb5d Compare February 7, 2025 15:27
Comment on lines +199 to +202
taskSources, err := fingerprint.Globs(dir, t.Sources)
if err != nil {
return allVars, fmt.Errorf("expand globs: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved to the end of this block so that TASK, TASK_DIR, etc. all still get assigned even if there's an error on glob expansion?

@vergenzt
Copy link
Contributor

I would love for this to get merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use sources as variable

2 participants