|
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"); |
3 | 3 |
|
4 | 4 | const shelljs = require("shelljs");
|
5 | 5 | const semver = require("semver");
|
6 | 6 |
|
7 | 7 | const SnapshotGenerator = require("./snapshot-generator");
|
8 | 8 | const {
|
9 |
| - CONSTANTS, |
10 |
| - createDirectory, |
11 |
| - getJsonFile, |
| 9 | + CONSTANTS |
12 | 10 | } = require("./utils");
|
13 | 11 | const {
|
14 | 12 | ANDROID_PROJECT_DIR,
|
15 | 13 | ANDROID_APP_PATH,
|
16 | 14 | ANDROID_CONFIGURATIONS_PATH,
|
17 | 15 | getAndroidRuntimeVersion,
|
18 | 16 | getAndroidV8Version,
|
| 17 | + getRuntimeNdkRevision, |
19 | 18 | getMksnapshotParams
|
20 | 19 | } = require("../../androidProjectHelpers");
|
21 | 20 |
|
22 |
| -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"; |
23 | 23 | const VALID_ANDROID_RUNTIME_TAGS = Object.freeze(["next", "rc"]);
|
24 |
| -const V8_VERSIONS_FILE_NAME = "v8-versions.json"; |
25 |
| -const V8_VERSIONS_URL = `https://raw.githubusercontent.com/NativeScript/android-runtime/master/${V8_VERSIONS_FILE_NAME}`; |
26 |
| -const V8_VERSIONS_LOCAL_PATH = resolve(CONSTANTS.SNAPSHOT_TMP_DIR, V8_VERSIONS_FILE_NAME); |
27 | 24 |
|
28 | 25 | const resolveRelativePath = (path) => {
|
29 | 26 | if (path)
|
@@ -120,73 +117,6 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function (projectRoot) {
|
120 | 117 | }
|
121 | 118 | }
|
122 | 119 |
|
123 |
| -const versionIsPrerelease = version => version.indexOf("-") > -1; |
124 |
| -const v8VersionsFileExists = () => existsSync(V8_VERSIONS_LOCAL_PATH); |
125 |
| -const saveV8VersionsFile = versionsMap => |
126 |
| - writeFileSync(V8_VERSIONS_LOCAL_PATH, JSON.stringify(versionsMap)); |
127 |
| -const readV8VersionsFile = () => JSON.parse(readFileSync(V8_VERSIONS_LOCAL_PATH)); |
128 |
| -const fetchV8VersionsFile = () => |
129 |
| - new Promise((resolve, reject) => { |
130 |
| - getJsonFile(V8_VERSIONS_URL) |
131 |
| - .then(versionsMap => { |
132 |
| - createDirectory(dirname(V8_VERSIONS_LOCAL_PATH)); |
133 |
| - saveV8VersionsFile(versionsMap); |
134 |
| - return resolve(versionsMap); |
135 |
| - }) |
136 |
| - .catch(reject); |
137 |
| - }); |
138 |
| - |
139 |
| -const findV8Version = (runtimeVersion, v8VersionsMap) => { |
140 |
| - const runtimeRange = Object.keys(v8VersionsMap) |
141 |
| - .find(range => semver.satisfies(runtimeVersion, range)); |
142 |
| - |
143 |
| - return v8VersionsMap[runtimeRange]; |
144 |
| -} |
145 |
| - |
146 |
| -const getV8VersionsMap = runtimeVersion => |
147 |
| - new Promise((resolve, reject) => { |
148 |
| - if (!v8VersionsFileExists() || versionIsPrerelease(runtimeVersion)) { |
149 |
| - fetchV8VersionsFile() |
150 |
| - .then(versionsMap => resolve({ versionsMap, latest: true })) |
151 |
| - .catch(reject); |
152 |
| - } else { |
153 |
| - const versionsMap = readV8VersionsFile(); |
154 |
| - return resolve({ versionsMap, latest: false }); |
155 |
| - } |
156 |
| - }); |
157 |
| - |
158 |
| -ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) { |
159 |
| - return new Promise((resolve, reject) => { |
160 |
| - const maybeV8Version = generationOptions.v8Version; |
161 |
| - if (maybeV8Version) { |
162 |
| - return resolve(maybeV8Version); |
163 |
| - } |
164 |
| - |
165 |
| - // try to get the V8 Version from the settings.json file in android runtime folder |
166 |
| - const runtimeV8Version = getAndroidV8Version(this.options.projectRoot); |
167 |
| - if (runtimeV8Version) { |
168 |
| - return resolve(runtimeV8Version); |
169 |
| - } |
170 |
| - |
171 |
| - const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot); |
172 |
| - getV8VersionsMap(runtimeVersion) |
173 |
| - .then(({ versionsMap, latest }) => { |
174 |
| - const v8Version = findV8Version(runtimeVersion, versionsMap); |
175 |
| - |
176 |
| - if (!v8Version && !latest) { |
177 |
| - fetchV8VersionsFile().then(latestVersionsMap => { |
178 |
| - const version = findV8Version(runtimeVersion, latestVersionsMap) |
179 |
| - return resolve(version); |
180 |
| - }) |
181 |
| - .catch(reject); |
182 |
| - } else { |
183 |
| - return resolve(v8Version); |
184 |
| - } |
185 |
| - }) |
186 |
| - .catch(reject); |
187 |
| - }); |
188 |
| -} |
189 |
| - |
190 | 120 | ProjectSnapshotGenerator.prototype.validateAndroidRuntimeVersion = function () {
|
191 | 121 | const currentRuntimeVersion = getAndroidRuntimeVersion(this.options.projectRoot);
|
192 | 122 |
|
@@ -224,53 +154,45 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
|
224 | 154 |
|
225 | 155 | // Generate snapshots
|
226 | 156 | const generator = new SnapshotGenerator({ buildPath: this.getBuildPath() });
|
227 |
| - |
228 | 157 | const noV8VersionFoundMessage = `Cannot find suitable v8 version!`;
|
229 |
| - let shouldRethrow = false; |
230 |
| - |
231 | 158 | const mksnapshotParams = getMksnapshotParams(this.options.projectRoot);
|
| 159 | + const recommendedAndroidNdkRevision = getRuntimeNdkRevision(this.options.projectRoot); |
| 160 | + const v8Version = generationOptions.v8Version || getAndroidV8Version(this.options.projectRoot); |
| 161 | + if (!v8Version) { |
| 162 | + throw new Error(noV8VersionFoundMessage); |
| 163 | + } |
232 | 164 |
|
233 |
| - return this.getV8Version(generationOptions).then(v8Version => { |
234 |
| - shouldRethrow = true; |
235 |
| - if (!v8Version) { |
236 |
| - throw new Error(noV8VersionFoundMessage); |
237 |
| - } |
| 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 | + } |
238 | 173 |
|
239 |
| - // NOTE: Order is important! Add new archs at the end of the array |
240 |
| - const defaultTargetArchs = ["arm", "arm64", "ia32", "ia64"]; |
241 |
| - const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot); |
242 |
| - if (runtimeVersion && semver.lt(semver.coerce(runtimeVersion), "6.0.2")) { |
243 |
| - const indexOfIa64 = defaultTargetArchs.indexOf("ia64"); |
244 |
| - // Before 6.0.2 version of Android runtime we supported only arm, arm64 and ia32. |
245 |
| - 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)."); |
246 | 196 | }
|
247 |
| - |
248 |
| - const options = { |
249 |
| - snapshotToolsPath, |
250 |
| - targetArchs: generationOptions.targetArchs || defaultTargetArchs, |
251 |
| - v8Version: generationOptions.v8Version || v8Version, |
252 |
| - preprocessedInputFile: generationOptions.preprocessedInputFile, |
253 |
| - useLibs: generationOptions.useLibs || false, |
254 |
| - inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")], |
255 |
| - androidNdkPath, |
256 |
| - mksnapshotParams: mksnapshotParams, |
257 |
| - snapshotInDocker: generationOptions.snapshotInDocker |
258 |
| - }; |
259 |
| - |
260 |
| - return generator.generate(options).then(() => { |
261 |
| - console.log("Snapshots build finished succesfully!"); |
262 |
| - |
263 |
| - if (generationOptions.install) { |
264 |
| - ProjectSnapshotGenerator.cleanSnapshotArtefacts(this.options.projectRoot); |
265 |
| - ProjectSnapshotGenerator.installSnapshotArtefacts(this.options.projectRoot); |
266 |
| - console.log(generationOptions.useLibs ? |
267 |
| - "Snapshot is included in the app as dynamically linked library (.so file)." : |
268 |
| - "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)."); |
269 |
| - } |
270 |
| - }); |
271 |
| - }).catch(error => { |
272 |
| - throw shouldRethrow ? |
273 |
| - error : |
274 |
| - new Error(`${noV8VersionFoundMessage} Original error: ${error.message || error}`); |
275 |
| - }); |
| 197 | + });; |
276 | 198 | }
|
0 commit comments