-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathsystem-reqs.js
112 lines (112 loc) · 3.98 KB
/
system-reqs.js
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
"use strict";
// Enforce system requirements for the CodeQL CLI.
// https://codeql.github.com/docs/codeql-overview/system-requirements/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.passesSystemRequirements = passesSystemRequirements;
const macos_version_1 = require("macos-version");
const util_1 = require("./util");
const fs_1 = require("fs");
const os_1 = __importDefault(require("os"));
const platformMap = {
'darwin': 'macOS',
'linux': 'Linux',
'win32': 'Windows',
};
const platformRequirements = {
'macOS': {
'version': ['13.0.1', '14.0.1'],
'arch': ['arm64', 'x64'],
},
'Linux': {
// We only accept Ubuntu 20.04, 21.04, and 22.04
'version': ['20.04', '21.04', '22.04'],
'arch': ['x64'],
},
'Windows': {
'version': ['10', 'Server 2019', '11', 'Server 2022'],
'arch': ['x64'],
},
};
function passesSystemRequirements() {
// CodeQL System requirements are two-level: the CLI must run on a specific platform,
// and that platform must have certain capabilities.
const platform = getPlatform();
switch (platform) {
case 'macOS':
return checkMacOSPlatform();
case 'Linux':
return checkLinuxPlatform();
case 'Windows':
return checkWindowsPlatform();
default:
(0, util_1.assertNever)(platform);
}
}
// MacOS checks
function checkMacOSPlatform() {
const macOSPlatformRequirements = platformRequirements['macOS'];
const passesSystemRequirements = checkMacOSVersion(macOSPlatformRequirements['version']) && checkMacOSArch(macOSPlatformRequirements['arch']);
return passesSystemRequirements;
}
function checkMacOSVersion(supportedVersions) {
return supportedVersions.some((version) => {
(0, macos_version_1.isMacOSVersionGreaterThanOrEqualTo)(version);
});
}
function checkMacOSArch(supportedArchs) {
const arch = getArch();
return supportedArchs.includes(arch);
}
// Linux checks
function checkLinuxPlatform() {
const linuxPlatformRequirements = platformRequirements['Linux'];
return checkLinuxVersion(linuxPlatformRequirements['version']) && checkLinuxArch(linuxPlatformRequirements['arch']);
}
function checkLinuxVersion(supportedVersions) {
const data = (0, fs_1.readFileSync)('/etc/os-release', 'utf8');
const lines = data.split('\n');
const releaseDetails = {};
lines.forEach((line) => {
// Split the line into a key and value delimited by '='
const words = line.split('=');
if (words.length === 2) {
releaseDetails[words[0].trim().toLowerCase()] = words[1].trim();
}
});
return releaseDetails.name == 'Ubuntu' && supportedVersions.includes(releaseDetails.version_id);
}
function checkLinuxArch(supportedArchs) {
const arch = getArch();
return supportedArchs.includes(arch);
}
// Windows checks
function checkWindowsPlatform() {
const windowsPlatformRequirements = platformRequirements['Windows'];
return checkWindowsVersion(windowsPlatformRequirements['version']) && checkWindowsArch(windowsPlatformRequirements['arch']);
}
function checkWindowsVersion(supportedVersions) {
// os.release() on windows returns a string like "Windows 11 Home"
const windowsVersion = os_1.default.release();
return supportedVersions.some(version => new RegExp(version, 'i').test(windowsVersion));
}
function checkWindowsArch(supportedArchs) {
const arch = getArch();
return supportedArchs.includes(arch);
}
;
// Auxiliary functions
function getPlatform() {
const platform = process.platform;
const mappedPlatform = platformMap[platform];
if (mappedPlatform === undefined) {
throw new util_1.ConfigurationError(`Unsupported platform: ${platform}`);
}
return mappedPlatform;
}
function getArch() {
return process.arch;
}
//# sourceMappingURL=system-reqs.js.map