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

refactor: read settings.json file in android runtime to determine V8 version #509

Merged
merged 6 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions projectHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
} = require("./nsCliHelpers");

const APP_DIR = "app";
const ANDROID_PROJECT_PATH = "platforms/android";

const isTypeScript = ({ projectDir, packageJson } = {}) => {
packageJson = packageJson || getPackageJson(projectDir);
Expand Down Expand Up @@ -54,6 +55,19 @@ const getAndroidRuntimeVersion = (projectDir) => {
}
}

const getAndroidV8Version = (projectDir) => {
try {
const androidSettingsJSON = getAndroidSettingsJson(projectDir);
if(androidSettingsJSON != null) {
return androidSettingsJSON.v8Version;
} else {
return null;
}
} catch (e) {
return null;
}
}

const getWebpackConfig = (projectDir, env, configPath = "webpack.config.js") => {
const configAbsolutePath = path.resolve(projectDir, configPath);
let config;
Expand Down Expand Up @@ -82,6 +96,15 @@ const getPackageJson = projectDir => {
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
};

const getAndroidSettingsJson = projectDir => {
const androidSettingsJsonPath = path.resolve(projectDir, ANDROID_PROJECT_PATH, "settings.json");
if (fs.existsSync(androidSettingsJsonPath)) {
return JSON.parse(fs.readFileSync(androidSettingsJsonPath, "utf8"));
} else {
return null;
}
};

const writePackageJson = (content, projectDir) => {
const packageJsonPath = getPackageJsonPath(projectDir);
fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2))
Expand All @@ -92,14 +115,13 @@ const toReleaseVersion = version =>
version.replace(/-.*/, "");

const getAndroidProjectPath = ({androidPackageVersion, projectRoot}) => {
const ANDROID_PROJECT_PATH = "platforms/android";
if (projectRoot) {
androidPackageVersion = getAndroidRuntimeVersion(projectRoot);
}

return semver.lt(androidPackageVersion, "3.4.0") ?
ANDROID_PROJECT_PATH :
path.join(ANDROID_PROJECT_PATH, "app");
path.join(ANDROID_PROJECT_PATH, APP_DIR);
};


Expand Down Expand Up @@ -153,6 +175,7 @@ module.exports = {
getAppResourcesPathFromProjectData,
getAndroidProjectPath,
getAndroidRuntimeVersion,
getAndroidV8Version,
getPackageJson,
getProjectDir,
getWebpackConfig,
Expand Down
7 changes: 7 additions & 0 deletions snapshot/android/project-snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
getPackageJson,
getAndroidRuntimeVersion,
getAndroidProjectPath,
getAndroidV8Version,
resolveAndroidAppPath,
resolveAndroidConfigurationsPath,
} = require("../../projectHelpers");
Expand Down Expand Up @@ -160,6 +161,12 @@ ProjectSnapshotGenerator.prototype.getV8Version = function (generationOptions) {
return resolve(maybeV8Version);
}

// try to get the V8 Version from the settings.json file in android runtime folder
const runtimeV8Version = getAndroidV8Version(this.options.projectRoot);
if(runtimeV8Version) {
return resolve(runtimeV8Version);
}

const runtimeVersion = getAndroidRuntimeVersion(this.options.projectRoot);
getV8VersionsMap(runtimeVersion)
.then(({ versionsMap, latest }) => {
Expand Down
12 changes: 7 additions & 5 deletions snapshot/android/snapshot-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ SnapshotGenerator.prototype.runMksnapshotTool = function(snapshotToolsPath, inpu

const androidArch = this.convertToAndroidArchName(arch);
console.log("***** Generating snapshot for " + androidArch + " *****");

// Generate .blob file
const currentArchBlobOutputPath = join(this.buildPath, "snapshots/blobs", androidArch);
shelljs.mkdir("-p", currentArchBlobOutputPath);
Expand Down Expand Up @@ -157,14 +157,16 @@ SnapshotGenerator.prototype.generate = function(options) {
if (!options.snapshotToolsPath) { throw new Error("snapshotToolsPath option is not specified."); }
const preprocessedInputFile = options.preprocessedInputFile || join(this.buildPath, "inputFile.preprocessed");

console.log("***** Starting snapshot generation using V8 version: ", options.v8Version);

this.preprocessInputFiles(options.inputFiles, preprocessedInputFile);

// generates the actual .blob and .c files
return this.runMksnapshotTool(
options.snapshotToolsPath,
preprocessedInputFile,
options.v8Version,
options.targetArchs,
options.snapshotToolsPath,
preprocessedInputFile,
options.v8Version,
options.targetArchs,
options.useLibs
).then(() => {
this.buildIncludeGradle();
Expand Down