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

Commit 88de04b

Browse files
vtrifonovsis0k0
authored andcommitted
refactor: read settings.json file in android runtime to determine V8 version (#509)
1 parent 625cbdd commit 88de04b

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

Diff for: projectHelpers.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
} = require("./nsCliHelpers");
1212

1313
const APP_DIR = "app";
14+
const ANDROID_PROJECT_PATH = "platforms/android";
1415

1516
const isTypeScript = ({ projectDir, packageJson } = {}) => {
1617
packageJson = packageJson || getPackageJson(projectDir);
@@ -54,6 +55,19 @@ const getAndroidRuntimeVersion = (projectDir) => {
5455
}
5556
}
5657

58+
const getAndroidV8Version = (projectDir) => {
59+
try {
60+
const androidSettingsJSON = getAndroidSettingsJson(projectDir);
61+
if(androidSettingsJSON != null) {
62+
return androidSettingsJSON.v8Version;
63+
} else {
64+
return null;
65+
}
66+
} catch (e) {
67+
return null;
68+
}
69+
}
70+
5771
const getWebpackConfig = (projectDir, env, configPath = "webpack.config.js") => {
5872
const configAbsolutePath = path.resolve(projectDir, configPath);
5973
let config;
@@ -82,6 +96,15 @@ const getPackageJson = projectDir => {
8296
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
8397
};
8498

99+
const getAndroidSettingsJson = projectDir => {
100+
const androidSettingsJsonPath = path.resolve(projectDir, ANDROID_PROJECT_PATH, "settings.json");
101+
if (fs.existsSync(androidSettingsJsonPath)) {
102+
return JSON.parse(fs.readFileSync(androidSettingsJsonPath, "utf8"));
103+
} else {
104+
return null;
105+
}
106+
};
107+
85108
const writePackageJson = (content, projectDir) => {
86109
const packageJsonPath = getPackageJsonPath(projectDir);
87110
fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2))
@@ -92,14 +115,13 @@ const toReleaseVersion = version =>
92115
version.replace(/-.*/, "");
93116

94117
const getAndroidProjectPath = ({androidPackageVersion, projectRoot}) => {
95-
const ANDROID_PROJECT_PATH = "platforms/android";
96118
if (projectRoot) {
97119
androidPackageVersion = getAndroidRuntimeVersion(projectRoot);
98120
}
99121

100122
return semver.lt(androidPackageVersion, "3.4.0") ?
101123
ANDROID_PROJECT_PATH :
102-
path.join(ANDROID_PROJECT_PATH, "app");
124+
path.join(ANDROID_PROJECT_PATH, APP_DIR);
103125
};
104126

105127

@@ -153,6 +175,7 @@ module.exports = {
153175
getAppResourcesPathFromProjectData,
154176
getAndroidProjectPath,
155177
getAndroidRuntimeVersion,
178+
getAndroidV8Version,
156179
getPackageJson,
157180
getProjectDir,
158181
getWebpackConfig,

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

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
getPackageJson,
1515
getAndroidRuntimeVersion,
1616
getAndroidProjectPath,
17+
getAndroidV8Version,
1718
resolveAndroidAppPath,
1819
resolveAndroidConfigurationsPath,
1920
} = require("../../projectHelpers");
@@ -160,6 +161,12 @@ ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) {
160161
return resolve(maybeV8Version);
161162
}
162163

164+
// try to get the V8 Version from the settings.json file in android runtime folder
165+
const runtimeV8Version = getAndroidV8Version(this.options.projectRoot);
166+
if(runtimeV8Version) {
167+
return resolve(runtimeV8Version);
168+
}
169+
163170
const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot);
164171
getV8VersionsMap(runtimeVersion)
165172
.then(({ versionsMap, latest }) => {

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu
9494

9595
const androidArch = this.convertToAndroidArchName(arch);
9696
console.log("***** Generating snapshot for " + androidArch + " *****");
97-
97+
9898
// Generate .blob file
9999
const currentArchBlobOutputPath = join(this.buildPath, "snapshots/blobs", androidArch);
100100
shelljs.mkdir("-p", currentArchBlobOutputPath);
@@ -157,14 +157,16 @@ SnapshotGenerator.prototype.generate = function(options) {
157157
if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); }
158158
const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed");
159159

160+
console.log("***** Starting snapshot generation using V8 version: ", options.v8Version);
161+
160162
this.preprocessInputFiles(options.inputFiles, preprocessedInputFile);
161163

162164
// generates the actual .blob and .c files
163165
return this.runMksnapshotTool(
164-
options.snapshotToolsPath,
165-
preprocessedInputFile,
166-
options.v8Version,
167-
options.targetArchs,
166+
options.snapshotToolsPath,
167+
preprocessedInputFile,
168+
options.v8Version,
169+
options.targetArchs,
168170
options.useLibs
169171
).then(() => {
170172
this.buildIncludeGradle();

0 commit comments

Comments
 (0)