From cb68dac19a06c03afd716a8cb9a1eac9e3183ddc Mon Sep 17 00:00:00 2001 From: Darin Dimitrov Date: Wed, 6 Feb 2019 19:00:50 +0200 Subject: [PATCH] =?UTF-8?q?feat(snapshot):=20The=20parameters=20passed=20t?= =?UTF-8?q?o=20mksnapshot=20are=20now=20retrieved=E2=80=A6=20(#789)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(snapshot): The parameters passed to mksnapshot are now retrieved from the runtime * chore: reverting version --- androidProjectHelpers.js | 14 ++++++++++++++ snapshot/android/project-snapshot-generator.js | 5 +++++ snapshot/android/snapshot-generator.js | 12 +++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/androidProjectHelpers.js b/androidProjectHelpers.js index 2ea1a6bc..e6a772a0 100644 --- a/androidProjectHelpers.js +++ b/androidProjectHelpers.js @@ -34,6 +34,19 @@ const getAndroidV8Version = (projectDir) => { } } +const getMksnapshotParams = (projectDir) => { + try { + const androidSettingsJSON = getAndroidSettingsJson(projectDir); + if (androidSettingsJSON !== null) { + return androidSettingsJSON.mksnapshotParams; + } else { + return null; + } + } catch (e) { + return null; + } +}; + const getAndroidSettingsJson = projectDir => { const androidSettingsJsonPath = resolve(projectDir, PLATFORMS_ANDROID, "settings.json"); if (existsSync(androidSettingsJsonPath)) { @@ -49,4 +62,5 @@ module.exports = { ANDROID_CONFIGURATIONS_PATH, getAndroidRuntimeVersion, getAndroidV8Version, + getMksnapshotParams }; \ No newline at end of file diff --git a/snapshot/android/project-snapshot-generator.js b/snapshot/android/project-snapshot-generator.js index 051fdc53..be5ef1f3 100644 --- a/snapshot/android/project-snapshot-generator.js +++ b/snapshot/android/project-snapshot-generator.js @@ -17,6 +17,7 @@ const { ANDROID_CONFIGURATIONS_PATH, getAndroidRuntimeVersion, getAndroidV8Version, + getMksnapshotParams } = require("../../androidProjectHelpers"); const MIN_ANDROID_RUNTIME_VERSION = "3.0.0"; @@ -227,6 +228,9 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) { const noV8VersionFoundMessage = `Cannot find suitable v8 version!`; let shouldRethrow = false; + + const mksnapshotParams = getMksnapshotParams(this.options.projectRoot); + return this.getV8Version(generationOptions).then(v8Version => { shouldRethrow = true; if (!v8Version) { @@ -241,6 +245,7 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) { useLibs: generationOptions.useLibs || false, inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")], androidNdkPath, + mksnapshotParams: mksnapshotParams }; return generator.generate(options).then(() => { diff --git a/snapshot/android/snapshot-generator.js b/snapshot/android/snapshot-generator.js index bbe8f7aa..f845ecee 100644 --- a/snapshot/android/snapshot-generator.js +++ b/snapshot/android/snapshot-generator.js @@ -80,7 +80,7 @@ SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) { } } -SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource) { +SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inputFile, v8Version, targetArchs, buildCSource, mksnapshotParams) { // Cleans the snapshot build folder shelljs.rm("-rf", join(this.buildPath, "snapshots")); @@ -98,7 +98,12 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu // Generate .blob file const currentArchBlobOutputPath = join(this.buildPath, "snapshots/blobs", androidArch); shelljs.mkdir("-p", currentArchBlobOutputPath); - const command = `${currentArchMksnapshotToolPath} ${inputFile} --startup_blob ${join(currentArchBlobOutputPath, `${SNAPSHOT_BLOB_NAME}.blob`)} --profile_deserialization`; + var params = "--profile_deserialization"; + if (mksnapshotParams) { + // Starting from android runtime 5.3.0, the parameters passed to mksnapshot are read from the settings.json file + params = mksnapshotParams; + } + const command = `${currentArchMksnapshotToolPath} ${inputFile} --startup_blob ${join(currentArchBlobOutputPath, `${SNAPSHOT_BLOB_NAME}.blob`)} ${params}`; return new Promise((resolve, reject) => { const child = child_process.exec(command, {encoding: "utf8"}, (error, stdout, stderr) => { @@ -167,7 +172,8 @@ SnapshotGenerator.prototype.generate = function(options) { preprocessedInputFile, options.v8Version, options.targetArchs, - options.useLibs + options.useLibs, + options.mksnapshotParams ).then(() => { this.buildIncludeGradle(); if (options.useLibs) {