Repository navigation
Expand file tree
/
Copy pathpatch-linux-window-ui.js
More file actions
93 lines (83 loc) · 2.63 KB
/
Copy pathpatch-linux-window-ui.js
File metadata and controls
93 lines (83 loc) · 2.63 KB
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
#!/usr/bin/env node
"use strict";
const {
createPatchReport,
criticalFailuresFromReport,
enabledFeatureFailuresFromReport,
writePatchReport,
} = require("./lib/patch-report.js");
const {
patchExtractedApp,
} = require("./patches/runner.js");
const {
isPatchIntegrityError,
} = require("./patches/integrity-error.js");
const USAGE = "Usage: patch-linux-window-ui.js [--report-json path] [--enforce-critical] <extracted-app-asar-dir>";
function main() {
const args = process.argv.slice(2);
let reportJson = null;
let enforceCritical = false;
const positional = [];
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
if (arg === "--report-json") {
reportJson = args[index + 1];
if (!reportJson) {
console.error(USAGE);
process.exit(1);
}
index += 1;
} else if (arg === "--enforce-critical") {
enforceCritical = true;
} else if (arg === "--help" || arg === "-h") {
console.log(USAGE);
process.exit(0);
} else {
positional.push(arg);
}
}
const extractedDir = positional[0];
if (!extractedDir || positional.length > 1) {
console.error(USAGE);
process.exit(1);
}
// Enforcement needs the report data even when no --report-json was requested.
const report = reportJson == null && !enforceCritical ? null : createPatchReport();
let integrityError = null;
try {
patchExtractedApp(extractedDir, { report });
} catch (error) {
if (!isPatchIntegrityError(error)) {
throw error;
}
integrityError = error;
}
// Write the report before gating so CI artifact upload sees it even on failure.
writePatchReport(reportJson, report);
if (integrityError != null) {
console.error(`Patch integrity failure: ${integrityError.message}`);
process.exit(1);
}
if (enforceCritical) {
const failures = [
...criticalFailuresFromReport(report),
...enabledFeatureFailuresFromReport(report),
].filter((failure, index, all) =>
all.findIndex((candidate) => candidate.name === failure.name && candidate.status === failure.status) === index,
);
if (failures.length > 0) {
console.error(`Critical patch failures (${failures.length}):`);
for (const failure of failures) {
console.error(` - ${failure.name} (${failure.status})${failure.reason ? `: ${failure.reason}` : ""}`);
}
console.error(
"Aborting: required patches or explicitly enabled feature patches drifted. " +
"Set CODEX_ENFORCE_CRITICAL_PATCHES=0 to bypass (emergency builds only).",
);
process.exit(1);
}
}
}
if (require.main === module) {
main();
}