Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/gulpfile.vscode.win32.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
'use strict';
6
7
const gulp = require('gulp');
8
const path = require('path');
9
const fs = require('fs');
10
const assert = require('assert');
11
const cp = require('child_process');
12
const util = require('./lib/util');
13
const task = require('./lib/task');
14
const pkg = require('../package.json');
15
const product = require('../product.json');
16
const vfs = require('vinyl-fs');
17
const rcedit = require('rcedit');
18
19
const repoPath = path.dirname(__dirname);
20
const buildPath = (/** @type {string} */ arch) => path.join(path.dirname(repoPath), `VSCode-win32-${arch}`);
21
const setupDir = (/** @type {string} */ arch, /** @type {string} */ target) => path.join(repoPath, '.build', `win32-${arch}`, `${target}-setup`);
22
const issPath = path.join(__dirname, 'win32', 'code.iss');
23
const innoSetupPath = path.join(path.dirname(path.dirname(require.resolve('innosetup'))), 'bin', 'ISCC.exe');
24
const signWin32Path = path.join(repoPath, 'build', 'azure-pipelines', 'common', 'sign-win32');
25
26
function packageInnoSetup(iss, options, cb) {
27
options = options || {};
28
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
/**
62
* @param {string} arch
63
* @param {string} target
64
*/
65
function buildWin32Setup(arch, target) {
66
if (target !== 'system' && target !== 'user') {
67
throw new Error('Invalid setup target');
68
}
69
70
return cb => {
71
const x64AppId = target === 'system' ? product.win32x64AppId : product.win32x64UserAppId;
72
const arm64AppId = target === 'system' ? product.win32arm64AppId : product.win32arm64UserAppId;
73
74
const sourcePath = buildPath(arch);
75
const outputPath = setupDir(arch, target);
76
fs.mkdirSync(outputPath, { recursive: true });
77
78
const originalProductJsonPath = path.join(sourcePath, '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 quality = product.quality || 'dev';
85
const definitions = {
86
NameLong: product.nameLong,
87
NameShort: product.nameShort,
88
DirName: product.win32DirName,
89
Version: pkg.version,
90
RawVersion: pkg.version.replace(/-\w+$/, ''),
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
Quality: quality
112
};
113
114
if (quality !== 'exploration') {
115
definitions['AppxPackage'] = `${quality === 'stable' ? 'code' : 'code_insider'}_${arch}.appx`;
116
definitions['AppxPackageDll'] = `${quality === 'stable' ? 'code' : 'code_insider'}_explorer_command_${arch}.dll`;
117
definitions['AppxPackageName'] = `${product.win32AppUserModelId}`;
118
}
119
120
packageInnoSetup(issPath, { definitions }, cb);
121
};
122
}
123
124
/**
125
* @param {string} arch
126
* @param {string} target
127
*/
128
function defineWin32SetupTasks(arch, target) {
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
/**
139
* @param {string} arch
140
*/
141
function copyInnoUpdater(arch) {
142
return () => {
143
return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
144
.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
145
};
146
}
147
148
/**
149
* @param {string} executablePath
150
*/
151
function updateIcon(executablePath) {
152
return cb => {
153
const icon = path.join(repoPath, 'resources', 'win32', 'code.ico');
154
rcedit(executablePath, { icon }, cb);
155
};
156
}
157
158
gulp.task(task.define('vscode-win32-x64-inno-updater', task.series(copyInnoUpdater('x64'), updateIcon(path.join(buildPath('x64'), 'tools', 'inno_updater.exe')))));
159
gulp.task(task.define('vscode-win32-arm64-inno-updater', task.series(copyInnoUpdater('arm64'), updateIcon(path.join(buildPath('arm64'), 'tools', 'inno_updater.exe')))));
160
161