@@ -36,13 +36,13 @@ module.exports = SnapshotGenerator;
36
36
37
37
SnapshotGenerator . SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot" ;
38
38
39
- SnapshotGenerator . prototype . shouldSnapshotInDocker = function ( hostOS ) {
39
+ SnapshotGenerator . prototype . shouldSnapshotInDocker = function ( hostOS , targetArchs ) {
40
40
let shouldSnapshotInDocker = false ;
41
41
const generateInDockerMessage = "The snapshots will be generated in a docker container." ;
42
42
if ( hostOS == CONSTANTS . WIN_OS_NAME ) {
43
43
console . log ( `The V8 snapshot tools are not supported on Windows. ${ generateInDockerMessage } ` ) ;
44
44
shouldSnapshotInDocker = true ;
45
- } else if ( isMacOSCatalinaOrHigher ( ) && has32BitArch ( options . targetArchs ) ) {
45
+ } else if ( isMacOSCatalinaOrHigher ( ) && has32BitArch ( targetArchs ) ) {
46
46
console . log ( `Starting from macOS Catalina, the 32-bit processes are no longer supported. ${ generateInDockerMessage } ` ) ;
47
47
shouldSnapshotInDocker = true ;
48
48
}
@@ -52,8 +52,6 @@ SnapshotGenerator.prototype.shouldSnapshotInDocker = function (hostOS) {
52
52
53
53
SnapshotGenerator . prototype . preprocessInputFiles = function ( inputFiles , outputFile ) {
54
54
// Make some modifcations on the original bundle and save it on the specified path
55
-
56
-
57
55
const bundlePreambleContent = fs . readFileSync ( BUNDLE_PREAMBLE_PATH , "utf8" ) ;
58
56
const bundleEndingContent = fs . readFileSync ( BUNDLE_ENDING_PATH , "utf8" ) ;
59
57
@@ -143,20 +141,20 @@ SnapshotGenerator.prototype.generateSnapshots = function (snapshotToolsPath, inp
143
141
}
144
142
145
143
if ( shouldDownloadDockerTools ) {
146
- return this . downloadMksnapshotTools ( snapshotToolsPath , v8Version , targetArchs , true ) . then ( ( dockerTools ) => {
147
- console . log ( `Executing ' ${ snapshotToolPath } ' in a docker container.` ) ;
144
+ return this . downloadMksnapshotTools ( snapshotToolsPath , v8Version , targetArchs , snapshotInDocker ) . then ( ( dockerTools ) => {
145
+ console . log ( `Generating snapshots in a docker container.` ) ;
148
146
return this . runMksnapshotTools ( snapshotToolsPath , dockerTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
149
147
} ) ;
150
- } else {
151
- return this . runMksnapshotTools ( snapshotToolsPath , localTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
152
148
}
149
+
150
+ return this . runMksnapshotTools ( snapshotToolsPath , localTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
153
151
} ) ;
154
152
}
155
153
156
154
157
155
SnapshotGenerator . prototype . runMksnapshotTools = function ( snapshotToolsBasePath , snapshotTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) {
158
156
let currentSnapshotOperation = Promise . resolve ( ) ;
159
- const canRunInParallel = snapshotTools . length <= 1 || ! snapshotInDocker ;
157
+ const canRunInParallel = ! snapshotInDocker ;
160
158
return Promise . all ( snapshotTools . map ( ( tool ) => {
161
159
if ( canRunInParallel ) {
162
160
return this . runMksnapshotTool ( tool , mksnapshotParams , inputFile , snapshotInDocker , snapshotToolsBasePath , buildCSource ) ;
@@ -224,7 +222,7 @@ SnapshotGenerator.prototype.generate = function (options) {
224
222
225
223
this . preprocessInputFiles ( options . inputFiles , preprocessedInputFile ) ;
226
224
const hostOS = getHostOS ( ) ;
227
- const snapshotInDocker = options . snapshotInDocker || this . shouldSnapshotInDocker ( hostOS ) ;
225
+ const snapshotInDocker = options . snapshotInDocker || this . shouldSnapshotInDocker ( hostOS , options . targetArchs ) ;
228
226
229
227
// generates the actual .blob and .c files
230
228
return this . generateSnapshots (
@@ -263,11 +261,11 @@ SnapshotGenerator.prototype.getPathInDocker = function (mappedLocalDir, mappedDo
263
261
return convertToUnixPath ( pathInDocker ) ;
264
262
}
265
263
266
- SnapshotGenerator . prototype . handleSnapshotToolResult = function ( error , stdout , stderr , androidArch ) {
264
+ SnapshotGenerator . prototype . handleSnapshotToolResult = function ( error , stdout , stderr , inputFile , androidArch ) {
267
265
let toolError = null ;
268
266
const errorHeader = `Target architecture: ${ androidArch } \n` ;
269
267
let errorFooter = `` ;
270
- if ( stderr . length || error ) {
268
+ if ( ( stderr && stderr . length ) || error ) {
271
269
try {
272
270
require ( inputFile ) ;
273
271
}
@@ -276,7 +274,7 @@ SnapshotGenerator.prototype.handleSnapshotToolResult = function (error, stdout,
276
274
}
277
275
}
278
276
279
- if ( stderr . length ) {
277
+ if ( stderr && stderr . length ) {
280
278
const message = `${ errorHeader } ${ stderr } ${ errorFooter } ` ;
281
279
toolError = new Error ( message ) ;
282
280
}
@@ -322,11 +320,11 @@ SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir,
322
320
} ) ;
323
321
}
324
322
325
- SnapshotGenerator . prototype . runMksnapshotTool = function ( tool , mksnapshotParams , inputFile , snapshotInDocker , allToolsDir , buildCSource ) {
323
+ SnapshotGenerator . prototype . runMksnapshotTool = function ( tool , mksnapshotParams , inputFile , snapshotInDocker , snapshotToolsPath , buildCSource ) {
326
324
const toolPath = tool . path ;
327
325
const androidArch = this . convertToAndroidArchName ( tool . arch ) ;
328
326
if ( ! fs . existsSync ( toolPath ) ) {
329
- throw new Error ( " Can't find mksnapshot tool for " + androidArch + " at path " + toolPath ) ;
327
+ throw new Error ( ` Can't find mksnapshot tool for ${ androidArch } at path ${ toolPath } ` ) ;
330
328
}
331
329
332
330
const tempFolders = [ ] ;
@@ -344,14 +342,14 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
344
342
const blobOutputDirInDocker = `/dist/blobs/${ androidArch } ` ;
345
343
const toolsTempFolder = join ( inputFileDir , "tmp" ) ;
346
344
tempFolders . push ( toolsTempFolder ) ;
347
- const toolPathInAppDir = this . copySnapshotTool ( allToolsDir , toolPath , toolsTempFolder ) ;
345
+ const toolPathInAppDir = this . copySnapshotTool ( snapshotToolsPath , toolPath , toolsTempFolder ) ;
348
346
const toolPathInDocker = this . getPathInDocker ( inputFileDir , appDirInDocker , toolPathInAppDir ) ;
349
347
const inputFilePathInDocker = this . getPathInDocker ( inputFileDir , appDirInDocker , inputFile ) ;
350
348
const outputPathInDocker = this . getPathInDocker ( blobOutputDir , blobOutputDirInDocker , blobOutputDir ) ;
351
349
const toolCommandInDocker = this . getSnapshotToolCommand ( toolPathInDocker , inputFilePathInDocker , outputPathInDocker , toolParams ) ;
352
350
command = `docker run -v "${ inputFileDir } :${ appDirInDocker } " -v "${ blobOutputDir } :${ blobOutputDirInDocker } " ${ SNAPSHOTS_DOCKER_IMAGE } /bin/sh -c "${ toolCommandInDocker } "` ;
353
351
} else {
354
- command = this . getSnapshotToolCommand ( toolPath , inputFilePath , outputPath , toolParams ) ;
352
+ command = this . getSnapshotToolCommand ( toolPath , inputFile , blobOutputDir , toolParams ) ;
355
353
}
356
354
357
355
// Generate .blob file
@@ -360,9 +358,9 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
360
358
shelljs . rm ( "-rf" , tempFolder ) ;
361
359
} ) ;
362
360
363
- const snapshotError = this . handleSnapshotToolResult ( error , stdout , stderr , androidArch ) ;
361
+ const snapshotError = this . handleSnapshotToolResult ( error , stdout , stderr , inputFile , androidArch ) ;
364
362
if ( snapshotError ) {
365
- return reject ( error ) ;
363
+ return reject ( snapshotError ) ;
366
364
}
367
365
368
366
return resolve ( blobOutputDir ) ;
0 commit comments