-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathmake.ts
219 lines (209 loc) · 5.44 KB
/
make.ts
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
const listTargets: Fig.Generator = {
custom: async (tokens, executeShellCommand) => {
// Plain target suggestions. These will be overridden if we can find a description for them.
const { stdout } = await executeShellCommand({
command: "bash",
args: [
"-c",
"make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\\/\\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' | sort -u",
],
});
const targetSuggestions = new Map<string, Fig.Suggestion>();
for (const target of stdout.split("\n")) {
if (target === "Makefile") continue;
targetSuggestions.set(target, {
name: target.trim(),
description: "Make target",
icon: "🎯",
priority: 80,
});
}
const { stdout: makefile } = await executeShellCommand({
command: "cat",
args: ["Makefile", "makefile"],
});
const matches = makefile.matchAll(
/((?:^#.*\n)*)(?:^\.[A-Z_]+:.*\n)*(^\S*?):.*?(?:\s#+[ \t]*(.+))?$/gm
);
const specialTargets = new Set([
".PHONY",
".SUFFIXES",
".DEFAULT",
".PRECIOUS",
".INTERMEDIATE",
".SECONDARY",
".SECONDEXPANSION",
".DELETE_ON_ERROR",
".IGNORE",
".LOW_RESOLUTION_TIME",
".SILENT",
".EXPORT_ALL_VARIABLES",
".NOTPARALLEL",
".ONESHELL",
".POSIX",
]);
for (const match of matches) {
const [_, leadingComment, target, inlineComment] = match;
if (specialTargets.has(target)) continue;
if (/\$\(.+?\)/.test(target)) continue;
const name = target.trim();
const description = inlineComment
? inlineComment.trim()
: leadingComment
? leadingComment.replace(/^#+\s*/gm, "").trim()
: "Make target";
targetSuggestions.set(name, {
name,
description,
icon: "🎯",
priority: 80,
});
}
return [...targetSuggestions.values()];
},
};
const completionSpec: Fig.Spec = {
name: "make",
args: {
name: "target",
generators: listTargets,
},
options: [
{
name: "-j",
args: [{ name: "number" }, { name: "target", generators: listTargets }],
},
{
name: ["--file", "-f", "--makefile"],
description: "Read FILE as a makefile",
args: {
name: "file",
template: "filepaths",
},
},
{
name: ["-C", "--directory"],
description: "Change to DIRECTORY before doing anything",
args: {
name: "directory",
template: "folders",
},
},
{
name: ["-B", "--always-make"],
description: "Unconditionally make all targets",
args: {
name: "target",
generators: listTargets,
},
},
{
name: ["-e", "--environment-overrides"],
description: "Environment variables override makefiles",
args: {
name: "target",
generators: listTargets,
},
},
{
name: ["-h", "--help"],
description: "Print this message and exit",
},
{
name: ["-i", "--ignore-errors"],
description: "Ignore errors from commands",
},
{
name: ["-k", "--keep-going"],
description: "Keep going when some targets can't be made",
},
{
name: ["-L", "--check-symlink-times"],
description: "Use the latest mtime between symlinks and target",
},
{
name: ["-p", "--print-data-base"],
description: "Print make's internal database",
},
{
name: ["-q", "--question"],
description: "Run no commands; exit status says if up to date",
},
{
name: ["-r", "--no-builtin-rules"],
description: "Disable the built-in implicit rules",
},
{
name: ["-R", "--no-builtin-variables"],
description: "Disable the built-in variable settings",
},
{
name: ["-t", "--touch"],
description: "Touch targets instead of remaking them",
},
{
name: ["-v", "--version"],
description: "Print the version number of make and exit",
},
{
name: ["-w", "--print-directory"],
description: "Print the current directory",
},
{
name: "-d",
description: "Print lots of debugging information",
},
{
name: "--debug",
description: "Print various types of debugging information",
},
{
name: ["-I", "--include-dir"],
args: {
name: "directory",
template: "folders",
},
description: "Search directory for included makefiles",
},
{
name: ["-l", "--load-average"],
args: {
name: "N",
isOptional: true,
},
description: "Don't start multiple jobs unless load is below N",
},
{
name: ["-o", "--old-file"],
args: {
name: "file",
template: "filepaths",
},
description: "Consider file to be very old and don't remake it",
},
{
name: "--no-print-directory",
description: "Turn off -w, even if it was turned on implicitly",
},
{
name: ["-W", "--what-if", "--new-file", "--assume-new"],
args: {
name: "file",
template: "filepaths",
},
description: "Consider file to be infinitely new",
},
{
name: "--warn-undefined-variables",
description: "Warn when an undefined variable is referenced",
},
{
name: ["-N", "--Next-option"],
args: {
name: "option",
},
description: "Turn on value of next option",
},
],
};
export default completionSpec;