Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/linux/rpm/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 { additionalDeps } from './dep-lists';
9
10
export function generatePackageDeps(files: string[]): Set<string>[] {
11
const dependencies: Set<string>[] = files.map(file => calculatePackageDeps(file));
12
const additionalDepsSet = new Set(additionalDeps);
13
dependencies.push(additionalDepsSet);
14
return dependencies;
15
}
16
17
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/rpm/calculate_package_deps.py.
18
function calculatePackageDeps(binaryPath: string): Set<string> {
19
try {
20
if (!(statSync(binaryPath).mode & constants.S_IXUSR)) {
21
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
22
}
23
} catch (e) {
24
// The package might not exist. Don't re-throw the error here.
25
console.error('Tried to stat ' + binaryPath + ' but failed.');
26
}
27
28
const findRequiresResult = spawnSync('/usr/lib/rpm/find-requires', { input: binaryPath + '\n' });
29
if (findRequiresResult.status !== 0) {
30
throw new Error(`find-requires failed with exit code ${findRequiresResult.status}.\nstderr: ${findRequiresResult.stderr}`);
31
}
32
33
const requires = new Set(findRequiresResult.stdout.toString('utf-8').trimEnd().split('\n'));
34
return requires;
35
}
36
37