Skip to content

Commit a7b5619

Browse files
Merge pull request #862 from DustinCampbell/package-manager
Add package management system for runtime dependency acquisition
2 parents b34806a + cf141d7 commit a7b5619

22 files changed

+1227
-769
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
bin
22
node_modules
33
out
4-
.omnisharp
4+
.omnisharp-*/
5+
6+
install.lock
57

68
*.vsix

gulpfile.js

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ const fs = require('fs');
99
const path = require('path');
1010
const del = require('del');
1111
const gulp = require('gulp');
12-
const gulpUtil = require('gulp-util');
1312
const mocha = require('gulp-mocha');
1413
const tslint = require('gulp-tslint');
1514
const vsce = require('vsce');
1615
const debugUtil = require('./out/src/coreclr-debug/util');
1716
const debugInstall = require('./out/src/coreclr-debug/install');
1817
const fs_extra = require('fs-extra-promise');
19-
const omnisharp = require('./out/src/omnisharp/omnisharp');
20-
const download = require('./out/src/omnisharp/download');
21-
const logger = require('./out/src/omnisharp/logger');
18+
const packages = require('./out/src/packages');
19+
const logger = require('./out/src/logger');
2220
const platform = require('./out/src/platform');
21+
const util = require('./out/src/common');
2322
const child_process = require('child_process');
2423

25-
const Flavor = omnisharp.Flavor;
26-
const CoreClrFlavor = platform.CoreClrFlavor;
24+
const Logger = logger.Logger;
25+
const PackageManager = packages.PackageManager;
2726
const PlatformInformation = platform.PlatformInformation;
2827

2928
/// used in offline packaging run so does not clean .vsix
@@ -37,31 +36,29 @@ gulp.task('clean', ['omnisharp:clean', 'debugger:clean', 'package:clean'], () =>
3736
});
3837

3938
/// Omnisharp Tasks
40-
function installOmnisharp(omnisharps) {
41-
const promises = omnisharps.map((omni, index) => {
42-
const log = new logger.Logger(message => process.stdout.write(message), index.toString());
39+
function installOmnisharp(platform, packageJSON) {
40+
const packageManager = new PackageManager(platform, packageJSON);
41+
const logger = new Logger(message => process.stdout.write(message));
4342

44-
return download.go(omni.flavor, omni.coreClrFlavor, log);
45-
});
46-
47-
return Promise.all(promises);
43+
return packageManager.DownloadPackages(logger)
44+
.then(() => {
45+
return packageManager.InstallPackages(logger);
46+
});
4847
}
4948

5049
function cleanOmnisharp() {
51-
return del('.omnisharp');
50+
return del('bin');
5251
}
5352

5453
gulp.task('omnisharp:clean', () => {
5554
return cleanOmnisharp();
5655
});
5756

5857
gulp.task('omnisharp:install', ['omnisharp:clean'], () => {
59-
const flavor = gulpUtil.env.flavor || Flavor.CoreCLR;
60-
61-
return PlatformInformation.GetCurrent().then(info => {
62-
const coreClrFlavor = gulpUtil.env.coreClrFlavor || info.getCoreClrFlavor();
63-
return installOmnisharp([{ flavor, coreClrFlavor }]);
64-
});
58+
return PlatformInformation.GetCurrent()
59+
.then(platformInfo => {
60+
return installOmnisharp(platformInfo, getPackageJSON());
61+
});
6562
});
6663

6764
/// Debugger Tasks
@@ -83,11 +80,13 @@ function cleanDebugger() {
8380
}
8481

8582
gulp.task('debugger:install', ['debugger:clean'], () => {
86-
installDebugger(gulp.env.runtimeId).then(() => {
87-
console.log('Installed Succesfully');
88-
}).catch((error) => {
89-
console.error(error);
90-
});
83+
installDebugger(gulp.env.runtimeId)
84+
.then(() => {
85+
console.log('Installed Succesfully');
86+
})
87+
.catch((error) => {
88+
console.error(error);
89+
});
9190
});
9291

9392
gulp.task('debugger:clean', () => {
@@ -112,14 +111,21 @@ function doPackageSync(packageName) {
112111
}
113112
}
114113

115-
function doOfflinePackage(runtimeId, omnisharps, packageName) {
116-
return clean().then(() => {
117-
return installDebugger(runtimeId);
118-
}).then(() => {
119-
return installOmnisharp(omnisharps);
120-
}).then(() => {
121-
doPackageSync(packageName + '-' + runtimeId + '.vsix');
122-
});
114+
function doOfflinePackage(runtimeId, platform, packageName, packageJSON) {
115+
return clean()
116+
.then(() => {
117+
return installDebugger(runtimeId);
118+
})
119+
.then(() => {
120+
return installOmnisharp(platform, packageJSON);
121+
})
122+
.then(() => {
123+
doPackageSync(packageName + '-' + runtimeId + '.vsix');
124+
});
125+
}
126+
127+
function getPackageJSON() {
128+
return JSON.parse(fs.readFileSync('package.json'));
123129
}
124130

125131
gulp.task('package:clean', () => {
@@ -131,28 +137,31 @@ gulp.task('package:online', ['clean'], () => {
131137
});
132138

133139
gulp.task('package:offline', ['clean'], () => {
134-
var json = JSON.parse(fs.readFileSync('package.json'));
135-
var name = json.name;
136-
var version = json.version;
140+
util.setExtensionPath(__dirname);
141+
142+
var packageJSON = getPackageJSON();
143+
var name = packageJSON.name;
144+
var version = packageJSON.version;
137145
var packageName = name + '.' + version;
138146

139147
var packages = [];
140-
packages.push({ rid: 'win7-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.Windows }, { flavor: Flavor.Desktop, coreClrFlavor: CoreClrFlavor.Windows }] });
141-
packages.push({ rid: 'osx.10.11-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.OSX }] });
142-
packages.push({ rid: 'centos.7-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.CentOS }] });
143-
packages.push({ rid: 'debian.8-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.Debian }] });
144-
packages.push({ rid: 'fedora.23-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.Fedora }] });
145-
packages.push({ rid: 'opensuse.13.2-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.OpenSUSE }] });
146-
packages.push({ rid: 'rhel.7.2-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.RHEL }] });
147-
packages.push({ rid: 'ubuntu.14.04-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.Ubuntu14 }] });
148-
packages.push({ rid: 'ubuntu.16.04-x64', omnisharps: [{ flavor: Flavor.CoreCLR, coreClrFlavor: CoreClrFlavor.Ubuntu16 }] });
148+
packages.push({ rid: 'win7-x64', platform: new PlatformInformation('win32') });
149+
packages.push({ rid: 'osx.10.11-x64', platform: new PlatformInformation('darwin', 'x86_64') });
150+
packages.push({ rid: 'centos.7-x64', platform: new PlatformInformation('linux', 'x86_64') });
151+
packages.push({ rid: 'debian.8-x64', platform: new PlatformInformation('linux', 'x86_64') });
152+
packages.push({ rid: 'fedora.23-x64', platform: new PlatformInformation('linux', 'x86_64') });
153+
packages.push({ rid: 'opensuse.13.2-x64', platform: new PlatformInformation('linux', 'x86_64') });
154+
packages.push({ rid: 'rhel.7.2-x64', platform: new PlatformInformation('linux', 'x86_64') });
155+
packages.push({ rid: 'ubuntu.14.04-x64', platform: new PlatformInformation('linux', 'x86_64') });
156+
packages.push({ rid: 'ubuntu.16.04-x64', platform: new PlatformInformation('linux', 'x86_64') });
149157

150158
var promise = Promise.resolve();
151159

152160
packages.forEach(data => {
153-
promise = promise.then(() => {
154-
return doOfflinePackage(data.rid, data.omnisharps, packageName);
155-
})
161+
promise = promise
162+
.then(() => {
163+
return doOfflinePackage(data.rid, data.platform, packageName, packageJSON);
164+
});
156165
});
157166

158167
return promise;

package.json

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@
2525
"postinstall": "node ./node_modules/vscode/bin/install"
2626
},
2727
"dependencies": {
28-
"decompress": "^4.0.0",
29-
"del": "^2.0.2",
3028
"fs-extra-promise": "^0.3.1",
3129
"http-proxy-agent": "^1.0.0",
3230
"https-proxy-agent": "^1.0.0",
3331
"lodash.debounce": "^4.0.8",
32+
"mkdirp": "^0.5.1",
3433
"open": "*",
3534
"semver": "*",
3635
"tmp": "0.0.28",
3736
"vscode-debugprotocol": "^1.6.1",
38-
"vscode-extension-telemetry": "0.0.4"
37+
"vscode-extension-telemetry": "0.0.4",
38+
"yauzl": "^2.5.0"
3939
},
4040
"devDependencies": {
41+
"del": "^2.0.2",
4142
"gulp": "^3.9.1",
4243
"gulp-mocha": "^2.1.3",
4344
"gulp-tslint": "^4.3.0",
@@ -50,6 +51,117 @@
5051
"chai": "^3.5.0",
5152
"vscode-textmate": "^2.1.1"
5253
},
54+
"runtimeDependencies": [
55+
{
56+
"description": "OmniSharp (Windows / x86)",
57+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-win-x86-net46.zip",
58+
"installPath": ".omnisharp-desktop",
59+
"runtimeIds": [
60+
"win7-x86"
61+
]
62+
},
63+
{
64+
"description": "OmniSharp (Windows / x64)",
65+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-win-x64-net46.zip",
66+
"installPath": ".omnisharp-desktop",
67+
"runtimeIds": [
68+
"win7-x64"
69+
]
70+
},
71+
{
72+
"description": "OmniSharp (.NET Core - Windows / x86)",
73+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-win-x86-netcoreapp1.0.zip",
74+
"installPath": ".omnisharp-coreclr",
75+
"runtimeIds": [
76+
"win7-x86"
77+
]
78+
},
79+
{
80+
"description": "OmniSharp (.NET Core - Windows / x64)",
81+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-win-x64-netcoreapp1.0.zip",
82+
"installPath": ".omnisharp-coreclr",
83+
"runtimeIds": [
84+
"win7-x64"
85+
]
86+
},
87+
{
88+
"description": "OmniSharp (.NET Core - OSX / x64)",
89+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-osx-x64-netcoreapp1.0.zip",
90+
"installPath": ".omnisharp-coreclr",
91+
"runtimeIds": [
92+
"osx.10.11-x64"
93+
]
94+
},
95+
{
96+
"description": "OmniSharp (.NET Core - CentOS / x64)",
97+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-centos-x64-netcoreapp1.0.zip",
98+
"installPath": ".omnisharp-coreclr",
99+
"runtimeIds": [
100+
"centos.7-x64"
101+
]
102+
},
103+
{
104+
"description": "OmniSharp (.NET Core - Debian / x64)",
105+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-debian-x64-netcoreapp1.0.zip",
106+
"installPath": ".omnisharp-coreclr",
107+
"runtimeIds": [
108+
"debian.8-x64"
109+
]
110+
},
111+
{
112+
"description": "OmniSharp (.NET Core - Fedora / x64)",
113+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-fedora-x64-netcoreapp1.0.zip",
114+
"installPath": ".omnisharp-coreclr",
115+
"runtimeIds": [
116+
"fedora.23-x64"
117+
]
118+
},
119+
{
120+
"description": "OmniSharp (.NET Core - OpenSUSE / x64)",
121+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-opensuse-x64-netcoreapp1.0.zip",
122+
"installPath": ".omnisharp-coreclr",
123+
"runtimeIds": [
124+
"opensuse.13.2-x64"
125+
]
126+
},
127+
{
128+
"description": "OmniSharp (.NET Core - RHEL / x64)",
129+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-rhel-x64-netcoreapp1.0.zip",
130+
"installPath": ".omnisharp-coreclr",
131+
"runtimeIds": [
132+
"rhel.7-x64"
133+
]
134+
},
135+
{
136+
"description": "OmniSharp (.NET Core - Ubuntu 14 / x64)",
137+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-ubuntu14-x64-netcoreapp1.0.zip",
138+
"installPath": ".omnisharp-coreclr",
139+
"runtimeIds": [
140+
"ubuntu.14.04-x64"
141+
]
142+
},
143+
{
144+
"description": "OmniSharp (.NET Core - Ubuntu 16 / x64)",
145+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-ubuntu16-x64-netcoreapp1.0.zip",
146+
"installPath": ".omnisharp-coreclr",
147+
"runtimeIds": [
148+
"ubuntu.16.04-x64"
149+
]
150+
},
151+
{
152+
"description": "OmniSharp (Mono)",
153+
"url": "https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-1.9-beta19-mono.zip",
154+
"installPath": ".omnisharp-mono",
155+
"architectures": [
156+
"x86",
157+
"x86_64"
158+
],
159+
"platforms": [
160+
"darwin",
161+
"linux"
162+
]
163+
}
164+
],
53165
"engines": {
54166
"vscode": "^1.3.0"
55167
},
@@ -699,4 +811,4 @@
699811
}
700812
]
701813
}
702-
}
814+
}

src/common.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as cp from 'child_process';
7+
import * as fs from 'fs';
8+
import * as path from 'path';
79

810
let extensionPath: string;
911

@@ -19,6 +21,16 @@ export function getExtensionPath() {
1921
return extensionPath;
2022
}
2123

24+
export function getBinPath() {
25+
return path.resolve(getExtensionPath(), "bin");
26+
}
27+
28+
export function buildPromiseChain<T, TResult>(array: T[], builder: (item: T) => Promise<TResult>): Promise<TResult> {
29+
return array.reduce(
30+
(promise, n) => promise.then(() => builder(n)),
31+
Promise.resolve<TResult>(null))
32+
}
33+
2234
export function execChildProcess(command: string, workingDirectory: string = getExtensionPath()): Promise<string> {
2335
return new Promise<string>((resolve, reject) => {
2436
cp.exec(command, { cwd: workingDirectory, maxBuffer: 500 * 1024 }, (error, stdout, stderr) => {
@@ -33,4 +45,37 @@ export function execChildProcess(command: string, workingDirectory: string = get
3345
}
3446
});
3547
});
48+
}
49+
50+
export function fileExists(filePath: string): Promise<boolean> {
51+
return new Promise<boolean>((resolve, reject) => {
52+
fs.stat(filePath, (err, stats) => {
53+
if (stats && stats.isFile()) {
54+
resolve(true);
55+
}
56+
else {
57+
resolve(false);
58+
}
59+
});
60+
});
61+
}
62+
63+
function getInstallLockFilePath(): string {
64+
return path.resolve(getExtensionPath(), 'install.lock');
65+
}
66+
67+
export function lockFileExists(): Promise<boolean> {
68+
return fileExists(getInstallLockFilePath());
69+
}
70+
71+
export function touchLockFile(): Promise<void> {
72+
return new Promise<void>((resolve, reject) => {
73+
fs.writeFile(getInstallLockFilePath(), '', err => {
74+
if (err) {
75+
return reject(err);
76+
}
77+
78+
resolve();
79+
});
80+
});
3681
}

0 commit comments

Comments
 (0)