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