Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24734](6_1_X) Add compatibility with Hyperloop AAR handling #9087

Merged
merged 5 commits into from May 26, 2017

Conversation

janvennemann
Copy link
Contributor

Hyperloop currently still has its own AAR handling which interferes with the new AAR handling in the SDK. This fix will ensure the compatibility by reverting any changes Hyperloop is trying to make to the builder.
@lokeshchdhry
Copy link
Contributor

FR Passed.

Checked it with the hyperloop examples app. No crash seen due to duplicate resources with .aar and Hyperloop.

Studio Ver: 4.9.0.201705180402
SDK Ver: 6.1.0 local build
OS Ver: 10.12.3
Xcode Ver: Xcode 8.3.2
Appc NPM: 4.2.9
Appc CLI: 6.2.2
Ti CLI Ver: 5.0.14
Alloy Ver: 1.9.11
Node Ver: 6.10.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 6 --- Android 6.0.1
Emulator: Android 4.4.2

@@ -9,6 +9,7 @@
*/

var AarTransformer = require('appc-aar-tools').AarTransformer;
var appc = require('node-appc');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this. init() is passed a 4th argument which is a node-appc instance.

exports.init = function (logger, config, cli, appc) {

You'll have to pass appc into registerHyperloopCompatibilityFixes().

@@ -45,6 +46,7 @@ exports.init = function (logger, config, cli) {
cli.on('build.pre.compile', {
post: function(builder, callback) {
scanProjectAndStartTransform(builder, logger, callback);
registerHyperloopCompatibilityFixes(cli, builder, logger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanProjectAndStartTransform() is async. The call to registerHyperloopCompatibilityFixes() must be done in scanProjectAndStartTransform()'s callback or if there's no conflict, registerHyperloopCompatibilityFixes() could simply be run before calling scanProjectAndStartTransform().

scanProjectAndStartTransform(builder, logger, function (err) {
    if (!err) {
        registerHyperloopCompatibilityFixes(cli, builder, logger);
    }
    callback(err);
});

*/
function registerHyperloopCompatibilityFixes(cli, builder, logger) {
var hyperloopModule = null;
builder.nativeLibModules.forEach(function (module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a builder.nativeLibModules.some() call and when you find the hyperloop module, return true; to break the looping.

* @param {Object} data Hook data
* @param {Function} callback Callback function
*/
pre: function(data, callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our JavaScript coding style mandates there be a space between constructs and parenthesis. This rule applies to function and while as well as if.

pre: function(data, callback) {
logger.trace('Cleaning AAPT options from changes made by Hyperloop');
var aaptOptions = data.args[1];
var extraPackagesIndex = aaptOptions.indexOf('--extra-packages') + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is insufficient. indexof() returns -1 if --extra-packages is not found. You have no error handling around this. If it is not found, then extraPackages will always be set to aaptOptions[0].

var extraPackagesIndex = aaptOptions.indexOf('--extra-packages') + 1;
var extraPackages = aaptOptions[extraPackagesIndex];
var parameterIndex = aaptOptions.indexOf('-S');
while(parameterIndex !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after while.

var resourcePath = aaptOptions[parameterIndex + 1];
if (resourcePath.indexOf(hyperloopBuildPath) !== -1) {
var manifestPathAndFilename = path.join(resourcePath, '../AndroidManifest.xml');
if (fs.existsSync(manifestPathAndFilename)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, fs.existsSync() has been deprecated. It's fine for now because it's everywhere else and we'd have to polyfill it anyways. The preferred way is calling fs.statSync() with a try/catch.

var manifestPathAndFilename = path.join(resourcePath, '../AndroidManifest.xml');
if (fs.existsSync(manifestPathAndFilename)) {
var manifestContent = fs.readFileSync(manifestPathAndFilename).toString();
var packageNameMatch = manifestContent.match(/package="(.*)"/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is in a loop, it is preferred that the regex be compiled ahead of time.

var packageNameMatch = manifestContent.match(/package="(.*)"/);
if (packageNameMatch !== null) {
var packageName = packageNameMatch[1];
extraPackages = extraPackages.replace(':' + packageName, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safer to split on the separator and re-join:

extraPackages = extraPackages.split(':').filter(n => n === packageName).join(':');

Copy link
Contributor

@cb1kenobi cb1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not have written it better myself. APPROVED!

logger.trace('Cleaning AAPT options from changes made by Hyperloop');
var aaptOptions = data.args[1];
var extraPackagesIndex = aaptOptions.indexOf('--extra-packages') + 1;
if (extraPackagesIndex === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be:

if (extraPackagesIndex === 0) {

?

@lokeshchdhry
Copy link
Contributor

FR for new changes passed.

  1. Ran the hyperloop example app with 2.1.0, 2.0.1 & 2.0.0 hyperloop & saw no crash.

Studio Ver: 4.9.0.201705180402
SDK Ver: 6.1.0 local build
OS Ver: 10.12.3
Xcode Ver: Xcode 8.3.2
Appc NPM: 4.2.9
Appc CLI: 6.2.2
Ti CLI Ver: 5.0.14
Alloy Ver: 1.9.11
Node Ver: 6.10.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 6 --- Android 6.0.1, Samsung Galaxy S4 --- Android 4.4.4
Hyperloop: 2.0.0, 2.0.1, 2.1.0

@lokeshchdhry lokeshchdhry merged commit 1de7a6a into tidev:6_1_X May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants