mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
build: support structured toml patches to reduce build breakage (#184201)
Currently the Cargo.toml patches are git patches, but these can break easily when surrounding lines are changed. Instead this lets us make "Cargo.patch.toml" which gets a structured merge.
This commit is contained in:
parent
5504c4b854
commit
42015fe01c
|
@ -6,13 +6,40 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const cp = require("child_process");
|
||||
const toml = require("@iarna/toml");
|
||||
function log(...args) {
|
||||
console.log(`[${new Date().toLocaleTimeString('en', { hour12: false })}]`, '[distro]', ...args);
|
||||
}
|
||||
log(`Applying CLI patches...`);
|
||||
const basePath = `.build/distro/cli-patches`;
|
||||
const patchTomlSuffix = '.patch.toml';
|
||||
function deepMerge(target, source) {
|
||||
for (const [key, value] of Object.entries(source)) {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
if (!target.hasOwnProperty(key)) {
|
||||
target[key] = value;
|
||||
}
|
||||
else {
|
||||
deepMerge(target[key], value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
target[key] = value;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
for (const patch of fs.readdirSync(basePath)) {
|
||||
if (patch.endsWith(patchTomlSuffix)) {
|
||||
// this does not support nested filepaths, but that's fine for now...
|
||||
const originalPath = `cli/${patch.slice(0, -patchTomlSuffix.length)}.toml`;
|
||||
const contents = toml.parse(fs.readFileSync(originalPath, 'utf8'));
|
||||
deepMerge(contents, toml.parse(fs.readFileSync(`${basePath}/${patch}`, 'utf8')));
|
||||
fs.writeFileSync(originalPath, toml.stringify(contents));
|
||||
}
|
||||
else {
|
||||
cp.execSync(`git apply --ignore-whitespace --ignore-space-change ${basePath}/${patch}`, { stdio: 'inherit' });
|
||||
}
|
||||
log('Applied CLI patch:', patch, '✔︎');
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwbH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xRQUFRLENBQUMsRUFBRTtJQUM3QyxJQUFJLEtBQUssQ0FBQyxRQUFRLENBQUMsZUFBZSxDQUFDLEVBQUU7UUFDcEMscUVBQXFFO1FBQ3JFLE1BQU0sWUFBWSxHQUFHLE9BQU8sS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDLEVBQUUsQ0FBQyxlQUFlLENBQUMsTUFBTSxDQUFDLE9BQU8sQ0FBQztRQUMzRSxNQUFNLFFBQVEsR0FBRyxJQUFJLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsWUFBWSxFQUFFLE1BQU0sQ0FBQyxDQUFDLENBQUM7UUFDbkUsU0FBUyxDQUFDLFFBQVEsRUFBRSxJQUFJLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsR0FBRyxRQUFRLElBQUksS0FBSyxFQUFFLEVBQUUsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2pGLEVBQUUsQ0FBQyxhQUFhLENBQUMsWUFBWSxFQUFFLElBQUksQ0FBQyxTQUFTLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQztLQUN6RDtTQUFNO1FBQ04sRUFBRSxDQUFDLFFBQVEsQ0FBQyx1REFBdUQsUUFBUSxJQUFJLEtBQUssRUFBRSxFQUFFLEVBQUUsS0FBSyxFQUFFLFNBQVMsRUFBRSxDQUFDLENBQUM7S0FDOUc7SUFDRCxHQUFHLENBQUMsb0JBQW9CLEVBQUUsS0FBSyxFQUFFLElBQUksQ0FBQyxDQUFDO0NBQ3ZDIn0=
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import * as fs from 'fs';
|
||||
import * as cp from 'child_process';
|
||||
import * as toml from '@iarna/toml';
|
||||
|
||||
function log(...args: any[]): void {
|
||||
console.log(`[${new Date().toLocaleTimeString('en', { hour12: false })}]`, '[distro]', ...args);
|
||||
|
@ -13,8 +14,32 @@ function log(...args: any[]): void {
|
|||
log(`Applying CLI patches...`);
|
||||
|
||||
const basePath = `.build/distro/cli-patches`;
|
||||
const patchTomlSuffix = '.patch.toml';
|
||||
|
||||
function deepMerge(target: any, source: any): any {
|
||||
for (const [key, value] of Object.entries(source)) {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
if (!target.hasOwnProperty(key)) {
|
||||
target[key] = value;
|
||||
} else {
|
||||
deepMerge(target[key], value);
|
||||
}
|
||||
} else {
|
||||
target[key] = value;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
for (const patch of fs.readdirSync(basePath)) {
|
||||
if (patch.endsWith(patchTomlSuffix)) {
|
||||
// this does not support nested filepaths, but that's fine for now...
|
||||
const originalPath = `cli/${patch.slice(0, -patchTomlSuffix.length)}.toml`;
|
||||
const contents = toml.parse(fs.readFileSync(originalPath, 'utf8'));
|
||||
deepMerge(contents, toml.parse(fs.readFileSync(`${basePath}/${patch}`, 'utf8')));
|
||||
fs.writeFileSync(originalPath, toml.stringify(contents));
|
||||
} else {
|
||||
cp.execSync(`git apply --ignore-whitespace --ignore-space-change ${basePath}/${patch}`, { stdio: 'inherit' });
|
||||
}
|
||||
log('Applied CLI patch:', patch, '✔︎');
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"@azure/identity": "^3.1.3",
|
||||
"@azure/storage-blob": "^12.13.0",
|
||||
"@electron/get": "^1.12.4",
|
||||
"@iarna/toml": "^2.2.5",
|
||||
"@types/ansi-colors": "^3.2.0",
|
||||
"@types/byline": "^4.2.32",
|
||||
"@types/cssnano": "^4.0.0",
|
||||
|
@ -23,6 +24,7 @@
|
|||
"@types/gulp-postcss": "^8.0.0",
|
||||
"@types/gulp-rename": "^0.0.33",
|
||||
"@types/gulp-sourcemaps": "^0.0.32",
|
||||
"@types/iarna__toml": "^2.0.2",
|
||||
"@types/mime": "0.0.29",
|
||||
"@types/minimatch": "^3.0.3",
|
||||
"@types/minimist": "^1.2.1",
|
||||
|
|
|
@ -339,6 +339,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.17.14.tgz#e81fb49de05fed91bf74251c9ca0343f4fc77d31"
|
||||
integrity sha512-gPQmsi2DKTaEgG14hc3CHXHp62k8g6qr0Pas+I4lUxRMugGSATh/Bi8Dgusoz9IQ0IfdrvLpco6kujEIBoaogA==
|
||||
|
||||
"@iarna/toml@^2.2.5":
|
||||
version "2.2.5"
|
||||
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
|
||||
integrity sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==
|
||||
|
||||
"@malept/cross-spawn-promise@^1.1.0":
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz#504af200af6b98e198bce768bc1730c6936ae01d"
|
||||
|
@ -501,6 +506,13 @@
|
|||
"@types/undertaker" "*"
|
||||
"@types/vinyl-fs" "*"
|
||||
|
||||
"@types/iarna__toml@^2.0.2":
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/iarna__toml/-/iarna__toml-2.0.2.tgz#2e61b079e50760b477bc70e4df1fe5b633ef6c63"
|
||||
integrity sha512-Q3obxKhBLVVbEQ8zsAmsQVobAAZhi8dFFFjF0q5xKXiaHvH8IkSxcbM27e46M9feUMieR03SPpmp5CtaNzpdBg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/js-beautify@*":
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-beautify/-/js-beautify-1.8.0.tgz#0369d3d0e1f35a6aec07cb4da2ee2bcda111367c"
|
||||
|
|
Loading…
Reference in a new issue