Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/gulpfile.scan.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
6
'use strict';
7
8
const gulp = require('gulp');
9
const path = require('path');
10
const task = require('./lib/task');
11
const util = require('./lib/util');
12
const electron = require('@vscode/gulp-electron');
13
const { config } = require('./lib/electron');
14
const filter = require('gulp-filter');
15
const deps = require('./lib/dependencies');
16
const { existsSync, readdirSync } = require('fs');
17
18
const root = path.dirname(__dirname);
19
20
const BUILD_TARGETS = [
21
{ platform: 'win32', arch: 'x64' },
22
{ platform: 'win32', arch: 'arm64' },
23
{ platform: 'darwin', arch: null, opts: { stats: true } },
24
{ platform: 'linux', arch: 'x64' },
25
{ platform: 'linux', arch: 'armhf' },
26
{ platform: 'linux', arch: 'arm64' },
27
];
28
29
// The following files do not have PDBs downloaded for them during the download symbols process.
30
const excludedCheckList = ['d3dcompiler_47.dll'];
31
32
BUILD_TARGETS.forEach(buildTarget => {
33
const dashed = (/** @type {string | null} */ str) => (str ? `-${str}` : ``);
34
const platform = buildTarget.platform;
35
const arch = buildTarget.arch;
36
37
const destinationExe = path.join(path.dirname(root), 'scanbin', `VSCode${dashed(platform)}${dashed(arch)}`, 'bin');
38
const destinationPdb = path.join(path.dirname(root), 'scanbin', `VSCode${dashed(platform)}${dashed(arch)}`, 'pdb');
39
40
const tasks = [];
41
42
// removal tasks
43
tasks.push(util.rimraf(destinationExe), util.rimraf(destinationPdb));
44
45
// electron
46
tasks.push(() => electron.dest(destinationExe, { ...config, platform, arch: arch === 'armhf' ? 'arm' : arch }));
47
48
// pdbs for windows
49
if (platform === 'win32') {
50
tasks.push(
51
() => electron.dest(destinationPdb, { ...config, platform, arch: arch === 'armhf' ? 'arm' : arch, pdbs: true }),
52
() => confirmPdbsExist(destinationExe, destinationPdb)
53
);
54
}
55
56
if (platform === 'linux') {
57
tasks.push(
58
() => electron.dest(destinationPdb, { ...config, platform, arch: arch === 'armhf' ? 'arm' : arch, symbols: true })
59
);
60
}
61
62
// node modules
63
tasks.push(
64
nodeModules(destinationExe, destinationPdb, platform)
65
);
66
67
const setupSymbolsTask = task.define(`vscode-symbols${dashed(platform)}${dashed(arch)}`,
68
task.series(...tasks)
69
);
70
71
gulp.task(setupSymbolsTask);
72
});
73
74
function getProductionDependencySources() {
75
const productionDependencies = deps.getProductionDependencies(root);
76
return productionDependencies.map(d => path.relative(root, d)).map(d => [`${d}/**`, `!${d}/**/{test,tests}/**`]).flat();
77
}
78
79
function nodeModules(destinationExe, destinationPdb, platform) {
80
81
const exe = () => {
82
return gulp.src(getProductionDependencySources(), { base: '.', dot: true })
83
.pipe(filter([
84
'**/*.node',
85
// Exclude these paths.
86
// We don't build the prebuilt node files so we don't scan them
87
'!**/prebuilds/**/*.node'
88
]))
89
.pipe(gulp.dest(destinationExe));
90
};
91
92
if (platform === 'win32') {
93
const pdb = () => {
94
return gulp.src(getProductionDependencySources(), { base: '.', dot: true })
95
.pipe(filter(['**/*.pdb']))
96
.pipe(gulp.dest(destinationPdb));
97
};
98
99
return gulp.parallel(exe, pdb);
100
}
101
102
if (platform === 'linux') {
103
const pdb = () => {
104
return gulp.src(getProductionDependencySources(), { base: '.', dot: true })
105
.pipe(filter(['**/*.sym']))
106
.pipe(gulp.dest(destinationPdb));
107
};
108
109
return gulp.parallel(exe, pdb);
110
}
111
112
return exe;
113
}
114
115
function confirmPdbsExist(destinationExe, destinationPdb) {
116
readdirSync(destinationExe).forEach(file => {
117
if (excludedCheckList.includes(file)) {
118
return;
119
}
120
121
if (file.endsWith('.dll') || file.endsWith('.exe')) {
122
const pdb = `${file}.pdb`;
123
if (!existsSync(path.join(destinationPdb, pdb))) {
124
throw new Error(`Missing pdb file for ${file}. Tried searching for ${pdb} in ${destinationPdb}.`);
125
}
126
}
127
});
128
return Promise.resolve();
129
}
130
131