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