vscode/build/gulpfile.vscode.win32.js

158 lines
6.2 KiB
JavaScript
Raw Normal View History

2016-07-20 11:17:52 +02:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const gulp = require('gulp');
const path = require('path');
2018-06-21 01:29:06 +02:00
const fs = require('fs');
const assert = require('assert');
const cp = require('child_process');
2017-05-10 12:56:18 +02:00
const _7z = require('7zip')['7z'];
2016-07-20 11:17:52 +02:00
const util = require('./lib/util');
2019-02-12 15:13:43 +01:00
const task = require('./lib/task');
const pkg = require('../package.json');
const product = require('../product.json');
const vfs = require('vinyl-fs');
2018-09-24 15:41:16 +02:00
const rcedit = require('rcedit');
2018-06-21 01:29:06 +02:00
const mkdirp = require('mkdirp');
2016-07-20 11:17:52 +02:00
const repoPath = path.dirname(__dirname);
2017-05-18 15:40:58 +02:00
const buildPath = arch => path.join(path.dirname(repoPath), `VSCode-win32-${arch}`);
const zipDir = arch => path.join(repoPath, '.build', `win32-${arch}`, 'archive');
const zipPath = arch => path.join(zipDir(arch), `VSCode-win32-${arch}.zip`);
2018-06-20 16:22:42 +02:00
const setupDir = (arch, target) => path.join(repoPath, '.build', `win32-${arch}`, `${target}-setup`);
const issPath = path.join(__dirname, 'win32', 'code.iss');
2019-06-18 17:08:18 +02:00
const innoSetupPath = path.join(path.dirname(path.dirname(require.resolve('innosetup'))), 'bin', 'ISCC.exe');
2021-07-09 15:33:33 +02:00
const signWin32Path = path.join(repoPath, 'build', 'azure-pipelines', 'common', 'sign-win32');
2016-07-20 11:17:52 +02:00
function packageInnoSetup(iss, options, cb) {
options = options || {};
const definitions = options.definitions || {};
2018-06-19 15:29:36 +02:00
if (process.argv.some(arg => arg === '--debug-inno')) {
2018-06-19 15:29:36 +02:00
definitions['Debug'] = 'true';
}
if (process.argv.some(arg => arg === '--sign')) {
definitions['Sign'] = 'true';
}
2016-07-28 09:07:22 +02:00
const keys = Object.keys(definitions);
2017-05-10 12:56:18 +02:00
keys.forEach(key => assert(typeof definitions[key] === 'string', `Missing value for '${key}' in Inno Setup package step`));
2016-07-28 09:07:22 +02:00
2017-05-10 12:56:18 +02:00
const defs = keys.map(key => `/d${key}=${definitions[key]}`);
2018-07-02 11:43:03 +02:00
const args = [
iss,
2018-07-02 14:14:54 +02:00
...defs,
2021-07-09 15:33:33 +02:00
`/sesrp=node ${signWin32Path} $f`
2018-07-02 11:43:03 +02:00
];
2018-06-21 01:29:06 +02:00
cp.spawn(innoSetupPath, args, { stdio: ['ignore', 'inherit', 'inherit'] })
.on('error', cb)
.on('exit', code => {
if (code === 0) {
cb(null);
} else {
cb(new Error(`InnoSetup returned exit code: ${code}`));
}
});
}
2018-06-20 16:22:42 +02:00
function buildWin32Setup(arch, target) {
if (target !== 'system' && target !== 'user') {
throw new Error('Invalid setup target');
}
2018-01-22 15:47:18 +01:00
return cb => {
2018-06-20 16:22:42 +02:00
const ia32AppId = target === 'system' ? product.win32AppId : product.win32UserAppId;
const x64AppId = target === 'system' ? product.win32x64AppId : product.win32x64UserAppId;
2020-05-26 16:18:03 +02:00
const arm64AppId = target === 'system' ? product.win32arm64AppId : product.win32arm64UserAppId;
2017-06-22 17:36:17 +02:00
2018-06-21 01:29:06 +02:00
const sourcePath = buildPath(arch);
const outputPath = setupDir(arch, target);
mkdirp.sync(outputPath);
const originalProductJsonPath = path.join(sourcePath, 'resources/app/product.json');
const productJsonPath = path.join(outputPath, 'product.json');
const productJson = JSON.parse(fs.readFileSync(originalProductJsonPath, 'utf8'));
productJson['target'] = target;
fs.writeFileSync(productJsonPath, JSON.stringify(productJson, undefined, '\t'));
2017-05-18 15:40:58 +02:00
const definitions = {
NameLong: product.nameLong,
NameShort: product.nameShort,
DirName: product.win32DirName,
Version: pkg.version,
RawVersion: pkg.version.replace(/-\w+$/, ''),
2018-06-27 15:31:31 +02:00
NameVersion: product.win32NameVersion + (target === 'user' ? ' (User)' : ''),
2017-05-18 15:40:58 +02:00
ExeBasename: product.nameShort,
RegValueName: product.win32RegValueName,
ShellNameShort: product.win32ShellNameShort,
AppMutex: product.win32MutexName,
2017-06-22 17:36:17 +02:00
Arch: arch,
2020-05-26 16:18:03 +02:00
AppId: { 'ia32': ia32AppId, 'x64': x64AppId, 'arm64': arm64AppId }[arch],
IncompatibleTargetAppId: { 'ia32': product.win32AppId, 'x64': product.win32x64AppId, 'arm64': product.win32arm64AppId }[arch],
IncompatibleArchAppId: { 'ia32': x64AppId, 'x64': ia32AppId, 'arm64': ia32AppId }[arch],
2017-05-18 15:40:58 +02:00
AppUserId: product.win32AppUserModelId,
2020-07-07 16:11:16 +02:00
ArchitecturesAllowed: { 'ia32': '', 'x64': 'x64', 'arm64': 'arm64' }[arch],
ArchitecturesInstallIn64BitMode: { 'ia32': '', 'x64': 'x64', 'arm64': 'arm64' }[arch],
2018-06-21 01:29:06 +02:00
SourceDir: sourcePath,
2017-05-18 15:40:58 +02:00
RepoDir: repoPath,
2018-06-21 01:29:06 +02:00
OutputDir: outputPath,
InstallTarget: target,
ProductJsonPath: productJsonPath
2017-05-18 15:40:58 +02:00
};
2018-01-22 15:47:18 +01:00
packageInnoSetup(issPath, { definitions }, cb);
2017-05-18 15:40:58 +02:00
};
2016-07-20 11:17:52 +02:00
}
2018-06-20 16:22:42 +02:00
function defineWin32SetupTasks(arch, target) {
2019-02-11 10:25:06 +01:00
const cleanTask = util.rimraf(setupDir(arch, target));
2019-02-12 20:43:28 +01:00
gulp.task(task.define(`vscode-win32-${arch}-${target}-setup`, task.series(cleanTask, buildWin32Setup(arch, target))));
2018-06-20 16:22:42 +02:00
}
2017-05-10 12:56:18 +02:00
2018-06-20 16:22:42 +02:00
defineWin32SetupTasks('ia32', 'system');
defineWin32SetupTasks('x64', 'system');
2020-05-26 16:18:03 +02:00
defineWin32SetupTasks('arm64', 'system');
2018-06-20 16:22:42 +02:00
defineWin32SetupTasks('ia32', 'user');
defineWin32SetupTasks('x64', 'user');
2020-05-26 16:18:03 +02:00
defineWin32SetupTasks('arm64', 'user');
2017-05-10 12:56:18 +02:00
2017-05-18 15:40:58 +02:00
function archiveWin32Setup(arch) {
return cb => {
2018-06-27 15:21:55 +02:00
const args = ['a', '-tzip', zipPath(arch), '-x!CodeSignSummary*.md', '.', '-r'];
2017-05-18 15:40:58 +02:00
2017-06-15 08:49:08 +02:00
cp.spawn(_7z, args, { stdio: 'inherit', cwd: buildPath(arch) })
2017-05-18 15:40:58 +02:00
.on('error', cb)
.on('exit', () => cb(null));
};
2017-05-10 12:56:18 +02:00
}
2019-02-12 20:43:28 +01:00
gulp.task(task.define('vscode-win32-ia32-archive', task.series(util.rimraf(zipDir('ia32')), archiveWin32Setup('ia32'))));
gulp.task(task.define('vscode-win32-x64-archive', task.series(util.rimraf(zipDir('x64')), archiveWin32Setup('x64'))));
2020-04-14 13:25:01 +02:00
gulp.task(task.define('vscode-win32-arm64-archive', task.series(util.rimraf(zipDir('arm64')), archiveWin32Setup('arm64'))));
2018-01-22 15:47:18 +01:00
function copyInnoUpdater(arch) {
return () => {
return gulp.src('build/win32/{inno_updater.exe,vcruntime140.dll}', { base: 'build/win32' })
.pipe(vfs.dest(path.join(buildPath(arch), 'tools')));
2018-01-22 15:47:18 +01:00
};
}
2019-07-31 14:38:17 +02:00
function updateIcon(executablePath) {
2018-09-24 15:41:16 +02:00
return cb => {
const icon = path.join(repoPath, 'resources', 'win32', 'code.ico');
2019-07-31 14:38:17 +02:00
rcedit(executablePath, { icon }, cb);
2018-09-24 15:41:16 +02:00
};
}
2019-07-31 14:38:17 +02:00
gulp.task(task.define('vscode-win32-ia32-inno-updater', task.series(copyInnoUpdater('ia32'), updateIcon(path.join(buildPath('ia32'), 'tools', 'inno_updater.exe')))));
gulp.task(task.define('vscode-win32-x64-inno-updater', task.series(copyInnoUpdater('x64'), updateIcon(path.join(buildPath('x64'), 'tools', 'inno_updater.exe')))));
2020-05-26 16:18:03 +02:00
gulp.task(task.define('vscode-win32-arm64-inno-updater', task.series(copyInnoUpdater('arm64'), updateIcon(path.join(buildPath('arm64'), 'tools', 'inno_updater.exe')))));