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

Commit 1bdfbb2

Browse files
author
Dimitar Tachev
authored
Merge pull request #1048 from NativeScript/tachev/snapshot-in-docker
feat: support snapshots in Docker
2 parents b1f3996 + 11ec7f4 commit 1bdfbb2

10 files changed

+338
-83
lines changed

Diff for: plugins/NativeScriptSnapshotPlugin/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ exports.NativeScriptSnapshotPlugin = (function () {
9797

9898
NativeScriptSnapshotPlugin.prototype.generate = function (webpackChunks) {
9999
const options = this.options;
100+
if (options.skipSnapshotTools) {
101+
console.log(`Skipping snapshot tools.`);
102+
return Promise.resolve();
103+
}
104+
100105
const inputFiles = webpackChunks.map(chunk => join(options.webpackConfig.output.path, chunk.files[0]));
101106
const preprocessedInputFile = join(
102107
this.options.projectRoot,
@@ -113,6 +118,8 @@ exports.NativeScriptSnapshotPlugin = (function () {
113118
useLibs: options.useLibs,
114119
androidNdkPath: options.androidNdkPath,
115120
v8Version: options.v8Version,
121+
snapshotInDocker: options.snapshotInDocker,
122+
skipSnapshotTools: options.skipSnapshotTools
116123
}).then(() => {
117124
// Make the original files empty
118125
inputFiles.forEach(inputFile =>

Diff for: plugins/NativeScriptSnapshotPlugin/options.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"type": "string"
66
},
77
"angular": {
8-
"type": "boolean",
9-
"default": false
8+
"type": "boolean",
9+
"default": false
1010
},
1111
"chunk": {
1212
"type": "string"
@@ -39,6 +39,13 @@
3939
"type": "boolean",
4040
"default": false
4141
},
42+
"snapshotInDocker": {
43+
"type": "boolean"
44+
},
45+
"skipSnapshotTools": {
46+
"type": "boolean",
47+
"default": false
48+
},
4249
"v8Version": {
4350
"type": "string"
4451
},
@@ -56,4 +63,4 @@
5663
"webpackConfig"
5764
],
5865
"additionalProperties": false
59-
}
66+
}

Diff for: snapshot/android/project-snapshot-generator-cli-ags-parser.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ module.exports = function parseProjectSnapshotGeneratorArgs() {
99
result.useLibs = parseBool(result.useLibs);
1010
}
1111

12+
if (result.snapshotInDocker !== undefined) {
13+
result.snapshotInDocker = parseBool(result.snapshotInDocker);
14+
}
15+
16+
if (result.skipSnapshotTools !== undefined) {
17+
result.skipSnapshotTools = parseBool(result.skipSnapshotTools);
18+
}
19+
1220
if (result.install !== undefined) {
1321
result.install = parseBool(result.install);
1422
}
@@ -22,7 +30,7 @@ function parseJsonFromProcessArgs() {
2230

2331
var currentKey = "";
2432
var currentValue = "";
25-
args.forEach(function(value, index, array) {
33+
args.forEach(function (value, index, array) {
2634
if (value.startsWith("--")) { // if is key
2735
addKeyAndValueToResult(currentKey, currentValue, result);
2836
currentKey = value.slice(2);

Diff for: snapshot/android/project-snapshot-generator.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const {
1010
createDirectory,
1111
getJsonFile,
1212
} = require("./utils");
13-
const { getPackageJson } = require("../../projectHelpers");
1413
const {
1514
ANDROID_PROJECT_DIR,
1615
ANDROID_APP_PATH,
@@ -114,7 +113,9 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function (projectRoot) {
114113
shelljs.cp("-R", blobsSrcPath + "/", resolve(appPath, "../snapshots"));
115114

116115
/*
117-
Rename TNSSnapshot.blob files to snapshot.blob files. The xxd tool uses the file name for the name of the static array. This is why the *.blob files are initially named TNSSnapshot.blob. After the xxd step, they must be renamed to snapshot.blob, because this is the filename that the Android runtime is looking for.
116+
Rename TNSSnapshot.blob files to snapshot.blob files. The xxd tool uses the file name for the name of the static array.
117+
This is why the *.blob files are initially named TNSSnapshot.blob.
118+
After the xxd step, they must be renamed to snapshot.blob, because this is the filename that the Android runtime is looking for.
118119
*/
119120
shelljs.exec("find " + blobsDestinationPath + " -name '*.blob' -execdir mv {} snapshot.blob ';'");
120121

@@ -170,7 +171,7 @@ ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) {
170171

171172
// try to get the V8 Version from the settings.json file in android runtime folder
172173
const runtimeV8Version = getAndroidV8Version(this.options.projectRoot);
173-
if(runtimeV8Version) {
174+
if (runtimeV8Version) {
174175
return resolve(runtimeV8Version);
175176
}
176177

@@ -184,7 +185,7 @@ ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) {
184185
const version = findV8Version(runtimeVersion, latestVersionsMap)
185186
return resolve(version);
186187
})
187-
.catch(reject);
188+
.catch(reject);
188189
} else {
189190
return resolve(v8Version);
190191
}
@@ -209,6 +210,11 @@ ProjectSnapshotGenerator.prototype.validateAndroidRuntimeVersion = function () {
209210
}
210211

211212
ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
213+
if (generationOptions.skipSnapshotTools) {
214+
console.log("Skipping snapshot tools.");
215+
return Promise.resolve();
216+
}
217+
212218
generationOptions = generationOptions || {};
213219

214220
console.log("Running snapshot generation with the following arguments: ");
@@ -254,7 +260,8 @@ ProjectSnapshotGenerator.prototype.generate = function (generationOptions) {
254260
useLibs: generationOptions.useLibs || false,
255261
inputFiles: generationOptions.inputFiles || [join(this.options.projectRoot, "__snapshot.js")],
256262
androidNdkPath,
257-
mksnapshotParams: mksnapshotParams
263+
mksnapshotParams: mksnapshotParams,
264+
snapshotInDocker: generationOptions.snapshotInDocker
258265
};
259266

260267
return generator.generate(options).then(() => {

0 commit comments

Comments
 (0)