Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/linux/debian/calculate-deps.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
import { spawnSync } from 'child_process';
7
import { constants, statSync } from 'fs';
8
import { tmpdir } from 'os';
9
import path from 'path';
10
import manifests from '../../../cgmanifest.json';
11
import { additionalDeps } from './dep-lists';
12
import { DebianArchString } from './types';
13
14
export function generatePackageDeps(files: string[], arch: DebianArchString, chromiumSysroot: string, vscodeSysroot: string): Set<string>[] {
15
const dependencies: Set<string>[] = files.map(file => calculatePackageDeps(file, arch, chromiumSysroot, vscodeSysroot));
16
const additionalDepsSet = new Set(additionalDeps);
17
dependencies.push(additionalDepsSet);
18
return dependencies;
19
}
20
21
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/debian/calculate_package_deps.py.
22
function calculatePackageDeps(binaryPath: string, arch: DebianArchString, chromiumSysroot: string, vscodeSysroot: string): Set<string> {
23
try {
24
if (!(statSync(binaryPath).mode & constants.S_IXUSR)) {
25
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
26
}
27
} catch (e) {
28
// The package might not exist. Don't re-throw the error here.
29
console.error('Tried to stat ' + binaryPath + ' but failed.');
30
}
31
32
// Get the Chromium dpkg-shlibdeps file.
33
const chromiumManifest = manifests.registrations.filter(registration => {
34
return registration.component.type === 'git' && registration.component.git!.name === 'chromium';
35
});
36
const dpkgShlibdepsUrl = `https://raw.githubusercontent.com/chromium/chromium/${chromiumManifest[0].version}/third_party/dpkg-shlibdeps/dpkg-shlibdeps.pl`;
37
const dpkgShlibdepsScriptLocation = `${tmpdir()}/dpkg-shlibdeps.pl`;
38
const result = spawnSync('curl', [dpkgShlibdepsUrl, '-o', dpkgShlibdepsScriptLocation]);
39
if (result.status !== 0) {
40
throw new Error('Cannot retrieve dpkg-shlibdeps. Stderr:\n' + result.stderr);
41
}
42
const cmd = [dpkgShlibdepsScriptLocation, '--ignore-weak-undefined'];
43
switch (arch) {
44
case 'amd64':
45
cmd.push(`-l${chromiumSysroot}/usr/lib/x86_64-linux-gnu`,
46
`-l${chromiumSysroot}/lib/x86_64-linux-gnu`,
47
`-l${vscodeSysroot}/usr/lib/x86_64-linux-gnu`,
48
`-l${vscodeSysroot}/lib/x86_64-linux-gnu`);
49
break;
50
case 'armhf':
51
cmd.push(`-l${chromiumSysroot}/usr/lib/arm-linux-gnueabihf`,
52
`-l${chromiumSysroot}/lib/arm-linux-gnueabihf`,
53
`-l${vscodeSysroot}/usr/lib/arm-linux-gnueabihf`,
54
`-l${vscodeSysroot}/lib/arm-linux-gnueabihf`);
55
break;
56
case 'arm64':
57
cmd.push(`-l${chromiumSysroot}/usr/lib/aarch64-linux-gnu`,
58
`-l${chromiumSysroot}/lib/aarch64-linux-gnu`,
59
`-l${vscodeSysroot}/usr/lib/aarch64-linux-gnu`,
60
`-l${vscodeSysroot}/lib/aarch64-linux-gnu`);
61
break;
62
}
63
cmd.push(`-l${chromiumSysroot}/usr/lib`);
64
cmd.push(`-L${vscodeSysroot}/debian/libxkbfile1/DEBIAN/shlibs`);
65
cmd.push('-O', '-e', path.resolve(binaryPath));
66
67
const dpkgShlibdepsResult = spawnSync('perl', cmd, { cwd: chromiumSysroot });
68
if (dpkgShlibdepsResult.status !== 0) {
69
throw new Error(`dpkg-shlibdeps failed with exit code ${dpkgShlibdepsResult.status}. stderr:\n${dpkgShlibdepsResult.stderr} `);
70
}
71
72
const shlibsDependsPrefix = 'shlibs:Depends=';
73
const requiresList = dpkgShlibdepsResult.stdout.toString('utf-8').trimEnd().split('\n');
74
let depsStr = '';
75
for (const line of requiresList) {
76
if (line.startsWith(shlibsDependsPrefix)) {
77
depsStr = line.substring(shlibsDependsPrefix.length);
78
}
79
}
80
// Refs https://chromium-review.googlesource.com/c/chromium/src/+/3572926
81
// Chromium depends on libgcc_s, is from the package libgcc1. However, in
82
// Bullseye, the package was renamed to libgcc-s1. To avoid adding a dep
83
// on the newer package, this hack skips the dep. This is safe because
84
// libgcc-s1 is a dependency of libc6. This hack can be removed once
85
// support for Debian Buster and Ubuntu Bionic are dropped.
86
//
87
// Remove kerberos native module related dependencies as the versions
88
// computed from sysroot will not satisfy the minimum supported distros
89
// Refs https://github.com/microsoft/vscode/issues/188881.
90
// TODO(deepak1556): remove this workaround in favor of computing the
91
// versions from build container for native modules.
92
const filteredDeps = depsStr.split(', ').filter(dependency => {
93
return !dependency.startsWith('libgcc-s1');
94
}).sort();
95
const requires = new Set(filteredDeps);
96
return requires;
97
}
98
99