-
-
Notifications
You must be signed in to change notification settings - Fork 40
Buhov/local snapshot improvements #194
Conversation
…m on demand before snapshot generation
…ual to true only when in snapshot context
this.generateTnsJavaClassesFile({ output: tnsJavaClassesDestination, options: generationOptions.tnsJavaClassesOptions }); | ||
} | ||
|
||
var snapshotToolsPath = generationOptions.snapshotToolsPath ? |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 = {}; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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]}); |
There was a problem hiding this comment.
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]}); |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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
24778ab
to
d18fd66
Compare
groceries |
mksnapshot
tools are now downloaded on demand before running them__snapshot
and__snapshotEnabled
global variables:__snapshotEnabled
-> has a value oftrue
if snapshot is loaded in the app__snapshot
-> has a value oftrue
when the executed code is in snapshot context andfalse
when the code is executed on device/emulatorplatforms/android/build
folder on snapshot generation in order to trigger full rebuild of the.apk
filesinclude.gradle
file even when blobs are used in order to exclude the snapshotted file from the apk.ANDROID_NDK_HOME
env variable in case androidNdkPath is not specified