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

Conversation

ivanbuhov
Copy link
Contributor

@ivanbuhov ivanbuhov commented Jun 19, 2017

  1. mksnapshot tools are now downloaded on demand before running them
  2. Introduce __snapshot and __snapshotEnabled global variables:
    __snapshotEnabled -> has a value of true if snapshot is loaded in the app
    __snapshot -> has a value of true when the executed code is in snapshot context and false when the code is executed on device/emulator
  3. Clean platforms/android/build folder on snapshot generation in order to trigger full rebuild of the .apk files
  4. Install include.gradle file even when blobs are used in order to exclude the snapshotted file from the apk.
  5. Respect ANDROID_NDK_HOME env variable in case androidNdkPath is not specified

@ivanbuhov ivanbuhov requested a review from sis0k0 June 19, 2017 10:56
this.generateTnsJavaClassesFile({ output: tnsJavaClassesDestination, options: generationOptions.tnsJavaClassesOptions });
}

var snapshotToolsPath = generationOptions.snapshotToolsPath ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: let's make it an arrow func instead of using ternary operator 2 times

const generator = new SnapshotGenerator({ buildPath: this.getBuildPath() });
const generatorBuildPath = generator.generate({
return generator.generate({
snapshotToolsPath: snapshotToolsPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: just snapshotToolsPath is more readable

options: options.tnsJavaClassesOptions
});

// Run the snapshot tool when the packing is done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: update the comment, too, or remove it

}
module.exports = SnapshotGenerator;

SnapshotGenerator.MKSNAPSHOT_TOOLS_PATH = path.join(__dirname, "snapshot-generator-tools/mksnapshot");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style suggestion:

const { join, dirname } = require("path");
...
const getAbsolutePath = path => join(__dirname, path);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think we need getAbsolutePath function? It is as verbose as using join(__dirname, path) but I find join(__dirname, path) to be more clear.

}

SnapshotGenerator.prototype.getMksnapshotToolsDirOrThrow = function(v8Version) {
var snapshotToolsDownloads = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

});
}

var downloadUrl = "https://raw.githubusercontent.com/NativeScript/mksnapshot-tools/production/" + mksnapshotToolRelativePath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const and maybe we should extract the url to some global var

throw new Error("Can't find mksnapshot tool for " + arch + " at path " + currentArchMksnapshotToolPath);
}

var androidArch = this.convertToAndroidArchName(arch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

var currentArchBlobOutputPath = path.join(this.buildPath, "snapshots/blobs", androidArch);
shelljs.mkdir("-p", currentArchBlobOutputPath);
var stdErrorStream = fs.openSync(mksnapshotStdErrPath, 'w');
child_process.execSync(currentArchMksnapshotToolPath + " " + inputFile + " --startup_blob " + path.join(currentArchBlobOutputPath, "TNSSnapshot.blob") + " --profile_deserialization", {encoding: "utf8", stdio: [process.stdin, process.stdout, stdErrorStream]});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract the command

var currentArchBlobOutputPath = path.join(this.buildPath, "snapshots/blobs", androidArch);
shelljs.mkdir("-p", currentArchBlobOutputPath);
var stdErrorStream = fs.openSync(mksnapshotStdErrPath, 'w');
child_process.execSync(currentArchMksnapshotToolPath + " " + inputFile + " --startup_blob " + path.join(currentArchBlobOutputPath, "TNSSnapshot.blob") + " --profile_deserialization", {encoding: "utf8", stdio: [process.stdin, process.stdout, stdErrorStream]});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erm, let's use exec and not pipe the error stream to a file

var currentArchSrcOutputPath = path.join(this.buildPath, "snapshots/src", androidArch);
shelljs.mkdir("-p", currentArchSrcOutputPath);
shellJsExecuteInDir(currentArchBlobOutputPath, function(){
shelljs.exec("xxd -i TNSSnapshot.blob > " + path.join(currentArchSrcOutputPath, "TNSSnapshot.c"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's extract TNSSnapshot (the filename) to a const somewhere

@ivanbuhov ivanbuhov force-pushed the buhov/local-snapshot-improvements branch from 24778ab to d18fd66 Compare June 20, 2017 13:08
@sis0k0
Copy link
Contributor

sis0k0 commented Jun 20, 2017

groceries

@ivanbuhov ivanbuhov merged commit dc897ea into master Jun 20, 2017
@ivanbuhov ivanbuhov deleted the buhov/local-snapshot-improvements branch June 20, 2017 16:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants