@@ -36,13 +36,13 @@ module.exports = SnapshotGenerator;
3636
3737SnapshotGenerator . SNAPSHOT_PACKAGE_NANE = "nativescript-android-snapshot" ;
3838
39- SnapshotGenerator . prototype . shouldSnapshotInDocker = function ( hostOS ) {
39+ SnapshotGenerator . prototype . shouldSnapshotInDocker = function ( hostOS , targetArchs ) {
4040 let shouldSnapshotInDocker = false ;
4141 const generateInDockerMessage = "The snapshots will be generated in a docker container." ;
4242 if ( hostOS == CONSTANTS . WIN_OS_NAME ) {
4343 console . log ( `The V8 snapshot tools are not supported on Windows. ${ generateInDockerMessage } ` ) ;
4444 shouldSnapshotInDocker = true ;
45- } else if ( isMacOSCatalinaOrHigher ( ) && has32BitArch ( options . targetArchs ) ) {
45+ } else if ( isMacOSCatalinaOrHigher ( ) && has32BitArch ( targetArchs ) ) {
4646 console . log ( `Starting from macOS Catalina, the 32-bit processes are no longer supported. ${ generateInDockerMessage } ` ) ;
4747 shouldSnapshotInDocker = true ;
4848 }
@@ -52,8 +52,6 @@ SnapshotGenerator.prototype.shouldSnapshotInDocker = function (hostOS) {
5252
5353SnapshotGenerator . prototype . preprocessInputFiles = function ( inputFiles , outputFile ) {
5454 // Make some modifcations on the original bundle and save it on the specified path
55-
56-
5755 const bundlePreambleContent = fs . readFileSync ( BUNDLE_PREAMBLE_PATH , "utf8" ) ;
5856 const bundleEndingContent = fs . readFileSync ( BUNDLE_ENDING_PATH , "utf8" ) ;
5957
@@ -143,20 +141,20 @@ SnapshotGenerator.prototype.generateSnapshots = function (snapshotToolsPath, inp
143141 }
144142
145143 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.` ) ;
148146 return this . runMksnapshotTools ( snapshotToolsPath , dockerTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
149147 } ) ;
150- } else {
151- return this . runMksnapshotTools ( snapshotToolsPath , localTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
152148 }
149+
150+ return this . runMksnapshotTools ( snapshotToolsPath , localTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) ;
153151 } ) ;
154152}
155153
156154
157155SnapshotGenerator . prototype . runMksnapshotTools = function ( snapshotToolsBasePath , snapshotTools , inputFile , mksnapshotParams , buildCSource , snapshotInDocker ) {
158156 let currentSnapshotOperation = Promise . resolve ( ) ;
159- const canRunInParallel = snapshotTools . length <= 1 || ! snapshotInDocker ;
157+ const canRunInParallel = ! snapshotInDocker ;
160158 return Promise . all ( snapshotTools . map ( ( tool ) => {
161159 if ( canRunInParallel ) {
162160 return this . runMksnapshotTool ( tool , mksnapshotParams , inputFile , snapshotInDocker , snapshotToolsBasePath , buildCSource ) ;
@@ -224,7 +222,7 @@ SnapshotGenerator.prototype.generate = function (options) {
224222
225223 this . preprocessInputFiles ( options . inputFiles , preprocessedInputFile ) ;
226224 const hostOS = getHostOS ( ) ;
227- const snapshotInDocker = options . snapshotInDocker || this . shouldSnapshotInDocker ( hostOS ) ;
225+ const snapshotInDocker = options . snapshotInDocker || this . shouldSnapshotInDocker ( hostOS , options . targetArchs ) ;
228226
229227 // generates the actual .blob and .c files
230228 return this . generateSnapshots (
@@ -263,11 +261,11 @@ SnapshotGenerator.prototype.getPathInDocker = function (mappedLocalDir, mappedDo
263261 return convertToUnixPath ( pathInDocker ) ;
264262}
265263
266- SnapshotGenerator . prototype . handleSnapshotToolResult = function ( error , stdout , stderr , androidArch ) {
264+ SnapshotGenerator . prototype . handleSnapshotToolResult = function ( error , stdout , stderr , inputFile , androidArch ) {
267265 let toolError = null ;
268266 const errorHeader = `Target architecture: ${ androidArch } \n` ;
269267 let errorFooter = `` ;
270- if ( stderr . length || error ) {
268+ if ( ( stderr && stderr . length ) || error ) {
271269 try {
272270 require ( inputFile ) ;
273271 }
@@ -276,7 +274,7 @@ SnapshotGenerator.prototype.handleSnapshotToolResult = function (error, stdout,
276274 }
277275 }
278276
279- if ( stderr . length ) {
277+ if ( stderr && stderr . length ) {
280278 const message = `${ errorHeader } ${ stderr } ${ errorFooter } ` ;
281279 toolError = new Error ( message ) ;
282280 }
@@ -322,11 +320,11 @@ SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir,
322320 } ) ;
323321}
324322
325- SnapshotGenerator . prototype . runMksnapshotTool = function ( tool , mksnapshotParams , inputFile , snapshotInDocker , allToolsDir , buildCSource ) {
323+ SnapshotGenerator . prototype . runMksnapshotTool = function ( tool , mksnapshotParams , inputFile , snapshotInDocker , snapshotToolsPath , buildCSource ) {
326324 const toolPath = tool . path ;
327325 const androidArch = this . convertToAndroidArchName ( tool . arch ) ;
328326 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 } ` ) ;
330328 }
331329
332330 const tempFolders = [ ] ;
@@ -344,14 +342,14 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
344342 const blobOutputDirInDocker = `/dist/blobs/${ androidArch } ` ;
345343 const toolsTempFolder = join ( inputFileDir , "tmp" ) ;
346344 tempFolders . push ( toolsTempFolder ) ;
347- const toolPathInAppDir = this . copySnapshotTool ( allToolsDir , toolPath , toolsTempFolder ) ;
345+ const toolPathInAppDir = this . copySnapshotTool ( snapshotToolsPath , toolPath , toolsTempFolder ) ;
348346 const toolPathInDocker = this . getPathInDocker ( inputFileDir , appDirInDocker , toolPathInAppDir ) ;
349347 const inputFilePathInDocker = this . getPathInDocker ( inputFileDir , appDirInDocker , inputFile ) ;
350348 const outputPathInDocker = this . getPathInDocker ( blobOutputDir , blobOutputDirInDocker , blobOutputDir ) ;
351349 const toolCommandInDocker = this . getSnapshotToolCommand ( toolPathInDocker , inputFilePathInDocker , outputPathInDocker , toolParams ) ;
352350 command = `docker run -v "${ inputFileDir } :${ appDirInDocker } " -v "${ blobOutputDir } :${ blobOutputDirInDocker } " ${ SNAPSHOTS_DOCKER_IMAGE } /bin/sh -c "${ toolCommandInDocker } "` ;
353351 } else {
354- command = this . getSnapshotToolCommand ( toolPath , inputFilePath , outputPath , toolParams ) ;
352+ command = this . getSnapshotToolCommand ( toolPath , inputFile , blobOutputDir , toolParams ) ;
355353 }
356354
357355 // Generate .blob file
@@ -360,9 +358,9 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
360358 shelljs . rm ( "-rf" , tempFolder ) ;
361359 } ) ;
362360
363- const snapshotError = this . handleSnapshotToolResult ( error , stdout , stderr , androidArch ) ;
361+ const snapshotError = this . handleSnapshotToolResult ( error , stdout , stderr , inputFile , androidArch ) ;
364362 if ( snapshotError ) {
365- return reject ( error ) ;
363+ return reject ( snapshotError ) ;
366364 }
367365
368366 return resolve ( blobOutputDir ) ;
0 commit comments