Skip to content

Commit

Permalink
Add support for building x64 snap package
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Sep 26, 2017
1 parent a38d660 commit d2b2b4d
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -11,6 +11,6 @@ trim_trailing_whitespace = true

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[{.travis.yml,npm-shrinkwrap.json,package.json,snapcraft.yaml}]
[{*.yml,*.yaml,npm-shrinkwrap.json,package.json}]
indent_style = space
indent_size = 2
36 changes: 21 additions & 15 deletions build/gulpfile.hygiene.js
Expand Up @@ -6,6 +6,7 @@
'use strict';

const gulp = require('gulp');
const path = require('path');
const filter = require('gulp-filter');
const es = require('event-stream');
const gulptslint = require('gulp-tslint');
Expand Down Expand Up @@ -172,21 +173,26 @@ const hygiene = exports.hygiene = (some, options) => {
});

const indentation = es.through(function (file) {
file.contents
.toString('utf8')
.split(/\r\n|\r|\n/)
.forEach((line, i) => {
if (/^\s*$/.test(line)) {
// empty or whitespace lines are OK
} else if (/^[\t]*[^\s]/.test(line)) {
// good indent
} else if (/^[\t]* \*/.test(line)) {
// block comment using an extra space
} else {
console.error(file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation');
errorCount++;
}
});
// Only do the indentation check for non-YAML files as they forbid tabs
// for indentation
const extname = path.extname(file.relative);
if (extname !== '.yaml' && extname !== '.yml') {

This comment has been minimized.

Copy link
@joaomoreno

joaomoreno Oct 4, 2017

Member

Why didn't you just use the filters defined above? 😕

3002756

This comment has been minimized.

Copy link
@Tyriar

Tyriar Oct 4, 2017

Author Member

Didn't know about it, thanks for fixing it up 😃

file.contents
.toString('utf8')
.split(/\r\n|\r|\n/)
.forEach((line, i) => {
if (/^\s*$/.test(line)) {
// empty or whitespace lines are OK
} else if (/^[\t]*[^\s]/.test(line)) {
// good indent
} else if (/^[\t]* \*/.test(line)) {
// block comment using an extra space
} else {
console.error(file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation');
errorCount++;
}
});
}

this.emit('data', file);
});
Expand Down
51 changes: 51 additions & 0 deletions build/gulpfile.vscode.linux.js
Expand Up @@ -55,6 +55,7 @@ function prepareDebPackage(arch) {
.pipe(replace('@@NAME_LONG@@', product.nameLong))
.pipe(replace('@@NAME_SHORT@@', product.nameShort))
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(replace('@@ICON@@', product.applicationName))
.pipe(rename('usr/share/applications/' + product.applicationName + '.desktop'));

const appdata = gulp.src('resources/linux/code.appdata.xml', { base: '.' })
Expand Down Expand Up @@ -131,6 +132,7 @@ function prepareRpmPackage(arch) {
.pipe(replace('@@NAME_LONG@@', product.nameLong))
.pipe(replace('@@NAME_SHORT@@', product.nameShort))
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(replace('@@ICON@@', product.applicationName))
.pipe(rename('BUILD/usr/share/applications/' + product.applicationName + '.desktop'));

const appdata = gulp.src('resources/linux/code.appdata.xml', { base: '.' })
Expand Down Expand Up @@ -178,6 +180,51 @@ function buildRpmPackage(arch) {
'cp "' + rpmOut + '/$(ls ' + rpmOut + ')" ' + destination + '/'
]);
}
function getSnapBuildPath(arch) {
return `.build/linux/snap/${arch}/${product.applicationName}-${arch}`;
}

function prepareSnapPackage(arch) {
const binaryDir = '../VSCode-linux-' + arch;
const destination = getSnapBuildPath(arch);

return function () {
const desktop = gulp.src('resources/linux/code.desktop', { base: '.' })
.pipe(replace('@@NAME_LONG@@', product.nameLong))
.pipe(replace('@@NAME_SHORT@@', product.nameShort))
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(replace('@@ICON@@', `/usr/share/pixmaps/${product.applicationName}.png`))
.pipe(rename(`usr/share/applications/${product.applicationName}.desktop`));

const icon = gulp.src('resources/linux/code.png', { base: '.' })
.pipe(rename(`usr/share/pixmaps/${product.applicationName}.png`));

const code = gulp.src(binaryDir + '/**/*', { base: binaryDir })
.pipe(rename(function (p) { p.dirname = 'usr/share/' + product.applicationName + '/' + p.dirname; }));

const snapcraft = gulp.src('resources/linux/snap/snapcraft.yaml', { base: '.' })
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(replace('@@VERSION@@', packageJson.version))
.pipe(replace('@@EPOCH@@', linuxPackageRevision))
.pipe(rename('snap/snapcraft.yaml'));

const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' })
.pipe(rename('electron-launch'));

const all = es.merge(desktop, icon, code, snapcraft, electronLaunch);

return all.pipe(vfs.dest(destination));
};
}

function buildSnapPackage(arch) {
const snapBuildPath = getSnapBuildPath(arch);

return shell.task([
`chmod +x ${snapBuildPath}/electron-launch`,
`cd ${snapBuildPath} && snapcraft snap`
]);
}

function getFlatpakArch(arch) {
return { x64: 'x86_64', ia32: 'i386', arm: 'arm' }[arch];
Expand Down Expand Up @@ -273,6 +320,10 @@ gulp.task('vscode-linux-ia32-build-rpm', ['vscode-linux-ia32-prepare-rpm'], buil
gulp.task('vscode-linux-x64-build-rpm', ['vscode-linux-x64-prepare-rpm'], buildRpmPackage('x64'));
gulp.task('vscode-linux-arm-build-rpm', ['vscode-linux-arm-prepare-rpm'], buildRpmPackage('arm'));

gulp.task('clean-vscode-linux-x64-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('vscode-linux-x64-prepare-snap', ['clean-vscode-linux-x64-snap'], prepareSnapPackage('x64'));
gulp.task('vscode-linux-x64-build-snap', ['vscode-linux-x64-prepare-snap'], buildSnapPackage('x64'));

gulp.task('clean-vscode-linux-ia32-flatpak', util.rimraf('.build/linux/flatpak/i386'));
gulp.task('clean-vscode-linux-x64-flatpak', util.rimraf('.build/linux/flatpak/x86_64'));
gulp.task('clean-vscode-linux-arm-flatpak', util.rimraf('.build/linux/flatpak/arm'));
Expand Down
2 changes: 1 addition & 1 deletion resources/linux/code.desktop
Expand Up @@ -3,7 +3,7 @@ Name=@@NAME_LONG@@
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/@@NAME@@/@@NAME@@ --unity-launch %F
Icon=@@NAME@@
Icon=@@ICON@@
Type=Application
StartupNotify=true
StartupWMClass=@@NAME_SHORT@@
Expand Down
30 changes: 30 additions & 0 deletions resources/linux/snap/electron-launch
@@ -0,0 +1,30 @@
#!/bin/sh

if test "$1" = "classic"; then
shift
case $SNAP_ARCH in
amd64)
TRIPLET="x86_64-linux-gnu"
;;
armhf)
TRIPLET="arm-linux-gnueabihf"
;;
arm64)
TRIPLET="aarch64-linux-gnu"
;;
*)
TRIPLET="$(uname -p)-linux-gnu"
;;
esac

# TODO: Swap LD lib paths whenever processes are launched
export LD_LIBRARY_PATH_OLD=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$SNAP/usr/lib:$SNAP/usr/lib/$TRIPLET:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/$TRIPLET:$LD_LIBRARY_PATH
fi

# Correct the TMPDIR path for Chromium Framework/Electron to ensure
# libappindicator has readable resources.
export TMPDIR=$XDG_RUNTIME_DIR

exec ${SNAP}/bin/desktop-launch $@
51 changes: 51 additions & 0 deletions resources/linux/snap/snapcraft.yaml
@@ -0,0 +1,51 @@
name: @@NAME@@
version: @@VERSION@@
epoch: @@EPOCH@@
summary: Code editing. Redefined.
description: |
Visual Studio Code is a new choice of tool that combines the
simplicity of a code editor with what developers need for the core
edit-build-debug cycle.
grade: stable
confinement: classic

parts:
code:
plugin: dump
source: .
# source: https://az764295.vo.msecnd.net/stable/27492b6bf3acb0775d82d2f87b25a93490673c6d/code_1.16.1-1505406497_amd64.deb
# source-type: deb
# Correct path to icon.
# Remove translated Name[xx]=
# - Due to http://pad.lv/1662456
# prepare: |
# sed -i 's|Icon=.code|Icon=/usr/share/pixmaps/code\.png|g' usr/share/applications/code.desktop
# sed -i '/^Name\[/d' usr/share/applications/code.desktop
after:
- desktop-gtk2
stage-packages:
- gconf2
- libasound2
- libnotify4
- libnspr4
- libnss3
- libpulse0
- libxss1
- libxtst6
prime:
- -usr/share/dh-python
electron-launch:
plugin: dump
source: .
organize:
electron-launch: bin/electron-launch
prime:
- -monitor.sh
- -OLD_VERSION
- -*.bz2

apps:
@@NAME@@:
command: bin/electron-launch classic ${SNAP}/usr/share/@@NAME@@/bin/@@NAME@@
desktop: usr/share/applications/@@NAME@@.desktop

0 comments on commit d2b2b4d

Please sign in to comment.