@@ -43,7 +43,7 @@ module.exports = SnapshotGenerator;
43
43
44
44
SnapshotGenerator . SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot" ;
45
45
46
- SnapshotGenerator . prototype . preprocessInputFiles = function ( inputFiles , outputFile ) {
46
+ SnapshotGenerator . prototype . preprocessInputFiles = function ( inputFiles , outputFile ) {
47
47
// Make some modifcations on the original bundle and save it on the specified path
48
48
const bundlePreambleContent = fs . readFileSync ( BUNDLE_PREAMBLE_PATH , "utf8" ) ;
49
49
const bundleEndingContent = fs . readFileSync ( BUNDLE_ENDING_PATH , "utf8" ) ;
@@ -67,7 +67,7 @@ SnapshotGenerator.prototype.preprocessInputFiles = function(inputFiles, outputFi
67
67
68
68
const snapshotToolsDownloads = { } ;
69
69
70
- SnapshotGenerator . prototype . downloadMksnapshotTool = function ( snapshotToolsPath , v8Version , targetArch ) {
70
+ SnapshotGenerator . prototype . downloadMksnapshotTool = function ( snapshotToolsPath , v8Version , targetArch ) {
71
71
const hostOS = getHostOS ( ) ;
72
72
const mksnapshotToolRelativePath = join ( "mksnapshot-tools" , "v8-v" + v8Version , hostOS + "-" + os . arch ( ) , "mksnapshot-" + targetArch ) ;
73
73
const mksnapshotToolPath = join ( snapshotToolsPath , mksnapshotToolRelativePath ) ;
@@ -96,7 +96,7 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath,
96
96
return snapshotToolsDownloads [ mksnapshotToolPath ] ;
97
97
}
98
98
99
- SnapshotGenerator . prototype . convertToAndroidArchName = function ( archName ) {
99
+ SnapshotGenerator . prototype . convertToAndroidArchName = function ( archName ) {
100
100
switch ( archName ) {
101
101
case "arm" : return "armeabi-v7a" ;
102
102
case "arm64" : return "arm64-v8a" ;
@@ -106,7 +106,7 @@ SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) {
106
106
}
107
107
}
108
108
109
- SnapshotGenerator . prototype . runMksnapshotTool = function ( snapshotToolsPath , inputFile , v8Version , targetArchs , buildCSource , mksnapshotParams ) {
109
+ SnapshotGenerator . prototype . runMksnapshotTool = function ( snapshotToolsPath , inputFile , v8Version , targetArchs , buildCSource , mksnapshotParams ) {
110
110
// Cleans the snapshot build folder
111
111
shelljs . rm ( "-rf" , join ( this . buildPath , "snapshots" ) ) ;
112
112
@@ -132,14 +132,22 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
132
132
const command = `${ currentArchMksnapshotToolPath } ${ inputFile } --startup_blob ${ join ( currentArchBlobOutputPath , `${ SNAPSHOT_BLOB_NAME } .blob` ) } ${ params } ` ;
133
133
134
134
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 ) => {
136
136
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
+ }
137
145
138
146
if ( stderr . length ) {
139
- const message = `${ errorHeader } ${ stderr } ` ;
147
+ const message = `${ errorHeader } ${ stderr } ${ errorFooter } ` ;
140
148
reject ( new Error ( message ) ) ;
141
149
} else if ( error ) {
142
- error . message = `${ errorHeader } ${ error . message } ` ;
150
+ error . message = `${ errorHeader } ${ error . message } ${ errorFooter } ` ;
143
151
reject ( error ) ;
144
152
} else {
145
153
console . log ( stdout ) ;
@@ -151,7 +159,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
151
159
if ( buildCSource ) {
152
160
const currentArchSrcOutputPath = join ( this . buildPath , "snapshots/src" , androidArch ) ;
153
161
shelljs . mkdir ( "-p" , currentArchSrcOutputPath ) ;
154
- shellJsExecuteInDir ( currentArchBlobOutputPath , function ( ) {
162
+ shellJsExecuteInDir ( currentArchBlobOutputPath , function ( ) {
155
163
shelljs . exec ( `xxd -i ${ SNAPSHOT_BLOB_NAME } .blob > ${ join ( currentArchSrcOutputPath , `${ SNAPSHOT_BLOB_NAME } .c` ) } ` ) ;
156
164
} ) ;
157
165
}
@@ -162,7 +170,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
162
170
} ) ;
163
171
}
164
172
165
- SnapshotGenerator . prototype . buildSnapshotLibs = function ( androidNdkBuildPath , targetArchs ) {
173
+ SnapshotGenerator . prototype . buildSnapshotLibs = function ( androidNdkBuildPath , targetArchs ) {
166
174
// Compile *.c files to produce *.so libraries with ndk-build tool
167
175
const ndkBuildPath = join ( this . buildPath , "ndk-build" ) ;
168
176
const androidArchs = targetArchs . map ( arch => this . convertToAndroidArchName ( arch ) ) ;
@@ -171,22 +179,22 @@ SnapshotGenerator.prototype.buildSnapshotLibs = function(androidNdkBuildPath, ta
171
179
shelljs . cp ( "-r" , NDK_BUILD_SEED_PATH , ndkBuildPath ) ;
172
180
fs . writeFileSync ( join ( ndkBuildPath , "jni/Application.mk" ) , "APP_ABI := " + androidArchs . join ( " " ) ) ; // create Application.mk file
173
181
shelljs . mv ( join ( this . buildPath , "snapshots/src/*" ) , join ( ndkBuildPath , "jni" ) ) ;
174
- shellJsExecuteInDir ( ndkBuildPath , function ( ) {
182
+ shellJsExecuteInDir ( ndkBuildPath , function ( ) {
175
183
shelljs . exec ( androidNdkBuildPath ) ;
176
184
} ) ;
177
185
return join ( ndkBuildPath , "libs" ) ;
178
186
}
179
187
180
- SnapshotGenerator . prototype . buildIncludeGradle = function ( ) {
188
+ SnapshotGenerator . prototype . buildIncludeGradle = function ( ) {
181
189
shelljs . cp ( INCLUDE_GRADLE_PATH , join ( this . buildPath , "include.gradle" ) ) ;
182
190
}
183
191
184
- SnapshotGenerator . prototype . generate = function ( options ) {
192
+ SnapshotGenerator . prototype . generate = function ( options ) {
185
193
// Arguments validation
186
194
options = options || { } ;
187
195
if ( ! options . v8Version ) { throw new Error ( "No v8 version specified." ) ; }
188
196
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" ) ;
190
198
191
199
console . log ( "***** Starting snapshot generation using V8 version: " , options . v8Version ) ;
192
200
0 commit comments