Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/gulpfile.vscode.win32.ts
4770 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 assert from 'assert';
6
import * as cp from 'child_process';
7
import * as fs from 'fs';
8
import gulp from 'gulp';
9
import * as path from 'path';
10
import rcedit from 'rcedit';
11
import vfs from 'vinyl-fs';
12
import pkg from '../package.json' with { type: 'json' };
13
import product from '../product.json' with { type: 'json' };
14
import { getVersion } from './lib/getVersion.ts';
15
import * as task from './lib/task.ts';
16
import * as util from './lib/util.ts';
17
18
import { createRequire } from 'module';
19
const require = createRequire(import.meta.url);
20
21
const repoPath = path.dirname(import.meta.dirname);
22
const commit = getVersion(repoPath);
23
const buildPath = (arch: string) => path.join(path.dirname(repoPath), `VSCode-win32-${arch}`);
24
const setupDir = (arch: string, target: string) => path.join(repoPath, '.build', `win32-${arch}`, `${target}-setup`);
25
const innoSetupPath = path.join(path.dirname(path.dirname(require.resolve('innosetup'))), 'bin', 'ISCC.exe');
26
const signWin32Path = path.join(repoPath, 'build', 'azure-pipelines', 'common', 'sign-win32.ts');
27
28
function packageInnoSetup(iss: string, options: { definitions?: Record<string, unknown> }, cb: (err?: Error | null) => void) {
29
const definitions = options.definitions || {};
30
31
if (process.argv.some(arg => arg === '--debug-inno')) {
32
definitions['Debug'] = 'true';
33
}
34
35
if (process.argv.some(arg => arg === '--sign')) {
36
definitions['Sign'] = 'true';
37
}
38
39
const keys = Object.keys(definitions);
40
41
keys.forEach(key => assert(typeof definitions[key] === 'string', `Missing value for '${key}' in Inno Setup package step`));
42
43
const defs = keys.map(key => `/d${key}=${definitions[key]}`);
44
const args = [
45
iss,
46
...defs,
47
`/sesrp=node ${signWin32Path} $f`
48
];
49
50
cp.spawn(innoSetupPath, args, { stdio: ['ignore', 'inherit', 'inherit'] })
51
.on('error', cb)
52
.on('exit', code => {
53
if (code === 0) {
54
cb(null);
55
} else {
56
cb(new Error(`InnoSetup returned exit code: ${code}`));
57
}
58
});
59
}
60
61
function buildWin32Setup(arch: string, target: string): task.CallbackTask {
62
if (target !== 'system' && target !== 'user') {
63
throw new Error('Invalid setup target');
64
}
65
66
return (cb) => {
67
const x64AppId = target === 'system' ? product.win32x64AppId : product.win32x64UserAppId;
68
const arm64AppId = target === 'system' ? product.win32arm64AppId : product.win32arm64UserAppId;
69
70
const sourcePath = buildPath(arch);
71
const outputPath = setupDir(arch, target);
72
fs.mkdirSync(outputPath, { recursive: true });
73
74
const quality = (product as typeof product & { quality?: string }).quality || 'dev';
75
let versionedResourcesFolder = '';
76
let issPath = path.join(import.meta.dirname, 'win32', 'code.iss');
77
if (quality && quality === 'insider') {
78
versionedResourcesFolder = commit!.substring(0, 10);
79
issPath = path.join(import.meta.dirname, 'win32', 'code-insider.iss');
80
}
81
const originalProductJsonPath = path.join(sourcePath, versionedResourcesFolder, 'resources/app/product.json');
82
const productJsonPath = path.join(outputPath, 'product.json');
83
const productJson = JSON.parse(fs.readFileSync(originalProductJsonPath, 'utf8'));
84
productJson['target'] = target;
85
fs.writeFileSync(productJsonPath, JSON.stringify(productJson, undefined, '\t'));
86
87
const definitions: Record<string, unknown> = {
88
NameLong: product.nameLong,
89
NameShort: product.nameShort,
90
DirName: product.win32DirName,
91
Version: pkg.version,
92
RawVersion: pkg.version.replace(/-\w+$/, ''),
93
Commit: commit,
94
NameVersion: product.win32NameVersion + (target === 'user' ? ' (User)' : ''),
95
ExeBasename: product.nameShort,
96
RegValueName: product.win32RegValueName,
97
ShellNameShort: product.win32ShellNameShort,
98
AppMutex: product.win32MutexName,
99
TunnelMutex: product.win32TunnelMutex,
100
TunnelServiceMutex: product.win32TunnelServiceMutex,
101
TunnelApplicationName: product.tunnelApplicationName,
102
ApplicationName: product.applicationName,
103
Arch: arch,
104
AppId: { 'x64': x64AppId, 'arm64': arm64AppId }[arch],
105
IncompatibleTargetAppId: { 'x64': product.win32x64AppId, 'arm64': product.win32arm64AppId }[arch],
106
AppUserId: product.win32AppUserModelId,
107
ArchitecturesAllowed: { 'x64': 'x64', 'arm64': 'arm64' }[arch],
108
ArchitecturesInstallIn64BitMode: { 'x64': 'x64', 'arm64': 'arm64' }[arch],
109
SourceDir: sourcePath,
110
RepoDir: repoPath,
111
OutputDir: outputPath,
112
InstallTarget: target,
113
ProductJsonPath: productJsonPath,
114
VersionedResourcesFolder: versionedResourcesFolder,
115
Quality: quality
116
};
117
118
if (quality === 'stable' || quality === 'insider') {
119
definitions['AppxPackage'] = `${quality === 'stable' ? 'code' : 'code_insider'}_${arch}.appx`;
120
definitions['AppxPackageDll'] = `${quality === 'stable' ? 'code' : 'code_insider'}_explorer_command_${arch}.dll`;
121
definitions['AppxPackageName'] = `${product.win32AppUserModelId}`;
122
}
123
124
packageInnoSetup(issPath, { definitions }, cb as (err?: Error | null) => void);
125
};
126
}
127
128
function defineWin32SetupTasks(arch: string, target: string) {
129
const cleanTask = util.rimraf(setupDir(arch, target));
130
gulp.task(task.define(`vscode-win32-${arch}-${target}-setup`, task.series(cleanTask, buildWin32Setup(arch, target))));
131
}
132
133
defineWin32SetupTasks('x64', 'system');
134
defineWin32SetupTasks('arm64', 'system');
135
defineWin32SetupTasks('x64', 'user');
136
defineWin32SetupTasks('arm64', 'user');
137
138
function copyInnoUpdater(arch: string) {
139
return () => {
140
return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
141
.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
142
};
143
}
144
145
function updateIcon(executablePath: string): task.CallbackTask {
146
return cb => {
147
const icon = path.join(repoPath, 'resources', 'win32', 'code.ico');
148
rcedit(executablePath, { icon }, cb);
149
};
150
}
151
152
gulp.task(task.define('vscode-win32-x64-inno-updater', task.series(copyInnoUpdater('x64'), updateIcon(path.join(buildPath('x64'), 'tools', 'inno_updater.exe')))));
153
gulp.task(task.define('vscode-win32-arm64-inno-updater', task.series(copyInnoUpdater('arm64'), updateIcon(path.join(buildPath('arm64'), 'tools', 'inno_updater.exe')))));
154
155