1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---@meta
local
---Creates a driver to execute a specified command with arguments and variable expansions, primarily for task management.
---The command is a string that may include references to environment variables using `${VAR}` syntax. Variables from the
---task’s environment are expanded to strings or lists of strings, allowing flexibility in argument construction.
---
---In addition to general variables, this driver supports the special variables `SRC` and `TGT`:
--- - `${SRC}`: Expands to the list of the task's declared inputs.
--- - `${TGT}`: Expands to the list of the task's declared outputs.
---
---Pattern processing is also supported: `${PATTERN:VAR}` expands `VAR` as a list, applying `PATTERN` to each element. If
---`PATTERN` includes `%s`, each element replaces `%s`; otherwise, the pattern and element are concatenated.
---Using `${VAR[index]}`, a specific item in a list variable can be retrieved.
---
---For example, if `env.PATTERN = '-I'` and `env.SRC = {'/usr/include', '/usr/local/include'}`, the syntax `${PATTERN:SRC}`
---would expand to `-I/usr/include -I/usr/local/include`.
---
---@param name string The driver’s name.
---@param color string Color for logging this driver’s output.
---@param command string The command to execute, potentially including variables for expansion.
---@param run_before string[]|nil Optional. The name of other drivers that this driver runs before. All tasks using this driver will be scheduled before tasks using the specified drivers.
---Creates a dependency-tracking command driver that runs the specified command, similar to `command_driver`.
---This driver is specifically tailored to parse dependency outputs generated by MSVC, GCC, and Clang, such as outputs from
---the `-MD` flag for GCC/Clang and `/sourceDependencies` for MSVC. Only these tools are supported by this driver.
---
---For tools that do not produce compatible dependency files, use a Lua script driver instead (`lua_driver`), which allows
---custom dependency parsing and handling.
---
---@param name string The name of the driver, used for identification.
---@param color string A color identifier for the driver, used for console log display.
---@param command string The command string to execute.
---@param run_before string[]|nil Optional. The name of other drivers that this driver runs before. All tasks using this driver will be scheduled before tasks using the specified drivers.
---Creates a Lua driver that executes a specified Lua script, allowing for custom task handling and dependency parsing.
---When the Lua script is run, the `Task` object is passed as an argument, allowing the script to access task details and
---dynamically determine dependencies. The script should return two values:
--- - An exit code, where `0` indicates success.
--- - A list of additional dependencies, which includes any required files not initially listed as task inputs.
---
---This Lua driver is especially useful for tools not supported by `dependency_driver`, allowing custom logic for dependency
---management.
---
---@param name string The name of the driver, used for identification.
---@param color string A color identifier for the driver, used for console log display.
---@param script Node The path to the Lua script file to execute.
---@param run_before string[]|nil Optional. The name of other drivers that this driver runs before. All tasks using this driver will be scheduled before tasks using the specified drivers.
---Represents a task generated by a specific generator and executable by a specified driver.
---Tasks track their dependencies, input and output nodes, and their environment, ensuring correct task execution order.
---@class Task
---@field driver string The name of the driver responsible for executing this task.
---@field generator string The name of the generator that created this task.
---@field group string The name of the task group, shared with other tasks in the same generator.
---@field env Environment The environment settings for this task, derived from the generator's environment.
---@field inputs Node[] A list of `Node` objects that serve as the inputs for this task.
---@field outputs Node[] A list of `Node` objects that are created or modified by this task.
Task =
---Adds one or more nodes as inputs to this task. Inputs are dependencies that must be up-to-date before the task executes.
---If adding an input creates a dependency cycle, no changes are made, and an error is raised.
---@param input Node|Node[] A `Node` or list of `Node` objects to be used as task inputs.
---Adds one or more nodes as outputs for this task. Outputs are the results created or modified by the task.
---If adding an output creates a dependency cycle, no changes are made, and an error is raised.
---@param output Node|Node[] A `Node` or list of `Node` objects that are produced by the task.
---Sets this task to run before the specified task.
---This ensures that this task is completed before the `other` task starts.
---
---@param other Task The task that should run after this task.
---Sets this task to run after the specified task.
---This ensures that the `other` task is completed before this task starts.
---
---@param other Task The task that should run before this task.
---Executes a command for the task, handling variable expansions as the `command_driver` would.
---This method allows Lua drivers to run commands with access to the task's environment, expanding any variables
---in the `command` string.
---
---Pattern expansion and list indexing follow the same rules as in `command_driver`. `${PATTERN:VAR}` applies `PATTERN`
---to each item in the list `VAR`, where `%s` in the pattern is replaced by each item. If `%s` is absent, the pattern and
---item are concatenated. `${VAR[index]}` allows retrieval of specific list elements.
---
---Returns:
--- - The command's exit code (`0` indicates success).
--- - Combined output and error logs.
--- - The expanded command string, showing what was actually executed.
---
---@param command string The command to execute, potentially including variables for expansion.
---@return number, string, string Exit code, combined output and error logs, and expanded command string.