1
1
const { join, isAbsolute, resolve } = require ( "path" ) ;
2
2
const fs = require ( "fs" ) ;
3
- const shelljs = require ( "shelljs" ) ;
4
3
const os = require ( "os" ) ;
5
4
5
+ const shelljs = require ( "shelljs" ) ;
6
+ const semver = require ( "semver" ) ;
7
+
6
8
const SnapshotGenerator = require ( "./snapshot-generator" ) ;
7
9
const TnsJavaClassesGenerator = require ( "./tns-java-classes-generator" ) ;
8
- const { isVersionGte } = require ( "../. ./utils" ) ;
10
+ const { getJsonFile } = require ( "./utils" ) ;
9
11
const { getPackageJson } = require ( "../../projectHelpers" ) ;
10
12
11
13
const MIN_ANDROID_RUNTIME_VERSION = "3.0.0" ;
12
14
const VALID_ANDROID_RUNTIME_TAGS = Object . freeze ( [ "next" , "rc" ] ) ;
15
+ const V8_VERSIONS_URL = "https://raw.githubusercontent.com/NativeScript/android-runtime/master/v8-versions.json" ;
13
16
14
17
const resolveRelativePath = ( path ) => {
15
18
if ( path )
@@ -95,23 +98,23 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function(projectRoot) {
95
98
}
96
99
}
97
100
98
- ProjectSnapshotGenerator . prototype . getV8Version = function ( ) {
99
- const runtimeVersion = this . getAndroidRuntimeVersion ( ) ;
100
-
101
- if ( ! runtimeVersion ) {
102
- return ;
103
- } else if (
104
- VALID_ANDROID_RUNTIME_TAGS . includes ( runtimeVersion ) ||
105
- isVersionGte ( runtimeVersion , "3.2.0" )
106
- ) {
107
- return "5.9.211" ;
108
- } else if ( isVersionGte ( runtimeVersion , "3.1.0" ) ) {
109
- return "5.5.372" ;
110
- } else if ( isVersionGte ( runtimeVersion , "2.4.0" ) ) {
111
- return "5.2.361" ;
112
- } else if ( isVersionGte ( runtimeVersion , "2.0.0" ) ) {
113
- return "4.7.80" ;
114
- }
101
+ ProjectSnapshotGenerator . prototype . getV8Version = function ( generationOptions ) {
102
+ return new Promise ( ( resolve , reject ) => {
103
+ const maybeV8Version = generationOptions . v8Version ;
104
+ if ( maybeV8Version ) {
105
+ return resolve ( maybeV8Version ) ;
106
+ }
107
+
108
+ getJsonFile ( V8_VERSIONS_URL ) . then ( v8VersionsMap => {
109
+ const runtimeVersion = this . getAndroidRuntimeVersion ( ) . replace ( / - . * / , "" ) ;
110
+
111
+ const runtimeRange = Object . keys ( v8VersionsMap )
112
+ . find ( range => semver . satisfies ( runtimeVersion , range ) ) ;
113
+ const v8Version = v8VersionsMap [ runtimeRange ] ;
114
+
115
+ return resolve ( v8Version ) ;
116
+ } ) . catch ( reject ) ;
117
+ } ) ;
115
118
}
116
119
117
120
ProjectSnapshotGenerator . prototype . validateAndroidRuntimeVersion = function ( ) {
@@ -124,7 +127,7 @@ ProjectSnapshotGenerator.prototype.validateAndroidRuntimeVersion = function() {
124
127
}
125
128
126
129
if ( ! VALID_ANDROID_RUNTIME_TAGS . includes ( currentRuntimeVersion ) &&
127
- ! isVersionGte ( currentRuntimeVersion , MIN_ANDROID_RUNTIME_VERSION ) ) {
130
+ ! semver . gte ( currentRuntimeVersion , MIN_ANDROID_RUNTIME_VERSION ) ) {
128
131
129
132
throw new Error ( "In order to support heap snapshots, you must have at least tns-android@" + MIN_ANDROID_RUNTIME_VERSION +
130
133
" installed. Current Android Runtime version is: " + currentRuntimeVersion + "." ) ;
@@ -178,23 +181,29 @@ ProjectSnapshotGenerator.prototype.generate = function(generationOptions) {
178
181
179
182
// Generate snapshots
180
183
const generator = new SnapshotGenerator ( { buildPath : this . getBuildPath ( ) } ) ;
181
- return generator . generate ( {
182
- snapshotToolsPath,
183
- inputFile : generationOptions . inputFile || join ( this . options . projectRoot , "__snapshot.js" ) ,
184
- targetArchs : generationOptions . targetArchs || [ "arm" , "arm64" , "ia32" ] ,
185
- v8Version : generationOptions . v8Version || this . getV8Version ( ) ,
186
- preprocessedInputFile : generationOptions . preprocessedInputFile ,
187
- useLibs : generationOptions . useLibs || false ,
188
- androidNdkPath
189
- } ) . then ( ( ) => {
190
- console . log ( "Snapshots build finished succesfully!" ) ;
191
-
192
- if ( generationOptions . install ) {
193
- ProjectSnapshotGenerator . cleanSnapshotArtefacts ( this . options . projectRoot ) ;
194
- ProjectSnapshotGenerator . installSnapshotArtefacts ( this . options . projectRoot ) ;
195
- console . log ( generationOptions . useLibs ?
196
- "Snapshot is included in the app as dynamically linked library (.so file)." :
197
- "Snapshot is included in the app as binary .blob file. The more space-efficient option is to embed it in a dynamically linked library (.so file)." ) ;
198
- }
184
+
185
+ return this . getV8Version ( generationOptions ) . then ( v8Version => {
186
+ return generator . generate ( {
187
+ snapshotToolsPath,
188
+ inputFile : generationOptions . inputFile || join ( this . options . projectRoot , "__snapshot.js" ) ,
189
+ targetArchs : generationOptions . targetArchs || [ "arm" , "arm64" , "ia32" ] ,
190
+ v8Version : generationOptions . v8Version || this . getV8Version ( ) ,
191
+ preprocessedInputFile : generationOptions . preprocessedInputFile ,
192
+ useLibs : generationOptions . useLibs || false ,
193
+ androidNdkPath
194
+ } ) . then ( ( ) => {
195
+ console . log ( "Snapshots build finished succesfully!" ) ;
196
+
197
+ if ( generationOptions . install ) {
198
+ ProjectSnapshotGenerator . cleanSnapshotArtefacts ( this . options . projectRoot ) ;
199
+ ProjectSnapshotGenerator . installSnapshotArtefacts ( this . options . projectRoot ) ;
200
+ console . log ( generationOptions . useLibs ?
201
+ "Snapshot is included in the app as dynamically linked library (.so file)." :
202
+ "Snapshot is included in the app as binary .blob file. The more space-efficient option is to embed it in a dynamically linked library (.so file)." ) ;
203
+ }
204
+ } ) ;
205
+ } ) . catch ( error => {
206
+ throw new Error ( `Cannot find suitable v8 version! Original error: ${ error . message || error } ` ) ;
199
207
} ) ;
200
208
}
209
+
0 commit comments