Skip to content

Commit

Permalink
Merge branch '9_0_X' into TIMOB-27784-9_0_X
Browse files Browse the repository at this point in the history
  • Loading branch information
ssekhri committed Mar 20, 2020
2 parents 8182707 + 6c1a206 commit 4227a3f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 49 deletions.
24 changes: 15 additions & 9 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ AndroidModuleBuilder.prototype.validate = function validate(logger, config, cli)
androidDetect(config, { packageJson: this.packageJson }, function (androidInfo) {
this.androidInfo = androidInfo;

if (!this.androidInfo.ndk) {
logger.error(__('Unable to find a suitable installed Android NDK.') + '\n');
process.exit(1);
}

const targetSDKMap = {

// placeholder for gradle to use
Expand Down Expand Up @@ -305,8 +300,8 @@ AndroidModuleBuilder.prototype.run = async function run(logger, config, cli, fin
cli.emit('build.module.pre.compile', this, resolve);
});

// If this is a "hybrid" module (has native and JS code), then make sure "manifest" is flagged as "commonjs".
await this.updateModuleManifest();
// Update module files such as "manifest" if needed.
await this.updateModuleFiles();

// Generate all gradle project files.
await this.generateRootProjectFiles();
Expand Down Expand Up @@ -459,7 +454,17 @@ AndroidModuleBuilder.prototype.cleanup = async function cleanup() {
}
};

AndroidModuleBuilder.prototype.updateModuleManifest = async function updateModuleManifest() {
AndroidModuleBuilder.prototype.updateModuleFiles = async function updateModuleFiles() {
// Add empty "build.gradle" template file to project folder if missing. Used to define library dependencies.
// Note: Appcelerator Studio looks for this file to determine if this is an Android module project.
const buildGradleFileName = 'build.gradle';
const buildGradleFilePath = path.join(this.projectDir, buildGradleFileName);
if (!await fs.exists(buildGradleFilePath)) {
await fs.copyFile(
path.join(this.platformPath, 'templates', 'module', 'default', 'template', 'android', buildGradleFileName),
buildGradleFilePath);
}

// Determine if "assets" directory contains at least 1 JavaScript file.
let hasJSFile = false;
if (await fs.exists(this.assetsDir)) {
Expand Down Expand Up @@ -504,7 +509,8 @@ AndroidModuleBuilder.prototype.generateRootProjectFiles = async function generat
await gradlew.writeGradlePropertiesFile(gradleProperties);

// Create a "local.properties" file providing a path to the Android SDK/NDK directories.
await gradlew.writeLocalPropertiesFile(this.androidInfo.sdk.path, this.androidInfo.ndk.path);
const androidNdkPath = this.androidInfo.ndk ? this.androidInfo.ndk.path : null;
await gradlew.writeLocalPropertiesFile(this.androidInfo.sdk.path, androidNdkPath);

// Copy our root "build.gradle" template script to the root build directory.
const templatesDir = path.join(this.platformPath, 'templates', 'build');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class KrollBindingGenerator
private HashMap<String, Object> tiModules = new HashMap<String, Object>();

private JSONUtils jsonUtils;
private boolean canOverwrite = true;

public KrollBindingGenerator(String outPath, String moduleId)
{
Expand Down Expand Up @@ -88,15 +89,16 @@ protected void saveTypeTemplate(Template template, String outFile, Map<Object, O
Writer writer = null;
try {
File file = new File(outPath, outFile);
System.out.println("Generating " + file.getAbsolutePath());

File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}

writer = new FileWriter(file);
template.process(root, writer);
if (this.canOverwrite || !file.exists()) {
System.out.println("Generating " + file.getAbsolutePath());
writer = new FileWriter(file);
template.process(root, writer);
}

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -229,6 +231,16 @@ public void loadBindingsFromJsonFile(String jsonPath) throws ParseException, IOE
loadBindingsFrom(properties);
}

public boolean getCanOverwrite()
{
return this.canOverwrite;
}

public void setCanOverwrite(boolean value)
{
this.canOverwrite = value;
}

public void loadBindingsFrom(Map<Object, Object> properties)
{
if (properties == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.appcelerator.kroll.annotations.generator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
Expand Down Expand Up @@ -112,6 +113,7 @@ public class KrollJSONGenerator extends AbstractProcessor
protected String jarJsonFileName;
protected String jsonFilePath;
protected boolean initialized = false;
private boolean hasPropertiesChanged = true;

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
Expand Down Expand Up @@ -756,8 +758,14 @@ protected void generateFullAPIName(Map<String, Object> proxyAttrs)

protected void generateJSON()
{
// Flag that JSON bindings/properties have changed since last write, unless the below says otherwise.
this.hasPropertiesChanged = true;

// Generate a JSON string from the "properties" dictionary.
String jsonString = JSONValue.toJSONString(this.properties);
if (jsonString == null) {
jsonString = "";
}

// Write a JSON file to the Java project we just read the annotations from.
// This will cause the JSON file to be bundled into the project's JAR file.
Expand All @@ -777,19 +785,39 @@ protected void generateJSON()

// Write a JSON file to the given file system path.
if (this.jsonFilePath != null) {
FileWriter writer = null;
try {
File filePath = new File(this.jsonFilePath);
filePath.getParentFile().mkdirs();
writer = new FileWriter(filePath);
writer.write(jsonString);
} catch (Exception e) {
debug("Exception trying to generate JSON file: %s, %s", this.jsonFilePath, e.getMessage());
} finally {
if (writer != null) {
try {
writer.close();
} catch (Exception e) {
// Determine if bindings have changed by reading last written JSON file, if it exists.
try (BufferedReader reader = new BufferedReader(new FileReader(this.jsonFilePath))) {
StringBuffer stringBuffer = new StringBuffer(Math.max(jsonString.length(), 32768));
char[] charBuffer = new char[2048];
while (true) {
int readBytes = reader.read(charBuffer, 0, charBuffer.length);
if (readBytes <= 0) {
break;
}
stringBuffer.append(charBuffer, 0, readBytes);
}
if (jsonString.contentEquals(stringBuffer)) {
this.hasPropertiesChanged = false;
}
} catch (Exception ex) {
}

// Write the JSON file if changed.
if (this.hasPropertiesChanged) {
FileWriter writer = null;
try {
File filePath = new File(this.jsonFilePath);
filePath.getParentFile().mkdirs();
writer = new FileWriter(filePath);
writer.write(jsonString);
} catch (Exception e) {
debug("Exception trying to generate JSON file: %s, %s", this.jsonFilePath, e.getMessage());
} finally {
if (writer != null) {
try {
writer.close();
} catch (Exception e) {
}
}
}
}
Expand Down Expand Up @@ -819,7 +847,12 @@ private void generateCppFiles()
KrollBindingGenerator generator = new KrollBindingGenerator(directoryPath, jsModuleName);
generator.loadBindingsFrom(this.properties);
if (tiBindingsJsonFilePath != null) {
// Load Titanium SDK library's bindings. We only do this for module builds.
generator.loadTitaniumBindingsFromJsonFile(tiBindingsJsonFilePath);
} else {
// Do incremental-like builds by only overwriting last C++ files if bindings have changed.
// Only do this for SDK builds. Can't do it for modules since we'd have to track SDK binding changes.
generator.setCanOverwrite(this.hasPropertiesChanged);
}
generator.generateBindings();
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

repositories {
google()
jcenter()
}

dependencies {
// Add the module's library dependencies here.
// See: https://developer.android.com/studio/build/dependencies
Expand Down
22 changes: 8 additions & 14 deletions build/lib/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,17 @@ async function createLocalPropertiesFile(sdkPath, ndkPath) {
}
}
}
if (!ndkPath) {
const message = 'Failed to find Android NDK directory path.';
if (await fs.exists(filePath)) {
console.warn(`Warning: ${message} Will use last generated "${fileName}" file.`);
return;
} else {
throw new Error(message);
}
}

// Create a "local.properties" file under Titanium's root "android" directory.
// This is required by the Android gradle plugin or else it will fail to build.
const fileContentString
= '# This file was generated by Titanium\'s build tools.\n'
+ 'sdk.dir=' + sdkPath.replace(/\\/g, '\\\\') + '\n'
+ 'ndk.dir=' + ndkPath.replace(/\\/g, '\\\\') + '\n';
await fs.writeFile(filePath, fileContentString);
const fileLines = [
'# This file was generated by Titanium\'s build tools.',
'sdk.dir=' + sdkPath.replace(/\\/g, '\\\\')
];
if (ndkPath) {
fileLines.push('ndk.dir=' + ndkPath.replace(/\\/g, '\\\\'));
}
await fs.writeFile(filePath, fileLines.join('\n') + '\n');
}

function versionStringSortComparer(element1, element2) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "titanium-mobile",
"description": "Appcelerator Titanium Mobile",
"version": "9.0.0",
"version": "9.0.1",
"moduleApiVersion": {
"iphone": "2",
"android": "4"
Expand Down
4 changes: 2 additions & 2 deletions support/module/packaged/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"integrity": "sha512-fVtskrodL5ot2rUoxoU9Lf8CBXhduzx7lnDwVOzla2VahgNIlXCyvUZhZP0t6kLmolUD0rVbG0ly6v1g4UzDdQ=="
},
"ti.coremotion": {
"url": "https://github.com/appcelerator-modules/ti.coremotion/releases/download/v2.0.1/ti.coremotion-iphone-2.0.1.zip",
"integrity": "sha512-h1wM7mE/cgpk2n1YOYBNMNBQq5ViLxil6+GRnVqSaFB3LY3ubGSZVkZQ5rzC74anLlNXJVpsH/bP98AQ6zzXbA=="
"url": "https://github.com/appcelerator-modules/ti.coremotion/releases/download/v2.1.0/ti.coremotion-iphone-2.1.0.zip",
"integrity": "sha512-/37884hmpvg9XoGZy9BJ3nA6luz04Eff/oYRwCE+wadYvmoMMGZmHhmWRjkBC4wIhUj6YY6MuQlHr7X7MO/Ccw=="
},
"ti.map": {
"url": "https://github.com/appcelerator-modules/ti.map/releases/download/v3.3.0-iphone/ti.map-iphone-3.3.0.zip",
Expand Down

0 comments on commit 4227a3f

Please sign in to comment.