Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/gulpfile.vscode.win32.ts
5248 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
const useVersionedUpdate = (product as typeof product & { win32VersionedUpdate?: boolean })?.win32VersionedUpdate;
76
const versionedResourcesFolder = useVersionedUpdate ? commit!.substring(0, 10) : '';
77
const issPath = path.join(import.meta.dirname, 'win32', 'code.iss');
78
const originalProductJsonPath = path.join(sourcePath, versionedResourcesFolder, 'resources/app/product.json');
79
const productJsonPath = path.join(outputPath, 'product.json');
80
const productJson = JSON.parse(fs.readFileSync(originalProductJsonPath, 'utf8'));
81
productJson['target'] = target;
82
fs.writeFileSync(productJsonPath, JSON.stringify(productJson, undefined, '\t'));
83
84
const definitions: Record<string, unknown> = {
85
NameLong: product.nameLong,
86
NameShort: product.nameShort,
87
DirName: product.win32DirName,
88
Version: pkg.version,
89
RawVersion: pkg.version.replace(/-\w+$/, ''),
90
Commit: commit,
91
NameVersion: product.win32NameVersion + (target === 'user' ? ' (User)' : ''),
92
ExeBasename: product.nameShort,
93
RegValueName: product.win32RegValueName,
94
ShellNameShort: product.win32ShellNameShort,
95
AppMutex: product.win32MutexName,
96
TunnelMutex: product.win32TunnelMutex,
97
TunnelServiceMutex: product.win32TunnelServiceMutex,
98
TunnelApplicationName: product.tunnelApplicationName,
99
ApplicationName: product.applicationName,
100
Arch: arch,
101
AppId: { 'x64': x64AppId, 'arm64': arm64AppId }[arch],
102
IncompatibleTargetAppId: { 'x64': product.win32x64AppId, 'arm64': product.win32arm64AppId }[arch],
103
AppUserId: product.win32AppUserModelId,
104
ArchitecturesAllowed: { 'x64': 'x64', 'arm64': 'arm64' }[arch],
105
ArchitecturesInstallIn64BitMode: { 'x64': 'x64', 'arm64': 'arm64' }[arch],
106
SourceDir: sourcePath,
107
RepoDir: repoPath,
108
OutputDir: outputPath,
109
InstallTarget: target,
110
ProductJsonPath: productJsonPath,
111
VersionedResourcesFolder: versionedResourcesFolder,
112
Quality: quality
113
};
114
115
if (quality === 'stable' || quality === 'insider') {
116
definitions['AppxPackage'] = `${quality === 'stable' ? 'code' : 'code_insider'}_${arch}.appx`;
117
definitions['AppxPackageDll'] = `${quality === 'stable' ? 'code' : 'code_insider'}_explorer_command_${arch}.dll`;
118
definitions['AppxPackageName'] = `${product.win32AppUserModelId}`;
119
}
120
121
packageInnoSetup(issPath, { definitions }, cb as (err?: Error | null) => void);
122
};
123
}
124
125
function defineWin32SetupTasks(arch: string, target: string) {
126
const cleanTask = util.rimraf(setupDir(arch, target));
127
gulp.task(task.define(`vscode-win32-${arch}-${target}-setup`, task.series(cleanTask, buildWin32Setup(arch, target))));
128
}
129
130
defineWin32SetupTasks('x64', 'system');
131
defineWin32SetupTasks('arm64', 'system');
132
defineWin32SetupTasks('x64', 'user');
133
defineWin32SetupTasks('arm64', 'user');
134
135
function copyInnoUpdater(arch: string) {
136
return () => {
137
return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
138
.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
139
};
140
}
141
142
function updateIcon(executablePath: string): task.CallbackTask {
143
return cb => {
144
const icon = path.join(repoPath, 'resources', 'win32', 'code.ico');
145
rcedit(executablePath, { icon }, cb);
146
};
147
}
148
149
gulp.task(task.define('vscode-win32-x64-inno-updater', task.series(copyInnoUpdater('x64'), updateIcon(path.join(buildPath('x64'), 'tools', 'inno_updater.exe')))));
150
gulp.task(task.define('vscode-win32-arm64-inno-updater', task.series(copyInnoUpdater('arm64'), updateIcon(path.join(buildPath('arm64'), 'tools', 'inno_updater.exe')))));
151
152