Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/linux/dependencies-generator.js
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
'use strict';
6
var __importDefault = (this && this.__importDefault) || function (mod) {
7
return (mod && mod.__esModule) ? mod : { "default": mod };
8
};
9
Object.defineProperty(exports, "__esModule", { value: true });
10
exports.getDependencies = getDependencies;
11
const child_process_1 = require("child_process");
12
const path_1 = __importDefault(require("path"));
13
const install_sysroot_1 = require("./debian/install-sysroot");
14
const calculate_deps_1 = require("./debian/calculate-deps");
15
const calculate_deps_2 = require("./rpm/calculate-deps");
16
const dep_lists_1 = require("./debian/dep-lists");
17
const dep_lists_2 = require("./rpm/dep-lists");
18
const types_1 = require("./debian/types");
19
const types_2 = require("./rpm/types");
20
const product = require("../../product.json");
21
// A flag that can easily be toggled.
22
// Make sure to compile the build directory after toggling the value.
23
// If false, we warn about new dependencies if they show up
24
// while running the prepare package tasks for a release.
25
// If true, we fail the build if there are new dependencies found during that task.
26
// The reference dependencies, which one has to update when the new dependencies
27
// are valid, are in dep-lists.ts
28
const FAIL_BUILD_FOR_NEW_DEPENDENCIES = true;
29
// Based on https://source.chromium.org/chromium/chromium/src/+/refs/tags/138.0.7204.235:chrome/installer/linux/BUILD.gn;l=64-80
30
// and the Linux Archive build
31
// Shared library dependencies that we already bundle.
32
const bundledDeps = [
33
'libEGL.so',
34
'libGLESv2.so',
35
'libvulkan.so.1',
36
'libvk_swiftshader.so',
37
'libffmpeg.so'
38
];
39
async function getDependencies(packageType, buildDir, applicationName, arch) {
40
if (packageType === 'deb') {
41
if (!(0, types_1.isDebianArchString)(arch)) {
42
throw new Error('Invalid Debian arch string ' + arch);
43
}
44
}
45
if (packageType === 'rpm' && !(0, types_2.isRpmArchString)(arch)) {
46
throw new Error('Invalid RPM arch string ' + arch);
47
}
48
// Get the files for which we want to find dependencies.
49
const canAsar = false; // TODO@esm ASAR disabled in ESM
50
const nativeModulesPath = path_1.default.join(buildDir, 'resources', 'app', canAsar ? 'node_modules.asar.unpacked' : 'node_modules');
51
const findResult = (0, child_process_1.spawnSync)('find', [nativeModulesPath, '-name', '*.node']);
52
if (findResult.status) {
53
console.error('Error finding files:');
54
console.error(findResult.stderr.toString());
55
return [];
56
}
57
const appPath = path_1.default.join(buildDir, applicationName);
58
// Add the native modules
59
const files = findResult.stdout.toString().trimEnd().split('\n');
60
// Add the tunnel binary.
61
files.push(path_1.default.join(buildDir, 'bin', product.tunnelApplicationName));
62
// Add the main executable.
63
files.push(appPath);
64
// Add chrome sandbox and crashpad handler.
65
files.push(path_1.default.join(buildDir, 'chrome-sandbox'));
66
files.push(path_1.default.join(buildDir, 'chrome_crashpad_handler'));
67
// Generate the dependencies.
68
let dependencies;
69
if (packageType === 'deb') {
70
const chromiumSysroot = await (0, install_sysroot_1.getChromiumSysroot)(arch);
71
const vscodeSysroot = await (0, install_sysroot_1.getVSCodeSysroot)(arch);
72
dependencies = (0, calculate_deps_1.generatePackageDeps)(files, arch, chromiumSysroot, vscodeSysroot);
73
}
74
else {
75
dependencies = (0, calculate_deps_2.generatePackageDeps)(files);
76
}
77
// Merge all the dependencies.
78
const mergedDependencies = mergePackageDeps(dependencies);
79
// Exclude bundled dependencies and sort
80
const sortedDependencies = Array.from(mergedDependencies).filter(dependency => {
81
return !bundledDeps.some(bundledDep => dependency.startsWith(bundledDep));
82
}).sort();
83
const referenceGeneratedDeps = packageType === 'deb' ?
84
dep_lists_1.referenceGeneratedDepsByArch[arch] :
85
dep_lists_2.referenceGeneratedDepsByArch[arch];
86
if (JSON.stringify(sortedDependencies) !== JSON.stringify(referenceGeneratedDeps)) {
87
const failMessage = 'The dependencies list has changed.'
88
+ '\nOld:\n' + referenceGeneratedDeps.join('\n')
89
+ '\nNew:\n' + sortedDependencies.join('\n');
90
if (FAIL_BUILD_FOR_NEW_DEPENDENCIES) {
91
throw new Error(failMessage);
92
}
93
else {
94
console.warn(failMessage);
95
}
96
}
97
return sortedDependencies;
98
}
99
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/merge_package_deps.py.
100
function mergePackageDeps(inputDeps) {
101
const requires = new Set();
102
for (const depSet of inputDeps) {
103
for (const dep of depSet) {
104
const trimmedDependency = dep.trim();
105
if (trimmedDependency.length && !trimmedDependency.startsWith('#')) {
106
requires.add(trimmedDependency);
107
}
108
}
109
}
110
return requires;
111
}
112
//# sourceMappingURL=dependencies-generator.js.map
113