Skip to content

Commit fe3988c

Browse files
committed
Add gulp tasks to build deb packages
Build, install and run: gulp vscode-linux-packages sudo dpkg -i out-linux/vscode-amd64.deb code . Installing the package does the following: - Puts VSCode dir at /usr/share/code - Puts code.sh launcher in /usr/bin - Defines a .desktop file to properly integrate with the launcher Fixes microsoft#2679
1 parent 9ca8d4c commit fe3988c

7 files changed

Lines changed: 114 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ out-editor/
99
out-editor-min/
1010
out-editor-ossfree/
1111
out-editor-ossfree-min/
12+
out-linux/
1213
out-vscode/
1314
out-vscode-min/
1415
build/node_modules

build/gulpfile.hygiene.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var indentationFilter = [
3232
'**',
3333
'!ThirdPartyNotices.txt',
3434
'!**/*.md',
35+
'!**/*.template',
3536
'!**/*.yml',
3637
'!**/lib/**',
3738
'!**/*.d.ts',
@@ -58,8 +59,10 @@ var indentationFilter = [
5859

5960
var copyrightFilter = [
6061
'**',
62+
'!**/*.desktop',
6163
'!**/*.json',
6264
'!**/*.html',
65+
'!**/*.template',
6366
'!**/test/**',
6467
'!**/*.md',
6568
'!**/*.bat',

build/gulpfile.vscode.js

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ var azure = require('gulp-azure-storage');
1313
var electron = require('gulp-atom-electron');
1414
var symdest = require('gulp-symdest');
1515
var rename = require('gulp-rename');
16+
var replace = require('gulp-replace');
1617
var filter = require('gulp-filter');
1718
var json = require('gulp-json-editor');
1819
var insert = require('gulp-insert');
1920
var remote = require('gulp-remote-src');
21+
var shell = require("gulp-shell");
2022
var File = require('vinyl');
2123
var rimraf = require('rimraf');
2224
var _ = require('underscore');
@@ -215,7 +217,7 @@ function packageTask(platform, arch, opts) {
215217
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], true))
216218
.pipe(util.cleanNodeModule('weak', ['binding.gyp', 'build/**', 'src/**'], true));
217219

218-
var resources = gulp.src('resources/*', { base: '.' });
220+
var resources = gulp.src(['resources/*','resources/common/**'], { base: '.' });
219221

220222
if (platform === 'win32') {
221223
resources = es.merge(resources, gulp.src('resources/win32/code_file.ico', { base: '.' }));
@@ -257,11 +259,88 @@ function packageTask(platform, arch, opts) {
257259
};
258260
}
259261

262+
function getFolderSize(root) {
263+
var size = 0;
264+
var paths = [root];
265+
while (paths.length > 0) {
266+
var current = path.normalize(paths.pop());
267+
var stat = fs.statSync(current);
268+
size += stat.size;
269+
if (stat.isDirectory()) {
270+
var newPaths = fs.readdirSync(current);
271+
newPaths.forEach(function(newPath) {
272+
paths.push(path.join(current, newPath));
273+
});
274+
}
275+
}
276+
return size;
277+
}
278+
279+
function getDebPackageArch(arch) {
280+
if (arch === 'x64')
281+
return 'amd64'
282+
if (arch === 'ia32')
283+
return 'i386';
284+
return undefined;
285+
}
286+
287+
function prepareDebPackage(arch) {
288+
var binaryDir = '../VSCode-linux-' + arch;
289+
var debArch = getDebPackageArch(arch);
290+
var destination = './out-linux/vscode-' + debArch;
291+
var packageRevision = '1';
292+
293+
return function () {
294+
var shortcut = gulp.src('resources/common/bin/code.sh', { base: '.' })
295+
.pipe(rename(function (p) {
296+
p.extname = ''
297+
p.dirname = 'usr/bin';
298+
}));
299+
300+
var desktop = gulp.src('resources/linux/debian/code.desktop', { base: '.' })
301+
.pipe(rename(function (p) { p.dirname = 'usr/share/applications'; }));
302+
303+
var icon = gulp.src('resources/linux/code.png', { base: '.' })
304+
.pipe(rename(function (p) { p.dirname = 'usr/share/pixmaps'; }));
305+
306+
var installedSize = Math.ceil(getFolderSize(root + '/' + binaryDir) / 1024);
307+
308+
var control = gulp.src('resources/linux/debian/control.template', { base: '.' })
309+
.pipe(replace('@@VERSION@@', packageJson.version + '-' + packageRevision))
310+
.pipe(replace('@@ARCHITECTURE@@', debArch))
311+
.pipe(replace('@@INSTALLEDSIZE@@', installedSize))
312+
.pipe(rename(function (p) {
313+
p.extname = '';
314+
p.dirname = 'DEBIAN';
315+
}));
316+
317+
var all = es.merge(
318+
control,
319+
desktop,
320+
icon,
321+
shortcut);
322+
323+
all.pipe(symdest(destination));
324+
325+
var binaryResult = gulp.src(binaryDir + '/**/*', { base: binaryDir })
326+
.pipe(gulp.dest(destination + '/usr/share/code'));
327+
328+
return es.merge(all, binaryResult);
329+
};
330+
}
331+
332+
function buildDebPackage(arch) {
333+
var debArch = getDebPackageArch(arch);
334+
return shell.task(['fakeroot dpkg-deb -b ' + path.join(root, 'out-linux', 'vscode-' + debArch)]);
335+
}
336+
260337
gulp.task('clean-vscode-win32', util.rimraf(path.join(path.dirname(root), 'VSCode-win32')));
261338
gulp.task('clean-vscode-darwin', util.rimraf(path.join(path.dirname(root), 'VSCode-darwin')));
262339
gulp.task('clean-vscode-linux-ia32', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-ia32')));
263340
gulp.task('clean-vscode-linux-x64', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-x64')));
264341
gulp.task('clean-vscode-linux-arm', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-arm')));
342+
gulp.task('clean-vscode-linux-ia32-deb', util.rimraf('out-linux/vscode-i386*'));
343+
gulp.task('clean-vscode-linux-x64-deb', util.rimraf('out-linux/vscode-amd64*'));
265344

266345
gulp.task('vscode-win32', ['optimize-vscode', 'clean-vscode-win32'], packageTask('win32'));
267346
gulp.task('vscode-darwin', ['optimize-vscode', 'clean-vscode-darwin'], packageTask('darwin'));
@@ -275,6 +354,12 @@ gulp.task('vscode-linux-ia32-min', ['minify-vscode', 'clean-vscode-linux-ia32'],
275354
gulp.task('vscode-linux-x64-min', ['minify-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64', { minified: true }));
276355
gulp.task('vscode-linux-arm-min', ['minify-vscode', 'clean-vscode-linux-arm'], packageTask('linux', 'arm', { minified: true }));
277356

357+
gulp.task('vscode-linux-ia32-prepare-deb', ['clean-vscode-linux-ia32-deb', 'vscode-linux-ia32'], prepareDebPackage('ia32'));
358+
gulp.task('vscode-linux-x64-prepare-deb', ['clean-vscode-linux-x64-deb'/*, 'vscode-linux-x64'*/], prepareDebPackage('x64'));
359+
gulp.task('vscode-linux-ia32-build-deb', ['vscode-linux-ia32-prepare-deb'], buildDebPackage('ia32'));
360+
gulp.task('vscode-linux-x64-build-deb', ['vscode-linux-x64-prepare-deb'], buildDebPackage('x64'));
361+
gulp.task('vscode-linux-packages', ['vscode-linux-ia32-build-deb', 'vscode-linux-x64-build-deb']);
362+
278363
// Sourcemaps
279364

280365
gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
@@ -285,4 +370,4 @@ gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
285370
container: 'sourcemaps',
286371
prefix: commit + '/'
287372
}));
288-
});
373+
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"gulp-mocha": "^2.1.3",
5858
"gulp-remote-src": "^0.4.0",
5959
"gulp-rename": "^1.2.0",
60+
"gulp-replace": "^0.5.4",
61+
"gulp-shell": "^0.5.2",
6062
"gulp-sourcemaps": "^1.6.0",
6163
"gulp-symdest": "^1.0.0",
6264
"gulp-tsb": "^1.10.1",

resources/common/bin/code.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
fi
2626
fi
2727

28-
VSCODE_LAUNCHER="$VSCODE_DIR/launcher.js"
28+
VSCODE_LAUNCHER="$VSCODE_DIR/resources/app/resources/common/bin/launcher.js"
2929

3030
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 VSCODE_PATH="$VSCODE_DIR/$ELECTRON_FILE" \
3131
"$VSCODE_DIR/$ELECTRON_FILE" $VSCODE_LAUNCHER "$@"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Desktop Entry]
2+
Name=Visual Studio Code
3+
Comment=Code Editing. Redefined.
4+
GenericName=Text Editor
5+
Exec=/usr/bin/code %U
6+
Icon=code
7+
Type=Application
8+
StartupNotify=true
9+
Categories=Utility;TextEditor;Development;IDE;
10+
MimeType=text/plain;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Package: visual-studio-code
2+
Version: @@VERSION@@
3+
Section: devel
4+
Priority: optional
5+
Architecture: @@ARCHITECTURE@@
6+
Maintainer: Microsoft Corporation <vscode-linux@microsoft.com>
7+
Homepage: https://github.com/Microsoft/vscode
8+
Installed-Size: @@INSTALLEDSIZE@@
9+
Description: Code Editing. Redefined.
10+
Build and debug modern web and cloud applications.

0 commit comments

Comments
 (0)