1- const { dirname , isAbsolute, join, resolve, sep } = require ( "path" ) ;
2- const { existsSync , readFileSync, writeFileSync } = require ( "fs" ) ;
1+ const { isAbsolute, join, resolve, sep } = require ( "path" ) ;
2+ const { readFileSync, writeFileSync } = require ( "fs" ) ;
33
44const shelljs = require ( "shelljs" ) ;
55const semver = require ( "semver" ) ;
66
77const SnapshotGenerator = require ( "./snapshot-generator" ) ;
88const {
9- CONSTANTS ,
10- createDirectory,
11- getJsonFile,
9+ CONSTANTS
1210} = require ( "./utils" ) ;
1311const {
1412 ANDROID_PROJECT_DIR ,
@@ -20,11 +18,9 @@ const {
2018 getMksnapshotParams
2119} = require ( "../../androidProjectHelpers" ) ;
2220
23- const MIN_ANDROID_RUNTIME_VERSION = "3.0.0" ;
21+ // min version with settings.json file specifying the V8 version
22+ const MIN_ANDROID_RUNTIME_VERSION = "5.2.1" ;
2423const VALID_ANDROID_RUNTIME_TAGS = Object . freeze ( [ "next" , "rc" ] ) ;
25- const V8_VERSIONS_FILE_NAME = "v8-versions.json" ;
26- const V8_VERSIONS_URL = `https://raw.githubusercontent.com/NativeScript/android-runtime/master/${ V8_VERSIONS_FILE_NAME } ` ;
27- const V8_VERSIONS_LOCAL_PATH = resolve ( CONSTANTS . SNAPSHOT_TMP_DIR , V8_VERSIONS_FILE_NAME ) ;
2824
2925const resolveRelativePath = ( path ) => {
3026 if ( path )
@@ -121,74 +117,6 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function (projectRoot) {
121117 }
122118}
123119
124- const versionIsPrerelease = version => version . indexOf ( "-" ) > - 1 ;
125- const v8VersionsFileExists = ( ) => existsSync ( V8_VERSIONS_LOCAL_PATH ) ;
126- const saveV8VersionsFile = versionsMap =>
127- writeFileSync ( V8_VERSIONS_LOCAL_PATH , JSON . stringify ( versionsMap ) ) ;
128- const readV8VersionsFile = ( ) => JSON . parse ( readFileSync ( V8_VERSIONS_LOCAL_PATH ) ) ;
129- const fetchV8VersionsFile = ( ) =>
130- new Promise ( ( resolve , reject ) => {
131- getJsonFile ( V8_VERSIONS_URL )
132- . then ( versionsMap => {
133- createDirectory ( dirname ( V8_VERSIONS_LOCAL_PATH ) ) ;
134- saveV8VersionsFile ( versionsMap ) ;
135- return resolve ( versionsMap ) ;
136- } )
137- . catch ( reject ) ;
138- } ) ;
139-
140- const findV8Version = ( runtimeVersion , v8VersionsMap ) => {
141- const runtimeRange = Object . keys ( v8VersionsMap )
142- . find ( range => semver . satisfies ( runtimeVersion , range ) ) ;
143-
144- return v8VersionsMap [ runtimeRange ] ;
145- }
146-
147- const getV8VersionsMap = runtimeVersion =>
148- new Promise ( ( resolve , reject ) => {
149- if ( ! v8VersionsFileExists ( ) || versionIsPrerelease ( runtimeVersion ) ) {
150- fetchV8VersionsFile ( )
151- . then ( versionsMap => resolve ( { versionsMap, latest : true } ) )
152- . catch ( reject ) ;
153- } else {
154- const versionsMap = readV8VersionsFile ( ) ;
155- return resolve ( { versionsMap, latest : false } ) ;
156- }
157- } ) ;
158-
159- // TODO: remove?
160- ProjectSnapshotGenerator . prototype . getV8Version = function ( generationOptions ) {
161- return new Promise ( ( resolve , reject ) => {
162- const maybeV8Version = generationOptions . v8Version ;
163- if ( maybeV8Version ) {
164- return resolve ( maybeV8Version ) ;
165- }
166-
167- // try to get the V8 Version from the settings.json file in android runtime folder
168- const runtimeV8Version = getAndroidV8Version ( this . options . projectRoot ) ;
169- if ( runtimeV8Version ) {
170- return resolve ( runtimeV8Version ) ;
171- }
172-
173- const runtimeVersion = getAndroidRuntimeVersion ( this . options . projectRoot ) ;
174- getV8VersionsMap ( runtimeVersion )
175- . then ( ( { versionsMap, latest } ) => {
176- const v8Version = findV8Version ( runtimeVersion , versionsMap ) ;
177-
178- if ( ! v8Version && ! latest ) {
179- fetchV8VersionsFile ( ) . then ( latestVersionsMap => {
180- const version = findV8Version ( runtimeVersion , latestVersionsMap )
181- return resolve ( version ) ;
182- } )
183- . catch ( reject ) ;
184- } else {
185- return resolve ( v8Version ) ;
186- }
187- } )
188- . catch ( reject ) ;
189- } ) ;
190- }
191-
192120ProjectSnapshotGenerator . prototype . validateAndroidRuntimeVersion = function ( ) {
193121 const currentRuntimeVersion = getAndroidRuntimeVersion ( this . options . projectRoot ) ;
194122
@@ -226,55 +154,45 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
226154
227155 // Generate snapshots
228156 const generator = new SnapshotGenerator ( { buildPath : this . getBuildPath ( ) } ) ;
229-
230157 const noV8VersionFoundMessage = `Cannot find suitable v8 version!` ;
231- let shouldRethrow = false ;
232-
233158 const mksnapshotParams = getMksnapshotParams ( this . options . projectRoot ) ;
234159 const recommendedAndroidNdkRevision = getRuntimeNdkRevision ( this . options . projectRoot ) ;
160+ const v8Version = generationOptions . v8Version || getAndroidV8Version ( this . options . projectRoot ) ;
161+ if ( ! v8Version ) {
162+ throw new Error ( noV8VersionFoundMessage ) ;
163+ }
235164
236- return this . getV8Version ( generationOptions ) . then ( v8Version => {
237- shouldRethrow = true ;
238- if ( ! v8Version ) {
239- throw new Error ( noV8VersionFoundMessage ) ;
240- }
165+ // NOTE: Order is important! Add new archs at the end of the array
166+ const defaultTargetArchs = [ "arm" , "arm64" , "ia32" , "ia64" ] ;
167+ const runtimeVersion = getAndroidRuntimeVersion ( this . options . projectRoot ) ;
168+ if ( runtimeVersion && semver . lt ( semver . coerce ( runtimeVersion ) , "6.0.2" ) ) {
169+ const indexOfIa64 = defaultTargetArchs . indexOf ( "ia64" ) ;
170+ // Before 6.0.2 version of Android runtime we supported only arm, arm64 and ia32.
171+ defaultTargetArchs . splice ( indexOfIa64 , defaultTargetArchs . length - indexOfIa64 ) ;
172+ }
241173
242- // NOTE: Order is important! Add new archs at the end of the array
243- const defaultTargetArchs = [ "arm" , "arm64" , "ia32" , "ia64" ] ;
244- const runtimeVersion = getAndroidRuntimeVersion ( this . options . projectRoot ) ;
245- if ( runtimeVersion && semver . lt ( semver . coerce ( runtimeVersion ) , "6.0.2" ) ) {
246- const indexOfIa64 = defaultTargetArchs . indexOf ( "ia64" ) ;
247- // Before 6.0.2 version of Android runtime we supported only arm, arm64 and ia32.
248- defaultTargetArchs . splice ( indexOfIa64 , defaultTargetArchs . length - indexOfIa64 ) ;
174+ const options = {
175+ snapshotToolsPath,
176+ targetArchs : generationOptions . targetArchs || defaultTargetArchs ,
177+ v8Version : generationOptions . v8Version || v8Version ,
178+ preprocessedInputFile : generationOptions . preprocessedInputFile ,
179+ useLibs : generationOptions . useLibs || false ,
180+ inputFiles : generationOptions . inputFiles || [ join ( this . options . projectRoot , "__snapshot.js" ) ] ,
181+ androidNdkPath,
182+ mksnapshotParams : mksnapshotParams ,
183+ snapshotInDocker : generationOptions . snapshotInDocker ,
184+ recommendedAndroidNdkRevision
185+ } ;
186+
187+ return generator . generate ( options ) . then ( ( ) => {
188+ console . log ( "Snapshots build finished succesfully!" ) ;
189+
190+ if ( generationOptions . install ) {
191+ ProjectSnapshotGenerator . cleanSnapshotArtefacts ( this . options . projectRoot ) ;
192+ ProjectSnapshotGenerator . installSnapshotArtefacts ( this . options . projectRoot ) ;
193+ console . log ( generationOptions . useLibs ?
194+ "Snapshot is included in the app as dynamically linked library (.so file)." :
195+ "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)." ) ;
249196 }
250-
251- const options = {
252- snapshotToolsPath,
253- targetArchs : generationOptions . targetArchs || defaultTargetArchs ,
254- v8Version : generationOptions . v8Version || v8Version ,
255- preprocessedInputFile : generationOptions . preprocessedInputFile ,
256- useLibs : generationOptions . useLibs || false ,
257- inputFiles : generationOptions . inputFiles || [ join ( this . options . projectRoot , "__snapshot.js" ) ] ,
258- androidNdkPath,
259- mksnapshotParams : mksnapshotParams ,
260- snapshotInDocker : generationOptions . snapshotInDocker ,
261- recommendedAndroidNdkRevision
262- } ;
263-
264- return generator . generate ( options ) . then ( ( ) => {
265- console . log ( "Snapshots build finished succesfully!" ) ;
266-
267- if ( generationOptions . install ) {
268- ProjectSnapshotGenerator . cleanSnapshotArtefacts ( this . options . projectRoot ) ;
269- ProjectSnapshotGenerator . installSnapshotArtefacts ( this . options . projectRoot ) ;
270- console . log ( generationOptions . useLibs ?
271- "Snapshot is included in the app as dynamically linked library (.so file)." :
272- "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)." ) ;
273- }
274- } ) ;
275- } ) . catch ( error => {
276- throw shouldRethrow ?
277- error :
278- new Error ( `${ noV8VersionFoundMessage } Original error: ${ error . message || error } ` ) ;
279- } ) ;
197+ } ) ; ;
280198}
0 commit comments