This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
rust-dist.js
119 lines (101 loc) · 3.07 KB
/
rust-dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
var debug = require('debug')(__filename.slice(__dirname.length + 1));
var Promise = require('promise');
var http = require('http');
var fs = require('fs');
var assert = require('assert');
var util = require('./crater-util');
/**
* Download the JSON index and return a promised JSON object. If
* `distAddr` is null the default remote address is used.
*/
function downloadIndex(config) {
var distAddr = config.rustDistAddr;
var index = distAddr + "/index.json";
return util.downloadToMem(index).then(function(data) {
return JSON.parse(data);
});
}
/**
* Converts the object returned by `downloadIndex` to a more concise form:
*
* { nightly: [dates], beta: [dates], stable: [dates] }
*
* Each is sorted from most recent to oldest.
*/
function getAvailableToolchainsFromIndex(index) {
// The index is kinda hacky and has an extra level of directory indirection.
// Peel it off here.
assert(index.ds.length == 1);
var index = index.ds[0].children;
var dirs = index.ds;
var nightly = [];
var beta = [];
var stable = [];
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var name = dir.name;
var files = dir.children.fs;
for (var j = 0; j < files.length; j++) {
var file = files[j];
if (file.name == "channel-rust-nightly") {
nightly.push(name);
} else if (file.name == "channel-rust-beta") {
beta.push(name);
} else if (file.name == "channel-rust-stable") {
stable.push(name);
}
}
}
nightly.sort();
beta.sort();
stable.sort();
var toolchains = {
nightly: nightly,
beta: beta,
stable: stable
};
return toolchains;
}
/**
* Downloads the Rust channel index and pulls out the available toolchains
* into an object with the shape:
*
* { nightly: [dates], beta: [dates], stable: [dates] }
*
* Each is sorted from most recent to oldest.
* Returns a promise.
*/
function getAvailableToolchains(config) {
var p = downloadIndex(config);
p = p.then(function(index) {
return getAvailableToolchainsFromIndex(index);
});
return p;
}
function installerUrlForToolchain(toolchain, triple, config) {
assert(toolchain.channel);
var rustDistAddr = config.rustDistAddr;
var manifest = rustDistAddr + "/" + toolchain.archiveDate + "/channel-rust-" + toolchain.channel;
debug("manifest addr: " + manifest);
return util.downloadToMem(manifest).then(function(data) {
var lines = data.match(/^.*([\n\r]+|$)/gm);
var res = null;
lines.forEach(function(line) {
var line = line.trim();
if (line.indexOf(triple) != -1 && line.indexOf(".tar.gz", line.length - ".tar.gz".length) !== -1) {
res = line.trim();
}
});
if (res) {
var url = rustDistAddr + "/" + toolchain.archiveDate + "/" + res;
return url;
} else {
return Promise.reject("no installer found for triple " + triple);
}
});
}
exports.downloadIndex = downloadIndex;
exports.getAvailableToolchainsFromIndex = getAvailableToolchainsFromIndex;
exports.getAvailableToolchains = getAvailableToolchains;
exports.installerUrlForToolchain = installerUrlForToolchain;