Skip to content

Commit 5ffb21d

Browse files
committed
Allow extraction of version from multiple headers
1 parent f8f5ba7 commit 5ffb21d

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

packed/index.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ var VersionExtractor = /** @class */ (function () {
14671467
this.minor_define = desc.minor_define;
14681468
this.patch_define = desc.patch_define;
14691469
this.header_paths = desc.header_paths;
1470-
this.header_filename = desc.header_filename;
1470+
this.header_filenames = desc.header_filenames;
14711471
}
14721472
VersionExtractor.prototype.extract_from_header_path = function (path) {
14731473
if (!fs.existsSync(path)) {
@@ -1476,17 +1476,17 @@ var VersionExtractor = /** @class */ (function () {
14761476
var contents = fs.readFileSync(path, "utf8");
14771477
var match_major = contents.match(new RegExp("#define[ \\t]+".concat(this.major_define, "[ \\t]+([0-9]+)")));
14781478
if (!match_major) {
1479-
throw new util_1.SetupSdlError("Unable to extract major version from ".concat(path));
1479+
return null;
14801480
}
14811481
var major_version = Number(match_major[1]);
14821482
var match_minor = contents.match(new RegExp("#define[ \\t]+".concat(this.minor_define, "[ \\t]+([0-9]+)")));
14831483
if (!match_minor) {
1484-
throw new util_1.SetupSdlError("Unable to extract minor version from ".concat(path));
1484+
return null;
14851485
}
14861486
var minor_version = Number(match_minor[1]);
14871487
var match_patch = contents.match(new RegExp("#define[ \\t]+".concat(this.patch_define, "[ \\t]+([0-9]+)")));
14881488
if (!match_patch) {
1489-
throw new util_1.SetupSdlError("Unable to extract patch version from ".concat(path));
1489+
return null;
14901490
}
14911491
var patch_version = Number(match_patch[1]);
14921492
return new Version({
@@ -1500,11 +1500,18 @@ var VersionExtractor = /** @class */ (function () {
15001500
var version = (function () {
15011501
for (var _i = 0, _a = _this.header_paths; _i < _a.length; _i++) {
15021502
var infix_path = _a[_i];
1503-
var hdr_path = "".concat(path, "/").concat(infix_path, "/").concat(_this.header_filename);
1504-
if (!fs.existsSync(hdr_path)) {
1505-
continue;
1503+
for (var _b = 0, _c = _this.header_filenames; _b < _c.length; _b++) {
1504+
var header_filename = _c[_b];
1505+
var hdr_path = "".concat(path, "/").concat(infix_path, "/").concat(header_filename);
1506+
if (!fs.existsSync(hdr_path)) {
1507+
continue;
1508+
}
1509+
var version_1 = _this.extract_from_header_path(hdr_path);
1510+
if (version_1 == null) {
1511+
continue;
1512+
}
1513+
return version_1;
15061514
}
1507-
return _this.extract_from_header_path(hdr_path);
15081515
}
15091516
throw new util_1.SetupSdlError("Could not extract version from ".concat(path, "."));
15101517
})();
@@ -1522,9 +1529,9 @@ exports.project_descriptions = (_a = {},
15221529
deps: [],
15231530
major_define: "SDL_MAJOR_VERSION",
15241531
minor_define: "SDL_MINOR_VERSION",
1525-
patch_define: "SDL_PATCHLEVEL",
1532+
patch_define: "(?:SDL_PATCHLEVEL|SDL_MICRO_VERSION)",
15261533
header_paths: ["include/SDL3", "include/SDL2"],
1527-
header_filename: "SDL_version.h",
1534+
header_filenames: ["SDL.h", "SDL_version.h"],
15281535
git_url: "https://github.com/libsdl-org/SDL.git",
15291536
repo_owner: "libsdl-org",
15301537
repo_name: "SDL",
@@ -1603,7 +1610,7 @@ exports.project_descriptions = (_a = {},
16031610
minor_define: "SDL_IMAGE_MINOR_VERSION",
16041611
patch_define: "SDL_IMAGE_PATCHLEVEL",
16051612
header_paths: ["include/SDL3_image", "include/SDL2"],
1606-
header_filename: "SDL_image.h",
1613+
header_filenames: ["SDL_image.h"],
16071614
git_url: "https://github.com/libsdl-org/SDL_image.git",
16081615
repo_owner: "libsdl-org",
16091616
repo_name: "SDL_image",
@@ -1618,7 +1625,7 @@ exports.project_descriptions = (_a = {},
16181625
minor_define: "SDL_MIXER_MINOR_VERSION",
16191626
patch_define: "SDL_MIXER_PATCHLEVEL",
16201627
header_paths: ["include/SDL3_mixer", "include/SDL2"],
1621-
header_filename: "SDL_mixer.h",
1628+
header_filenames: ["SDL_mixer.h"],
16221629
git_url: "https://github.com/libsdl-org/SDL_mixer.git",
16231630
repo_owner: "libsdl-org",
16241631
repo_name: "SDL_mixer",
@@ -1633,7 +1640,7 @@ exports.project_descriptions = (_a = {},
16331640
minor_define: "SDL_NET_MINOR_VERSION",
16341641
patch_define: "SDL_NET_PATCHLEVEL",
16351642
header_paths: ["include/SDL3_net", "include/SDL2", "include"],
1636-
header_filename: "SDL_net.h",
1643+
header_filenames: ["SDL_net.h"],
16371644
git_url: "https://github.com/libsdl-org/SDL_net.git",
16381645
repo_owner: "libsdl-org",
16391646
repo_name: "SDL_net",
@@ -1648,7 +1655,7 @@ exports.project_descriptions = (_a = {},
16481655
minor_define: "SDL_RTF_MINOR_VERSION",
16491656
patch_define: "SDL_RTF_PATCHLEVEL",
16501657
header_paths: ["include/SDL3_rtf", "include/SDL2", "include"],
1651-
header_filename: "SDL_rtf.h",
1658+
header_filenames: ["SDL_rtf.h"],
16521659
git_url: "https://github.com/libsdl-org/SDL_rtf.git",
16531660
repo_owner: "libsdl-org",
16541661
repo_name: "SDL_rtf",
@@ -1663,7 +1670,7 @@ exports.project_descriptions = (_a = {},
16631670
minor_define: "SDL_TTF_MINOR_VERSION",
16641671
patch_define: "SDL_TTF_PATCHLEVEL",
16651672
header_paths: ["include/SDL3_ttf", "include/SDL2"],
1666-
header_filename: "SDL_ttf.h",
1673+
header_filenames: ["SDL_ttf.h"],
16671674
git_url: "https://github.com/libsdl-org/SDL_ttf.git",
16681675
repo_owner: "libsdl-org",
16691676
repo_name: "SDL_ttf",

src/version.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ interface ProjectDescription {
127127
minor_define: string;
128128
patch_define: string;
129129
header_paths: string[];
130-
header_filename: string;
130+
header_filenames: string[];
131131
git_url: string;
132132
repo_owner: string;
133133
repo_name: string;
@@ -140,17 +140,17 @@ export class VersionExtractor {
140140
minor_define: string;
141141
patch_define: string;
142142
header_paths: string[];
143-
header_filename: string;
143+
header_filenames: string[];
144144

145145
constructor(desc: ProjectDescription) {
146146
this.major_define = desc.major_define;
147147
this.minor_define = desc.minor_define;
148148
this.patch_define = desc.patch_define;
149149
this.header_paths = desc.header_paths;
150-
this.header_filename = desc.header_filename;
150+
this.header_filenames = desc.header_filenames;
151151
}
152152

153-
extract_from_header_path(path: string): Version {
153+
extract_from_header_path(path: string): Version | null {
154154
if (!fs.existsSync(path)) {
155155
throw new SetupSdlError(`Cannot find ${path}`);
156156
}
@@ -161,23 +161,23 @@ export class VersionExtractor {
161161
new RegExp(`#define[ \\t]+${this.major_define}[ \\t]+([0-9]+)`),
162162
);
163163
if (!match_major) {
164-
throw new SetupSdlError(`Unable to extract major version from ${path}`);
164+
return null;
165165
}
166166
const major_version = Number(match_major[1]);
167167

168168
const match_minor = contents.match(
169169
new RegExp(`#define[ \\t]+${this.minor_define}[ \\t]+([0-9]+)`),
170170
);
171171
if (!match_minor) {
172-
throw new SetupSdlError(`Unable to extract minor version from ${path}`);
172+
return null;
173173
}
174174
const minor_version = Number(match_minor[1]);
175175

176176
const match_patch = contents.match(
177177
new RegExp(`#define[ \\t]+${this.patch_define}[ \\t]+([0-9]+)`),
178178
);
179179
if (!match_patch) {
180-
throw new SetupSdlError(`Unable to extract patch version from ${path}`);
180+
return null;
181181
}
182182
const patch_version = Number(match_patch[1]);
183183

@@ -191,11 +191,17 @@ export class VersionExtractor {
191191
extract_from_install_prefix(path: string): Version {
192192
const version = (() => {
193193
for (const infix_path of this.header_paths) {
194-
const hdr_path = `${path}/${infix_path}/${this.header_filename}`;
195-
if (!fs.existsSync(hdr_path)) {
196-
continue;
194+
for (const header_filename of this.header_filenames) {
195+
const hdr_path = `${path}/${infix_path}/${header_filename}`;
196+
if (!fs.existsSync(hdr_path)) {
197+
continue;
198+
}
199+
const version = this.extract_from_header_path(hdr_path);
200+
if (version == null) {
201+
continue;
202+
}
203+
return version;
197204
}
198-
return this.extract_from_header_path(hdr_path);
199205
}
200206
throw new SetupSdlError(`Could not extract version from ${path}.`);
201207
})();
@@ -212,9 +218,9 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
212218
deps: [],
213219
major_define: "SDL_MAJOR_VERSION",
214220
minor_define: "SDL_MINOR_VERSION",
215-
patch_define: "SDL_PATCHLEVEL",
221+
patch_define: "(?:SDL_PATCHLEVEL|SDL_MICRO_VERSION)",
216222
header_paths: ["include/SDL3", "include/SDL2"],
217-
header_filename: "SDL_version.h",
223+
header_filenames: ["SDL.h", "SDL_version.h"],
218224
git_url: "https://github.com/libsdl-org/SDL.git",
219225
repo_owner: "libsdl-org",
220226
repo_name: "SDL",
@@ -293,7 +299,7 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
293299
minor_define: "SDL_IMAGE_MINOR_VERSION",
294300
patch_define: "SDL_IMAGE_PATCHLEVEL",
295301
header_paths: ["include/SDL3_image", "include/SDL2"],
296-
header_filename: "SDL_image.h",
302+
header_filenames: ["SDL_image.h"],
297303
git_url: "https://github.com/libsdl-org/SDL_image.git",
298304
repo_owner: "libsdl-org",
299305
repo_name: "SDL_image",
@@ -308,7 +314,7 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
308314
minor_define: "SDL_MIXER_MINOR_VERSION",
309315
patch_define: "SDL_MIXER_PATCHLEVEL",
310316
header_paths: ["include/SDL3_mixer", "include/SDL2"],
311-
header_filename: "SDL_mixer.h",
317+
header_filenames: ["SDL_mixer.h"],
312318
git_url: "https://github.com/libsdl-org/SDL_mixer.git",
313319
repo_owner: "libsdl-org",
314320
repo_name: "SDL_mixer",
@@ -323,7 +329,7 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
323329
minor_define: "SDL_NET_MINOR_VERSION",
324330
patch_define: "SDL_NET_PATCHLEVEL",
325331
header_paths: ["include/SDL3_net", "include/SDL2", "include"],
326-
header_filename: "SDL_net.h",
332+
header_filenames: ["SDL_net.h"],
327333
git_url: "https://github.com/libsdl-org/SDL_net.git",
328334
repo_owner: "libsdl-org",
329335
repo_name: "SDL_net",
@@ -338,7 +344,7 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
338344
minor_define: "SDL_RTF_MINOR_VERSION",
339345
patch_define: "SDL_RTF_PATCHLEVEL",
340346
header_paths: ["include/SDL3_rtf", "include/SDL2", "include"],
341-
header_filename: "SDL_rtf.h",
347+
header_filenames: ["SDL_rtf.h"],
342348
git_url: "https://github.com/libsdl-org/SDL_rtf.git",
343349
repo_owner: "libsdl-org",
344350
repo_name: "SDL_rtf",
@@ -353,7 +359,7 @@ export const project_descriptions: { [key in Project]: ProjectDescription } = {
353359
minor_define: "SDL_TTF_MINOR_VERSION",
354360
patch_define: "SDL_TTF_PATCHLEVEL",
355361
header_paths: ["include/SDL3_ttf", "include/SDL2"],
356-
header_filename: "SDL_ttf.h",
362+
header_filenames: ["SDL_ttf.h"],
357363
git_url: "https://github.com/libsdl-org/SDL_ttf.git",
358364
repo_owner: "libsdl-org",
359365
repo_name: "SDL_ttf",

0 commit comments

Comments
 (0)