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

Commit 2e9b753

Browse files
committed
feat: support V8 snapshots on Windows
1 parent f555118 commit 2e9b753

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

Diff for: lib/utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ const { isAndroid } = require("../projectHelpers");
33

44
function shouldSnapshot(config) {
55
const platformSupportsSnapshot = isAndroid(config.platform);
6-
const osSupportsSnapshot = os.type() !== "Windows_NT";
76

8-
return config.release && platformSupportsSnapshot && osSupportsSnapshot;
7+
return config.release && platformSupportsSnapshot;
98
}
109

1110
function convertToUnixPath(relativePath) {

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { dirname, isAbsolute, join, resolve } = require("path");
1+
const { dirname, isAbsolute, join, resolve, sep } = require("path");
22
const { existsSync, readFileSync, writeFileSync } = require("fs");
33

44
const shelljs = require("shelljs");
@@ -102,22 +102,15 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function (projectRoot) {
102102

103103
// Copy the libs to the specified destination in the platforms folder
104104
shelljs.mkdir("-p", libsDestinationPath);
105-
shelljs.cp("-R", join(buildPath, "ndk-build/libs") + "/", libsDestinationPath);
105+
shelljs.cp("-R", join(buildPath, "ndk-build/libs") + sep, libsDestinationPath);
106106
} else {
107107
// useLibs = false
108108
const blobsSrcPath = join(buildPath, "snapshots/blobs");
109109
const blobsDestinationPath = resolve(appPath, "../snapshots");
110110
const appPackageJsonPath = join(appPath, "package.json");
111111

112112
// Copy the blobs in the prepared app folder
113-
shelljs.cp("-R", blobsSrcPath + "/", resolve(appPath, "../snapshots"));
114-
115-
/*
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.
119-
*/
120-
shelljs.exec("find " + blobsDestinationPath + " -name '*.blob' -execdir mv {} snapshot.blob ';'");
113+
shelljs.cp("-R", blobsSrcPath + sep, resolve(appPath, "../snapshots"));
121114

122115
// Update the package.json file
123116
const appPackageJson = shelljs.test("-e", appPackageJsonPath) ? JSON.parse(readFileSync(appPackageJsonPath, 'utf8')) : {};

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ SnapshotGenerator.prototype.generate = function (options) {
244244
}
245245

246246
SnapshotGenerator.prototype.getSnapshotToolCommand = function (snapshotToolPath, inputFilePath, outputPath, toolParams) {
247-
return `${snapshotToolPath} ${inputFilePath} --startup_blob ${join(outputPath, `${SNAPSHOT_BLOB_NAME}.blob`)} ${toolParams}`;
247+
return `${snapshotToolPath} ${inputFilePath} --startup_blob ${outputPath} ${toolParams}`;
248248
}
249249

250250
SnapshotGenerator.prototype.getXxdCommand = function (srcOutputDir, xxdLocation) {
251251
// https://github.com/NativeScript/docker-images/tree/master/v8-snapshot/bin
252-
return `${xxdLocation || ""}xxd -i ${SNAPSHOT_BLOB_NAME}.blob > ${join(srcOutputDir, `${SNAPSHOT_BLOB_NAME}.c`)}`;
252+
return `/bin/xxd -i ${SNAPSHOT_BLOB_NAME}.blob > ${srcOutputDir}`;
253253
}
254254

255255
SnapshotGenerator.prototype.getPathInDocker = function (mappedLocalDir, mappedDockerDir, targetPath) {
@@ -309,11 +309,12 @@ SnapshotGenerator.prototype.buildCSource = function (androidArch, blobInputDir,
309309
if (snapshotInDocker) {
310310
const blobsInputInDocker = `/blobs/${androidArch}`
311311
const srcOutputDirInDocker = `/dist/src/${androidArch}`;
312-
const buildCSourceCommand = this.getXxdCommand(srcOutputDirInDocker, "/bin/");
312+
const outputPathInDocker = this.getPathInDocker(srcOutputDir, srcOutputDirInDocker, join(srcOutputDir, `${SNAPSHOT_BLOB_NAME}.c`));
313+
const buildCSourceCommand = this.getXxdCommand(outputPathInDocker);
313314
command = `docker run --rm -v "${blobInputDir}:${blobsInputInDocker}" -v "${srcOutputDir}:${srcOutputDirInDocker}" ${SNAPSHOTS_DOCKER_IMAGE} /bin/sh -c "cd ${blobsInputInDocker} && ${buildCSourceCommand}"`;
314315
}
315316
else {
316-
command = this.getXxdCommand(srcOutputDir);
317+
command = this.getXxdCommand(join(srcOutputDir, `${SNAPSHOT_BLOB_NAME}.c`));
317318
}
318319
shellJsExecuteInDir(blobInputDir, function () {
319320
shelljs.exec(command);
@@ -345,11 +346,11 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
345346
const toolPathInAppDir = this.copySnapshotTool(snapshotToolsPath, toolPath, toolsTempFolder);
346347
const toolPathInDocker = this.getPathInDocker(inputFileDir, appDirInDocker, toolPathInAppDir);
347348
const inputFilePathInDocker = this.getPathInDocker(inputFileDir, appDirInDocker, inputFile);
348-
const outputPathInDocker = this.getPathInDocker(blobOutputDir, blobOutputDirInDocker, blobOutputDir);
349+
const outputPathInDocker = this.getPathInDocker(blobOutputDir, blobOutputDirInDocker, join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`));
349350
const toolCommandInDocker = this.getSnapshotToolCommand(toolPathInDocker, inputFilePathInDocker, outputPathInDocker, toolParams);
350351
command = `docker run --rm -v "${inputFileDir}:${appDirInDocker}" -v "${blobOutputDir}:${blobOutputDirInDocker}" ${SNAPSHOTS_DOCKER_IMAGE} /bin/sh -c "${toolCommandInDocker}"`;
351352
} else {
352-
command = this.getSnapshotToolCommand(toolPath, inputFile, blobOutputDir, toolParams);
353+
command = this.getSnapshotToolCommand(toolPath, inputFile, join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`), toolParams);
353354
}
354355

355356
// Generate .blob file
@@ -370,6 +371,12 @@ SnapshotGenerator.prototype.runMksnapshotTool = function (tool, mksnapshotParams
370371
if (buildCSource) {
371372
this.buildCSource(androidArch, blobOutputDir, snapshotInDocker)
372373
}
374+
375+
/*
376+
Rename TNSSnapshot.blob files to snapshot.blob files. The xxd tool uses the file name for the name of the static array.
377+
This is why the *.blob files are initially named TNSSnapshot.blob.
378+
After the xxd step, they must be renamed to snapshot.blob, because this is the filename that the Android runtime is looking for.
379+
*/
380+
shelljs.mv(join(blobOutputDir, `${SNAPSHOT_BLOB_NAME}.blob`), join(blobOutputDir, `snapshot.blob`));
373381
});
374382
}
375-

0 commit comments

Comments
 (0)