Skip to content

Commit

Permalink
Merge pull request #35317 from Microsoft/tyriar/snap
Browse files Browse the repository at this point in the history
Add gulp tasks to build snap packages
  • Loading branch information
Tyriar authored Oct 2, 2017
2 parents cdd2de7 + 081a57c commit b672303
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
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}]
[{*.yml,*.yaml,npm-shrinkwrap.json,package.json}]
indent_style = space
indent_size = 2
36 changes: 21 additions & 15 deletions build/gulpfile.hygiene.js
Original file line number Diff line number Diff line change
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') {
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
62 changes: 58 additions & 4 deletions build/gulpfile.vscode.linux.js
Original file line number Diff line number Diff line change
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,50 @@ 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(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 @@ -258,6 +304,12 @@ gulp.task('clean-vscode-linux-arm-deb', util.rimraf('.build/linux/deb/armhf'));
gulp.task('clean-vscode-linux-ia32-rpm', util.rimraf('.build/linux/rpm/i386'));
gulp.task('clean-vscode-linux-x64-rpm', util.rimraf('.build/linux/rpm/x86_64'));
gulp.task('clean-vscode-linux-arm-rpm', util.rimraf('.build/linux/rpm/armhf'));
gulp.task('clean-vscode-linux-ia32-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('clean-vscode-linux-x64-snap', util.rimraf('.build/linux/snap/x64'));
gulp.task('clean-vscode-linux-arm-snap', util.rimraf('.build/linux/snap/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'));

gulp.task('vscode-linux-ia32-prepare-deb', ['clean-vscode-linux-ia32-deb'], prepareDebPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-deb', ['clean-vscode-linux-x64-deb'], prepareDebPackage('x64'));
Expand All @@ -273,14 +325,16 @@ 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-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'));
gulp.task('vscode-linux-ia32-prepare-snap', ['clean-vscode-linux-ia32-snap'], prepareSnapPackage('ia32'));
gulp.task('vscode-linux-x64-prepare-snap', ['clean-vscode-linux-x64-snap'], prepareSnapPackage('x64'));
gulp.task('vscode-linux-arm-prepare-snap', ['clean-vscode-linux-arm-snap'], prepareSnapPackage('arm'));
gulp.task('vscode-linux-ia32-build-snap', ['vscode-linux-ia32-prepare-snap'], buildSnapPackage('ia32'));
gulp.task('vscode-linux-x64-build-snap', ['vscode-linux-x64-prepare-snap'], buildSnapPackage('x64'));
gulp.task('vscode-linux-arm-build-snap', ['vscode-linux-arm-prepare-snap'], buildSnapPackage('arm'));

gulp.task('vscode-linux-ia32-prepare-flatpak', ['clean-vscode-linux-ia32-flatpak'], prepareFlatpak('ia32'));
gulp.task('vscode-linux-x64-prepare-flatpak', ['clean-vscode-linux-x64-flatpak'], prepareFlatpak('x64'));
gulp.task('vscode-linux-arm-prepare-flatpak', ['clean-vscode-linux-arm-flatpak'], prepareFlatpak('arm'));

gulp.task('vscode-linux-ia32-flatpak', ['vscode-linux-ia32-prepare-flatpak'], buildFlatpak('ia32'));
gulp.task('vscode-linux-x64-flatpak', ['vscode-linux-x64-prepare-flatpak'], buildFlatpak('x64'));
gulp.task('vscode-linux-arm-flatpak', ['vscode-linux-arm-prepare-flatpak'], buildFlatpak('arm'));
2 changes: 1 addition & 1 deletion build/tfs/common/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async function publish(commit: string, quality: string, platform: string, type:

console.log('Publishing...');
console.log('Quality:', quality);
console.log('Platforn:', platform);
console.log('Platform:', platform);
console.log('Type:', type);
console.log('Name:', name);
console.log('Version:', version);
Expand Down
8 changes: 8 additions & 0 deletions build/tfs/linux/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ step "Build Debian package" \
step "Build RPM package" \
npm run gulp -- "vscode-linux-$ARCH-build-rpm"

step "Build snap package" \
npm run gulp -- "vscode-linux-$ARCH-build-snap"

(cd $BUILD_SOURCESDIRECTORY/build/tfs/common && \
step "Install build dependencies" \
npm install --unsafe-perm)
Expand Down Expand Up @@ -49,6 +52,11 @@ RPM_PATH="$REPO/.build/linux/rpm/$RPM_ARCH/$RPM_FILENAME"
step "Publish RPM package" \
node build/tfs/common/publish.js $VSCODE_QUALITY $PLATFORM_RPM package $RPM_FILENAME $VERSION true $RPM_PATH

SNAP_FILENAME="$(ls $REPO/.build/linux/snap/$ARCH/ | grep .snap)"
SNAP_PATH="$REPO/.build/linux/snap/$ARCH/$SNAP_FILENAME"
echo 'SNAP_PATH'
echo $SNAP_PATH

if [ -z "$VSCODE_QUALITY" ]; then
echo "VSCODE_QUALITY is not set, skipping repo package publish"
else
Expand Down
2 changes: 1 addition & 1 deletion resources/linux/code.desktop
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 $@
42 changes: 42 additions & 0 deletions resources/linux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: @@NAME@@
version: @@VERSION@@
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: .
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 b672303

Please sign in to comment.