Skip to content

Commit d2b2b4d

Browse files
committed
Add support for building x64 snap package
1 parent a38d660 commit d2b2b4d

6 files changed

Lines changed: 155 additions & 17 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ trim_trailing_whitespace = true
1111

1212
# The indent size used in the `package.json` file cannot be changed
1313
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
14-
[{.travis.yml,npm-shrinkwrap.json,package.json,snapcraft.yaml}]
14+
[{*.yml,*.yaml,npm-shrinkwrap.json,package.json}]
1515
indent_style = space
1616
indent_size = 2

build/gulpfile.hygiene.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
const gulp = require('gulp');
9+
const path = require('path');
910
const filter = require('gulp-filter');
1011
const es = require('event-stream');
1112
const gulptslint = require('gulp-tslint');
@@ -172,21 +173,26 @@ const hygiene = exports.hygiene = (some, options) => {
172173
});
173174

174175
const indentation = es.through(function (file) {
175-
file.contents
176-
.toString('utf8')
177-
.split(/\r\n|\r|\n/)
178-
.forEach((line, i) => {
179-
if (/^\s*$/.test(line)) {
180-
// empty or whitespace lines are OK
181-
} else if (/^[\t]*[^\s]/.test(line)) {
182-
// good indent
183-
} else if (/^[\t]* \*/.test(line)) {
184-
// block comment using an extra space
185-
} else {
186-
console.error(file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation');
187-
errorCount++;
188-
}
189-
});
176+
// Only do the indentation check for non-YAML files as they forbid tabs
177+
// for indentation
178+
const extname = path.extname(file.relative);
179+
if (extname !== '.yaml' && extname !== '.yml') {
180+
file.contents
181+
.toString('utf8')
182+
.split(/\r\n|\r|\n/)
183+
.forEach((line, i) => {
184+
if (/^\s*$/.test(line)) {
185+
// empty or whitespace lines are OK
186+
} else if (/^[\t]*[^\s]/.test(line)) {
187+
// good indent
188+
} else if (/^[\t]* \*/.test(line)) {
189+
// block comment using an extra space
190+
} else {
191+
console.error(file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation');
192+
errorCount++;
193+
}
194+
});
195+
}
190196

191197
this.emit('data', file);
192198
});

build/gulpfile.vscode.linux.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function prepareDebPackage(arch) {
5555
.pipe(replace('@@NAME_LONG@@', product.nameLong))
5656
.pipe(replace('@@NAME_SHORT@@', product.nameShort))
5757
.pipe(replace('@@NAME@@', product.applicationName))
58+
.pipe(replace('@@ICON@@', product.applicationName))
5859
.pipe(rename('usr/share/applications/' + product.applicationName + '.desktop'));
5960

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

136138
const appdata = gulp.src('resources/linux/code.appdata.xml', { base: '.' })
@@ -178,6 +180,51 @@ function buildRpmPackage(arch) {
178180
'cp "' + rpmOut + '/$(ls ' + rpmOut + ')" ' + destination + '/'
179181
]);
180182
}
183+
function getSnapBuildPath(arch) {
184+
return `.build/linux/snap/${arch}/${product.applicationName}-${arch}`;
185+
}
186+
187+
function prepareSnapPackage(arch) {
188+
const binaryDir = '../VSCode-linux-' + arch;
189+
const destination = getSnapBuildPath(arch);
190+
191+
return function () {
192+
const desktop = gulp.src('resources/linux/code.desktop', { base: '.' })
193+
.pipe(replace('@@NAME_LONG@@', product.nameLong))
194+
.pipe(replace('@@NAME_SHORT@@', product.nameShort))
195+
.pipe(replace('@@NAME@@', product.applicationName))
196+
.pipe(replace('@@ICON@@', `/usr/share/pixmaps/${product.applicationName}.png`))
197+
.pipe(rename(`usr/share/applications/${product.applicationName}.desktop`));
198+
199+
const icon = gulp.src('resources/linux/code.png', { base: '.' })
200+
.pipe(rename(`usr/share/pixmaps/${product.applicationName}.png`));
201+
202+
const code = gulp.src(binaryDir + '/**/*', { base: binaryDir })
203+
.pipe(rename(function (p) { p.dirname = 'usr/share/' + product.applicationName + '/' + p.dirname; }));
204+
205+
const snapcraft = gulp.src('resources/linux/snap/snapcraft.yaml', { base: '.' })
206+
.pipe(replace('@@NAME@@', product.applicationName))
207+
.pipe(replace('@@VERSION@@', packageJson.version))
208+
.pipe(replace('@@EPOCH@@', linuxPackageRevision))
209+
.pipe(rename('snap/snapcraft.yaml'));
210+
211+
const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' })
212+
.pipe(rename('electron-launch'));
213+
214+
const all = es.merge(desktop, icon, code, snapcraft, electronLaunch);
215+
216+
return all.pipe(vfs.dest(destination));
217+
};
218+
}
219+
220+
function buildSnapPackage(arch) {
221+
const snapBuildPath = getSnapBuildPath(arch);
222+
223+
return shell.task([
224+
`chmod +x ${snapBuildPath}/electron-launch`,
225+
`cd ${snapBuildPath} && snapcraft snap`
226+
]);
227+
}
181228

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

323+
gulp.task('clean-vscode-linux-x64-snap', util.rimraf('.build/linux/snap/x64'));
324+
gulp.task('vscode-linux-x64-prepare-snap', ['clean-vscode-linux-x64-snap'], prepareSnapPackage('x64'));
325+
gulp.task('vscode-linux-x64-build-snap', ['vscode-linux-x64-prepare-snap'], buildSnapPackage('x64'));
326+
276327
gulp.task('clean-vscode-linux-ia32-flatpak', util.rimraf('.build/linux/flatpak/i386'));
277328
gulp.task('clean-vscode-linux-x64-flatpak', util.rimraf('.build/linux/flatpak/x86_64'));
278329
gulp.task('clean-vscode-linux-arm-flatpak', util.rimraf('.build/linux/flatpak/arm'));

resources/linux/code.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Name=@@NAME_LONG@@
33
Comment=Code Editing. Redefined.
44
GenericName=Text Editor
55
Exec=/usr/share/@@NAME@@/@@NAME@@ --unity-launch %F
6-
Icon=@@NAME@@
6+
Icon=@@ICON@@
77
Type=Application
88
StartupNotify=true
99
StartupWMClass=@@NAME_SHORT@@
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
if test "$1" = "classic"; then
4+
shift
5+
case $SNAP_ARCH in
6+
amd64)
7+
TRIPLET="x86_64-linux-gnu"
8+
;;
9+
armhf)
10+
TRIPLET="arm-linux-gnueabihf"
11+
;;
12+
arm64)
13+
TRIPLET="aarch64-linux-gnu"
14+
;;
15+
*)
16+
TRIPLET="$(uname -p)-linux-gnu"
17+
;;
18+
esac
19+
20+
# TODO: Swap LD lib paths whenever processes are launched
21+
export LD_LIBRARY_PATH_OLD=$LD_LIBRARY_PATH
22+
export LD_LIBRARY_PATH=$SNAP/usr/lib:$SNAP/usr/lib/$TRIPLET:$LD_LIBRARY_PATH
23+
export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/$TRIPLET:$LD_LIBRARY_PATH
24+
fi
25+
26+
# Correct the TMPDIR path for Chromium Framework/Electron to ensure
27+
# libappindicator has readable resources.
28+
export TMPDIR=$XDG_RUNTIME_DIR
29+
30+
exec ${SNAP}/bin/desktop-launch $@
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: @@NAME@@
2+
version: @@VERSION@@
3+
epoch: @@EPOCH@@
4+
summary: Code editing. Redefined.
5+
description: |
6+
Visual Studio Code is a new choice of tool that combines the
7+
simplicity of a code editor with what developers need for the core
8+
edit-build-debug cycle.
9+
10+
grade: stable
11+
confinement: classic
12+
13+
parts:
14+
code:
15+
plugin: dump
16+
source: .
17+
# source: https://az764295.vo.msecnd.net/stable/27492b6bf3acb0775d82d2f87b25a93490673c6d/code_1.16.1-1505406497_amd64.deb
18+
# source-type: deb
19+
# Correct path to icon.
20+
# Remove translated Name[xx]=
21+
# - Due to http://pad.lv/1662456
22+
# prepare: |
23+
# sed -i 's|Icon=.code|Icon=/usr/share/pixmaps/code\.png|g' usr/share/applications/code.desktop
24+
# sed -i '/^Name\[/d' usr/share/applications/code.desktop
25+
after:
26+
- desktop-gtk2
27+
stage-packages:
28+
- gconf2
29+
- libasound2
30+
- libnotify4
31+
- libnspr4
32+
- libnss3
33+
- libpulse0
34+
- libxss1
35+
- libxtst6
36+
prime:
37+
- -usr/share/dh-python
38+
electron-launch:
39+
plugin: dump
40+
source: .
41+
organize:
42+
electron-launch: bin/electron-launch
43+
prime:
44+
- -monitor.sh
45+
- -OLD_VERSION
46+
- -*.bz2
47+
48+
apps:
49+
@@NAME@@:
50+
command: bin/electron-launch classic ${SNAP}/usr/share/@@NAME@@/bin/@@NAME@@
51+
desktop: usr/share/applications/@@NAME@@.desktop

0 commit comments

Comments
 (0)