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

Commit 1a9c4b2

Browse files
committed
fix: log the real snapshot tool error by trying to evaluate the input file script
1 parent 7586d4c commit 1a9c4b2

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Diff for: snapshot/android/snapshot-generator.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = SnapshotGenerator;
4343

4444
SnapshotGenerator.SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot";
4545

46-
SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFile) {
46+
SnapshotGenerator.prototype.preprocessInputFiles = function (inputFiles, outputFile) {
4747
// Make some modifcations on the original bundle and save it on the specified path
4848
const bundlePreambleContent = fs.readFileSync(BUNDLE_PREAMBLE_PATH, "utf8");
4949
const bundleEndingContent = fs.readFileSync(BUNDLE_ENDING_PATH, "utf8");
@@ -67,7 +67,7 @@ SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFi
6767

6868
const snapshotToolsDownloads = {};
6969

70-
SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath, v8Version, targetArch) {
70+
SnapshotGenerator.prototype.downloadMksnapshotTool = function (snapshotToolsPath, v8Version, targetArch) {
7171
const hostOS = getHostOS();
7272
const mksnapshotToolRelativePath = join("mksnapshot-tools", "v8-v" + v8Version, hostOS + "-" + os.arch(), "mksnapshot-" + targetArch);
7373
const mksnapshotToolPath = join(snapshotToolsPath, mksnapshotToolRelativePath);
@@ -96,7 +96,7 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath,
9696
return snapshotToolsDownloads[mksnapshotToolPath];
9797
}
9898

99-
SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) {
99+
SnapshotGenerator.prototype.convertToAndroidArchName = function (archName) {
100100
switch (archName) {
101101
case "arm": return "armeabi-v7a";
102102
case "arm64": return "arm64-v8a";
@@ -106,7 +106,7 @@ SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) {
106106
}
107107
}
108108

109-
SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams) {
109+
SnapshotGenerator.prototype.runMksnapshotTool = function (snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams) {
110110
// Cleans the snapshot build folder
111111
shelljs.rm("-rf", join(this.buildPath, "snapshots"));
112112

@@ -132,14 +132,22 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
132132
const command = `${currentArchMksnapshotToolPath} ${inputFile} --startup_blob ${join(currentArchBlobOutputPath, `${SNAPSHOT_BLOB_NAME}.blob`)} ${params}`;
133133

134134
return new Promise((resolve, reject) => {
135-
const child = child_process.exec(command, {encoding: "utf8"}, (error, stdout, stderr) => {
135+
const child = child_process.exec(command, { encoding: "utf8" }, (error, stdout, stderr) => {
136136
const errorHeader = `Target architecture: ${androidArch}\n`;
137+
let errorFooter = ``;
138+
if (stderr.length || error) {
139+
try {
140+
require(inputFile);
141+
} catch (e) {
142+
errorFooter = `\nJavaScript execution error: ${e.stack}$`;
143+
}
144+
}
137145

138146
if (stderr.length) {
139-
const message = `${errorHeader}${stderr}`;
147+
const message = `${errorHeader}${stderr}${errorFooter}`;
140148
reject(new Error(message));
141149
} else if (error) {
142-
error.message = `${errorHeader}${error.message}`;
150+
error.message = `${errorHeader}${error.message}${errorFooter}`;
143151
reject(error);
144152
} else {
145153
console.log(stdout);
@@ -151,7 +159,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
151159
if (buildCSource) {
152160
const currentArchSrcOutputPath = join(this.buildPath, "snapshots/src", androidArch);
153161
shelljs.mkdir("-p", currentArchSrcOutputPath);
154-
shellJsExecuteInDir(currentArchBlobOutputPath, function() {
162+
shellJsExecuteInDir(currentArchBlobOutputPath, function () {
155163
shelljs.exec(`xxd -i ${SNAPSHOT_BLOB_NAME}.blob > ${join(currentArchSrcOutputPath, `${SNAPSHOT_BLOB_NAME}.c`)}`);
156164
});
157165
}
@@ -162,7 +170,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
162170
});
163171
}
164172

165-
SnapshotGenerator.prototype.buildSnapshotLibs = function(androidNdkBuildPath, targetArchs) {
173+
SnapshotGenerator.prototype.buildSnapshotLibs = function (androidNdkBuildPath, targetArchs) {
166174
// Compile *.c files to produce *.so libraries with ndk-build tool
167175
const ndkBuildPath = join(this.buildPath, "ndk-build");
168176
const androidArchs = targetArchs.map(arch => this.convertToAndroidArchName(arch));
@@ -171,22 +179,22 @@ SnapshotGenerator.prototype.buildSnapshotLibs = function(androidNdkBuildPath, ta
171179
shelljs.cp("-r", NDK_BUILD_SEED_PATH, ndkBuildPath);
172180
fs.writeFileSync(join(ndkBuildPath, "jni/Application.mk"), "APP_ABI := " + androidArchs.join(" ")); // create Application.mk file
173181
shelljs.mv(join(this.buildPath, "snapshots/src/*"), join(ndkBuildPath, "jni"));
174-
shellJsExecuteInDir(ndkBuildPath, function(){
182+
shellJsExecuteInDir(ndkBuildPath, function () {
175183
shelljs.exec(androidNdkBuildPath);
176184
});
177185
return join(ndkBuildPath, "libs");
178186
}
179187

180-
SnapshotGenerator.prototype.buildIncludeGradle = function() {
188+
SnapshotGenerator.prototype.buildIncludeGradle = function () {
181189
shelljs.cp(INCLUDE_GRADLE_PATH, join(this.buildPath, "include.gradle"));
182190
}
183191

184-
SnapshotGenerator.prototype.generate = function(options) {
192+
SnapshotGenerator.prototype.generate = function (options) {
185193
// Arguments validation
186194
options = options || {};
187195
if (!options.v8Version) { throw new Error("No v8 version specified."); }
188196
if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); }
189-
const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed");
197+
const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed");
190198

191199
console.log("***** Starting snapshot generation using V8 version: ", options.v8Version);
192200

0 commit comments

Comments
 (0)