Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat(snapshot): The parameters passed to mksnapshot are now retrieved… #789

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions androidProjectHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -49,4 +62,5 @@ module.exports = {
ANDROID_CONFIGURATIONS_PATH,
getAndroidRuntimeVersion,
getAndroidV8Version,
getMksnapshotParams
};
5 changes: 5 additions & 0 deletions snapshot/android/project-snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
ANDROID_CONFIGURATIONS_PATH,
getAndroidRuntimeVersion,
getAndroidV8Version,
getMksnapshotParams
} = require("../../androidProjectHelpers");

const MIN_ANDROID_RUNTIME_VERSION = "3.0.0";
Expand Down Expand Up @@ -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) {
Expand All @@ -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(() => {
Expand Down
12 changes: 9 additions & 3 deletions snapshot/android/snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand All @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down