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

Fix dest overwrite #539

Closed
wants to merge 4 commits into from
Closed

Conversation

kkirby
Copy link
Contributor

@kkirby kkirby commented Nov 8, 2018

Platforms affected

Android

What does this PR do?

Makes sure that we don't overwrite the target-dir of a source-file if the project base is android studio and the target-dir is the proper install path and doesn't need to be re-mapped.

What testing has been done on this change?

I've added a new unit test, confirmed the problem exists, fixed the issue and re-ran the tests.

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

More details

Latest release (7.1.2) breaks our build. After investigation it appears that source-file.install handler was updated to extract the functionality of path remapping for android studio. However, if the path doesn't need to be remapped, the function returns undefined, thus updating dest to be undefined.

Related lines

7a97fd7...7.1.2#diff-4f73e5f70cec312ae82aa7d023e3c88bR320
7a97fd7...7.1.2#diff-4f73e5f70cec312ae82aa7d023e3c88bR50

Resolution

Just change line 50 to studioPathRemap(obj) || dest

@kkirby kkirby changed the title Hotfix/fix dest overwrite Fix dest overwrite Nov 8, 2018
@brodybits
Copy link
Contributor

brodybits commented Nov 9, 2018

Can you confirm the following:

  • Does the test case show the functionality working on 7.1.1 but not 7.1.2? Answer is yes.
  • Is this an issue on the master branch? Answer is yes.

I think this should solve the issue in #540.

@brodybits
Copy link
Contributor

Unfortunately this proposal does not resolve the issue reported in #540.

@dpogue
Copy link
Member

dpogue commented Nov 9, 2018

Thanks! I'd like to get this merged in.

There's one other spot in uninstall where the same pattern appears, does that also need to be updated?

@brodybits
Copy link
Contributor

There's one other spot in uninstall where the same pattern appears, does that also need to be updated?

I think so, would like to see unit test coverage to ensure it does not break again. Not sure if we need to do this in the hotfix.

This fix is definitely needed in master as well.

@jcesarmobile
Copy link
Member

jcesarmobile commented Nov 9, 2018

Supposedly, studioPathRemap should not remap if the path starts with app/src/main as that's how they should start. I think this PR breaks that remapping for old plugins that didn't update the target-dir paths yet.

EDIT: Ah, shit, just noticed studioPathRemap doesn't return the original path when it doesn't start with app/src/main

@brodybits
Copy link
Contributor

I think this PR breaks that remapping for old plugins that didn't update the target-dir paths yet

The update is only for the case when studioPathRemap returns null. Without this change there is a case, reproduced in the proposed test update, where a working "target-dir" path would be overwritten with a null value.

I think it should not break a supported case that is already working. If I am mistaken a specific example would be really helpful.

@jcesarmobile
Copy link
Member

Yeah, sorry, see my edit, the remap function should not return null, it should return the path unmodified, that’s why I thought it will break it as I only checked the changes, once I checked the code I noticed that was missing

@kkirby
Copy link
Contributor Author

kkirby commented Nov 10, 2018

@jcesarmobile I didn't want to introduce too many changes to the codebase. Passing in the existing dest and returning it doesn't make sense to me. I think if anything we should check if the path needs to be modified and then call studioPathRemap. Though, like I said, I didn't want to introduce too many changes. I just wanted to put in a quick fix.

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

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

Looks good to me, but send the PR to master and we will cherry pick

for Java source only (GH-539)

Co-Authored-By: Christopher J. Brody <chris.brody@gmail.com>
Co-Authored-By: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
@brodybits
Copy link
Contributor

I just pushed changes to add unit test and fix the issue in case of uninstall.

Unfortunately I am not able to rebase this fix onto master since the code in master seems to assume that it always has Android Studio mapping. I will investigate a possible solution.

@jcesarmobile jcesarmobile changed the base branch from 7.1.x to master November 11, 2018 19:45
@jcesarmobile jcesarmobile changed the base branch from master to 7.1.x November 11, 2018 19:46
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 11, 2018
for Java source only (apacheGH-539)

Co-Authored-By: Christopher J. Brody <chris.brody@gmail.com>
Co-Authored-By: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 11, 2018
Fallback to old path mapping if no Android Studio path mapping exists

Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
Co-authored-by: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
@@ -34,7 +34,7 @@ var handlers = {
// a later plugins release. This is for legacy plugins to work with Cordova.

if (options && options.android_studio === true) {
dest = studioPathRemap(obj);
dest = studioPathRemap(obj) || dest;
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not possible to cherry-pick or rebase this change to work on master. This change will be clobbered by another solution that works more easily on master.

Fallback to old path mapping if no Android Studio path mapping exists

(with minor change needed to work on for 7.1.x branch)

Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
Co-authored-by: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
@brodybits
Copy link
Contributor

I just pushed an update that would be much easier to cherry-pick between 7.1.x and master. Note that this update basically clobbers the change proposed by @kkirby in ed0991c.

At this point I can think of 2 ways forward:

@jcesarmobile please tell me which way you want to proceed with this.

I would like to express appreciation to @kkirby for pointing out the issue and contributing the unit test, even if we cannot use the originally proposed solution.

@jcesarmobile
Copy link
Member

I prefer the other one as it’s going to be easier to maintain in case we need more hot fixes before we have a 8.0.0 ready

@brodybits
Copy link
Contributor

What do you mean by "the other one"?

@brodybits brodybits changed the base branch from 7.1.x to master November 11, 2018 22:45
@brodybits
Copy link
Contributor

brodybits commented Nov 11, 2018

I just rebased on master (actually pushed the first 3 changes from PR #542 to resolve the original issue on master). Fix should be straightforward to cherry-pick on 7.1.x.

@jcesarmobile please give final confirmation so that I can merge this one into master.

@brodybits
Copy link
Contributor

brodybits commented Nov 11, 2018

P.S. If someone else does a squash merge, please keep the "Co-authored-by" comments from the commits to give due credit to both @kkirby and myself.

@jcesarmobile
Copy link
Member

The “other” was #542, but as you keep changing both I don’t know anymore

@brodybits
Copy link
Contributor

@jcesarmobile I was hoping to close in on an approved solution for this one and #540, sorry I did not really understand you before. I would slightly favor keeping this one separate from #540 since they are two different problems. A final review of the changes I pushed would be really helpful as well.

@brodybits brodybits changed the base branch from master to 7.1.x November 12, 2018 17:17
@brodybits
Copy link
Contributor

Closing now in favor of PR #542. I just put this change back onto the 7.1.x branch (including the original commits by @kkirby).

I am closing this because the proposed change is only a partial solution for the issues we need to fix in #542, to resolve #540 and maybe some other issues with plugins using the old project structure.

@kkirby will absolutely get co-author credit for the added test and solution for the case when studioPathRemap returns null.

@brodybits brodybits closed this Nov 12, 2018
brodybits pushed a commit that referenced this pull request Nov 12, 2018
jcesarmobile pushed a commit to jcesarmobile/cordova-android that referenced this pull request Nov 13, 2018
@jcesarmobile jcesarmobile mentioned this pull request Nov 13, 2018
3 tasks
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 14, 2018
for Java source only (apacheGH-539)

Co-Authored-By: Christopher J. Brody <chris.brody@gmail.com>
Co-Authored-By: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 14, 2018
Fallback to old path mapping if no Android Studio path mapping exists

(with slight difference on 7.1.x branch)

Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
Co-authored-by: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
@brodybits brodybits mentioned this pull request Nov 14, 2018
7 tasks
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 16, 2018
for Java source only (apacheGH-539)

Co-Authored-By: Christopher J. Brody <chris.brody@gmail.com>
Co-Authored-By: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 16, 2018
Fallback to old path mapping if no Android Studio path mapping exists

(with slight difference on 7.1.x branch)

Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
Co-authored-by: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 16, 2018
for Java source only (apacheGH-539)

Co-Authored-By: Christopher J. Brody <chris.brody@gmail.com>
Co-Authored-By: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
brodybits pushed a commit to brodybits/cordova-android that referenced this pull request Nov 16, 2018
Fallback to old path mapping if no Android Studio path mapping exists

(with slight difference on 7.1.x branch)

Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
Co-authored-by: Kyle Kirbatski <kkirbatski@gmrmarketing.com>
@brodybits
Copy link
Contributor

Now fixed in the latest patch release

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