Skip to content

Commit

Permalink
Add gulp tasks to build deb packages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tyriar committed Feb 11, 2016
1 parent 9ca8d4c commit fe3988c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ out-editor/
out-editor-min/
out-editor-ossfree/
out-editor-ossfree-min/
out-linux/
out-vscode/
out-vscode-min/
build/node_modules
3 changes: 3 additions & 0 deletions build/gulpfile.hygiene.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var indentationFilter = [
'**',
'!ThirdPartyNotices.txt',
'!**/*.md',
'!**/*.template',
'!**/*.yml',
'!**/lib/**',
'!**/*.d.ts',
Expand All @@ -58,8 +59,10 @@ var indentationFilter = [

var copyrightFilter = [
'**',
'!**/*.desktop',
'!**/*.json',
'!**/*.html',
'!**/*.template',
'!**/test/**',
'!**/*.md',
'!**/*.bat',
Expand Down
89 changes: 87 additions & 2 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ var azure = require('gulp-azure-storage');
var electron = require('gulp-atom-electron');
var symdest = require('gulp-symdest');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var filter = require('gulp-filter');
var json = require('gulp-json-editor');
var insert = require('gulp-insert');
var remote = require('gulp-remote-src');
var shell = require("gulp-shell");
var File = require('vinyl');
var rimraf = require('rimraf');
var _ = require('underscore');
Expand Down Expand Up @@ -215,7 +217,7 @@ function packageTask(platform, arch, opts) {
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], true))
.pipe(util.cleanNodeModule('weak', ['binding.gyp', 'build/**', 'src/**'], true));

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

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

function getFolderSize(root) {
var size = 0;
var paths = [root];
while (paths.length > 0) {
var current = path.normalize(paths.pop());
var stat = fs.statSync(current);
size += stat.size;
if (stat.isDirectory()) {
var newPaths = fs.readdirSync(current);
newPaths.forEach(function(newPath) {
paths.push(path.join(current, newPath));
});
}
}
return size;
}

function getDebPackageArch(arch) {
if (arch === 'x64')
return 'amd64'
if (arch === 'ia32')
return 'i386';
return undefined;
}

function prepareDebPackage(arch) {
var binaryDir = '../VSCode-linux-' + arch;
var debArch = getDebPackageArch(arch);
var destination = './out-linux/vscode-' + debArch;
var packageRevision = '1';

return function () {
var shortcut = gulp.src('resources/common/bin/code.sh', { base: '.' })
.pipe(rename(function (p) {
p.extname = ''
p.dirname = 'usr/bin';
}));

var desktop = gulp.src('resources/linux/debian/code.desktop', { base: '.' })
.pipe(rename(function (p) { p.dirname = 'usr/share/applications'; }));

var icon = gulp.src('resources/linux/code.png', { base: '.' })
.pipe(rename(function (p) { p.dirname = 'usr/share/pixmaps'; }));

var installedSize = Math.ceil(getFolderSize(root + '/' + binaryDir) / 1024);

var control = gulp.src('resources/linux/debian/control.template', { base: '.' })
.pipe(replace('@@VERSION@@', packageJson.version + '-' + packageRevision))
.pipe(replace('@@ARCHITECTURE@@', debArch))
.pipe(replace('@@INSTALLEDSIZE@@', installedSize))
.pipe(rename(function (p) {
p.extname = '';
p.dirname = 'DEBIAN';
}));

var all = es.merge(
control,
desktop,
icon,
shortcut);

all.pipe(symdest(destination));

var binaryResult = gulp.src(binaryDir + '/**/*', { base: binaryDir })
.pipe(gulp.dest(destination + '/usr/share/code'));

return es.merge(all, binaryResult);
};
}

function buildDebPackage(arch) {
var debArch = getDebPackageArch(arch);
return shell.task(['fakeroot dpkg-deb -b ' + path.join(root, 'out-linux', 'vscode-' + debArch)]);
}

gulp.task('clean-vscode-win32', util.rimraf(path.join(path.dirname(root), 'VSCode-win32')));
gulp.task('clean-vscode-darwin', util.rimraf(path.join(path.dirname(root), 'VSCode-darwin')));
gulp.task('clean-vscode-linux-ia32', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-ia32')));
gulp.task('clean-vscode-linux-x64', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-x64')));
gulp.task('clean-vscode-linux-arm', util.rimraf(path.join(path.dirname(root), 'VSCode-linux-arm')));
gulp.task('clean-vscode-linux-ia32-deb', util.rimraf('out-linux/vscode-i386*'));
gulp.task('clean-vscode-linux-x64-deb', util.rimraf('out-linux/vscode-amd64*'));

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

gulp.task('vscode-linux-ia32-prepare-deb', ['clean-vscode-linux-ia32-deb', 'vscode-linux-ia32'], prepareDebPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-deb', ['clean-vscode-linux-x64-deb'/*, 'vscode-linux-x64'*/], prepareDebPackage('x64'));
gulp.task('vscode-linux-ia32-build-deb', ['vscode-linux-ia32-prepare-deb'], buildDebPackage('ia32'));
gulp.task('vscode-linux-x64-build-deb', ['vscode-linux-x64-prepare-deb'], buildDebPackage('x64'));
gulp.task('vscode-linux-packages', ['vscode-linux-ia32-build-deb', 'vscode-linux-x64-build-deb']);

// Sourcemaps

gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
Expand All @@ -285,4 +370,4 @@ gulp.task('vscode-sourcemaps', ['minify-vscode'], function () {
container: 'sourcemaps',
prefix: commit + '/'
}));
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"gulp-mocha": "^2.1.3",
"gulp-remote-src": "^0.4.0",
"gulp-rename": "^1.2.0",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-symdest": "^1.0.0",
"gulp-tsb": "^1.10.1",
Expand Down
2 changes: 1 addition & 1 deletion resources/common/bin/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
fi
fi

VSCODE_LAUNCHER="$VSCODE_DIR/launcher.js"
VSCODE_LAUNCHER="$VSCODE_DIR/resources/app/resources/common/bin/launcher.js"

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

0 comments on commit fe3988c

Please sign in to comment.