-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild.js
More file actions
168 lines (148 loc) · 5.28 KB
/
build.js
File metadata and controls
168 lines (148 loc) · 5.28 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* @license
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const cp = require('child_process');
const fs = require('fs');
const https = require('https');
const path = require('path');
const rimraf = require('rimraf');
const tar = require('tar');
const util = require('util');
const os = require('os');
const url = require('url');
const zip = require('adm-zip');
const HttpsProxyAgent = require('https-proxy-agent');
const ProgressBar = require('progress');
const mkdir = util.promisify(fs.mkdir);
const exists = util.promisify(fs.exists);
const rename = util.promisify(fs.rename);
const unlink = util.promisify(fs.unlink);
// Determine which tarball to download based on the OS platform and arch:
const platform = os.platform().toLowerCase();
const platformArch = `${platform}-${os.arch().toLowerCase()}`;
let ANGLE_BINARY_URI = 'https://storage.googleapis.com/angle-builds/';
if (platform === 'darwin') {
// TODO(add debug flag?)
ANGLE_BINARY_URI += `angle-3729-${platformArch}.tar.gz`;
} else if (platform === 'linux') {
// TODO(add debug flag?)
ANGLE_BINARY_URI += `angle-3729-${platformArch}.tar.gz`;
} else if (platform === 'win32') {
ANGLE_BINARY_URI += `angle-3729-${platformArch}.zip`;
} else {
console.log('platform: ' + platform);
throw new Error(`The platform ${platformArch} is not currently supported!`);
}
console.log(`Downloading ANGLE from: ${ANGLE_BINARY_URI}`);
// Dependency storage paths:
const depsPath = path.join(__dirname, '..', 'deps');
//
// Ensures that a directory exists at a given path.
//
async function ensureDir(dirPath) {
if (!await exists(dirPath)) {
await mkdir(dirPath);
}
}
//
// Downloads the ANGLE tarball set at `ANGLE_BINARY_URI` with an optional
// callback when downloading and extracting has finished.
//
async function downloadAngleLibs(callback) {
console.error('* Downloading ANGLE');
await ensureDir(depsPath);
// If HTTPS_PROXY, https_proxy, HTTP_PROXY, or http_proxy is set
const proxy = process.env['HTTPS_PROXY'] || process.env['https_proxy'] ||
process.env['HTTP_PROXY'] || process.env['http_proxy'] || '';
// Using object destructuring to construct the options object for the
// http request. the '...url.parse(ANGLE_BINARY_URI)' part fills in the host,
// path, protocol, etc from the ANGLE_BINARY_URI and then we set the agent to
// the default agent which is overridden a few lines down if there is a proxy
const options = {
...url.parse(ANGLE_BINARY_URI),
agent: https.globalAgent,
headers: { 'Cache-Control': 'no-cache' }
};
if (proxy !== '') {
options.agent = new HttpsProxyAgent(proxy);
}
const request = https.get(options, response => {
const bar = new ProgressBar('[:bar] :rate/bps :percent :etas', {
complete: '=',
incomplete: ' ',
width: 30,
total: parseInt(response.headers['content-length'], 10)
});
if (platform === 'win32') {
// Save zip file to disk, extract, and delete the downloaded zip file.
const tempFileName = path.join(__dirname, '_tmp.zip');
const outputFile = fs.createWriteStream(tempFileName);
response.on('data', chunk => bar.tick(chunk.length))
.pipe(outputFile)
.on('close', async () => {
const zipFile = new zip(tempFileName);
zipFile.extractAllTo(depsPath, true /* overwrite */);
await unlink(tempFileName);
// The .lib files for the two .dll files we care about have a name
// the compiler doesn't like - rename them:
await rename(
path.join(
depsPath, 'angle', 'out', 'Release', 'libGLESv2.dll.lib'),
path.join(
depsPath, 'angle', 'out', 'Release', 'libGLESv2.lib'));
await rename(
path.join(
depsPath, 'angle', 'out', 'Release', 'libEGL.dll.lib'),
path.join(depsPath, 'angle', 'out', 'Release', 'libEGL.lib'));
if (callback !== undefined) {
callback();
}
});
} else {
// All other platforms use a tarball:
response
.on('data',
(chunk) => {
bar.tick(chunk.length);
})
.pipe(tar.x({ C: depsPath, strict: true }))
.on('close', () => {
if (callback !== undefined) {
callback();
}
});
}
});
request.end();
}
//
// Wraps and executes a node-gyp rebuild command.
//
async function buildBindings() {
console.error('* Building ANGLE bindings')
cp.execSync('node-gyp rebuild', (err) => {
if (err) {
throw new Error('node-gyp failed with: ' + err);
}
});
}
//
// Main execution function for this script.
//
async function run() {
await downloadAngleLibs(buildBindings);
}
run();