wyvrnpm 2.10.2 → 2.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1914 -1860
- package/bin/{wyvrn.js → wyvrnpm.js} +66 -0
- package/cmake/cpp.cmake +9 -9
- package/cmake/functions.cmake +224 -224
- package/cmake/macros.cmake +284 -284
- package/package.json +3 -2
- package/src/auth.js +66 -66
- package/src/binary-dir.js +95 -0
- package/src/bootstrap/cookbook.js +196 -196
- package/src/bootstrap/detect.js +150 -150
- package/src/bootstrap/index.js +220 -220
- package/src/bootstrap/version.js +72 -72
- package/src/build/cache.js +344 -344
- package/src/build/clone.js +170 -170
- package/src/build/cmake.js +342 -342
- package/src/build/index.js +299 -297
- package/src/build/msvc-env.js +260 -260
- package/src/build/recipe.js +188 -188
- package/src/commands/add.js +141 -141
- package/src/commands/bootstrap.js +96 -96
- package/src/commands/build.js +482 -452
- package/src/commands/cache.js +189 -189
- package/src/commands/clean.js +80 -80
- package/src/commands/configure.js +92 -92
- package/src/commands/init.js +70 -70
- package/src/commands/install-skill.js +115 -115
- package/src/commands/install.js +730 -674
- package/src/commands/link.js +320 -320
- package/src/commands/profile.js +237 -237
- package/src/commands/publish.js +584 -555
- package/src/commands/show.js +252 -252
- package/src/commands/version.js +187 -0
- package/src/compat.js +273 -273
- package/src/conf/index.js +415 -391
- package/src/conf/namespaces.js +94 -94
- package/src/context.js +230 -230
- package/src/http-fetch.js +53 -53
- package/src/ignore.js +118 -118
- package/src/logger.js +122 -122
- package/src/options.js +303 -303
- package/src/settings-overrides.js +152 -152
- package/src/toolchain/deps.js +164 -164
- package/src/toolchain/index.js +212 -212
- package/src/toolchain/presets.js +356 -340
- package/src/toolchain/template.cmake +77 -77
- package/src/upload-built.js +265 -265
- package/src/version-range.js +301 -301
- package/src/zip-safe.js +52 -52
- package/src/zip-stream.js +126 -0
package/src/toolchain/presets.js
CHANGED
|
@@ -1,340 +1,356 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
|
-
const
|
|
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
|
-
return
|
|
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
|
-
* @param {
|
|
60
|
-
* @param {string} args.
|
|
61
|
-
*
|
|
62
|
-
* @param {string
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
// configurePreset — the fresh `newBuilds`
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const { DEFAULT_BINARY_DIR_ROOT } = require('../binary-dir');
|
|
7
|
+
|
|
8
|
+
const VENDOR_KEY = 'wyvrnpm/generated';
|
|
9
|
+
|
|
10
|
+
// Local copy of the arch→VS-platform mapping. Duplicated here rather than
|
|
11
|
+
// imported from ./index so preset generation can run standalone (keeps
|
|
12
|
+
// the dependency graph simple — presets.js doesn't otherwise need the
|
|
13
|
+
// toolchain generator). Keep in sync with `archToVsPlatform` in index.js.
|
|
14
|
+
const ARCH_VS_PLATFORM = {
|
|
15
|
+
x86_64: 'x64',
|
|
16
|
+
x86: 'Win32',
|
|
17
|
+
armv8: 'ARM64',
|
|
18
|
+
armv7: 'ARM',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function isVsGenerator(name) {
|
|
22
|
+
return typeof name === 'string' && /^Visual Studio \d/.test(name);
|
|
23
|
+
}
|
|
24
|
+
const SCHEMA_VERSION = 3; // requires CMake ≥ 3.21
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Safely parse a JSON file; returns null on any error (missing, malformed, …).
|
|
28
|
+
* @param {string} p
|
|
29
|
+
* @returns {object|null}
|
|
30
|
+
*/
|
|
31
|
+
function safeReadJson(p) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* True if the parsed presets object was produced by wyvrnpm (i.e. carries our
|
|
41
|
+
* vendor marker). Hand-edited or user-owned files return false.
|
|
42
|
+
*
|
|
43
|
+
* @param {object|null} presets
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
46
|
+
function isWyvrnGenerated(presets) {
|
|
47
|
+
return !!presets && typeof presets.vendor === 'object' && !!presets.vendor[VENDOR_KEY];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Build the configure preset object for the active profile.
|
|
52
|
+
*
|
|
53
|
+
* When the project has its own `build` recipe (i.e. it's a publishable
|
|
54
|
+
* library with `build.generator` / `build.configure` declared), those are
|
|
55
|
+
* propagated into the generated preset so `wyvrnpm build` locally honours
|
|
56
|
+
* the same knobs the source-build + publish paths use. Without this, a
|
|
57
|
+
* publisher's recipe is effectively advisory at install-time (F15 fix).
|
|
58
|
+
*
|
|
59
|
+
* @param {object} args
|
|
60
|
+
* @param {string} args.profileName
|
|
61
|
+
* @param {string} args.profileHash
|
|
62
|
+
* @param {string} args.toolchainRelPath Relative from project root, CMake-style
|
|
63
|
+
* forward slashes.
|
|
64
|
+
* @param {string|null} [args.generator] Single generator name to pin on the
|
|
65
|
+
* preset (e.g. "Ninja Multi-Config").
|
|
66
|
+
* Null / undefined → let CMake pick.
|
|
67
|
+
* @param {Record<string,string>|null} [args.extraCacheVariables]
|
|
68
|
+
* Merged into cacheVariables alongside
|
|
69
|
+
* `CMAKE_TOOLCHAIN_FILE`. Usually
|
|
70
|
+
* derived from the project's own
|
|
71
|
+
* `build.configure` -D args.
|
|
72
|
+
* @param {string|null} [args.profileArch] Active profile arch — used to pin
|
|
73
|
+
* `architecture` for VS generators
|
|
74
|
+
* so `cmake --preset` produces
|
|
75
|
+
* binaries matching the profile
|
|
76
|
+
* (VS otherwise defaults to x64).
|
|
77
|
+
* @param {string[]|null} [args.configs] Build recipe's `configs` list
|
|
78
|
+
* (e.g. ['Debug','Release','MinSizeRel']).
|
|
79
|
+
* When provided, drives
|
|
80
|
+
* `CMAKE_CONFIGURATION_TYPES` so
|
|
81
|
+
* multi-config generators (Ninja
|
|
82
|
+
* Multi-Config, VS) actually
|
|
83
|
+
* produce every config the recipe
|
|
84
|
+
* declares. Null/empty → omitted
|
|
85
|
+
* (let CMake use its generator
|
|
86
|
+
* default). `extraCacheVariables`
|
|
87
|
+
* wins on explicit collision so
|
|
88
|
+
* authors that already bake the
|
|
89
|
+
* list into `build.configure`
|
|
90
|
+
* aren't overridden.
|
|
91
|
+
* @param {string|null} [args.binaryDirRoot] Project-relative subdir for the
|
|
92
|
+
* preset's binaryDir. Defaults to
|
|
93
|
+
* `"build"`. Override via
|
|
94
|
+
* `--build-dir` or
|
|
95
|
+
* `wyvrn.local.json:binaryDirRoot`
|
|
96
|
+
* when the repo has a `BUILD`
|
|
97
|
+
* Bazel/Buck file at root that
|
|
98
|
+
* collides with `build/` on
|
|
99
|
+
* case-insensitive filesystems.
|
|
100
|
+
*/
|
|
101
|
+
function buildConfigurePreset({
|
|
102
|
+
profileName,
|
|
103
|
+
profileHash,
|
|
104
|
+
toolchainRelPath,
|
|
105
|
+
generator = null,
|
|
106
|
+
extraCacheVariables = null,
|
|
107
|
+
installDir = null,
|
|
108
|
+
profileArch = null,
|
|
109
|
+
configs = null,
|
|
110
|
+
binaryDirRoot = DEFAULT_BINARY_DIR_ROOT,
|
|
111
|
+
}) {
|
|
112
|
+
const root = binaryDirRoot || DEFAULT_BINARY_DIR_ROOT;
|
|
113
|
+
const binaryDir = `\${sourceDir}/${root}/wyvrn-${profileName}`;
|
|
114
|
+
// CMAKE_CONFIGURATION_TYPES is a defensible default from the recipe's
|
|
115
|
+
// declared `configs` list. Applied FIRST (lowest precedence) so an
|
|
116
|
+
// explicit `-DCMAKE_CONFIGURATION_TYPES=...` in `build.configure`
|
|
117
|
+
// still wins — authors who already pin the list shouldn't silently
|
|
118
|
+
// lose their override. The wyvrn-owned entries (toolchain, install
|
|
119
|
+
// prefix) still win over both below.
|
|
120
|
+
const configsDefault = (Array.isArray(configs) && configs.length > 0)
|
|
121
|
+
? { CMAKE_CONFIGURATION_TYPES: configs.join(';') }
|
|
122
|
+
: {};
|
|
123
|
+
const cacheVariables = {
|
|
124
|
+
...configsDefault,
|
|
125
|
+
...(extraCacheVariables ?? {}),
|
|
126
|
+
CMAKE_TOOLCHAIN_FILE: `\${sourceDir}/${toolchainRelPath}`,
|
|
127
|
+
};
|
|
128
|
+
if (installDir) {
|
|
129
|
+
// `installDir` in wyvrn.json is defined as relative to the binary dir
|
|
130
|
+
// (same semantics as the source-build path, which passes
|
|
131
|
+
// -DCMAKE_INSTALL_PREFIX=<buildDir>/<installDir>). Without this, a
|
|
132
|
+
// `wyvrnpm build --install` falls back to CMake's system default —
|
|
133
|
+
// on Windows that's `C:/Program Files (x86)/<Project>`, which needs
|
|
134
|
+
// admin rights and almost always fails.
|
|
135
|
+
cacheVariables.CMAKE_INSTALL_PREFIX = `${binaryDir}/${installDir}`;
|
|
136
|
+
}
|
|
137
|
+
const preset = {
|
|
138
|
+
name: `wyvrn-${profileName}`,
|
|
139
|
+
displayName: `wyvrnpm (${profileName})`,
|
|
140
|
+
description: `Generated by wyvrnpm install — profile hash ${profileHash}`,
|
|
141
|
+
binaryDir,
|
|
142
|
+
cacheVariables,
|
|
143
|
+
};
|
|
144
|
+
if (generator) preset.generator = generator;
|
|
145
|
+
|
|
146
|
+
// Visual Studio generators default to x64 when `architecture` is
|
|
147
|
+
// unspecified — which silently overrides the profile arch and makes
|
|
148
|
+
// find_package() reject 32-bit installed packages with a pointer-size
|
|
149
|
+
// mismatch. Pin `architecture` from the profile so `cmake --preset`
|
|
150
|
+
// produces the right artefacts end-to-end.
|
|
151
|
+
if (isVsGenerator(generator) && profileArch && ARCH_VS_PLATFORM[profileArch]) {
|
|
152
|
+
preset.architecture = {
|
|
153
|
+
value: ARCH_VS_PLATFORM[profileArch],
|
|
154
|
+
strategy: 'set',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return preset;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* One build preset per configuration the recipe declares (or the
|
|
163
|
+
* legacy default pair `Debug` + `Release` when no list is provided).
|
|
164
|
+
*
|
|
165
|
+
* The preset name suffix is the configuration name lower-cased — matches
|
|
166
|
+
* the previous Debug/Release naming for those two, and extends to
|
|
167
|
+
* `wyvrn-<profile>-relwithdebinfo` / `-minsizerel` for the multi-config
|
|
168
|
+
* cases. Authors whose recipes include `MinSizeRel` in `build.configs`
|
|
169
|
+
* can now `cmake --build --preset wyvrn-<profile>-minsizerel` directly.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} profileName
|
|
172
|
+
* @param {string[]|null} [configs] Recipe's declared configurations. When
|
|
173
|
+
* null/empty, emits the pre-2.8.1 `Debug` + `Release` pair so existing
|
|
174
|
+
* CMakePresets.json files remain byte-identical.
|
|
175
|
+
* @returns {Array<object>}
|
|
176
|
+
*/
|
|
177
|
+
function buildBuildPresets(profileName, configs = null) {
|
|
178
|
+
const base = `wyvrn-${profileName}`;
|
|
179
|
+
const list = (Array.isArray(configs) && configs.length > 0)
|
|
180
|
+
? configs
|
|
181
|
+
: ['Debug', 'Release'];
|
|
182
|
+
return list.map((cfg) => ({
|
|
183
|
+
name: `${base}-${cfg.toLowerCase()}`,
|
|
184
|
+
displayName: `wyvrn ${profileName} (${cfg})`,
|
|
185
|
+
configurePreset: base,
|
|
186
|
+
configuration: cfg,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Build a fresh presets file from scratch (no prior content to merge).
|
|
192
|
+
*/
|
|
193
|
+
function buildFreshPresetsFile({
|
|
194
|
+
profileName,
|
|
195
|
+
profileHash,
|
|
196
|
+
toolchainRelPath,
|
|
197
|
+
generator = null,
|
|
198
|
+
extraCacheVariables = null,
|
|
199
|
+
installDir = null,
|
|
200
|
+
profileArch = null,
|
|
201
|
+
configs = null,
|
|
202
|
+
binaryDirRoot = DEFAULT_BINARY_DIR_ROOT,
|
|
203
|
+
}) {
|
|
204
|
+
return {
|
|
205
|
+
version: SCHEMA_VERSION,
|
|
206
|
+
vendor: {
|
|
207
|
+
[VENDOR_KEY]: {
|
|
208
|
+
profileName,
|
|
209
|
+
profileHash,
|
|
210
|
+
generatedAt: new Date().toISOString(),
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
configurePresets: [buildConfigurePreset({
|
|
214
|
+
profileName, profileHash, toolchainRelPath, generator, extraCacheVariables, installDir, profileArch, configs, binaryDirRoot,
|
|
215
|
+
})],
|
|
216
|
+
buildPresets: buildBuildPresets(profileName, configs),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Merge the current profile's presets into an existing wyvrnpm-generated
|
|
222
|
+
* file. Presets with matching `name` are replaced; others are preserved so
|
|
223
|
+
* `wyvrnpm install --profile release` followed by `wyvrnpm install --profile
|
|
224
|
+
* debug` leaves both profiles available in the file.
|
|
225
|
+
*
|
|
226
|
+
* @param {object} existing
|
|
227
|
+
* @param {object} args forwarded to the preset builders
|
|
228
|
+
* @returns {object}
|
|
229
|
+
*/
|
|
230
|
+
function mergeIntoExisting(existing, {
|
|
231
|
+
profileName,
|
|
232
|
+
profileHash,
|
|
233
|
+
toolchainRelPath,
|
|
234
|
+
generator = null,
|
|
235
|
+
extraCacheVariables = null,
|
|
236
|
+
installDir = null,
|
|
237
|
+
profileArch = null,
|
|
238
|
+
configs = null,
|
|
239
|
+
binaryDirRoot = DEFAULT_BINARY_DIR_ROOT,
|
|
240
|
+
}) {
|
|
241
|
+
const newConfigure = buildConfigurePreset({
|
|
242
|
+
profileName, profileHash, toolchainRelPath, generator, extraCacheVariables, installDir, profileArch, configs, binaryDirRoot,
|
|
243
|
+
});
|
|
244
|
+
const newBuilds = buildBuildPresets(profileName, configs);
|
|
245
|
+
const newConfigureNames = new Set([newConfigure.name]);
|
|
246
|
+
// When replacing THIS profile's build presets, drop every pre-existing
|
|
247
|
+
// one that targets the same configurePreset — the fresh `newBuilds`
|
|
248
|
+
// list fully replaces them. Scoping to configurePreset avoids stepping
|
|
249
|
+
// on presets for OTHER profiles in the same file, which is the whole
|
|
250
|
+
// point of the merge path.
|
|
251
|
+
//
|
|
252
|
+
// Without this, editing `build.configs` from 4 configs down to 2 would
|
|
253
|
+
// leave orphan build presets pointing at configurations CMake won't
|
|
254
|
+
// generate.
|
|
255
|
+
const myBase = `wyvrn-${profileName}`;
|
|
256
|
+
const isMyBuildPreset = (p) => p && p.configurePreset === myBase;
|
|
257
|
+
|
|
258
|
+
const configurePresets = (existing.configurePresets ?? []).filter((p) => !newConfigureNames.has(p.name));
|
|
259
|
+
configurePresets.push(newConfigure);
|
|
260
|
+
|
|
261
|
+
// Drop every pre-existing build preset that targets THIS profile's
|
|
262
|
+
// configurePreset — the fresh `newBuilds` list (one per current
|
|
263
|
+
// `configs` entry) fully replaces them. Presets for OTHER profiles
|
|
264
|
+
// stay untouched so the multi-profile merge story is preserved.
|
|
265
|
+
const buildPresets = (existing.buildPresets ?? []).filter((p) => !isMyBuildPreset(p));
|
|
266
|
+
buildPresets.push(...newBuilds);
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
...existing,
|
|
270
|
+
version: existing.version ?? SCHEMA_VERSION,
|
|
271
|
+
vendor: {
|
|
272
|
+
...(existing.vendor ?? {}),
|
|
273
|
+
[VENDOR_KEY]: {
|
|
274
|
+
profileName,
|
|
275
|
+
profileHash,
|
|
276
|
+
generatedAt: new Date().toISOString(),
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
configurePresets,
|
|
280
|
+
buildPresets,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Write a CMakePresets.json (or CMakeUserPresets.json, as fallback) under
|
|
286
|
+
* `projectRoot`. Never overwrites a user-owned file.
|
|
287
|
+
*
|
|
288
|
+
* Resolution order:
|
|
289
|
+
* 1. CMakePresets.json
|
|
290
|
+
* - Does not exist → create it.
|
|
291
|
+
* - Exists, wyvrn-gen → merge into it.
|
|
292
|
+
* - Exists, user-owned → leave alone, fall through.
|
|
293
|
+
* 2. CMakeUserPresets.json
|
|
294
|
+
* - Does not exist → create it.
|
|
295
|
+
* - Exists, wyvrn-gen → merge into it.
|
|
296
|
+
* - Exists, user-owned → skip (action: "skipped").
|
|
297
|
+
*
|
|
298
|
+
* @param {object} args
|
|
299
|
+
* @param {string} args.projectRoot Directory containing top-level CMakeLists.txt.
|
|
300
|
+
* @param {string} args.profileName
|
|
301
|
+
* @param {string} args.profileHash
|
|
302
|
+
* @param {string} args.toolchainRelPath CMake-style forward slashes, relative to projectRoot.
|
|
303
|
+
* @param {string|null} [args.generator] Propagated onto the configure preset's `generator` field.
|
|
304
|
+
* @param {Record<string,string>|null} [args.extraCacheVariables]
|
|
305
|
+
* Merged into the configure preset's `cacheVariables`.
|
|
306
|
+
* @returns {{ path: string|null, action: 'created'|'updated'|'skipped', isUser: boolean }}
|
|
307
|
+
*/
|
|
308
|
+
function generateCMakePresets({
|
|
309
|
+
projectRoot,
|
|
310
|
+
profileName,
|
|
311
|
+
profileHash,
|
|
312
|
+
toolchainRelPath,
|
|
313
|
+
generator = null,
|
|
314
|
+
extraCacheVariables = null,
|
|
315
|
+
installDir = null,
|
|
316
|
+
profileArch = null,
|
|
317
|
+
configs = null,
|
|
318
|
+
binaryDirRoot = DEFAULT_BINARY_DIR_ROOT,
|
|
319
|
+
}) {
|
|
320
|
+
const args = { profileName, profileHash, toolchainRelPath, generator, extraCacheVariables, installDir, profileArch, configs, binaryDirRoot };
|
|
321
|
+
const candidates = [
|
|
322
|
+
{ filePath: path.join(projectRoot, 'CMakePresets.json'), isUser: false },
|
|
323
|
+
{ filePath: path.join(projectRoot, 'CMakeUserPresets.json'), isUser: true },
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
for (const { filePath, isUser } of candidates) {
|
|
327
|
+
if (!fs.existsSync(filePath)) {
|
|
328
|
+
const content = buildFreshPresetsFile(args);
|
|
329
|
+
fs.writeFileSync(filePath, JSON.stringify(content, null, 2) + '\n', 'utf8');
|
|
330
|
+
return { path: filePath, action: 'created', isUser };
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const existing = safeReadJson(filePath);
|
|
334
|
+
if (isWyvrnGenerated(existing)) {
|
|
335
|
+
const merged = mergeIntoExisting(existing, args);
|
|
336
|
+
fs.writeFileSync(filePath, JSON.stringify(merged, null, 2) + '\n', 'utf8');
|
|
337
|
+
return { path: filePath, action: 'updated', isUser };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// User-owned — do not touch, try next candidate.
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return { path: null, action: 'skipped', isUser: false };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
module.exports = {
|
|
347
|
+
generateCMakePresets,
|
|
348
|
+
// Exported for tests
|
|
349
|
+
isWyvrnGenerated,
|
|
350
|
+
buildConfigurePreset,
|
|
351
|
+
buildBuildPresets,
|
|
352
|
+
buildFreshPresetsFile,
|
|
353
|
+
mergeIntoExisting,
|
|
354
|
+
VENDOR_KEY,
|
|
355
|
+
SCHEMA_VERSION,
|
|
356
|
+
};
|