Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit cbabe4d

Browse files
committed
- use system curl instead of grunt-curl to prevent out of memory error downloading the OSX symbols
- fix the download issues with Windows
1 parent 9630a91 commit cbabe4d

File tree

1 file changed

+85
-10
lines changed

1 file changed

+85
-10
lines changed

tasks/setup.js

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ module.exports = function (grunt) {
6767
return exec("unzip -q " + src + " -d " + dest);
6868
}
6969

70+
function curl(src, dest) {
71+
grunt.verbose.writeln("Downloading " + src);
72+
return exec("curl -o " + dest + " " + src);
73+
}
74+
7075
// task: cef
7176
grunt.registerTask("cef", "Download and setup CEF", function () {
7277
var config = "cef-" + platform + common.arch(),
@@ -127,8 +132,50 @@ module.exports = function (grunt) {
127132
grunt.task.run("curl-dir:" + grunt.config("cefConfig"));
128133
});
129134

130-
function symbolFileLocation() {
131-
return path.resolve(process.cwd(), "deps/cef/symbols/");
135+
grunt.registerTask("curl-download", function () {
136+
var downloadConfig = arguments[0],
137+
downloadSource = grunt.config("curl-dir." + downloadConfig + ".src"),
138+
downloadDest = path.join(process.cwd(), grunt.config("curl-dir." + downloadConfig + ".dest")),
139+
downloadSourceURLS = downloadSource,
140+
done = this.async();
141+
142+
if (!Array.isArray(downloadSource)) {
143+
downloadSourceURLS = [];
144+
downloadSourceURLS.push(downloadSource);
145+
}
146+
147+
var promises = downloadSourceURLS.map(function (srcUrl) {
148+
var filename = path.basename(srcUrl),
149+
dest = path.join(downloadDest, filename);
150+
151+
grunt.verbose.writeln("Download " + srcUrl + " to " + dest);
152+
return curl(srcUrl, dest);
153+
});
154+
155+
q.all(promises).then(done).catch(function (err) {
156+
done(err);
157+
});
158+
});
159+
160+
function cefFileLocation() {
161+
return path.resolve(process.cwd(), "deps/cef");
162+
}
163+
164+
// Deduct the configuration (debug|release) from the zip file name
165+
function symbolCompileConfiguration(zipFileName) {
166+
if (zipFileName) {
167+
var re = /\w+?[\d+\.\d+\.\d+]+_\w+?_(\w+?)_\w+\.zip/;
168+
var match = zipFileName.match(re);
169+
170+
if (!match) {
171+
grunt.log.error("File name doesn't match the pattern for cef symbols:", zipFileName);
172+
return zipFileName;
173+
}
174+
175+
return match[1];
176+
} else {
177+
grunt.log.error("Please provide a zip file name");
178+
}
132179
}
133180

134181
grunt.registerTask("cef-symbols", "Download and unpack the CEF symbols", function () {
@@ -146,7 +193,8 @@ module.exports = function (grunt) {
146193
symbolSrcUrls.forEach(function (srcUrl) {
147194
var zipName = path.basename(srcUrl),
148195
zipDest = path.resolve(process.cwd(), path.join(grunt.config("curl-dir." + config + ".dest"), zipName)),
149-
txtName;
196+
txtName,
197+
_symbolFileLocation;
150198

151199
// extract zip file name and set config property
152200
grunt.config("cefConfig", config);
@@ -155,9 +203,11 @@ module.exports = function (grunt) {
155203
txtName = path.basename(zipName, ".zip") + ".txt";
156204

157205
// optionally download if CEF is not found
158-
if (!grunt.file.exists(path.resolve(path.join(symbolFileLocation(), txtName)))) {
206+
_symbolFileLocation = path.join(cefFileLocation(), symbolCompileConfiguration(zipName));
207+
208+
if (!grunt.file.exists(path.resolve(path.join(_symbolFileLocation, txtName)))) {
159209
// pass the name of the zip file
160-
var zipDestSafe = zipDest.replace(":", "|");
210+
var zipDestSafe = zipDest.replace(":", "|");
161211
var cefTasks = ["cef-symbols-extract" + ":" + zipDestSafe];
162212

163213
if (grunt.file.exists(zipDest)) {
@@ -168,7 +218,7 @@ module.exports = function (grunt) {
168218

169219
grunt.task.run(cefTasks);
170220
} else {
171-
grunt.verbose.writeln("Skipping CEF symbols download. Found deps/cef/symbols/" + txtName);
221+
grunt.verbose.writeln("Skipping CEF symbols download. Found " + _symbolFileLocation + "/" + txtName);
172222
}
173223
});
174224
}
@@ -183,11 +233,35 @@ module.exports = function (grunt) {
183233
zipName = path.basename(zipDest, '.zip'),
184234
unzipPromise;
185235

186-
// unzip to deps/cef/symbols/
187-
unzipPromise = unzip(zipDest, symbolFileLocation());
236+
var symbolFileLocation = path.join(cefFileLocation(), symbolCompileConfiguration(path.basename(zipDest)));
237+
238+
// unzip to deps/cef
239+
unzipPromise = unzip(zipDest, symbolFileLocation);
240+
241+
var symbolDir = path.join(symbolFileLocation, zipName);
188242

189243
unzipPromise.then(function () {
190-
var memo = path.resolve(path.join(symbolFileLocation(), zipName + ".txt"));
244+
var rename = q.denodeify(fs.rename),
245+
readdir = q.denodeify(fs.readdir);
246+
247+
return readdir(symbolDir).then(function (files) {
248+
if (files.length) {
249+
var promises = files.map(function (file) {
250+
return rename(path.join(symbolDir, file), path.join(path.dirname(symbolDir), file));
251+
});
252+
253+
return q.all(promises);
254+
} else {
255+
return;
256+
}
257+
}, function (err) {
258+
return err;
259+
});
260+
}).then(function () {
261+
var rmdir = q.denodeify(fs.rmdir);
262+
return rmdir(symbolDir);
263+
}).then(function () {
264+
var memo = path.resolve(path.join(symbolFileLocation, zipName + ".txt"));
191265

192266
// write empty file with zip file
193267
grunt.file.write(memo, "");
@@ -208,7 +282,8 @@ module.exports = function (grunt) {
208282
grunt.log.writeln("Downloading " + downloadConfig + ". This may take a while...");
209283
// curl doesn't give me the option to handle download errors on my own. If the requested file can't
210284
// be found, curl will log an error to the console.
211-
grunt.task.run("curl-dir:" + downloadConfig);
285+
//grunt.task.run("curl-dir:" + downloadConfig);
286+
grunt.task.run("curl-download:" + downloadConfig);
212287
});
213288

214289
// task: cef-extract

0 commit comments

Comments
 (0)