mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-19 16:18:58 +01:00
Refactor package dependencies generators (#157845)
This commit is contained in:
35
build/linux/rpm/calculate-deps.js
Normal file
35
build/linux/rpm/calculate-deps.js
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generatePackageDeps = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
const dep_lists_1 = require("./dep-lists");
|
||||
function generatePackageDeps(files) {
|
||||
const dependencies = files.map(file => calculatePackageDeps(file));
|
||||
const additionalDepsSet = new Set(dep_lists_1.additionalDeps);
|
||||
dependencies.push(additionalDepsSet);
|
||||
return dependencies;
|
||||
}
|
||||
exports.generatePackageDeps = generatePackageDeps;
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/calculate_package_deps.py.
|
||||
function calculatePackageDeps(binaryPath) {
|
||||
try {
|
||||
if (!((0, fs_1.statSync)(binaryPath).mode & fs_1.constants.S_IXUSR)) {
|
||||
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// The package might not exist. Don't re-throw the error here.
|
||||
console.error('Tried to stat ' + binaryPath + ' but failed.');
|
||||
}
|
||||
const findRequiresResult = (0, child_process_1.spawnSync)('/usr/lib/rpm/find-requires', { input: binaryPath + '\n' });
|
||||
if (findRequiresResult.status !== 0) {
|
||||
throw new Error(`find-requires failed with exit code ${findRequiresResult.status}.\nstderr: ${findRequiresResult.stderr}`);
|
||||
}
|
||||
const requires = new Set(findRequiresResult.stdout.toString('utf-8').trimEnd().split('\n'));
|
||||
return requires;
|
||||
}
|
||||
35
build/linux/rpm/calculate-deps.ts
Normal file
35
build/linux/rpm/calculate-deps.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { spawnSync } from 'child_process';
|
||||
import { constants, statSync } from 'fs';
|
||||
import { additionalDeps } from './dep-lists';
|
||||
|
||||
export function generatePackageDeps(files: string[]): Set<string>[] {
|
||||
const dependencies: Set<string>[] = files.map(file => calculatePackageDeps(file));
|
||||
const additionalDepsSet = new Set(additionalDeps);
|
||||
dependencies.push(additionalDepsSet);
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/calculate_package_deps.py.
|
||||
function calculatePackageDeps(binaryPath: string): Set<string> {
|
||||
try {
|
||||
if (!(statSync(binaryPath).mode & constants.S_IXUSR)) {
|
||||
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
|
||||
}
|
||||
} catch (e) {
|
||||
// The package might not exist. Don't re-throw the error here.
|
||||
console.error('Tried to stat ' + binaryPath + ' but failed.');
|
||||
}
|
||||
|
||||
const findRequiresResult = spawnSync('/usr/lib/rpm/find-requires', { input: binaryPath + '\n' });
|
||||
if (findRequiresResult.status !== 0) {
|
||||
throw new Error(`find-requires failed with exit code ${findRequiresResult.status}.\nstderr: ${findRequiresResult.stderr}`);
|
||||
}
|
||||
|
||||
const requires = new Set(findRequiresResult.stdout.toString('utf-8').trimEnd().split('\n'));
|
||||
return requires;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.referenceGeneratedDepsByArch = exports.bundledDeps = exports.additionalDeps = void 0;
|
||||
exports.referenceGeneratedDepsByArch = exports.additionalDeps = void 0;
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/additional_deps
|
||||
// Additional dependencies not in the rpm find-requires output.
|
||||
exports.additionalDeps = [
|
||||
@@ -17,18 +17,6 @@ exports.additionalDeps = [
|
||||
'libcurl.so.4()(64bit)',
|
||||
'xdg-utils' // OS integration
|
||||
];
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/refs/tags/98.0.4758.109:chrome/installer/linux/BUILD.gn;l=64-80
|
||||
// and the Linux Archive build
|
||||
// Shared library dependencies that we already bundle.
|
||||
exports.bundledDeps = [
|
||||
'libEGL.so',
|
||||
'libGLESv2.so',
|
||||
'libvulkan.so.1',
|
||||
'swiftshader_libEGL.so',
|
||||
'swiftshader_libGLESv2.so',
|
||||
'libvk_swiftshader.so',
|
||||
'libffmpeg.so'
|
||||
];
|
||||
exports.referenceGeneratedDepsByArch = {
|
||||
'x86_64': [
|
||||
'ca-certificates',
|
||||
|
||||
@@ -16,19 +16,6 @@ export const additionalDeps = [
|
||||
'xdg-utils' // OS integration
|
||||
];
|
||||
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/refs/tags/98.0.4758.109:chrome/installer/linux/BUILD.gn;l=64-80
|
||||
// and the Linux Archive build
|
||||
// Shared library dependencies that we already bundle.
|
||||
export const bundledDeps = [
|
||||
'libEGL.so',
|
||||
'libGLESv2.so',
|
||||
'libvulkan.so.1',
|
||||
'swiftshader_libEGL.so',
|
||||
'swiftshader_libGLESv2.so',
|
||||
'libvk_swiftshader.so',
|
||||
'libffmpeg.so'
|
||||
];
|
||||
|
||||
export const referenceGeneratedDepsByArch = {
|
||||
'x86_64': [
|
||||
'ca-certificates',
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDependencies = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
const path = require("path");
|
||||
const dep_lists_1 = require("./dep-lists");
|
||||
// A flag that can easily be toggled.
|
||||
// Make sure to compile the build directory after toggling the value.
|
||||
// If false, we warn about new dependencies if they show up
|
||||
// while running the rpm prepare package task for a release.
|
||||
// If true, we fail the build if there are new dependencies found during that task.
|
||||
// The reference dependencies, which one has to update when the new dependencies
|
||||
// are valid, are in dep-lists.ts
|
||||
const FAIL_BUILD_FOR_NEW_DEPENDENCIES = true;
|
||||
function getDependencies(buildDir, applicationName, arch) {
|
||||
// Get the files for which we want to find dependencies.
|
||||
const nativeModulesPath = path.join(buildDir, 'resources', 'app', 'node_modules.asar.unpacked');
|
||||
const findResult = (0, child_process_1.spawnSync)('find', [nativeModulesPath, '-name', '*.node']);
|
||||
if (findResult.status) {
|
||||
console.error('Error finding files:');
|
||||
console.error(findResult.stderr.toString());
|
||||
return [];
|
||||
}
|
||||
const files = findResult.stdout.toString().trimEnd().split('\n');
|
||||
const appPath = path.join(buildDir, applicationName);
|
||||
files.push(appPath);
|
||||
// Add chrome sandbox and crashpad handler.
|
||||
files.push(path.join(buildDir, 'chrome-sandbox'));
|
||||
files.push(path.join(buildDir, 'chrome_crashpad_handler'));
|
||||
// Generate the dependencies.
|
||||
const dependencies = files.map((file) => calculatePackageDeps(file));
|
||||
// Add additional dependencies.
|
||||
const additionalDepsSet = new Set(dep_lists_1.additionalDeps);
|
||||
dependencies.push(additionalDepsSet);
|
||||
// Merge all the dependencies.
|
||||
const mergedDependencies = mergePackageDeps(dependencies);
|
||||
let sortedDependencies = [];
|
||||
for (const dependency of mergedDependencies) {
|
||||
sortedDependencies.push(dependency);
|
||||
}
|
||||
sortedDependencies.sort();
|
||||
// Exclude bundled dependencies
|
||||
sortedDependencies = sortedDependencies.filter(dependency => {
|
||||
return !dep_lists_1.bundledDeps.some(bundledDep => dependency.startsWith(bundledDep));
|
||||
});
|
||||
const referenceGeneratedDeps = dep_lists_1.referenceGeneratedDepsByArch[arch];
|
||||
if (JSON.stringify(sortedDependencies) !== JSON.stringify(referenceGeneratedDeps)) {
|
||||
const failMessage = 'The dependencies list has changed. '
|
||||
+ 'Printing newer dependencies list that one can use to compare against referenceGeneratedDeps:\n'
|
||||
+ sortedDependencies.join('\n');
|
||||
if (FAIL_BUILD_FOR_NEW_DEPENDENCIES) {
|
||||
throw new Error(failMessage);
|
||||
}
|
||||
else {
|
||||
console.warn(failMessage);
|
||||
}
|
||||
}
|
||||
return sortedDependencies;
|
||||
}
|
||||
exports.getDependencies = getDependencies;
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/calculate_package_deps.py.
|
||||
function calculatePackageDeps(binaryPath) {
|
||||
try {
|
||||
if (!((0, fs_1.statSync)(binaryPath).mode & fs_1.constants.S_IXUSR)) {
|
||||
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// The package might not exist. Don't re-throw the error here.
|
||||
console.error('Tried to stat ' + binaryPath + ' but failed.');
|
||||
}
|
||||
const findRequiresResult = (0, child_process_1.spawnSync)('/usr/lib/rpm/find-requires', { input: binaryPath + '\n' });
|
||||
if (findRequiresResult.status !== 0) {
|
||||
throw new Error(`find-requires failed with exit code ${findRequiresResult.status}.\nstderr: ${findRequiresResult.stderr}`);
|
||||
}
|
||||
const requires = new Set(findRequiresResult.stdout.toString('utf-8').trimEnd().split('\n'));
|
||||
return requires;
|
||||
}
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/merge_package_deps.py.
|
||||
function mergePackageDeps(inputDeps) {
|
||||
const requires = new Set();
|
||||
for (const depSet of inputDeps) {
|
||||
for (const dep of depSet) {
|
||||
const trimmedDependency = dep.trim();
|
||||
if (trimmedDependency.length && !trimmedDependency.startsWith('#')) {
|
||||
requires.add(trimmedDependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
return requires;
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { spawnSync } from 'child_process';
|
||||
import { constants, statSync } from 'fs';
|
||||
import path = require('path');
|
||||
import { additionalDeps, bundledDeps, referenceGeneratedDepsByArch } from './dep-lists';
|
||||
import { ArchString } from './types';
|
||||
|
||||
// A flag that can easily be toggled.
|
||||
// Make sure to compile the build directory after toggling the value.
|
||||
// If false, we warn about new dependencies if they show up
|
||||
// while running the rpm prepare package task for a release.
|
||||
// If true, we fail the build if there are new dependencies found during that task.
|
||||
// The reference dependencies, which one has to update when the new dependencies
|
||||
// are valid, are in dep-lists.ts
|
||||
const FAIL_BUILD_FOR_NEW_DEPENDENCIES: boolean = true;
|
||||
|
||||
export function getDependencies(buildDir: string, applicationName: string, arch: ArchString): string[] {
|
||||
// Get the files for which we want to find dependencies.
|
||||
const nativeModulesPath = path.join(buildDir, 'resources', 'app', 'node_modules.asar.unpacked');
|
||||
const findResult = spawnSync('find', [nativeModulesPath, '-name', '*.node']);
|
||||
if (findResult.status) {
|
||||
console.error('Error finding files:');
|
||||
console.error(findResult.stderr.toString());
|
||||
return [];
|
||||
}
|
||||
|
||||
const files = findResult.stdout.toString().trimEnd().split('\n');
|
||||
|
||||
const appPath = path.join(buildDir, applicationName);
|
||||
files.push(appPath);
|
||||
|
||||
// Add chrome sandbox and crashpad handler.
|
||||
files.push(path.join(buildDir, 'chrome-sandbox'));
|
||||
files.push(path.join(buildDir, 'chrome_crashpad_handler'));
|
||||
|
||||
// Generate the dependencies.
|
||||
const dependencies: Set<string>[] = files.map((file) => calculatePackageDeps(file));
|
||||
|
||||
// Add additional dependencies.
|
||||
const additionalDepsSet = new Set(additionalDeps);
|
||||
dependencies.push(additionalDepsSet);
|
||||
|
||||
// Merge all the dependencies.
|
||||
const mergedDependencies = mergePackageDeps(dependencies);
|
||||
let sortedDependencies: string[] = [];
|
||||
for (const dependency of mergedDependencies) {
|
||||
sortedDependencies.push(dependency);
|
||||
}
|
||||
sortedDependencies.sort();
|
||||
|
||||
// Exclude bundled dependencies
|
||||
sortedDependencies = sortedDependencies.filter(dependency => {
|
||||
return !bundledDeps.some(bundledDep => dependency.startsWith(bundledDep));
|
||||
});
|
||||
|
||||
const referenceGeneratedDeps = referenceGeneratedDepsByArch[arch];
|
||||
if (JSON.stringify(sortedDependencies) !== JSON.stringify(referenceGeneratedDeps)) {
|
||||
const failMessage = 'The dependencies list has changed. '
|
||||
+ 'Printing newer dependencies list that one can use to compare against referenceGeneratedDeps:\n'
|
||||
+ sortedDependencies.join('\n');
|
||||
if (FAIL_BUILD_FOR_NEW_DEPENDENCIES) {
|
||||
throw new Error(failMessage);
|
||||
} else {
|
||||
console.warn(failMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return sortedDependencies;
|
||||
}
|
||||
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/calculate_package_deps.py.
|
||||
function calculatePackageDeps(binaryPath: string): Set<string> {
|
||||
try {
|
||||
if (!(statSync(binaryPath).mode & constants.S_IXUSR)) {
|
||||
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
|
||||
}
|
||||
} catch (e) {
|
||||
// The package might not exist. Don't re-throw the error here.
|
||||
console.error('Tried to stat ' + binaryPath + ' but failed.');
|
||||
}
|
||||
|
||||
const findRequiresResult = spawnSync('/usr/lib/rpm/find-requires', { input: binaryPath + '\n' });
|
||||
if (findRequiresResult.status !== 0) {
|
||||
throw new Error(`find-requires failed with exit code ${findRequiresResult.status}.\nstderr: ${findRequiresResult.stderr}`);
|
||||
}
|
||||
|
||||
const requires = new Set(findRequiresResult.stdout.toString('utf-8').trimEnd().split('\n'));
|
||||
return requires;
|
||||
}
|
||||
|
||||
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/merge_package_deps.py.
|
||||
function mergePackageDeps(inputDeps: Set<string>[]): Set<string> {
|
||||
const requires = new Set<string>();
|
||||
for (const depSet of inputDeps) {
|
||||
for (const dep of depSet) {
|
||||
const trimmedDependency = dep.trim();
|
||||
if (trimmedDependency.length && !trimmedDependency.startsWith('#')) {
|
||||
requires.add(trimmedDependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
return requires;
|
||||
}
|
||||
@@ -4,3 +4,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isRpmArchString = void 0;
|
||||
function isRpmArchString(s) {
|
||||
return ['x86_64', 'armv7hl', 'aarch64'].includes(s);
|
||||
}
|
||||
exports.isRpmArchString = isRpmArchString;
|
||||
|
||||
@@ -3,4 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export type ArchString = 'x86_64' | 'armv7hl' | 'aarch64';
|
||||
export type RpmArchString = 'x86_64' | 'armv7hl' | 'aarch64';
|
||||
|
||||
export function isRpmArchString(s: string): s is RpmArchString {
|
||||
return ['x86_64', 'armv7hl', 'aarch64'].includes(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user